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.*;
28  import org.eclipse.draw2d.geometry.Rectangle;
29  import org.eclipse.swt.SWT;
30  
31  public class ErrorFigure extends Shape {
32  
33      boolean selected;
34  
35      public ErrorFigure() {
36          super();
37          setBorder(new MarginBorder(3,3,3,3));
38          setOpaque(false);
39      }
40  
41      protected void outlineShape(Graphics graphics) {
42  
43          Rectangle r = getBounds();
44          int centerX = r.x + r.width / 2;
45          int centerY = r.y + r.height / 2;
46          
47          double rad = Math.min(r.width / 2, r.height / 2) - 2 - getLineWidth();
48          
49          double sqrthalf = 0.705;
50          double sqrt = 1.41;
51          
52          int pt1x = centerX - (int)Math.round(rad * sqrthalf); 
53          int pt1y = centerY + (int)Math.round(rad * sqrthalf);
54          
55          int pt2x = centerX - (int)Math.round(rad * sqrt / 4); 
56          int pt2y = centerY - (int)Math.round(rad * sqrt / 4);
57          
58          int pt3x = centerX - (int)Math.round(rad * sqrthalf / 4); 
59          int pt3y = centerY - (int)Math.round(rad * sqrthalf / 4);
60  
61          int pt4x = centerX + (int)Math.round(rad * sqrthalf / 4); 
62          int pt4y = centerY + (int)Math.round(rad * sqrthalf / 4);
63          
64          int pt5x = centerX + (int)Math.round(rad * sqrt / 4); 
65          int pt5y = centerY + (int)Math.round(rad * sqrt / 4);
66          
67          int pt6x = centerX + (int)Math.round(rad * sqrthalf); 
68          int pt6y = centerY - (int)Math.round(rad * sqrthalf);
69          
70          graphics.setLineWidth(1);
71          graphics.setBackgroundColor(getForegroundColor());
72          graphics.fillPolygon(new int[] {pt1x, pt1y, pt2x, pt2y, pt3x, pt3y});
73          graphics.fillPolygon(new int[] {pt4x, pt4y, pt5x, pt5y, pt6x, pt6y});
74  
75          graphics.drawOval(centerX - r.width / 2 + getLineWidth(), centerY - r.height / 2 + getLineWidth(),
76                  (r.width / 2) * 2 - 2 * getLineWidth(), (r.height / 2) * 2 - 2 * getLineWidth());
77          graphics.drawOval(centerX - r.width / 2 + getLineWidth() + 2, centerY - r.height / 2 + getLineWidth() + 2,
78                  (r.width / 2) * 2 - 2 * getLineWidth() - 4, (r.height / 2) * 2 - 2 * getLineWidth() - 4);
79  
80          graphics.setLineCap(SWT.CAP_FLAT);
81          graphics.setLineWidth(1 + ((int)rad / 10));
82          graphics.drawLine(pt2x, pt2y, pt5x, pt5y);
83  
84      }
85  
86      protected void fillShape(Graphics g) {
87          Rectangle r = getBounds();
88          int centerX = r.x + r.width / 2;
89          int centerY = r.y + r.height / 2;
90          g.fillOval(centerX - r.width / 2 + getLineWidth(), centerY - r.height / 2 + getLineWidth(),
91                  (r.width / 2) * 2 - 2 * getLineWidth(), (r.height / 2) * 2 - 2 * getLineWidth());
92      }
93  
94      public void setSelected(boolean selected) {
95          if (this.selected == selected)
96              return;
97          this.selected = selected;
98          repaint();
99      }
100 
101     
102 }
103