KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > workfloweditor > flowchart > shapes > AbstractWorkflowShape


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.workfloweditor.flowchart.shapes;
20
21 import java.awt.Graphics2D JavaDoc;
22 import java.awt.Paint JavaDoc;
23 import java.awt.Stroke JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.openharmonise.workfloweditor.flowchart.*;
28
29
30 /**
31  * Base class for all shapes in a workflow diagram.
32  *
33  * @author Matthew Large
34  * @version $Revision: 1.1 $
35  *
36  */

37 public abstract class AbstractWorkflowShape {
38
39     /**
40      * X co-ordinate of shape.
41      */

42     private float m_x = 0;
43     
44     /**
45      * Y co-ordinate of shape.
46      */

47     private float m_y = 0;
48
49     /**
50      * List of {@link MoveListener} objects.
51      */

52     private ArrayList JavaDoc m_moveListeners = new ArrayList JavaDoc();
53
54     /**
55      * Constructs a new abstract workflow shape.
56      *
57      * @param x X co-ordinate of shape
58      * @param y Y co-ordinate of shape
59      */

60     public AbstractWorkflowShape(float x, float y) {
61         super();
62         this.m_x = x;
63         this.m_y = y;
64     }
65     
66     /**
67      * Returns the X co-ordinate of this shape.
68      *
69      * @return X co-ordinate
70      */

71     public float getX() {
72         return this.m_x;
73     }
74     
75     /**
76      * Returns the Y co-ordinate of this shape.
77      *
78      * @return Y co-ordinate
79      */

80     public float getY() {
81         return this.m_y;
82     }
83     
84     /**
85      * Sets the X co-ordinate of this shape.
86      *
87      * @param x X co-ordinate
88      */

89     public void setX(float x) {
90         this.m_x = x;
91         this.fireMoveEvent();
92     }
93     
94     /**
95      * Sets the Y co-ordinate of this shape.
96      *
97      * @param y Y co-ordinate
98      */

99     public void setY(float y) {
100         this.m_y = y;
101         this.fireMoveEvent();
102     }
103     
104     /**
105      * Draws this shape in the given graphics context.
106      *
107      * @param g Graphics context
108      */

109     public void draw(Graphics2D JavaDoc g) {
110         Stroke JavaDoc oldStroke = g.getStroke();
111         Paint JavaDoc oldPaint = g.getPaint();
112         
113         this.drawSelf(g);
114         
115         g.setStroke(oldStroke);
116         g.setPaint(oldPaint);
117         
118     }
119
120     /**
121      * Adds a move listener to this shape.
122      *
123      * @param listener Move listener to add
124      */

125     public void addMoveListener(MoveListener listener) {
126         this.m_moveListeners.add(listener);
127     }
128     
129     /**
130      * Removes a move listener to this shape.
131      *
132      * @param listener Move listener to remove
133      */

134     public void removeMoveListener(MoveListener listener) {
135         this.m_moveListeners.remove(listener);
136     }
137     
138     /**
139      * Fires a move event to all the move listeners for this shape.
140      *
141      */

142     private void fireMoveEvent() {
143         Iterator JavaDoc itor = this.m_moveListeners.iterator();
144         while (itor.hasNext()) {
145             MoveListener listener = (MoveListener) itor.next();
146             listener.moved(this);
147         }
148     }
149     
150     /**
151      * Draws this shape in the given graphics context.
152      *
153      * @param g Graphics context
154      */

155     public abstract void drawSelf(Graphics2D JavaDoc g);
156
157 }
158
Popular Tags