KickJava   Java API By Example, From Geeks To Geeks.

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


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.geom.*;
22
23 import javax.swing.*;
24
25 import org.openharmonise.workfloweditor.model.*;
26
27
28 /**
29  * Shape representing a role selection box.
30  *
31  * @author Matthew Large
32  * @version $Revision: 1.1 $
33  *
34  */

35 public class RoleShape extends JCheckBox {
36
37     /**
38      * Role
39      */

40     private Role m_role = null;
41     
42     /**
43      * Workflow stage
44      */

45     private WorkflowStage m_stage = null;
46     
47     /**
48      * Rectangle of shape
49      */

50     private Rectangle2D.Float m_rect = null;
51
52     /**
53      * Constructs a new role shape.
54      *
55      * @param role Role
56      * @param stage Workflow stage
57      */

58     public RoleShape(Role role, WorkflowStage stage) {
59         super(role.getTitle());
60         this.m_role = role;
61         this.m_stage = stage;
62         if(this.m_stage.getRoles().contains(role)) {
63             this.setSelected(true, true);
64         }
65     }
66     
67     /**
68      * Checks if this shape contains a given co-ordinate.
69      *
70      * @param x X co-ordinate to check
71      * @param y Y co-ordinate to check
72      * @return true if the shape contains the co-ordinate
73      */

74     public boolean contains(double x, double y) {
75         if(this.m_rect!=null) {
76             return this.m_rect.contains(x, y);
77         } else {
78             return false;
79         }
80     }
81     
82     /**
83      * Sets the rectangle for the shape.
84      *
85      * @param rect rectangle
86      */

87     public void setRect(Rectangle2D.Float rect) {
88         this.m_rect = rect;
89     }
90
91     /* (non-Javadoc)
92      * @see javax.swing.AbstractButton#setSelected(boolean)
93      */

94     public void setSelected(boolean bSelected, boolean bApplyToStage) {
95         super.setSelected(bSelected);
96         if(bApplyToStage) {
97             if(bSelected) {
98                 if(!this.m_stage.getRoles().contains(m_role)) {
99                     this.m_stage.addRole(m_role);
100                 }
101             } else {
102                 if(this.m_stage.getRoles().contains(m_role)) {
103                     this.m_stage.removeRole(m_role);
104                 }
105             }
106         }
107     }
108     
109     /**
110      * Returns the role that this shape represents.
111      *
112      * @return Role
113      */

114     public Role getRole() {
115         return this.m_role;
116     }
117
118     /**
119      * @param arg0
120      */

121     private RoleShape(String JavaDoc arg0) {
122         super(arg0);
123     }
124
125     /**
126      * @param arg0
127      * @param arg1
128      */

129     private RoleShape(String JavaDoc arg0, boolean arg1) {
130         super(arg0, arg1);
131     }
132
133     /**
134      * @param arg0
135      */

136     private RoleShape(Action arg0) {
137         super(arg0);
138     }
139
140     /**
141      * @param arg0
142      */

143     private RoleShape(Icon arg0) {
144         super(arg0);
145     }
146
147     /**
148      * @param arg0
149      * @param arg1
150      */

151     private RoleShape(Icon arg0, boolean arg1) {
152         super(arg0, arg1);
153     }
154
155     /**
156      * @param arg0
157      * @param arg1
158      */

159     private RoleShape(String JavaDoc arg0, Icon arg1) {
160         super(arg0, arg1);
161     }
162
163     /**
164      * @param arg0
165      * @param arg1
166      * @param arg2
167      */

168     private RoleShape(String JavaDoc arg0, Icon arg1, boolean arg2) {
169         super(arg0, arg1, arg2);
170     }
171
172 }
173
Popular Tags