View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2007, Ontotext Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2007</p>
22   * <p>Company: Ontotext Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.bpmo.figures;
26  
27  import org.eclipse.draw2d.ColorConstants;
28  import org.eclipse.draw2d.Figure;
29  import org.eclipse.draw2d.Graphics;
30  import org.eclipse.draw2d.geometry.PointList;
31  import org.eclipse.draw2d.geometry.Rectangle;
32  
33  /***
34   * A figure that has a bent corner in the top right hand. Typically used for sticky notes.
35   */
36  public class BentCornerFigure
37  	extends Figure
38  {
39  
40  /***
41   * The default amount of pixels subtracted from the figure's height and width to determine
42   * the size of the corner.
43   */
44  protected static int DEFAULT_CORNER_SIZE = 10;
45  
46  private int cornerSize;
47  
48  /***
49   * Constructs an empty BentCornerFigure with default background color of 
50   * ColorConstants.tooltipBackground and default corner size.
51   */
52  public BentCornerFigure() {
53  	setBackgroundColor(ColorConstants.tooltipBackground);
54  	setForegroundColor(ColorConstants.tooltipForeground);
55  	setCornerSize(DEFAULT_CORNER_SIZE);
56  }
57  
58  /***
59   * Returns the size, in pixels, that the figure should use to draw its bent corner.
60   * 
61   * @return size of the corner
62   */
63  public int getCornerSize() {
64  	return cornerSize;
65  }
66  
67  /***
68   * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
69   */
70  protected void paintFigure(Graphics graphics) {
71  	Rectangle rect = getBounds().getCopy();
72  
73  	graphics.translate(getLocation());
74  
75  	// fill the note
76  	PointList outline = new PointList();
77  	
78  	outline.addPoint(0, 0);
79  	outline.addPoint(rect.width - cornerSize, 0);
80  	outline.addPoint(rect.width - 1, cornerSize);
81  	outline.addPoint(rect.width - 1, rect.height - 1);
82  	outline.addPoint(0, rect.height - 1);
83  	
84  	graphics.fillPolygon(outline); 
85  	
86  	// draw the inner outline
87  	PointList innerLine = new PointList();
88  	
89  	innerLine.addPoint(rect.width - cornerSize - 1, 0);
90  	innerLine.addPoint(rect.width - cornerSize - 1, cornerSize);
91  	innerLine.addPoint(rect.width - 1, cornerSize);
92  	innerLine.addPoint(rect.width - cornerSize - 1, 0);
93  	innerLine.addPoint(0, 0);
94  	innerLine.addPoint(0, rect.height - 1);
95  	innerLine.addPoint(rect.width - 1, rect.height - 1);
96  	innerLine.addPoint(rect.width - 1, cornerSize);
97  	
98  	graphics.drawPolygon(innerLine);
99  	
100 	graphics.translate(getLocation().getNegated());
101 }
102 
103 /***
104  * Sets the size of the figure's corner to the given offset.
105  * 
106  * @param newSize the new size to use.
107  */
108 public void setCornerSize(int newSize) {
109 	cornerSize = newSize;
110 }
111 
112 }
113 
114 /*
115  * $Log$
116  * Revision 1.1  2007/03/20 10:05:46  alex_simov
117  * SBP modeller initial version
118  *
119  */