001: package org.enhydra.jawe.components.graph;
002:
003: import java.awt.Color;
004: import java.awt.Font;
005: import java.awt.Point;
006: import java.awt.Rectangle;
007: import java.util.List;
008: import java.util.Map;
009: import java.util.Properties;
010:
011: import org.enhydra.jawe.JaWEManager;
012: import org.enhydra.shark.xpdl.elements.Activity;
013: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
014: import org.enhydra.shark.xpdl.elements.Participant;
015: import org.enhydra.shark.xpdl.elements.Transition;
016: import org.jgraph.graph.AttributeMap;
017: import org.jgraph.graph.GraphConstants;
018:
019: /**
020: * Factory for generating graph objects.
021: * @author Sasa Bojanic
022: */
023: public class GraphObjectFactory {
024:
025: protected Properties properties;
026:
027: public void configure(Properties props) throws Exception {
028: this .properties = props;
029: }
030:
031: public GraphActivityInterface createActivity(Map viewMap,
032: Activity act, Point partPoint) {
033: String type = JaWEManager.getInstance().getJaWEController()
034: .getTypeResolver().getJaWEType(act).getTypeId();
035: Point offset = GraphUtilities.getOffsetPoint(act);
036: GraphActivityInterface gact = createActivityCell(act, type);
037:
038: Map m = initActivityProperties(partPoint, offset, act, type);
039:
040: viewMap.put(gact, m);
041: return gact;
042: }
043:
044: protected GraphActivityInterface createActivityCell(Activity act,
045: String type) {
046: return new DefaultGraphActivity(act);
047: }
048:
049: protected Map initActivityProperties(Point partPoint, Point offset,
050: Activity act, String type) {
051: AttributeMap map = new AttributeMap();
052: Rectangle bounds = new Rectangle(partPoint.x + offset.x,
053: partPoint.y + offset.y, GraphUtilities
054: .getGraphController().getGraphSettings()
055: .getActivityWidth(), GraphUtilities
056: .getGraphController().getGraphSettings()
057: .getActivityHeight());
058: GraphConstants.setBounds(map, bounds);
059: GraphConstants.setOpaque(map, true);
060: GraphConstants.setBorderColor(map, Color.darkGray);
061: String fntn = JaWEManager.getFontName();
062: int fntsize = GraphUtilities.getGraphController()
063: .getGraphSettings().getGraphFontSize();
064: javax.swing.plaf.FontUIResource f;
065: try {
066: try {
067: f = new javax.swing.plaf.FontUIResource(fntn,
068: Font.PLAIN, fntsize);
069: } catch (Exception ex) {
070: f = new javax.swing.plaf.FontUIResource("Label.font",
071: Font.PLAIN, fntsize);
072: }
073: GraphConstants.setFont(map, f);
074: } catch (Exception ex) {
075: }
076: return map;
077: }
078:
079: public GraphBubbleActivityInterface createStart(Map viewMap,
080: ExtendedAttribute sea, Point partPoint) {
081: GraphBubbleActivityInterface gact = createStartCell(sea);
082:
083: Map m = initStartProperties(partPoint, sea);
084:
085: viewMap.put(gact, m);
086: return gact;
087: }
088:
089: protected GraphBubbleActivityInterface createStartCell(
090: ExtendedAttribute sea) {
091: return new DefaultGraphBubbleActivity(sea);
092: }
093:
094: protected Map initStartProperties(Point partPoint,
095: ExtendedAttribute sea) {
096: AttributeMap map = new AttributeMap();
097: StartEndDescription sed = new StartEndDescription(sea);
098: Rectangle bounds = new Rectangle(partPoint.x
099: + sed.getOffset().x, partPoint.y + sed.getOffset().y,
100: GraphUtilities.getGraphController().getGraphSettings()
101: .getActivityHeight() / 5 * 3, GraphUtilities
102: .getGraphController().getGraphSettings()
103: .getActivityHeight() / 5 * 3);
104: GraphConstants.setBounds(map, bounds);
105: GraphConstants.setOpaque(map, true);
106: GraphConstants.setBorderColor(map, Color.darkGray);
107: String fntn = JaWEManager.getFontName();
108: int fntsize = GraphUtilities.getGraphController()
109: .getGraphSettings().getGraphFontSize();
110: javax.swing.plaf.FontUIResource f;
111: try {
112: try {
113: f = new javax.swing.plaf.FontUIResource(fntn,
114: Font.PLAIN, fntsize);
115: } catch (Exception ex) {
116: f = new javax.swing.plaf.FontUIResource("Label.font",
117: Font.PLAIN, fntsize);
118: }
119: GraphConstants.setFont(map, f);
120: } catch (Exception ex) {
121: }
122: return map;
123: }
124:
125: public GraphBubbleActivityInterface createEnd(Map viewMap,
126: ExtendedAttribute eea, Point partPoint) {
127: GraphBubbleActivityInterface gact = createEndCell(eea);
128:
129: Map m = initEndProperties(partPoint, eea);
130:
131: viewMap.put(gact, m);
132: return gact;
133: }
134:
135: protected GraphBubbleActivityInterface createEndCell(
136: ExtendedAttribute eea) {
137: return new DefaultGraphBubbleActivity(eea);
138: }
139:
140: protected Map initEndProperties(Point partPoint,
141: ExtendedAttribute eea) {
142: AttributeMap map = new AttributeMap();
143: StartEndDescription sed = new StartEndDescription(eea);
144: Rectangle bounds = new Rectangle(partPoint.x
145: + sed.getOffset().x, partPoint.y + sed.getOffset().y,
146: GraphUtilities.getGraphController().getGraphSettings()
147: .getActivityHeight() / 5 * 3, GraphUtilities
148: .getGraphController().getGraphSettings()
149: .getActivityHeight() / 5 * 3);
150: GraphConstants.setBounds(map, bounds);
151: GraphConstants.setOpaque(map, true);
152: GraphConstants.setBorderColor(map, Color.darkGray);
153: String fntn = JaWEManager.getFontName();
154: int fntsize = GraphUtilities.getGraphController()
155: .getGraphSettings().getGraphFontSize();
156: javax.swing.plaf.FontUIResource f;
157: try {
158: try {
159: f = new javax.swing.plaf.FontUIResource(fntn,
160: Font.PLAIN, fntsize);
161: } catch (Exception ex) {
162: f = new javax.swing.plaf.FontUIResource("Label.font",
163: Font.PLAIN, fntsize);
164: }
165: GraphConstants.setFont(map, f);
166: } catch (Exception ex) {
167: }
168: return map;
169: }
170:
171: public GraphParticipantInterface createParticipant(
172: Rectangle bounds, Map viewMap, Participant par) {
173: GraphParticipantInterface gpar = createParticipantCell(par);
174:
175: Map m = initParticipantProperties(bounds, par);
176:
177: viewMap.put(gpar, m);
178: return gpar;
179: }
180:
181: protected GraphParticipantInterface createParticipantCell(
182: Participant par) {
183: return new DefaultGraphParticipant(par);
184: }
185:
186: protected Map initParticipantProperties(Rectangle bounds,
187: Participant par) {
188: AttributeMap map = new AttributeMap();
189: GraphConstants.setBounds(map, bounds);
190: GraphConstants.setOpaque(map, false);
191: GraphConstants.setBorderColor(map, Color.black);
192: GraphConstants.setMoveable(map, false);
193: String fntn = JaWEManager.getFontName();
194: int fntsize = GraphUtilities.getGraphController()
195: .getGraphSettings().getGraphFontSize();
196: javax.swing.plaf.FontUIResource f;
197: try {
198: try {
199: f = new javax.swing.plaf.FontUIResource(fntn,
200: Font.PLAIN, fntsize);
201: } catch (Exception ex) {
202: f = new javax.swing.plaf.FontUIResource("Label.font",
203: Font.PLAIN, fntsize);
204: }
205: GraphConstants.setFont(map, f);
206: } catch (Exception ex) {
207: }
208: return map;
209: }
210:
211: public GraphTransitionInterface createTransition(List points,
212: Map viewMap, Transition tra) {
213: GraphTransitionInterface gtra = createTransitionCell(tra);
214:
215: Map m = initTransitionProperties(points, tra);
216:
217: viewMap.put(gtra, m);
218:
219: return gtra;
220: }
221:
222: public GraphTransitionInterface createBubbleTransition(List points,
223: Map viewMap, String style) {
224: GraphTransitionInterface gtra = createTransitionCell(null);
225:
226: Map m = initBubbleTransitionProperties(points, style);
227:
228: viewMap.put(gtra, m);
229:
230: return gtra;
231: }
232:
233: protected GraphTransitionInterface createTransitionCell(
234: Transition tra) {
235: return new DefaultGraphTransition(tra);
236: }
237:
238: protected Map initTransitionProperties(List points, Transition tra) {
239: AttributeMap map = new AttributeMap();
240: //if (points!=null && points.size()>0) System.out.println("Setting points "+points);
241: GraphConstants.setPoints(map, points);
242: setTransitionStyle(GraphUtilities.getStyle(tra), map);
243:
244: //GraphConstants.setLineColor(map,Utils.getColor(JaWEConfig.getInstance().getTransitionColor()));
245: GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
246: GraphConstants.setEndFill(map, true);
247: GraphConstants.setEndSize(map, 10);
248: String fntn = JaWEManager.getFontName();
249: int fntsize = GraphUtilities.getGraphController()
250: .getGraphSettings().getGraphFontSize();
251: javax.swing.plaf.FontUIResource f;
252: try {
253: try {
254: f = new javax.swing.plaf.FontUIResource(fntn,
255: Font.PLAIN, fntsize);
256: } catch (Exception ex) {
257: f = new javax.swing.plaf.FontUIResource("Label.font",
258: Font.PLAIN, fntsize);
259: }
260: GraphConstants.setFont(map, f);
261: } catch (Exception ex) {
262: }
263:
264: return map;
265: }
266:
267: protected Map initBubbleTransitionProperties(List points,
268: String style) {
269: AttributeMap map = new AttributeMap();
270: //if (points!=null && points.size()>0) System.out.println("Setting points "+points);
271: GraphConstants.setPoints(map, points);
272: setTransitionStyle(style, map);
273: //GraphConstants.setLineColor(map,Utils.getColor(JaWEConfig.getInstance().getTransitionColor()));
274: GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
275: GraphConstants.setEndFill(map, true);
276: GraphConstants.setEndSize(map, 10);
277: String fntn = JaWEManager.getFontName();
278: int fntsize = GraphUtilities.getGraphController()
279: .getGraphSettings().getGraphFontSize();
280: javax.swing.plaf.FontUIResource f;
281: try {
282: try {
283: f = new javax.swing.plaf.FontUIResource(fntn,
284: Font.PLAIN, fntsize);
285: } catch (Exception ex) {
286: f = new javax.swing.plaf.FontUIResource("Label.font",
287: Font.PLAIN, fntsize);
288: }
289: GraphConstants.setFont(map, f);
290: } catch (Exception ex) {
291: }
292:
293: return map;
294: }
295:
296: protected void setTransitionStyle(String style, AttributeMap map) {
297: if (style
298: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_BEZIER)) {
299: GraphConstants.setLineStyle(map,
300: GraphConstants.STYLE_BEZIER);
301: } else if (style
302: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_SPLINE)) {
303: GraphConstants.setLineStyle(map,
304: GraphConstants.STYLE_SPLINE);
305: } else if (style
306: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_SIMPLE_ROUTING_BEZIER)) {
307: GraphConstants.setRouting(map,
308: GraphConstants.ROUTING_SIMPLE);
309: GraphConstants.setLineStyle(map,
310: GraphConstants.STYLE_BEZIER);
311: } else if (style
312: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_SIMPLE_ROUTING_ORTHOGONAL)) {
313: GraphConstants.setRouting(map,
314: GraphConstants.ROUTING_SIMPLE);
315: GraphConstants.setLineStyle(map,
316: GraphConstants.STYLE_ORTHOGONAL);
317: } else if (style
318: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_SIMPLE_ROUTING_SPLINE)) {
319: GraphConstants.setRouting(map,
320: GraphConstants.ROUTING_SIMPLE);
321: GraphConstants.setLineStyle(map,
322: GraphConstants.STYLE_SPLINE);
323: } else {
324: GraphConstants.setLineStyle(map,
325: GraphConstants.STYLE_ORTHOGONAL);
326: }
327: }
328:
329: public GraphPortInterface createPort(String name, String type) {
330: GraphPortInterface gpor = createPortCell(name, type);
331: return gpor;
332: }
333:
334: protected GraphPortInterface createPortCell(String name, String type) {
335: return new DefaultGraphPort(name, type);
336: }
337:
338: protected Map initPortProperties(String type) {
339: AttributeMap map = new AttributeMap();
340: return map;
341: }
342: }
|