1
28 package demo.view.flowchart.painters;
29
30 import y.view.EdgeLabel;
31 import y.view.GenericNodeRealizer;
32 import y.view.LineType;
33 import y.view.NodeRealizer;
34 import y.view.EdgeRealizer;
35 import y.view.PolyLineEdgeRealizer;
36 import y.view.Arrow;
37 import y.view.ShadowNodePainter;
38
39
40 import java.awt.Color;
41 import java.util.Map;
42
43
48 public class FlowchartRealizerFactory implements FlowchartRealizerConstants{
49
50 static {
51
52 register(FLOWCHART_PROCESS_CONFIG_NAME, new FlowchartProcessPainter());
54
55 register(FLOWCHART_DIRECT_DATA_CONFIG_NAME, new FlowchartDirectDataPainter());
57
58 register(FLOWCHART_DATABASE_CONFIG_NAME, new FlowchartDataBasePainter());
60
61 register(FLOWCHART_DECISION_CONFIG_NAME, new FlowchartDecisionPainter());
63
64 register(FLOWCHART_DOCUMENT_CONFIG_NAME, new FlowchartDocumentPainter());
66
67 register(FLOWCHART_DATA_CONFIG_NAME, new FlowchartDataPainter());
69
70 register(FLOWCHART_START1_CONFIG_NAME, new FlowchartStart1Painter());
72
73 register(FLOWCHART_START2_CONFIG_NAME, new FlowchartStart2Painter());
75
76 register(FLOWCHART_PREDEFINED_PROCESS_CONFIG_NAME, new FlowchartPredefinedProcessPainter());
78
79 register(FLOWCHART_STORED_DATA_CONFIG_NAME, new FlowchartStoredDataPainter());
81
82 register(FLOWCHART_INTERNAL_STORAGE_CONFIG_NAME, new FlowchartInternalStoragePainter());
84
85 register(FLOWCHART_SEQUENTIAL_DATA_CONFIG_NAME, new FlowchartSequentialDataPainter());
87
88 register(FLOWCHART_MANUAL_INPUT_CONFIG_NAME, new FlowchartManualInputPainter());
90
91 register(FLOWCHART_CARD_CONFIG_NAME, new FlowchartCardPainter());
93
94 register(FLOWCHART_PAPER_TYPE_CONFIG_NAME, new FlowchartPaperTapePainter());
96
97 register(FLOWCHART_CLOUD_TYPE_CONFIG_NAME, new FlowchartCloudPainter());
99
100 register(FLOWCHART_DELAY_CONFIG_NAME, new FlowchartDelayPainter());
102
103 register(FLOWCHART_DISPLAY_CONFIG_NAME, new FlowchartDisplayPainter());
105
106 register(FLOWCHART_MANUAL_OPERATION_CONFIG_NAME, new FlowchartManualOperationPainter());
108
109 register(FLOWCHART_PREPARATION_CONFIG_NAME, new FlowchartPreparationPainter());
111
112 register(FLOWCHART_LOOP_LIMIT_CONFIG_NAME, new FlowchartLoopLimitPainter());
114
115 register(FLOWCHART_LOOP_LIMIT_END_CONFIG_NAME, new FlowchartLoopLimitPainter(false));
117
118 register(FLOWCHART_TERMINATOR_CONFIG_NAME, new FlowchartTerminatorPainter());
120
121 register(FLOWCHART_ON_PAGE_REFERENCE_CONFIG_NAME, new FlowchartOnPageReferencePainter());
123
124 register(FLOWCHART_OFF_PAGE_REFERENCE_CONFIG_NAME, new FlowchartOffPageReferencePainter());
126
127 final GenericNodeRealizer.Painter painterImpl = new FlowchartAnnotationPainter();
129 GenericNodeRealizer.Factory factory = GenericNodeRealizer.getFactory();
130 Map implementationsMap = factory.createDefaultConfigurationMap();
131 implementationsMap.put(GenericNodeRealizer.Painter.class, new ShadowNodePainter(painterImpl));
132 implementationsMap.put(GenericNodeRealizer.ContainsTest.class, painterImpl);
133 implementationsMap.put(GenericNodeRealizer.LayerHandler.class, new FlowchartAnnotationLayerHandler());
134 factory.addConfiguration(FLOWCHART_ANNOTATION_CONFIG_NAME, implementationsMap);
135
136 register(FLOWCHART_USER_MESSAGE_CONFIG_NAME, new FlowchartMessagePainter(true));
138
139 register(FLOWCHART_NETWORK_MESSAGE_CONFIG_NAME, new FlowchartMessagePainter(false));
141 }
142
143 private FlowchartRealizerFactory() {
144 }
145
146
147
151 public static NodeRealizer createDirectData() {
152 return createConfigured(FLOWCHART_DIRECT_DATA_CONFIG_NAME);
153 }
154
155
159 public static NodeRealizer createDataBase() {
160 GenericNodeRealizer nodeRealizer = createConfigured(FLOWCHART_DATABASE_CONFIG_NAME);
161 nodeRealizer.setSize(60,40);
162 return nodeRealizer;
163 }
164
165
169 public static NodeRealizer createProcess() {
170 return createConfigured(FLOWCHART_PROCESS_CONFIG_NAME);
171 }
172
173
177 public static NodeRealizer createDecision() {
178 return createConfigured(FLOWCHART_DECISION_CONFIG_NAME);
179 }
180
181
186 public static NodeRealizer createDocument() {
187 return createConfigured(FLOWCHART_DOCUMENT_CONFIG_NAME);
188 }
189
190
194 public static NodeRealizer createData() {
195 return createConfigured(FLOWCHART_DATA_CONFIG_NAME);
196 }
197
198
202 public static NodeRealizer createStart1() {
203 return createConfigured(FLOWCHART_START1_CONFIG_NAME);
204 }
205
206
210 public static NodeRealizer createStart2() {
211 return createConfigured(FLOWCHART_START2_CONFIG_NAME);
212 }
213
214
218 public static NodeRealizer createPredefinedProcess() {
219 return createConfigured(FLOWCHART_PREDEFINED_PROCESS_CONFIG_NAME);
220 }
221
222
226 public static NodeRealizer createStoredData() {
227 return createConfigured(FLOWCHART_STORED_DATA_CONFIG_NAME);
228 }
229
230
234 public static NodeRealizer createInternalStorage() {
235 return createConfigured(FLOWCHART_INTERNAL_STORAGE_CONFIG_NAME);
236 }
237
238
242 public static NodeRealizer createSequentialData() {
243 return createConfigured(FLOWCHART_SEQUENTIAL_DATA_CONFIG_NAME);
244 }
245
246
250 public static NodeRealizer createManualInput() {
251 return createConfigured(FLOWCHART_MANUAL_INPUT_CONFIG_NAME);
252 }
253
254
258 public static NodeRealizer createCard() {
259 return createConfigured(FLOWCHART_CARD_CONFIG_NAME);
260 }
261
262
266 public static NodeRealizer createPaperTape() {
267 return createConfigured(FLOWCHART_PAPER_TYPE_CONFIG_NAME);
268 }
269
270
274 public static NodeRealizer createCloud() {
275 GenericNodeRealizer nodeRealizer = createConfigured(FLOWCHART_CLOUD_TYPE_CONFIG_NAME);
276 nodeRealizer.setSize(80,50);
277 return nodeRealizer;
278 }
279
280
284 public static NodeRealizer createDelay() {
285 return createConfigured(FLOWCHART_DELAY_CONFIG_NAME);
286 }
287
288
292 public static NodeRealizer createDisplay() {
293 return createConfigured(FLOWCHART_DISPLAY_CONFIG_NAME);
294 }
295
296
300 public static NodeRealizer createManualOperation() {
301 return createConfigured(FLOWCHART_MANUAL_OPERATION_CONFIG_NAME);
302 }
303
304
308 public static NodeRealizer createPreparation() {
309 return createConfigured(FLOWCHART_PREPARATION_CONFIG_NAME);
310 }
311
312
316 public static NodeRealizer createLoopLimit() {
317 return createConfigured(FLOWCHART_LOOP_LIMIT_CONFIG_NAME);
318 }
319
320
324 public static NodeRealizer createLoopLimitEnd() {
325 return createConfigured(FLOWCHART_LOOP_LIMIT_END_CONFIG_NAME);
326 }
327
328
332 public static NodeRealizer createTerminator() {
333 return createConfigured(FLOWCHART_TERMINATOR_CONFIG_NAME);
334 }
335
336
340 public static NodeRealizer createOnPageReference() {
341 return createConfigured(FLOWCHART_ON_PAGE_REFERENCE_CONFIG_NAME);
342 }
343
344
348 public static NodeRealizer createOffPageReference() {
349 return createConfigured(FLOWCHART_OFF_PAGE_REFERENCE_CONFIG_NAME);
350 }
351
352
364 public static NodeRealizer createAnnotation(byte orientation) {
365 GenericNodeRealizer nodeRealizer = createConfigured(FLOWCHART_ANNOTATION_CONFIG_NAME);
366 nodeRealizer.setLineType(LineType.LINE_2);
367 nodeRealizer.setStyleProperty(PROPERTY_ORIENTATION, new Byte(orientation));
368 return nodeRealizer;
369 }
370
371
375 public static NodeRealizer createUserMessage(){
376 return createConfigured(FLOWCHART_USER_MESSAGE_CONFIG_NAME);
377 }
378
379
383 public static NodeRealizer createNetworkMessage(){
384 return createConfigured(FLOWCHART_NETWORK_MESSAGE_CONFIG_NAME);
385 }
386
387
391 public static EdgeRealizer createDefaultConnection() {
392 final PolyLineEdgeRealizer pel = new PolyLineEdgeRealizer();
393 pel.setSmoothedBends(true);
394 pel.setTargetArrow(Arrow.STANDARD);
395 pel.getLabel().setModel(EdgeLabel.SIX_POS);
396 pel.getLabel().setPosition(EdgeLabel.STAIL);
397 return pel;
398 }
399
400
404 public static EdgeRealizer createNoConnection() {
405 final PolyLineEdgeRealizer pel = new PolyLineEdgeRealizer();
406 pel.setSmoothedBends(true);
407 pel.setTargetArrow(Arrow.STANDARD);
408 pel.setLabelText("No");
409 pel.getLabel().setModel(EdgeLabel.SIX_POS);
410 pel.getLabel().setPosition(EdgeLabel.STAIL);
411 return pel;
412 }
413
414
418 public static EdgeRealizer createYesConnection() {
419 final PolyLineEdgeRealizer pel = new PolyLineEdgeRealizer();
420 pel.setSmoothedBends(true);
421 pel.setTargetArrow(Arrow.STANDARD);
422 pel.setLabelText("Yes");
423 pel.getLabel().setModel(EdgeLabel.SIX_POS);
424 pel.getLabel().setPosition(EdgeLabel.STAIL);
425 return pel;
426 }
427
428
433 private static void register(final String configName, final GenericNodeRealizer.Painter impl) {
434 GenericNodeRealizer.Factory factory = GenericNodeRealizer.getFactory();
435 Map implementationsMap = factory.createDefaultConfigurationMap();
436 implementationsMap.put(GenericNodeRealizer.Painter.class, new ShadowNodePainter(impl));
437 implementationsMap.put(GenericNodeRealizer.ContainsTest.class, impl);
438 factory.addConfiguration(configName, implementationsMap);
439 }
440
441
446 private static GenericNodeRealizer createConfigured(String configName) {
447 GenericNodeRealizer nodeRealizer = new GenericNodeRealizer();
448 nodeRealizer.setConfiguration(configName);
449 nodeRealizer.setFillColor2(new Color(183, 201, 227));
450 nodeRealizer.setFillColor(new Color(232, 238, 247));
451 nodeRealizer.setSize(80, 40);
452 return nodeRealizer;
453 }
454 }
455