D:\NewZebra\JavaApplications\DesignPatternsProject\src\structural_patterns\pdf_facade_pattern\DesignPatternLesson.java |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package structural_patterns.pdf_facade_pattern;
21
22
23
24 @author
25
26
27
28 import java.text.*;
29 import java.lang.*;
30 import java.util.*;
31 import java.awt.event.*;
32 import java.awt.*;
33 import javax.swing.*;
34
35 public class DesignPatternLesson implements Command {
36
37 JScrollPane functionsJScrollPane = null;
38 JScrollPane documentJScrollPane = null;
39 JSplitPane splitPane = null;
40
41 CommandPanel localCommandPanelReference = null;
42
43
44
45 public DesignPatternLesson() {
46 }
47
48
49
50 public void execute(CommandPanel passedCommandPanel){
51
52 if(passedCommandPanel != null) {
53
54 passedCommandPanel.removeAll();
55
56 passedCommandPanel.setVisible(false);
57
58 localCommandPanelReference = passedCommandPanel;
59 functionsJScrollPane = new JScrollPane();
60 functionsJScrollPane.setLayout(null);
61
62 addPatternsButtoons(functionsJScrollPane);
63
64
65 localCommandPanelReference.commandPanelTextArea = new JTextArea();
66 localCommandPanelReference.commandPanelTextArea.setEditable(false);
67 localCommandPanelReference.commandPanelTextArea.setFont(new java.awt.Font("Helvetica", Font.BOLD, 12));
68
69 int count;
70
71
72
73 localCommandPanelReference.commandPanelTextArea.append(" Singleton\n\n");
74
75 localCommandPanelReference.commandPanelTextArea.append(" The Singleton Pattern is a Creational pattern. In programming, you may need to make sure that there is\n");
76
77 localCommandPanelReference.commandPanelTextArea.append(" only one instance of a class running. For example, a company’s email archiving system; it should be\n");
78
79 localCommandPanelReference.commandPanelTextArea.append(" only one instance of an archiving class that handles all the archiving of all the company’s emails\n");
80
81 localCommandPanelReference.commandPanelTextArea.append(" otherwise the same email would be archived more than once. This would result in redundant of effort,\n");
82
83 localCommandPanelReference.commandPanelTextArea.append(" waist of time and space. Singleton Pattern is the answer to have only one instance of a class running and\n");
84
85 localCommandPanelReference.commandPanelTextArea.append(" every process that needs such a class must use this Singleton instance.\n");
86
87
88 localCommandPanelReference.commandPanelTextArea.append(" One instance:\n");
89 localCommandPanelReference.commandPanelTextArea.append(" There are a number of issues that needed to be discussed on how to handle the creation and use of a \n");
90
91 localCommandPanelReference.commandPanelTextArea.append(" Singleton Class. The following are some of them:\n");
92
93
94 localCommandPanelReference.commandPanelTextArea.append(" How to insure that there is only once instance?\n");
95
96 localCommandPanelReference.commandPanelTextArea.append(" • How to prevent threading from a possible creation of more than one instance?\n");
97
98
99 localCommandPanelReference.commandPanelTextArea.append(" • How to handle freeing the Singleton class?\n");
100
101 localCommandPanelReference.commandPanelTextArea.append(" • Sub-Classing Singleton?\n");
102
103
104 localCommandPanelReference.commandPanelTextArea.append(" • Casting\n");
105
106 localCommandPanelReference.commandPanelTextArea.append(" • Servlets, Threading and Singleton\n");
107
108 localCommandPanelReference.commandPanelTextArea.append(" • Cloneable, Class-Loaders, Remote Classes, Reflection, Serialization and Deserialization\n");
109
110
111 localCommandPanelReference.commandPanelTextArea.append(" • How can we set a clear rule of communication between the developer who would create the\n");
112 localCommandPanelReference.commandPanelTextArea.append(" Singleton class and the developer who would use (instantiate) the Singleton class?\n");
113
114
115 localCommandPanelReference.commandPanelTextArea.append("\n\n\n");
116 localCommandPanelReference.commandPanelTextArea.moveCaretPosition(0);
117 documentJScrollPane = new JScrollPane(localCommandPanelReference.commandPanelTextArea);
118
119
120 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
121 functionsJScrollPane, documentJScrollPane);
122 splitPane.setOneTouchExpandable(true);
123 splitPane.setDividerLocation(200);
124 BorderLayout borderLayout = new BorderLayout();
125 passedCommandPanel.setLayout(borderLayout);
126 passedCommandPanel.add(splitPane, BorderLayout.CENTER);
127 passedCommandPanel.setVisible(true);
128 }
129 else
130 reportError();
131 }
132
133
134
135 public void reportError(){
136 JOptionPane.showMessageDialog(null, "DesignPatternLesson ", "Field Error", JOptionPane.ERROR_MESSAGE);
137 }
138
139
140
141 public void addPatternsButtoons(JScrollPane passedfunctionsJScrollPane){
142
143 int y_position = 10;
144 int x_position = 10;
145 int space_1 = 10;
146 int space_2 = 25;
147
148 JButton aJButton;
149
150 Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
151
152 aJButton = new JButton("Design Pattern");
153 aJButton.setCursor(handCursor);
154
155 aJButton.setBounds(x_position, y_position , 150, 14);
156 passedfunctionsJScrollPane.add(aJButton);
157 aJButton.addActionListener(new ActionListener()
158 {
159 public void actionPerformed(ActionEvent PassedActionEvent)
160 {
161 localCommandPanelReference.commandPanelTextArea.setText("");
162 localCommandPanelReference.commandPanelTextArea.repaint();
163 localCommandPanelReference.documentNameJTextField.setText("Design Pattern");
164 }
165 });
166
167 y_position += 35;
168
169 aJButton = new JButton("Behovioral Patterns");
170 aJButton.setCursor(handCursor);
171
172 aJButton.setBounds(x_position + space_1, y_position , 150, 15);
173 passedfunctionsJScrollPane.add(aJButton);
174 aJButton.addActionListener(new ActionListener()
175 {
176 public void actionPerformed(ActionEvent PassedActionEvent)
177 {
178 localCommandPanelReference.commandPanelTextArea.setText("");
179 TextObjectDisplayer tempObject = new TextObjectDisplayer(PDF_Base.FOLDER_PATH, "command.data");
180 localCommandPanelReference.commandPanelCurrentDocName = "command.data";
181 tempObject.populateTextArea(localCommandPanelReference.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, 12));
182 localCommandPanelReference.documentNameJTextField.setText("Behovioral Patterns");
183 }
184 });
185
186 y_position += 20;
187
188
189 aJButton = new JButton("Chain of Responsibility");
190 aJButton.setCursor(handCursor);
191
192 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
193 passedfunctionsJScrollPane.add(aJButton);
194 aJButton.addActionListener(new ActionListener()
195 {
196 public void actionPerformed(ActionEvent PassedActionEvent)
197 {
198 localCommandPanelReference.commandPanelTextArea.setText("");
199 TextObjectDisplayer tempObject = new TextObjectDisplayer(PDF_Base.FOLDER_PATH, "singleton.data");
200 localCommandPanelReference.commandPanelCurrentDocName = "singleton.data";
201 tempObject.populateTextArea(localCommandPanelReference.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, 12));
202 localCommandPanelReference.documentNameJTextField.setText("Chain of Responsibility");
203 }
204 });
205
206 y_position += 20;
207
208 aJButton = new JButton("Command");
209 aJButton.setCursor(handCursor);
210
211 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
212 passedfunctionsJScrollPane.add(aJButton);
213 aJButton.addActionListener(new ActionListener()
214 {
215 public void actionPerformed(ActionEvent PassedActionEvent)
216 {
217
218 }
219 });
220
221 y_position += 20;
222
223 aJButton = new JButton("Interpreter");
224 aJButton.setCursor(handCursor);
225
226 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
227 passedfunctionsJScrollPane.add(aJButton);
228 aJButton.addActionListener(new ActionListener()
229 {
230 public void actionPerformed(ActionEvent PassedActionEvent)
231 {
232
233 }
234 });
235
236 y_position += 20;
237
238 aJButton = new JButton("Iterator");
239 aJButton.setCursor(handCursor);
240
241 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
242 passedfunctionsJScrollPane.add(aJButton);
243 aJButton.addActionListener(new ActionListener()
244 {
245 public void actionPerformed(ActionEvent PassedActionEvent)
246 {
247
248 }
249 });
250
251 y_position += 20;
252
253 aJButton = new JButton("Mediator");
254 aJButton.setCursor(handCursor);
255
256 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
257 passedfunctionsJScrollPane.add(aJButton);
258 aJButton.addActionListener(new ActionListener()
259 {
260 public void actionPerformed(ActionEvent PassedActionEvent)
261 {
262
263 }
264 });
265
266 y_position += 20;
267
268 aJButton = new JButton("Mementor");
269 aJButton.setCursor(handCursor);
270
271 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
272 passedfunctionsJScrollPane.add(aJButton);
273 aJButton.addActionListener(new ActionListener()
274 {
275 public void actionPerformed(ActionEvent PassedActionEvent)
276 {
277
278 }
279 });
280
281 y_position += 20;
282
283 aJButton = new JButton("Observert");
284 aJButton.setCursor(handCursor);
285
286 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
287 passedfunctionsJScrollPane.add(aJButton);
288 aJButton.addActionListener(new ActionListener()
289 {
290 public void actionPerformed(ActionEvent PassedActionEvent)
291 {
292
293 }
294 });
295
296 y_position += 20;
297
298 aJButton = new JButton("State");
299 aJButton.setCursor(handCursor);
300
301 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
302 passedfunctionsJScrollPane.add(aJButton);
303 aJButton.addActionListener(new ActionListener()
304 {
305 public void actionPerformed(ActionEvent PassedActionEvent)
306 {
307
308 }
309 });
310
311 y_position += 20;
312
313 aJButton = new JButton("Strategy");
314 aJButton.setCursor(handCursor);
315
316 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
317 passedfunctionsJScrollPane.add(aJButton);
318 aJButton.addActionListener(new ActionListener()
319 {
320 public void actionPerformed(ActionEvent PassedActionEvent)
321 {
322
323 }
324 });
325
326 y_position += 20;
327
328 aJButton = new JButton("Template");
329 aJButton.setCursor(handCursor);
330
331 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
332 passedfunctionsJScrollPane.add(aJButton);
333 aJButton.addActionListener(new ActionListener()
334 {
335 public void actionPerformed(ActionEvent PassedActionEvent)
336 {
337
338 }
339 });
340
341 y_position += 20;
342
343 aJButton = new JButton("Visitor");
344 aJButton.setCursor(handCursor);
345
346 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
347 passedfunctionsJScrollPane.add(aJButton);
348 aJButton.addActionListener(new ActionListener()
349 {
350 public void actionPerformed(ActionEvent PassedActionEvent)
351 {
352
353 }
354 });
355
356 y_position += 35;
357
358 aJButton = new JButton("Creational Patterns");
359 aJButton.setCursor(handCursor);
360
361 aJButton.setBounds(x_position + space_1, y_position , 150, 15);
362 passedfunctionsJScrollPane.add(aJButton);
363 aJButton.addActionListener(new ActionListener()
364 {
365 public void actionPerformed(ActionEvent PassedActionEvent)
366 {
367
368 }
369 });
370
371 y_position += 20;
372
373 aJButton = new JButton("AbstractFactory");
374 aJButton.setCursor(handCursor);
375
376 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
377 passedfunctionsJScrollPane.add(aJButton);
378 aJButton.addActionListener(new ActionListener()
379 {
380 public void actionPerformed(ActionEvent PassedActionEvent)
381 {
382
383 }
384 });
385
386 y_position += 20;
387
388 aJButton = new JButton("Builder");
389 aJButton.setCursor(handCursor);
390
391 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
392 passedfunctionsJScrollPane.add(aJButton);
393 aJButton.addActionListener(new ActionListener()
394 {
395 public void actionPerformed(ActionEvent PassedActionEvent)
396 {
397
398 }
399 });
400
401 y_position += 20;
402
403 aJButton = new JButton("Factory");
404 aJButton.setCursor(handCursor);
405
406 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
407 passedfunctionsJScrollPane.add(aJButton);
408 aJButton.addActionListener(new ActionListener()
409 {
410 public void actionPerformed(ActionEvent PassedActionEvent)
411 {
412
413 }
414 });
415
416 y_position += 20;
417
418 aJButton = new JButton("Prototype");
419 aJButton.setCursor(handCursor);
420
421 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
422 passedfunctionsJScrollPane.add(aJButton);
423 aJButton.addActionListener(new ActionListener()
424 {
425 public void actionPerformed(ActionEvent PassedActionEvent)
426 {
427
428 }
429 });
430
431 y_position += 20;
432
433 aJButton = new JButton("Singleton");
434 aJButton.setCursor(handCursor);
435
436 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
437 passedfunctionsJScrollPane.add(aJButton);
438 aJButton.addActionListener(new ActionListener()
439 {
440 public void actionPerformed(ActionEvent PassedActionEvent)
441 {
442
443 }
444 });
445
446 y_position += 35;
447
448 aJButton = new JButton("Structural Patterns");
449 aJButton.setCursor(handCursor);
450
451 aJButton.setBounds(x_position + space_1, y_position , 150, 15);
452 passedfunctionsJScrollPane.add(aJButton);
453 aJButton.addActionListener(new ActionListener()
454 {
455 public void actionPerformed(ActionEvent PassedActionEvent)
456 {
457
458 }
459 });
460
461 y_position += 20;
462
463 aJButton = new JButton("Adapter");
464 aJButton.setCursor(handCursor);
465
466 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
467 passedfunctionsJScrollPane.add(aJButton);
468 aJButton.addActionListener(new ActionListener()
469 {
470 public void actionPerformed(ActionEvent PassedActionEvent)
471 {
472
473 }
474 });
475
476 y_position += 20;
477
478 aJButton = new JButton("Bridge");
479 aJButton.setCursor(handCursor);
480
481 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
482 passedfunctionsJScrollPane.add(aJButton);
483 aJButton.addActionListener(new ActionListener()
484 {
485 public void actionPerformed(ActionEvent PassedActionEvent)
486 {
487
488 }
489 });
490
491 y_position += 20;
492
493 aJButton = new JButton("Flyweight");
494 aJButton.setCursor(handCursor);
495
496 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
497 passedfunctionsJScrollPane.add(aJButton);
498 aJButton.addActionListener(new ActionListener()
499 {
500 public void actionPerformed(ActionEvent PassedActionEvent)
501 {
502
503 }
504 });
505
506 y_position += 20;
507
508 aJButton = new JButton("Proxyt");
509 aJButton.setCursor(handCursor);
510
511 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
512 passedfunctionsJScrollPane.add(aJButton);
513 aJButton.addActionListener(new ActionListener()
514 {
515 public void actionPerformed(ActionEvent PassedActionEvent)
516 {
517
518 }
519 });
520
521 y_position += 20;
522
523 aJButton = new JButton("Decorator");
524 aJButton.setCursor(handCursor);
525
526 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
527 passedfunctionsJScrollPane.add(aJButton);
528 aJButton.addActionListener(new ActionListener()
529 {
530 public void actionPerformed(ActionEvent PassedActionEvent)
531 {
532
533 }
534 });
535
536 y_position += 20;
537
538 aJButton = new JButton("Composite");
539 aJButton.setCursor(handCursor);
540
541 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
542 passedfunctionsJScrollPane.add(aJButton);
543 aJButton.addActionListener(new ActionListener()
544 {
545 public void actionPerformed(ActionEvent PassedActionEvent)
546 {
547
548 }
549 });
550
551 y_position += 20;
552
553 aJButton = new JButton("Façader");
554 aJButton.setCursor(handCursor);
555
556 aJButton.setBounds(x_position + space_2, y_position , 150, 15);
557 passedfunctionsJScrollPane.add(aJButton);
558 aJButton.addActionListener(new ActionListener()
559 {
560 public void actionPerformed(ActionEvent PassedActionEvent)
561 {
562
563 }
564 });
565
566 }
567
568 }
569
570