1 package com.bonevich.erj.ui;
2
3 import com.bonevich.erj.ui.editor.*;
4
5 import javax.swing.*;
6 import java.awt.*;
7 import java.awt.event.*;
8
9 /*** Command to open a dialog to edit a model element's
10 * properties.
11 * @see Command */
12 public abstract class CmdProperties extends Command
13 {
14 //////////////////////////////////////////////////////////
15 // Constants
16 protected static final String EDITOR_NAME = "editorName";
17 protected static final String PARENT_WINDOW = "parentWindow";
18
19 //////////////////////////////////////////////////////////
20 // Attributes
21 protected ModelEditor _editor = null;
22 protected JDialog _dialog = null;
23 protected JButton _okBtn = new JButton("OK");
24 protected JButton _applyBtn = new JButton("Apply");
25 protected JButton _cancelBtn = new JButton("Cancel");
26 protected int _mode = 0;
27
28 //////////////////////////////////////////////////////////
29 // Constructors
30 public CmdProperties(String name)
31 {
32 super(name, NOT_GLOBAL);
33 addActionListeners();
34 }
35
36 public boolean doIt()
37 {
38 String editorName = (String) getValue(EDITOR_NAME);
39
40 //FIXME: call cmp.getParent()
41 Window parentWin = (Window) getValue(PARENT_WINDOW);
42 if (parentWin instanceof Frame)
43 {
44 _dialog = new JDialog((Frame) parentWin, editorName, true);
45 }
46 else if (parentWin instanceof JDialog)
47 {
48 _dialog = new JDialog((JDialog) parentWin, editorName, true);
49 }
50 else
51 {
52 System.err.println("No parent window was specified!");
53 return false;
54 }
55 _dialog.setResizable(false);
56 Container content = _dialog.getContentPane();
57
58 //FIXME: leave decision to create a tabbed pane up to editors
59 JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP);
60 _editor = createModelEditor(tabPane);
61 _editor.setWindow(_dialog);
62 tabPane.setSelectedIndex(getMode());
63
64 JPanel btnPane = new JPanel();
65 ( (FlowLayout)btnPane.getLayout() ).setAlignment(FlowLayout.CENTER);
66 btnPane.add(_okBtn);
67 btnPane.add(_applyBtn);
68 btnPane.add(_cancelBtn);
69
70 content.add(tabPane, BorderLayout.CENTER);
71 content.add(btnPane, BorderLayout.SOUTH);
72 _dialog.pack();
73
74 _dialog.setLocationRelativeTo(parentWin);
75 _dialog.show();
76
77 return true;
78 }
79
80 public void undoIt()
81 {
82 System.out.println("Undo does not make sense for CmdProperties");
83 }
84
85 public void setMode(int mode)
86 {
87 _mode = mode;
88 }
89 public int getMode()
90 {
91 return _mode;
92 }
93
94 private void addActionListeners()
95 {
96 _okBtn.addActionListener(
97 new ActionListener()
98 {
99 public void actionPerformed(ActionEvent e)
100 {
101 if (CmdProperties.this._editor.validate())
102 {
103 CmdProperties.this._editor.updateModel();
104 CmdProperties.this._dialog.dispose();
105 }
106 }
107 }
108 );
109
110 _applyBtn.addActionListener(
111 new ActionListener()
112 {
113 public void actionPerformed(ActionEvent e)
114 {
115 if (CmdProperties.this._editor.validate())
116 {
117 CmdProperties.this._editor.updateModel();
118 CmdProperties.this._editor.updateEditor();
119 }
120 }
121 }
122 );
123
124 _cancelBtn.addActionListener(
125 new ActionListener()
126 {
127 public void actionPerformed(ActionEvent e)
128 {
129 CmdProperties.this._dialog.dispose();
130 }
131 }
132 );
133 }
134
135 protected abstract ModelEditor createModelEditor(Component cmp);
136
137 } /* end class CmdProperties */
This page was automatically generated by Maven