1 package com.bonevich.erj.ui;
2
3 import com.bonevich.erj.ErjConstants;
4 import com.bonevich.erj.app.Project;
5 import com.bonevich.util.ResourceUtilities;
6
7 import org.tigris.gef.base.*;
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import javax.swing.event.*;
13 import java.util.*;
14 import java.io.*;
15
16 /***
17 * An abstract button command class.
18 * @author jbonevic
19 */
20 public abstract class Command extends AbstractAction
21 {
22 //////////////////////////////////////////////////////////
23 // Constants
24 public static final boolean IS_GLOBAL = true;
25 public static final boolean NOT_GLOBAL = false;
26
27 //////////////////////////////////////////////////////////
28 // Attributes
29 protected static CommandManager _manager = new CommandManager();
30
31 protected boolean _modifiesProject = false;
32
33 //////////////////////////////////////////////////////////
34 // Command instances
35
36 // File Menu
37 public static Command NewProject = new CommandNewProject();
38 public static Command NewDiagram = new CommandNewDiagram();
39 public static Command Open = new CommandOpen();
40 public static Command Save = new CommandSave();
41 public static Command SaveAs = new CommandSaveAs();
42 public static Command Print = new CommandPrint();
43 public static Command PageSetup = new CommandPageSetup();
44 public static Command Exit = new CommandExit();
45
46 // Edit Menu
47 public static Command Undo = new CommandUndo();
48 public static Command Redo = new CommandRedo();
49 public static Command Cut = new CommandCut();
50 public static Command Copy = new CommandCopy();
51 public static Command Paste = new CommandPaste();
52 public static Command Delete = new CommandDelete();
53 public static Command SelectAll = new CommandSelectAll();
54 public static Command Remove = new CommandRemove();
55 public static Command History = new CommandHistory();
56 public static Command Prefs = new CommandPrefs();
57
58 // View Menu
59 public static Command Zoom = new CommandZoom();
60 public static Command ZoomIn = new CommandZoomIn();
61 public static Command ZoomOut = new CommandZoomOut();
62 public static Command Goto = new CommandGoto();
63 public static Command AdjustGrid = new CommandAdjustGrid();
64 public static Command AdjustSnap = new CommandAdjustSnap();
65 public static Command AdjustPageBreak = new CommandAdjustPageBreak();
66
67 // Project Menu
68 public static Command TargetDatabase = new CommandTargetDatabase();
69 public static Command ProjectProps = new CommandProjectProps();
70
71 // Tools Menu
72 public static Command Generate = new CommandGenerate();
73 public static Command Synchronize = new CommandSynchronize();
74 public static Command Arrange = new CommandArrange();
75
76 // Help Menu
77 public static Command Contents = new CommandContents();
78 public static Command About = new CommandAbout();
79
80 // Diagram Pane Popup
81 public static Command DeleteDiagram = new CommandDeleteDiagram();
82 public static Command RenameDiagram = new CommandRenameDiagram();
83 public static Command ReorderDiagrams = new CommandReorderDiagrams();
84
85 //////////////////////////////////////////////////////////
86 // Constructors
87 public Command(String name)
88 {
89 this(name, IS_GLOBAL);
90 }
91
92 public Command(String name, boolean isGlobal)
93 {
94 super(name);
95 if (isGlobal)
96 {
97 _manager.register(this);
98 }
99 putValue(Action.SHORT_DESCRIPTION, name);
100 updateEnabled();
101 }
102
103 //////////////////////////////////////////////////////////
104 // Operations
105 public void actionPerformed(ActionEvent e)
106 {
107 invoke();
108 }
109
110 public void invoke()
111 {
112 // manager will call doIt(), etc.
113 _manager.invoke(this);
114 if (_modifiesProject)
115 {
116 markProjectModified();
117 }
118 }
119
120 public abstract boolean doIt();
121
122 public abstract void undoIt();
123
124 /*** Mark the current project as out-of-date. */
125 public void markProjectModified()
126 {
127 ErjFrame browser = ErjFrame.getInstance();
128 Project p = browser.getApplication().getCurrentProject();
129 p.markAsModified();
130 }
131
132 protected void setModifiesProject(boolean modifies)
133 {
134 _modifiesProject = modifies;
135 }
136
137 public void updateEnabled()
138 {
139 setEnabled(shouldBeEnabled());
140 }
141
142 public boolean shouldBeEnabled()
143 {
144 return true;
145 }
146
147 public String getName()
148 {
149 return (String) getValue(NAME);
150 }
151 public void setName(String name)
152 {
153 putValue(NAME, name);
154 }
155
156 public static void updateAllEnabled()
157 {
158 _manager.updateAllRegisteredCommands();
159 }
160
161 public JButton getButton()
162 {
163 JButton button = new JButton(this);
164 button.setText(ErjConstants.EMPTY_STR);
165 button.setMargin(new Insets(0,0,0,0));
166 button.setIcon(
167 new ImageIcon(
168 ResourceUtilities.getResourceAsURL(
169 "com/bonevich/erj/images/general/" + getIconName() + ".gif"
170 )
171 )
172 );
173 return button;
174 }
175
176 protected String getIconName() { return null; }
177
178
179 /***
180 * Command to open a project from a specified file
181 * in the history.
182 * Had to make this an inner class to get rid of annoying
183 * compile-time warnings.
184 */
185 static class CommandOpenFromHistory extends Command
186 {
187 private String _filepath = null;
188
189 public CommandOpenFromHistory(String filepath)
190 {
191 super(ErjConstants.EMPTY_STR);
192 _filepath = filepath;
193 }
194
195 public boolean doIt()
196 {
197 if (SaveProjectConfirm.confirm())
198 {
199 ErjFrame frame = ErjFrame.getInstance();
200 frame.getApplication().loadProject(_filepath);
201 frame.getFileHistory().insertPathname(_filepath);
202 }
203
204 return false;
205 }
206
207 public void undoIt() { }
208 } /* end class CommandOpenFromHistory */
209
210 } /* end class Command */
211
212
213 //////////////////////////////////////////////////////////
214 // Convenient Command classes
215
216 /***
217 * Command to create a new project. Also confirms that the current
218 * project has been saved before trashing it.
219 */
220 class CommandNewProject extends Command
221 {
222 public CommandNewProject() { super("Project..."); }
223
224 public boolean doIt()
225 {
226 if (SaveProjectConfirm.confirm())
227 {
228 ErjFrame frame = ErjFrame.getInstance();
229 Project newProject = frame.getApplication().createDefaultProject();
230 JDialog props = new ProjectPropertiesDialog(newProject);
231 props.show();
232 }
233 return false;
234 }
235
236 public void undoIt() { }
237
238 protected String getIconName() { return "New16"; }
239 } /* end class CommandNewProject */
240
241
242 /***
243 * Command to create a new diagram in the current project
244 */
245 class CommandNewDiagram extends Command
246 {
247 public CommandNewDiagram()
248 {
249 super("Insert Diagram...");
250 setModifiesProject(true);
251 }
252
253 public boolean doIt()
254 {
255 //FIXME: we should create an editor so you can set name, etc.
256 ErjFrame browser = ErjFrame.getInstance();
257 Project project = browser.getApplication().getCurrentProject();
258 project.createDiagram();
259 return false;
260 }
261
262 public void undoIt() { }
263 } /* end class CommandNewDiagram */
264
265
266 /***
267 * Abstract Command subclassed by CommandOpen and CommandSaveAs so
268 * that they may share an instance of JFileChooser. Also means that
269 * the chooser will remember the "current working directory"
270 * between uses.
271 */
272 abstract class CommandFileChooser extends Command
273 {
274 protected JFileChooser _chooser = new JFileChooser();
275
276 public CommandFileChooser(String name) { super(name); }
277
278 } /* end class CommandFileChooser */
279
280
281 /***
282 * Command to open an existing project. Confirms that the current
283 * project needs to be saved.
284 */
285 class CommandOpen extends CommandFileChooser
286 {
287 public CommandOpen() { super("Open..."); }
288
289 public boolean doIt()
290 {
291 if (SaveProjectConfirm.confirm())
292 {
293 _chooser.addChoosableFileFilter(ErjFileFilter.ERJ);
294 _chooser.addChoosableFileFilter(ErjFileFilter.SQL);
295 _chooser.addChoosableFileFilter(ErjFileFilter.SVG);
296 _chooser.setFileFilter(ErjFileFilter.ERJ);
297 int choice = _chooser.showOpenDialog(null);
298 if (choice == JFileChooser.APPROVE_OPTION)
299 {
300 File projectFile = _chooser.getSelectedFile();
301 String filepath = projectFile.getAbsolutePath();
302
303 ErjFrame frame = ErjFrame.getInstance();
304 frame.getApplication().loadProject(filepath);
305 frame.getFileHistory().insertPathname(filepath);
306 }
307 }
308
309 return false;
310 }
311
312 public void undoIt() { }
313
314 protected String getIconName() { return "Open16"; }
315 } /* end class CommandOpen */
316
317
318 /***
319 * Command to save the current project
320 */
321 class CommandSave extends Command
322 {
323 public CommandSave() { super("Save"); }
324
325 public boolean doIt()
326 {
327 ErjFrame frame = ErjFrame.getInstance();
328 Project p = frame.getApplication().getCurrentProject();
329 //System.err.println("project status = " + (p.isNew() ? "new" : "saved") +
330 // ", " + (p.isModified() ? "modified" : "clean"));
331 if (p.isNew())
332 {
333 Command.SaveAs.invoke();
334 }
335 else
336 {
337 p.save();
338 }
339 return false;
340 }
341
342 public void undoIt() { }
343
344 public boolean shouldBeEnabled()
345 {
346 ErjFrame frame = ErjFrame.getInstance();
347 if (frame.isVisible())
348 {
349 Project p = frame.getApplication().getCurrentProject();
350 if (p != null)
351 {
352 return p.isNew() || p.isModified();
353 }
354 }
355 return false;
356 }
357
358 protected String getIconName() { return "Save16"; }
359 } /* end class CommandSave */
360
361
362 /***
363 * Command to save the current project under a new filename
364 * and/or in a different format
365 */
366 class CommandSaveAs extends CommandFileChooser
367 {
368 public CommandSaveAs() { super("Save As..."); }
369
370 public boolean doIt()
371 {
372 ErjFrame frame = ErjFrame.getInstance();
373 Project p = frame.getApplication().getCurrentProject();
374 File path = new File(p.getFilepath());
375 _chooser.setCurrentDirectory(path);
376 _chooser.addChoosableFileFilter(ErjFileFilter.ERJ);
377 _chooser.addChoosableFileFilter(ErjFileFilter.UML);
378 _chooser.addChoosableFileFilter(ErjFileFilter.SQL);
379 _chooser.addChoosableFileFilter(ErjFileFilter.SVG);
380 _chooser.addChoosableFileFilter(ErjFileFilter.GIF);
381 _chooser.setFileFilter(ErjFileFilter.ERJ);
382 int choice = _chooser.showSaveDialog(null);
383 if (choice == JFileChooser.APPROVE_OPTION)
384 {
385 File projectFile = _chooser.getSelectedFile();
386 String filepath = projectFile.getAbsolutePath();
387 p.save(filepath);
388 frame.getFileHistory().insertPathname(p.getFilepath());
389 }
390 return false;
391 }
392
393 public void undoIt() { }
394
395 protected String getIconName() { return "SaveAs16"; }
396 } /* end class CommandSaveAs */
397
398
399 /***
400 * Command to print diagram(s)
401 */
402 class CommandPrint extends Command
403 {
404 public CommandPrint() { super("Print..."); }
405
406 public boolean doIt()
407 {
408 //FIXME: reimplement using java.awt.print library
409 CmdPrint cmd = new CmdPrint();
410 ErjFrame browser = ErjFrame.getInstance();
411 Diagram diagram = browser.getActiveDiagram();
412 cmd.setDiagramName(diagram.getName());
413 cmd.doIt();
414
415 return false;
416 }
417
418 public void undoIt() { }
419
420 protected String getIconName() { return "Print16"; }
421 } /* end class CommandPrint */
422
423
424 /***
425 * Command to change the current page settings
426 */
427 class CommandPageSetup extends Command
428 {
429 public CommandPageSetup() { super("Page Setup..."); }
430
431 public boolean doIt()
432 {
433 //FIXME: reimplement using java.awt.print library
434 return false;
435 }
436
437 public void undoIt() { }
438
439 public boolean shouldBeEnabled() { return false; }
440
441 protected String getIconName() { return "PageSetup16"; }
442 } /* end class CommandPageSetup */
443
444
445 /***
446 * Command to exit the application
447 */
448 class CommandExit extends Command
449 {
450 public CommandExit() { super("Exit"); }
451
452 public boolean doIt()
453 {
454 // check if the current project needs saving
455 if (SaveProjectConfirm.confirm())
456 {
457 ErjFrame.getInstance().exit();
458 }
459 return false;
460 }
461
462 public void undoIt() { }
463 } /* end class CommandExit */
464
465
466 /***
467 * Command to remove the currently selected figure(s) from the
468 * active editor, placing a copy in the application clipboard,
469 * but not remove them from the model.
470 */
471 class CommandCut extends Command
472 {
473 public CommandCut() { super("Cut"); }
474
475 public boolean doIt()
476 {
477 return false;
478 }
479
480 public void undoIt() { }
481
482 public boolean shouldBeEnabled() { return false; }
483
484 protected String getIconName() { return "Cut16"; }
485 } /* end class CommandCut */
486
487
488 /***
489 * Command to copy the currently selected figure(s) from the
490 * active editor to the application clipboard.
491 */
492 class CommandCopy extends Command
493 {
494 public CommandCopy() { super("Copy"); }
495
496 public boolean doIt()
497 {
498 Vector figs = getSelections();
499 if (figs.isEmpty())
500 {
501 return false;
502 }
503 //Transferable object = new TransferableFigSelection(figs);
504 //ErjFrame.getInstance().getClipboard().setContents(object, object);
505 return true;
506 }
507
508 public void undoIt() { }
509
510 public boolean shouldBeEnabled()
511 {
512 Vector figs = getSelections();
513 if (! (figs != null && !figs.isEmpty()) )
514 {
515 return false;
516 }
517 return true;
518 }
519
520 private Vector getSelections()
521 {
522 Editor editor = Globals.curEditor();
523 if (editor == null)
524 {
525 return new Vector();
526 }
527 SelectionManager sm = editor.getSelectionManager();
528 return sm.getFigs();
529 }
530
531 protected String getIconName() { return "Copy16"; }
532 } /* end class CommandCopy */
533
534
535 /***
536 * Command to paste the contents of the application clipboard
537 * into the currently active editor. Automatically places the
538 * figures.
539 */
540 class CommandPaste extends Command
541 {
542 public CommandPaste() { super("Paste"); }
543
544 public boolean doIt()
545 {
546 return false;
547 }
548
549 public void undoIt() { }
550
551 public boolean shouldBeEnabled() { return false; }
552
553 protected String getIconName() { return "Paste16"; }
554 } /* end class CommandPaste */
555
556
557 /***
558 * Command to remove the currently selected figure(s) from the
559 * active editor, but not from the model. Copies are not saved
560 * in the application clipboard.
561 */
562 class CommandDelete extends Command
563 {
564 public CommandDelete() { super("Delete"); }
565
566 public boolean doIt()
567 {
568 return false;
569 }
570
571 public void undoIt() { }
572
573 public boolean shouldBeEnabled() { return false; }
574 } /* end class CommandDelete */
575
576
577 /***
578 * Command to cause all figures in the active editor to be
579 * selected.
580 */
581 class CommandSelectAll extends Command
582 {
583 public CommandSelectAll() { super("Select All"); }
584
585 public boolean doIt()
586 {
587 Editor editor = Globals.curEditor();
588 if (editor == null)
589 {
590 return false;
591 }
592 SelectionManager sm = editor.getSelectionManager();
593 sm.select(editor.getLayerManager().getActiveLayer().getContents());
594 return false;
595 }
596
597 public void undoIt() { }
598 } /* end class CommandSelectAll */
599
600
601 /***
602 * Command to remove the currently selected figure(s) from the
603 * active editor and the model. Copies are not saved in the
604 * application clipboard.
605 */
606 class CommandRemove extends Command
607 {
608 public CommandRemove() { super("Remove From Model"); }
609
610 public boolean doIt()
611 {
612 return false;
613 }
614
615 public void undoIt() { }
616
617 public boolean shouldBeEnabled() { return false; }
618 } /* end class CommandRemove */
619
620
621 /***
622 * Command to view the application project file history, and
623 * to open an editor on it.
624 */
625 class CommandHistory extends Command
626 {
627 public CommandHistory() { super("History..."); }
628
629 public boolean doIt()
630 {
631 ErjFrame.getInstance().getFileHistory().processList();
632 return false;
633 }
634
635 public void undoIt() { }
636 } /* end class CommandHistory */
637
638
639 /***
640 * Command to open an editor on the application preferences.
641 */
642 class CommandPrefs extends Command
643 {
644 public CommandPrefs() { super("Preferences..."); }
645
646 public boolean doIt()
647 {
648 Cmd cmd = new CmdOpenWindow(
649 "org.tigris.gef.base.PrefsEditor",
650 "Preferences..."
651 );
652 cmd.doIt();
653 return false;
654 }
655
656 public void undoIt() { }
657 } /* end class CommandPrefs */
658
659
660 /***
661 * Command to zoom the diagram on the current editor to
662 * a desired factor.
663 */
664 class CommandZoom extends Command
665 {
666 public CommandZoom() { super("Zoom..."); }
667
668 public boolean doIt()
669 {
670 return false;
671 }
672
673 public void undoIt() { }
674
675 public boolean shouldBeEnabled() { return false; }
676 } /* end class CommandZoom */
677
678
679 /***
680 * Command to zoom the diagram in one increment on the current editor.
681 */
682 class CommandZoomIn extends Command
683 {
684 public CommandZoomIn() { super("Zoom In"); }
685
686 public boolean doIt()
687 {
688 return false;
689 }
690
691 public void undoIt() { }
692
693 public boolean shouldBeEnabled() { return false; }
694
695 protected String getIconName() { return "ZoomIn16"; }
696 } /* end class CommandZoomIn */
697
698
699 /***
700 * Command to zoom the diagram out one increment on the current editor.
701 */
702 class CommandZoomOut extends Command
703 {
704 public CommandZoomOut() { super("Zoom Out"); }
705
706 public boolean doIt()
707 {
708 return false;
709 }
710
711 public void undoIt() { }
712
713 public boolean shouldBeEnabled() { return false; }
714
715 protected String getIconName() { return "ZoomOut16"; }
716 } /* end class CommandZoomOut */
717
718
719 /***
720 * Command to go to the editor with a selected relation.
721 */
722 class CommandGoto extends Command
723 {
724 public CommandGoto() { super("Goto"); }
725
726 public boolean doIt()
727 {
728 return false;
729 }
730
731 public void undoIt() { }
732
733 public boolean shouldBeEnabled() { return false; }
734 } /* end class CommandGoto */
735
736
737 /***
738 * Command to adjust the grid size on the current editor.
739 */
740 class CommandAdjustGrid extends Command
741 {
742 public CommandAdjustGrid() { super("Adjust Grid"); }
743
744 public boolean doIt()
745 {
746 return false;
747 }
748
749 public void undoIt() { }
750
751 public boolean shouldBeEnabled() { return false; }
752 } /* end class CommandAdjustGrid */
753
754
755 /***
756 * Command to adjust the grid snap on the current editor.
757 */
758 class CommandAdjustSnap extends Command
759 {
760 public CommandAdjustSnap() { super("Adjust Snap"); }
761
762 public boolean doIt()
763 {
764 return false;
765 }
766
767 public void undoIt() { }
768
769 public boolean shouldBeEnabled() { return false; }
770 } /* end class CommandAdjustSnap */
771
772
773 /***
774 * Command to adjust the page breaks on the current editor.
775 */
776 class CommandAdjustPageBreak extends Command
777 {
778 public CommandAdjustPageBreak() { super("Adjust Page Break"); }
779
780 public boolean doIt()
781 {
782 return false;
783 }
784
785 public void undoIt() { }
786
787 public boolean shouldBeEnabled() { return false; }
788 } /* end class CommandAdjustPageBreak */
789
790
791 /***
792 * Command to select a target database and define login parameters.
793 */
794 class CommandTargetDatabase extends Command
795 {
796 public CommandTargetDatabase() { super("Target Database..."); }
797
798 public boolean doIt()
799 {
800 Project p = ErjFrame.getInstance().getApplication().getCurrentProject();
801 TargetDatabaseDialog dialog = new TargetDatabaseDialog(p);
802 dialog.show();
803 return false;
804 }
805
806 public void undoIt() { }
807
808 } /* end class CommandTargetDatabase */
809
810
811 /***
812 * Command to bring up an editor on the project properties.
813 */
814 class CommandProjectProps extends Command
815 {
816 public CommandProjectProps()
817 {
818 super("Project Properties...");
819 //Project takes care of modification flagging itself
820 //setModifiesProject();
821 }
822
823 public boolean doIt()
824 {
825 Project p = ErjFrame.getInstance().getApplication().getCurrentProject();
826 ProjectPropertiesDialog dialog = new ProjectPropertiesDialog(p);
827 dialog.show();
828 return false;
829 }
830
831 public void undoIt() { }
832
833 } /* end class CommandProjectProps */
834
835
836 /***
837 * Command to generate SQL DDL scripts from a model.
838 */
839 class CommandGenerate extends Command
840 {
841 public CommandGenerate() { super("Generate..."); }
842
843 public boolean doIt()
844 {
845 Project p = ErjFrame.getInstance().getApplication().getCurrentProject();
846 GenerateDDLDialog dialog = new GenerateDDLDialog(p);
847 dialog.show();
848 return false;
849 }
850
851 public void undoIt() { }
852
853 } /* end class CommandGenerate */
854
855
856 /***
857 * Command to synchronize the current model with an actual
858 * database schema.
859 */
860 class CommandSynchronize extends Command
861 {
862 public CommandSynchronize() { super("Synchronize..."); }
863
864 public boolean doIt()
865 {
866 return false;
867 }
868
869 public void undoIt() { }
870
871 public boolean shouldBeEnabled() { return false; }
872 } /* end class CommandSynchronize */
873
874
875 /***
876 * Command to auto-arrange figures in the current editor.
877 */
878 class CommandArrange extends Command
879 {
880 public CommandArrange() { super("Arrange"); }
881
882 public boolean doIt()
883 {
884 return false;
885 }
886
887 public void undoIt() { }
888
889 public boolean shouldBeEnabled() { return false; }
890 } /* end class CommandArrange */
891
892
893 /***
894 * Command to bring up ERJ help.
895 */
896 class CommandContents extends Command
897 {
898 public CommandContents() { super("Contents"); }
899
900 public boolean doIt()
901 {
902 return false;
903 }
904
905 public void undoIt() { }
906
907 public boolean shouldBeEnabled() { return false; }
908 } /* end class CommandContents */
909
910
911 /***
912 * Command to bring up information about ERJ.
913 */
914 class CommandAbout extends Command
915 {
916 public CommandAbout() { super("About"); }
917
918 public boolean doIt()
919 {
920 return false;
921 }
922
923 public void undoIt() { }
924
925 public boolean shouldBeEnabled() { return false; }
926 } /* end class CommandAbout */
927
928
929 /***
930 * Command to delete the currently selected diagram tab.
931 * Note: this does not remove anything from the underlying
932 * information model.
933 */
934 class CommandDeleteDiagram extends Command
935 {
936 public CommandDeleteDiagram() { super("Delete Diagram"); }
937
938 public boolean doIt()
939 {
940 // confirm that they really, really want to do this
941 ErjFrame browser = ErjFrame.getInstance();
942 String confirm = "Deleting a diagram cannot be undone.\n\nAre You Sure?";
943 Object[] options = {"OK", "Cancel"};
944 int rez = JOptionPane.showOptionDialog(
945 browser, confirm, "Warning", JOptionPane.DEFAULT_OPTION,
946 JOptionPane.WARNING_MESSAGE, null, options, options[0]
947 );
948 if (rez == JOptionPane.YES_OPTION)
949 {
950 browser.deleteActiveDiagram();
951 setModifiesProject(true);
952 }
953 else
954 {
955 setModifiesProject(false);
956 }
957 return false;
958 }
959
960 public void undoIt() { }
961 } /* end class CommandDeleteDiagram */
962
963
964 /***
965 * Command to rename a diagram, and thus update its
966 * diagram tab title.
967 */
968 class CommandRenameDiagram extends Command
969 {
970 private boolean _canUndo = false;
971 private JTextField _tf = new JTextField(20);
972 private JButton _okButton = new JButton("Ok");
973 private JButton _cancelButton = new JButton("Cancel");
974 private JDialog _dialog;
975 {
976 ErjFrame browser = ErjFrame.getInstance();
977 String msg = "Rename Diagram";
978 _dialog = new JDialog(browser, msg, true);
979 _dialog.setResizable(false);
980 JPanel buttons = new JPanel();
981 buttons.add(_okButton);
982 buttons.add(_cancelButton);
983 Container content = _dialog.getContentPane();
984 content.add(_tf, BorderLayout.CENTER);
985 content.add(buttons, BorderLayout.SOUTH);
986 addActionListeners();
987 _dialog.pack();
988 _dialog.setLocationRelativeTo(browser);
989 }
990
991 public CommandRenameDiagram() { super("Rename Diagram"); }
992
993 public boolean doIt()
994 {
995 ErjFrame browser = ErjFrame.getInstance();
996 _tf.setText(browser.getActiveDiagram().getName());
997 _dialog.show();
998 return _canUndo;
999 }
1000
1001 private void addActionListeners()
1002 {
1003 _okButton.addActionListener(
1004 new ActionListener()
1005 {
1006 public void actionPerformed(ActionEvent e)
1007 {
1008 ErjFrame browser = ErjFrame.getInstance();
1009 Diagram diagram = browser.getActiveDiagram();
1010 try {
1011 diagram.setName(_tf.getText());
1012 } catch (Exception err) {}
1013 CommandRenameDiagram.this.setModifiesProject(true);
1014 CommandRenameDiagram.this._canUndo = true;
1015 _dialog.dispose();
1016 }
1017 }
1018 );
1019 _cancelButton.addActionListener(
1020 new ActionListener()
1021 {
1022 public void actionPerformed(ActionEvent e)
1023 {
1024 CommandRenameDiagram.this.setModifiesProject(false);
1025 CommandRenameDiagram.this._canUndo = false;
1026 _dialog.dispose();
1027 }
1028 }
1029 );
1030 }
1031
1032 public void undoIt() { }
1033 } /* end class CommandRenameDiagram */
1034
1035
1036 /***
1037 * Command to re-define the order of diagrams in a project.
1038 */
1039 class CommandReorderDiagrams extends Command
1040 {
1041 public CommandReorderDiagrams() { super("Reorder Diagrams..."); }
1042
1043 public boolean doIt()
1044 {
1045 return false;
1046 }
1047
1048 public void undoIt() { }
1049
1050 public boolean shouldBeEnabled() { return false; }
1051 } /* end class CommandReorderDiagrams */
1052
1053
1054 //////////////////////////////////////////////////////////
1055 // Useful cross-command components
1056 /***
1057 * Confirm whether to save a modified project.
1058 */
1059 class SaveProjectConfirm
1060 {
1061 public static boolean confirm()
1062 {
1063 ErjFrame browser = ErjFrame.getInstance();
1064 Project p = browser.getApplication().getCurrentProject();
1065 if (p.isModified())
1066 {
1067 String confirm = "Save changes to " + p.getName();
1068 int rez = JOptionPane.showConfirmDialog(
1069 browser, confirm, confirm, JOptionPane.YES_NO_CANCEL_OPTION);
1070 if (rez == JOptionPane.CANCEL_OPTION)
1071 {
1072 return false;
1073 }
1074 else if (rez == JOptionPane.YES_OPTION)
1075 {
1076 Command.Save.invoke();
1077 return true;
1078 }
1079 }
1080 return true;
1081 }
1082 } /* end class SaveProjectConfirm */
This page was automatically generated by Maven