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.geom.*;
022:
023: import javax.swing.*;
024:
025: import org.openharmonise.workfloweditor.model.*;
026:
027: /**
028: * Shape representing a role selection box.
029: *
030: * @author Matthew Large
031: * @version $Revision: 1.1 $
032: *
033: */
034: public class RoleShape extends JCheckBox {
035:
036: /**
037: * Role
038: */
039: private Role m_role = null;
040:
041: /**
042: * Workflow stage
043: */
044: private WorkflowStage m_stage = null;
045:
046: /**
047: * Rectangle of shape
048: */
049: private Rectangle2D.Float m_rect = null;
050:
051: /**
052: * Constructs a new role shape.
053: *
054: * @param role Role
055: * @param stage Workflow stage
056: */
057: public RoleShape(Role role, WorkflowStage stage) {
058: super (role.getTitle());
059: this .m_role = role;
060: this .m_stage = stage;
061: if (this .m_stage.getRoles().contains(role)) {
062: this .setSelected(true, true);
063: }
064: }
065:
066: /**
067: * Checks if this shape contains a given co-ordinate.
068: *
069: * @param x X co-ordinate to check
070: * @param y Y co-ordinate to check
071: * @return true if the shape contains the co-ordinate
072: */
073: public boolean contains(double x, double y) {
074: if (this .m_rect != null) {
075: return this .m_rect.contains(x, y);
076: } else {
077: return false;
078: }
079: }
080:
081: /**
082: * Sets the rectangle for the shape.
083: *
084: * @param rect rectangle
085: */
086: public void setRect(Rectangle2D.Float rect) {
087: this .m_rect = rect;
088: }
089:
090: /* (non-Javadoc)
091: * @see javax.swing.AbstractButton#setSelected(boolean)
092: */
093: public void setSelected(boolean bSelected, boolean bApplyToStage) {
094: super .setSelected(bSelected);
095: if (bApplyToStage) {
096: if (bSelected) {
097: if (!this .m_stage.getRoles().contains(m_role)) {
098: this .m_stage.addRole(m_role);
099: }
100: } else {
101: if (this .m_stage.getRoles().contains(m_role)) {
102: this .m_stage.removeRole(m_role);
103: }
104: }
105: }
106: }
107:
108: /**
109: * Returns the role that this shape represents.
110: *
111: * @return Role
112: */
113: public Role getRole() {
114: return this .m_role;
115: }
116:
117: /**
118: * @param arg0
119: */
120: private RoleShape(String arg0) {
121: super (arg0);
122: }
123:
124: /**
125: * @param arg0
126: * @param arg1
127: */
128: private RoleShape(String arg0, boolean arg1) {
129: super (arg0, arg1);
130: }
131:
132: /**
133: * @param arg0
134: */
135: private RoleShape(Action arg0) {
136: super (arg0);
137: }
138:
139: /**
140: * @param arg0
141: */
142: private RoleShape(Icon arg0) {
143: super (arg0);
144: }
145:
146: /**
147: * @param arg0
148: * @param arg1
149: */
150: private RoleShape(Icon arg0, boolean arg1) {
151: super (arg0, arg1);
152: }
153:
154: /**
155: * @param arg0
156: * @param arg1
157: */
158: private RoleShape(String arg0, Icon arg1) {
159: super (arg0, arg1);
160: }
161:
162: /**
163: * @param arg0
164: * @param arg1
165: * @param arg2
166: */
167: private RoleShape(String arg0, Icon arg1, boolean arg2) {
168: super(arg0, arg1, arg2);
169: }
170:
171: }
|