D:\NewZebra\JavaApplications\DesignPatternsProject\src\structural_patterns\pdf_facade_pattern\PDF__CoreCommandsPerformer.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
29 import java.text.*;
30 import java.util.*;
31 import java.awt.event.*;
32 import java.awt.*;
33 import javax.swing.*;
34
35
36
37 public class PDF__CoreCommandsPerformer extends JFrame implements CommandsPerformer {
38
39
40 public String [] menuListingArray
41 = {
42 "File",
43 "Edit",
44 "View",
45 "Tools",
46 "Help"
47 };
48
49 public static String [] commandFileListingArray
50 = {
51 "Open",
52 "Save",
53 "Save As",
54 "Close",
55 "Print",
56 "Exit"
57 };
58
59 public static String [] commandEditListingArray
60 = {
61 "Undo",
62 "Redo",
63 "Cut",
64 "Copy",
65 "Paste",
66 "Delete",
67 "Select All",
68 "Deselect All",
69 "Find"
70 };
71
72 public static String [] commandViewListingArray
73 = {
74 "Goto",
75 "Zoom",
76 "Page Display",
77 "Full Screen"
78 };
79
80
81 public String [] commandToolsListingArray
82 = {
83 "Customize ",
84 "Options",
85 "Templates"
86 };
87
88 public String [] commandHelpListingArray
89 = {
90 "Help Contents",
91 "About"
92 };
93
94 CommandPanel aCommandPanel = null;
95 JMenuBar mainJMenuBar;
96 Vector menuVector = null;
97 CommandObject currentCommandObjectHandle = null;
98 JButton nextPageJButton;
99 JButton previousPageJButton;
100 JButton increaseFontSizeJButton;
101 JButton decreaseFontSizeJButton;
102 JTextField pageNumberJTextField;
103 JComboBox fontsSizeList;
104
105 public PDF__CoreCommandsPerformer() {
106
107
108
109 try {
110
111
112 }
113 catch (Exception e)
114 {
115 }
116
117 setSize(868,762);
118 setTitle(" PDF Facade Pattern JFrame");
119 setLayout(null);
120 instantiateCommandPanel();
121 queuingCommands();
122 runCommands();
123
124 setVisible(true);
125
126 }
127
128
129
130 public void instantiateCommandPanel(){
131
132
133
134 aCommandPanel = new CommandPanel();
135 aCommandPanel.setBounds(0,25,860,675);
136
137
138
139
140
141 add(aCommandPanel);
142 addToolBar();
143 }
144
145
146
147 public void queuingCommands(){
148 int menuIndex = 0;
149 int itemIndex = 0;
150 CommandObject commandObjectHandle = null;
151
152 menuVector = new Vector();
153 for(menuIndex = 0; menuIndex < menuListingArray.length; menuIndex++)
154 {
155 Vector menuItemsVector = new Vector();
156 switch(menuIndex)
157 {
158 case 0:
159 for(itemIndex = 0; itemIndex < commandFileListingArray.length; itemIndex++)
160 {
161 commandObjectHandle = new CommandObject();
162 commandObjectHandle.commandName = commandFileListingArray[itemIndex];
163 switch(itemIndex)
164 {
165 case 0:
166
167 commandObjectHandle.itemCommand = new xxx();
168 break;
169 case 1:
170 case 2:
171 case 3:
172 case 4:
173 case 5:
174 commandObjectHandle.itemCommand = new DummyObject("File");
175 break;
176 default:
177 commandObjectHandle.itemCommand = new DummyObject("File");
178 }
179 menuItemsVector.add(commandObjectHandle);
180 }
181 break;
182 case 1:
183 for(itemIndex = 0; itemIndex < commandEditListingArray.length; itemIndex++)
184 {
185 commandObjectHandle = new CommandObject();
186 commandObjectHandle.commandName = commandEditListingArray[itemIndex];
187 switch(itemIndex)
188 {
189 case 0:
190 case 1:
191 case 2:
192 case 3:
193 case 4:
194 case 5:
195 case 6:
196 case 7:
197 case 8:
198 commandObjectHandle.itemCommand = new DummyObject("Edit");
199 break;
200 default:
201 commandObjectHandle.itemCommand = new DummyObject("Edit");
202 }
203 menuItemsVector.add(commandObjectHandle);
204 }
205 break;
206 case 2:
207 for(itemIndex = 0; itemIndex < commandViewListingArray.length; itemIndex++)
208 {
209 commandObjectHandle = new CommandObject();
210 commandObjectHandle.commandName = commandViewListingArray[itemIndex];
211 switch(itemIndex)
212 {
213 case 0:
214 case 1:
215 case 2:
216 case 3:
217 commandObjectHandle.itemCommand = new DummyObject("View");
218 break;
219 default:
220 commandObjectHandle.itemCommand = new DummyObject("View");
221 }
222 menuItemsVector.add(commandObjectHandle);
223 }
224 break;
225 case 3:
226 for(itemIndex = 0; itemIndex < commandToolsListingArray.length; itemIndex++)
227 {
228 commandObjectHandle = new CommandObject();
229 commandObjectHandle.commandName = commandToolsListingArray[itemIndex];
230 switch(itemIndex)
231 {
232 case 0:
233 case 1:
234 case 2:
235 commandObjectHandle.itemCommand = new DummyObject("Tools");
236 break;
237 default:
238 commandObjectHandle.itemCommand = new DummyObject("Tools");
239 }
240 menuItemsVector.add(commandObjectHandle);
241 }
242 break;
243 case 4:
244 default:
245 for(itemIndex = 0; itemIndex < commandHelpListingArray.length; itemIndex++)
246 {
247 commandObjectHandle = new CommandObject();
248 commandObjectHandle.commandName = commandHelpListingArray[itemIndex];
249 switch(itemIndex)
250 {
251 case 0:
252 case 1:
253 commandObjectHandle.itemCommand = new DummyObject("Help");
254 break;
255 default:
256 commandObjectHandle.itemCommand = new DummyObject("Help");
257 }
258 menuItemsVector.add(commandObjectHandle);
259 }
260 break;
261 }
262 menuVector.add(menuItemsVector);
263 }
264 }
265
266
267
268 public void runCommands(){
269 addMenuBar();
270
271 CommandObject commandObjectHandle = null;
272 commandObjectHandle = new CommandObject();
273 commandObjectHandle.commandName = commandFileListingArray[0];
274
275 commandObjectHandle.itemCommand = new xxx();
276 commandObjectHandle.itemCommand.execute(aCommandPanel);
277 currentCommandObjectHandle = commandObjectHandle;
278 }
279
280
281
282 void addMenuBar()
283 {
284 int count;
285 int numberOfFunctions;
286
287 mainJMenuBar = new JMenuBar();
288 for(count = 0; count < menuListingArray.length; count++)
289 {
290 JMenu aJMenu = new JMenu(menuListingArray[count]);
291 addJMenuItem(aJMenu, count);
292 mainJMenuBar.add(aJMenu);
293 }
294 this.setJMenuBar(mainJMenuBar);
295 }
296
297
298
299 void addJMenuItem(JMenu passedMenu, int menuNumber)
300 {
301 String [] itemArray;
302 int count;
303
304 Vector menuItemsVector = (Vector)menuVector.elementAt(menuNumber);
305 for(int index = 0; index < menuItemsVector.size(); index++)
306 {
307 CommandObject tempCommandObject = (CommandObject) menuItemsVector.elementAt(index);
308 JMenuItem item = new JMenuItem(tempCommandObject.commandName);
309 final Command finalCommand = tempCommandObject.itemCommand;
310
311 item.addActionListener(new ActionListener()
312 {
313 public void actionPerformed(ActionEvent PassedActionEvent)
314 {
315 finalCommand.execute(aCommandPanel);
316 }
317 });
318 passedMenu.add(item);
319 }
320 }
321
322
323
324 void addToolBar() {
325 int x_position = 2;
326 int y_position = 2;
327 int buttonWidth = 35;
328 int buttonHieght = 22;
329 int textFieldHieght = 20;
330 int textFieldWidth = 60;
331 int jComboBoxWidth = 60;
332 int jComboBoxHieght = 20;
333
334 int x_positionGape = 2;
335 int x_positionLargeGape = 30;
336
337 JToolBar toolBar = new JToolBar();
338 toolBar.setLayout(null);
339 toolBar.setBounds(0,0,860,25);
340
341 previousPageJButton = new JButton("<=");
342 x_position += x_positionGape;
343 previousPageJButton.setBounds(x_position, y_position, buttonWidth, buttonHieght);
344 toolBar.add(previousPageJButton);
345 previousPageJButton.addActionListener(new ActionListener()
346 {
347 public void actionPerformed(ActionEvent PassedActionEvent)
348 {
349
350
351
352 }
353 });
354
355 nextPageJButton = new JButton("=>");
356 x_position += buttonWidth + x_positionGape;
357 nextPageJButton.setBounds(x_position, y_position, buttonWidth, buttonHieght);
358 toolBar.add(nextPageJButton);
359 nextPageJButton.addActionListener(new ActionListener()
360 {
361 public void actionPerformed(ActionEvent PassedActionEvent)
362 {
363
364
365
366 }
367 });
368
369 pageNumberJTextField = new JTextField("Page " + (aCommandPanel.commandPanelCurrentPage + 1) );
370 x_position += buttonWidth + x_positionGape;
371 pageNumberJTextField.setBounds(x_position, y_position, textFieldWidth, textFieldHieght);
372 pageNumberJTextField.setEnabled(false);
373 toolBar.add(pageNumberJTextField);
374
375
376 pageNumberJTextField.addActionListener(new ActionListener()
377 {
378 public void actionPerformed(ActionEvent PassedActionEvent)
379 {
380 }
381 });
382
383
384
385
386
387
388
389 decreaseFontSizeJButton = new JButton("-");
390 x_position += buttonWidth + textFieldWidth + x_positionLargeGape;
391 decreaseFontSizeJButton.setBounds(x_position, y_position, buttonWidth, buttonHieght);
392 toolBar.add(decreaseFontSizeJButton);
393 decreaseFontSizeJButton.addActionListener(new ActionListener()
394 {
395 public void actionPerformed(ActionEvent PassedActionEvent)
396 {
397 aCommandPanel.commandPanelTextArea.setText("");
398 TextObjectDisplayer tempObject = new TextObjectDisplayer(PDF_Base.FOLDER_PATH, aCommandPanel.commandPanelCurrentDocName);
399 switch(aCommandPanel.commandPanelCurrentFontIndex)
400 {
401 case PDF_Base.FONT50_INDEX:
402 decreaseFontSizeJButton.setEnabled(false);
403 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT50_INDEX_VALUE));
404 break;
405 case PDF_Base.FONT75_INDEX:
406 decreaseFontSizeJButton.setEnabled(false);
407 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT50_INDEX;
408 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT50_INDEX_VALUE));
409 break;
410 case PDF_Base.FONT100_INDEX:
411 decreaseFontSizeJButton.setEnabled(true);
412 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT75_INDEX;
413 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT75_INDEX_VALUE));
414 break;
415 case PDF_Base.FONT125_INDEX:
416 decreaseFontSizeJButton.setEnabled(true);
417 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT100_INDEX;
418 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT100_INDEX_VALUE));
419 break;
420 case PDF_Base.FONT150_INDEX:
421 decreaseFontSizeJButton.setEnabled(true);
422 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT125_INDEX;
423 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT125_INDEX_VALUE));
424 break;
425 case PDF_Base.FONT175_INDEX:
426 decreaseFontSizeJButton.setEnabled(true);
427 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT150_INDEX;
428 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT150_INDEX_VALUE));
429 break;
430 case PDF_Base.FONT200_INDEX:
431 decreaseFontSizeJButton.setEnabled(true);
432 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT175_INDEX;
433 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT200_INDEX_VALUE));
434 break;
435 default:
436 decreaseFontSizeJButton.setEnabled(true);
437 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT100_INDEX;
438 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT100_INDEX_VALUE));
439 }
440 increaseFontSizeJButton.setEnabled(true);
441 aCommandPanel.commandPanelTextArea.repaint();
442 fontsSizeList.setSelectedIndex(aCommandPanel.commandPanelCurrentFontIndex);
443 }
444 });
445
446 increaseFontSizeJButton = new JButton("+");
447 x_position += buttonWidth + x_positionGape;
448 increaseFontSizeJButton.setBounds(x_position, y_position, buttonWidth, buttonHieght);
449 toolBar.add(increaseFontSizeJButton);
450 increaseFontSizeJButton.addActionListener(new ActionListener()
451 {
452 public void actionPerformed(ActionEvent PassedActionEvent)
453 {
454 aCommandPanel.commandPanelTextArea.setText("");
455 TextObjectDisplayer tempObject = new TextObjectDisplayer(PDF_Base.FOLDER_PATH, aCommandPanel.commandPanelCurrentDocName);
456 switch(aCommandPanel.commandPanelCurrentFontIndex)
457 {
458 case PDF_Base.FONT50_INDEX:
459 increaseFontSizeJButton.setEnabled(true);
460 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT75_INDEX;
461 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT75_INDEX_VALUE));
462 break;
463 case PDF_Base.FONT75_INDEX:
464 increaseFontSizeJButton.setEnabled(true);
465 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT100_INDEX;
466 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT100_INDEX_VALUE));
467 break;
468 case PDF_Base.FONT100_INDEX:
469 increaseFontSizeJButton.setEnabled(true);
470 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT125_INDEX;
471 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT125_INDEX_VALUE));
472 break;
473 case PDF_Base.FONT125_INDEX:
474 increaseFontSizeJButton.setEnabled(true);
475 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT150_INDEX;
476 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT150_INDEX_VALUE));
477 break;
478 case PDF_Base.FONT150_INDEX:
479 increaseFontSizeJButton.setEnabled(true);
480 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT175_INDEX;
481 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT175_INDEX_VALUE));
482 break;
483 case PDF_Base.FONT175_INDEX:
484 increaseFontSizeJButton.setEnabled(false);
485 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT200_INDEX;
486 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT200_INDEX_VALUE));
487 break;
488 case PDF_Base.FONT200_INDEX:
489 increaseFontSizeJButton.setEnabled(false);
490 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT200_INDEX;
491 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT200_INDEX_VALUE));
492 break;
493 default:
494 increaseFontSizeJButton.setEnabled(true);
495 aCommandPanel.commandPanelCurrentFontIndex = PDF_Base.FONT100_INDEX;
496 tempObject.populateTextArea(aCommandPanel.commandPanelTextArea, new java.awt.Font("Helvetica", Font.BOLD, PDF_Base.FONT50_INDEX_VALUE));
497 }
498 decreaseFontSizeJButton.setEnabled(true);
499 aCommandPanel.commandPanelTextArea.repaint();
500 fontsSizeList.setSelectedIndex(aCommandPanel.commandPanelCurrentFontIndex);
501 }
502 });
503 add(toolBar);
504
505 fontsSizeList = new JComboBox(aCommandPanel.fontSizeArray);
506 x_position += buttonWidth + x_positionGape;
507 fontsSizeList.setBounds(x_position, y_position, jComboBoxWidth, jComboBoxHieght);
508 fontsSizeList.setBackground(Color.white);
509 fontsSizeList.setSelectedIndex(aCommandPanel.commandPanelCurrentFontIndex);
510 fontsSizeList.addActionListener(new ActionListener()
511 {
512 public void actionPerformed(ActionEvent eActionEvent) {
513 JComboBox localJComboBox = (JComboBox)eActionEvent.getSource();
514 String tempgeneration = (String)localJComboBox.getSelectedItem();
515 int mu = (int)localJComboBox.getSelectedIndex();
516
517 }
518 });
519 toolBar.add(fontsSizeList);
520
521
522 aCommandPanel.documentNameJTextField = new JTextField("Chain of Command");
523 x_position += buttonWidth + x_positionGape + jComboBoxWidth;
524 aCommandPanel.documentNameJTextField.setBounds(x_position, y_position, 150, textFieldHieght);
525 aCommandPanel.documentNameJTextField.setEnabled(false);
526 toolBar.add(aCommandPanel.documentNameJTextField);
527
528
529 aCommandPanel.documentNameJTextField.addActionListener(new ActionListener()
530 {
531 public void actionPerformed(ActionEvent PassedActionEvent)
532 {
533 }
534 });
535
536 }
537
538
539
540 public static void main (String[] args)
541 {
542 PDF__CoreCommandsPerformer pdf_CoreCommandsPerformerHandle = new PDF__CoreCommandsPerformer();
543 }
544
545 }
546
547
548