1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.ui; |
40 | |
|
41 | |
import java.awt.Dimension; |
42 | |
import java.awt.event.ActionEvent; |
43 | |
import java.awt.event.ActionListener; |
44 | |
import java.awt.event.WindowEvent; |
45 | |
import java.awt.event.WindowListener; |
46 | |
import java.util.Iterator; |
47 | |
|
48 | |
import javax.swing.JButton; |
49 | |
import javax.swing.JPanel; |
50 | |
import javax.swing.JTabbedPane; |
51 | |
import javax.swing.SwingConstants; |
52 | |
|
53 | |
import org.argouml.application.api.GUISettingsTabInterface; |
54 | |
import org.argouml.i18n.Translator; |
55 | |
import org.argouml.kernel.Project; |
56 | |
import org.argouml.kernel.ProjectManager; |
57 | |
import org.argouml.util.ArgoDialog; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | 12 | public class ProjectSettingsDialog |
67 | |
extends ArgoDialog implements WindowListener { |
68 | |
|
69 | |
private JButton applyButton; |
70 | |
private JButton resetToDefaultButton; |
71 | |
|
72 | |
private JTabbedPane tabs; |
73 | |
|
74 | |
private boolean doingShow; |
75 | |
|
76 | |
private boolean windowOpen; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public ProjectSettingsDialog() { |
82 | 100 | super(Translator.localize("dialog.file.properties"), |
83 | |
ArgoDialog.OK_CANCEL_OPTION, |
84 | |
true); |
85 | |
|
86 | 100 | tabs = new JTabbedPane(); |
87 | |
|
88 | 100 | applyButton = new JButton(Translator.localize("button.apply")); |
89 | 100 | String mnemonic = Translator.localize("button.apply.mnemonic"); |
90 | 100 | if (mnemonic != null && mnemonic.length() > 0) { |
91 | 100 | applyButton.setMnemonic(mnemonic.charAt(0)); |
92 | |
} |
93 | 100 | applyButton.addActionListener(new ActionListener() { |
94 | |
public void actionPerformed(ActionEvent e) { |
95 | 6 | handleSave(); |
96 | 6 | } |
97 | |
}); |
98 | 100 | addButton(applyButton); |
99 | |
|
100 | 100 | resetToDefaultButton = new JButton( |
101 | |
Translator.localize("button.reset-to-default")); |
102 | 100 | mnemonic = Translator.localize("button.reset-to-default.mnemonic"); |
103 | 100 | if (mnemonic != null && mnemonic.length() > 0) { |
104 | 100 | resetToDefaultButton.setMnemonic(mnemonic.charAt(0)); |
105 | |
} |
106 | 100 | resetToDefaultButton.addActionListener(new ActionListener() { |
107 | |
public void actionPerformed(ActionEvent e) { |
108 | 6 | handleResetToDefault(); |
109 | 6 | } |
110 | |
}); |
111 | 100 | addButton(resetToDefaultButton); |
112 | |
|
113 | |
|
114 | 100 | Iterator iter = GUI.getInstance().getProjectSettingsTabs().iterator(); |
115 | 500 | while (iter.hasNext()) { |
116 | 400 | GUISettingsTabInterface stp = |
117 | |
(GUISettingsTabInterface) iter.next(); |
118 | |
|
119 | 400 | tabs.addTab( |
120 | |
Translator.localize(stp.getTabKey()), |
121 | |
stp.getTabPanel()); |
122 | 400 | } |
123 | |
|
124 | |
|
125 | 100 | final int minimumWidth = 480; |
126 | 100 | tabs.setPreferredSize(new Dimension(Math.max(tabs |
127 | |
.getPreferredSize().width, minimumWidth), tabs |
128 | |
.getPreferredSize().height)); |
129 | |
|
130 | 100 | tabs.setTabPlacement(SwingConstants.LEFT); |
131 | 100 | setContent(tabs); |
132 | 100 | addWindowListener(this); |
133 | 100 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public void showDialog() { |
139 | |
|
140 | 100 | if (doingShow) { |
141 | 0 | return; |
142 | |
} |
143 | 100 | doingShow = true; |
144 | 100 | handleRefresh(); |
145 | 100 | setVisible(true); |
146 | 12 | toFront(); |
147 | 12 | doingShow = false; |
148 | |
|
149 | 12 | } |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public void actionPerformed(ActionEvent ev) { |
156 | 12 | super.actionPerformed(ev); |
157 | 12 | if (ev.getSource() == getOkButton()) { |
158 | 6 | handleSave(); |
159 | 6 | } else if (ev.getSource() == getCancelButton()) { |
160 | 6 | handleCancel(); |
161 | |
} |
162 | 12 | } |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
private void handleSave() { |
168 | 60 | for (int i = 0; i < tabs.getComponentCount(); i++) { |
169 | 48 | Object o = tabs.getComponent(i); |
170 | 48 | if (o instanceof GUISettingsTabInterface) { |
171 | 48 | ((GUISettingsTabInterface) o).handleSettingsTabSave(); |
172 | |
} |
173 | |
} |
174 | 12 | windowOpen = false; |
175 | 12 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
private void handleCancel() { |
181 | 30 | for (int i = 0; i < tabs.getComponentCount(); i++) { |
182 | 24 | Object o = tabs.getComponent(i); |
183 | 24 | if (o instanceof GUISettingsTabInterface) { |
184 | 24 | ((GUISettingsTabInterface) o).handleSettingsTabCancel(); |
185 | |
} |
186 | |
} |
187 | 6 | windowOpen = false; |
188 | 6 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
private void handleRefresh() { |
194 | 500 | for (int i = 0; i < tabs.getComponentCount(); i++) { |
195 | 400 | Object o = tabs.getComponent(i); |
196 | 400 | if (o instanceof GUISettingsTabInterface) { |
197 | 400 | if (o instanceof GUIProjectSettingsTabInterface) { |
198 | |
|
199 | |
|
200 | 400 | Project p = ProjectManager.getManager().getCurrentProject(); |
201 | 400 | ((GUIProjectSettingsTabInterface) o).setProject(p); |
202 | |
} |
203 | 400 | ((GUISettingsTabInterface) o).handleSettingsTabRefresh(); |
204 | |
} |
205 | |
} |
206 | 100 | } |
207 | |
|
208 | |
private void handleOpen() { |
209 | |
|
210 | 200 | if (!windowOpen) { |
211 | 100 | getOkButton().requestFocusInWindow(); |
212 | 100 | windowOpen = true; |
213 | |
} |
214 | 200 | } |
215 | |
|
216 | |
private void handleResetToDefault() { |
217 | 30 | for (int i = 0; i < tabs.getComponentCount(); i++) { |
218 | 24 | Object o = tabs.getComponent(i); |
219 | 24 | if (o instanceof GUISettingsTabInterface) { |
220 | 24 | ((GUISettingsTabInterface) o).handleResetToDefault(); |
221 | |
} |
222 | |
} |
223 | 6 | } |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public void windowActivated(WindowEvent e) { |
229 | 100 | handleOpen(); |
230 | 100 | } |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
public void windowClosed(WindowEvent e) { |
236 | |
|
237 | 12 | } |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
public void windowDeactivated(WindowEvent e) { |
243 | |
|
244 | 51 | } |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
public void windowDeiconified(WindowEvent e) { |
250 | |
|
251 | 0 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
public void windowIconified(WindowEvent e) { |
257 | |
|
258 | 0 | } |
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
public void windowOpened(WindowEvent e) { |
264 | 100 | handleOpen(); |
265 | 100 | } |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
public void windowClosing(WindowEvent e) { |
271 | |
|
272 | 0 | handleCancel(); |
273 | 0 | } |
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
public void showDialog(JPanel tab) { |
281 | |
try { |
282 | 0 | tabs.setSelectedComponent(tab); |
283 | 0 | } catch (Throwable t) { |
284 | |
|
285 | 0 | } |
286 | 0 | showDialog(); |
287 | 0 | } |
288 | |
|
289 | |
} |