001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.workfloweditor.flowchart.shapes;
020:
021: import java.awt.Graphics2D;
022: import java.awt.Paint;
023: import java.awt.Stroke;
024: import java.util.ArrayList;
025: import java.util.Iterator;
026:
027: import org.openharmonise.workfloweditor.flowchart.*;
028:
029: /**
030: * Base class for all shapes in a workflow diagram.
031: *
032: * @author Matthew Large
033: * @version $Revision: 1.1 $
034: *
035: */
036: public abstract class AbstractWorkflowShape {
037:
038: /**
039: * X co-ordinate of shape.
040: */
041: private float m_x = 0;
042:
043: /**
044: * Y co-ordinate of shape.
045: */
046: private float m_y = 0;
047:
048: /**
049: * List of {@link MoveListener} objects.
050: */
051: private ArrayList m_moveListeners = new ArrayList();
052:
053: /**
054: * Constructs a new abstract workflow shape.
055: *
056: * @param x X co-ordinate of shape
057: * @param y Y co-ordinate of shape
058: */
059: public AbstractWorkflowShape(float x, float y) {
060: super ();
061: this .m_x = x;
062: this .m_y = y;
063: }
064:
065: /**
066: * Returns the X co-ordinate of this shape.
067: *
068: * @return X co-ordinate
069: */
070: public float getX() {
071: return this .m_x;
072: }
073:
074: /**
075: * Returns the Y co-ordinate of this shape.
076: *
077: * @return Y co-ordinate
078: */
079: public float getY() {
080: return this .m_y;
081: }
082:
083: /**
084: * Sets the X co-ordinate of this shape.
085: *
086: * @param x X co-ordinate
087: */
088: public void setX(float x) {
089: this .m_x = x;
090: this .fireMoveEvent();
091: }
092:
093: /**
094: * Sets the Y co-ordinate of this shape.
095: *
096: * @param y Y co-ordinate
097: */
098: public void setY(float y) {
099: this .m_y = y;
100: this .fireMoveEvent();
101: }
102:
103: /**
104: * Draws this shape in the given graphics context.
105: *
106: * @param g Graphics context
107: */
108: public void draw(Graphics2D g) {
109: Stroke oldStroke = g.getStroke();
110: Paint oldPaint = g.getPaint();
111:
112: this .drawSelf(g);
113:
114: g.setStroke(oldStroke);
115: g.setPaint(oldPaint);
116:
117: }
118:
119: /**
120: * Adds a move listener to this shape.
121: *
122: * @param listener Move listener to add
123: */
124: public void addMoveListener(MoveListener listener) {
125: this .m_moveListeners.add(listener);
126: }
127:
128: /**
129: * Removes a move listener to this shape.
130: *
131: * @param listener Move listener to remove
132: */
133: public void removeMoveListener(MoveListener listener) {
134: this .m_moveListeners.remove(listener);
135: }
136:
137: /**
138: * Fires a move event to all the move listeners for this shape.
139: *
140: */
141: private void fireMoveEvent() {
142: Iterator itor = this .m_moveListeners.iterator();
143: while (itor.hasNext()) {
144: MoveListener listener = (MoveListener) itor.next();
145: listener.moved(this );
146: }
147: }
148:
149: /**
150: * Draws this shape in the given graphics context.
151: *
152: * @param g Graphics context
153: */
154: public abstract void drawSelf(Graphics2D g);
155:
156: }
|