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 | |
package org.argouml.uml.diagram.ui; |
39 | |
|
40 | |
import java.awt.BorderLayout; |
41 | |
import java.awt.Component; |
42 | |
import java.awt.Dimension; |
43 | |
import java.awt.FlowLayout; |
44 | |
import java.awt.GridBagConstraints; |
45 | |
import java.awt.GridBagLayout; |
46 | |
import java.awt.Insets; |
47 | |
import java.awt.event.ActionEvent; |
48 | |
import java.awt.event.ActionListener; |
49 | |
|
50 | |
import javax.swing.BoxLayout; |
51 | |
import javax.swing.JButton; |
52 | |
import javax.swing.JCheckBox; |
53 | |
import javax.swing.JLabel; |
54 | |
import javax.swing.JPanel; |
55 | |
|
56 | |
import org.argouml.application.api.Argo; |
57 | |
import org.argouml.configuration.Configuration; |
58 | |
import org.argouml.configuration.ConfigurationKey; |
59 | |
import org.argouml.i18n.Translator; |
60 | |
import org.argouml.kernel.Project; |
61 | |
import org.argouml.kernel.ProjectSettings; |
62 | |
import org.argouml.swingext.JLinkButton; |
63 | |
import org.argouml.ui.ActionProjectSettings; |
64 | |
import org.argouml.ui.ArgoJFontChooser; |
65 | |
import org.argouml.ui.GUIProjectSettingsTabInterface; |
66 | |
import org.argouml.ui.ShadowComboBox; |
67 | |
import org.argouml.uml.diagram.DiagramAppearance; |
68 | |
import org.argouml.uml.diagram.DiagramSettings; |
69 | |
import org.argouml.uml.diagram.DiagramUndoManager; |
70 | |
import org.argouml.util.ArgoFrame; |
71 | |
import org.tigris.gef.undo.Memento; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 951 | public class SettingsTabDiagramAppearance extends JPanel implements |
85 | |
GUIProjectSettingsTabInterface { |
86 | |
|
87 | |
private Project p; |
88 | |
|
89 | |
private JButton jbtnDiagramFont; |
90 | |
private JCheckBox showBoldNames; |
91 | |
private JCheckBox hideBidirectionalArrows; |
92 | |
private ShadowComboBox defaultShadowWidth; |
93 | |
|
94 | |
private String selectedDiagramFontName; |
95 | |
|
96 | |
private int selectedDiagramFontSize; |
97 | |
|
98 | |
private int scope; |
99 | |
|
100 | 1800 | private JLabel jlblDiagramFont = null; |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public SettingsTabDiagramAppearance(int settingsScope) { |
109 | 1800 | super(); |
110 | 1800 | scope = settingsScope; |
111 | 1800 | initialize(); |
112 | 1800 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
private void initialize() { |
118 | |
|
119 | 1800 | this.setLayout(new BorderLayout()); |
120 | 1800 | JPanel top = new JPanel(); |
121 | 1800 | top.setLayout(new BorderLayout()); |
122 | |
|
123 | 1800 | if (scope == Argo.SCOPE_APPLICATION) { |
124 | 900 | JPanel warning = new JPanel(); |
125 | 900 | warning.setLayout(new BoxLayout(warning, BoxLayout.PAGE_AXIS)); |
126 | 900 | JLabel warningLabel = new JLabel( |
127 | |
Translator.localize("label.warning")); |
128 | 900 | warningLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); |
129 | 900 | warning.add(warningLabel); |
130 | |
|
131 | 900 | JLinkButton projectSettings = new JLinkButton(); |
132 | 900 | projectSettings.setAction(new ActionProjectSettings()); |
133 | 900 | projectSettings.setText( |
134 | |
Translator.localize("button.project-settings")); |
135 | 900 | projectSettings.setIcon(null); |
136 | 900 | projectSettings.setAlignmentX(Component.RIGHT_ALIGNMENT); |
137 | 900 | warning.add(projectSettings); |
138 | |
|
139 | 900 | top.add(warning, BorderLayout.NORTH); |
140 | |
} |
141 | |
|
142 | 1800 | JPanel settings = new JPanel(); |
143 | 1800 | settings.setLayout(new GridBagLayout()); |
144 | |
|
145 | 1800 | GridBagConstraints constraints = new GridBagConstraints(); |
146 | 1800 | constraints.anchor = GridBagConstraints.WEST; |
147 | 1800 | constraints.fill = GridBagConstraints.HORIZONTAL; |
148 | 1800 | constraints.gridy = 0; |
149 | 1800 | constraints.gridx = 0; |
150 | 1800 | constraints.gridwidth = 1; |
151 | 1800 | constraints.gridheight = 1; |
152 | 1800 | constraints.weightx = 1.0; |
153 | 1800 | constraints.insets = new Insets(0, 30, 0, 4); |
154 | |
|
155 | 1800 | constraints.gridy = GridBagConstraints.RELATIVE; |
156 | |
|
157 | 1800 | showBoldNames = createCheckBox("label.show-bold-names"); |
158 | 1800 | settings.add(showBoldNames, constraints); |
159 | |
|
160 | 1800 | hideBidirectionalArrows = |
161 | |
createCheckBox("label.hide-bidirectional-arrows"); |
162 | 1800 | settings.add(hideBidirectionalArrows, constraints); |
163 | |
|
164 | 1800 | constraints.insets = new Insets(5, 30, 0, 4); |
165 | 1800 | JPanel defaultShadowWidthPanel = new JPanel(new FlowLayout( |
166 | |
FlowLayout.LEFT, 5, 0)); |
167 | 1800 | JLabel defaultShadowWidthLabel = createLabel( |
168 | |
"label.default-shadow-width"); |
169 | 1800 | defaultShadowWidth = new ShadowComboBox(); |
170 | 1800 | defaultShadowWidthLabel.setLabelFor(defaultShadowWidth); |
171 | 1800 | defaultShadowWidthPanel.add(defaultShadowWidthLabel); |
172 | 1800 | defaultShadowWidthPanel.add(defaultShadowWidth); |
173 | 1800 | settings.add(defaultShadowWidthPanel, constraints); |
174 | |
|
175 | 1800 | jlblDiagramFont = new JLabel(); |
176 | 1800 | jlblDiagramFont.setText(Translator |
177 | |
.localize("label.diagramappearance.diagramfont")); |
178 | 1800 | JPanel fontButtonPanel = new JPanel(new FlowLayout( |
179 | |
FlowLayout.LEFT, 5, 0)); |
180 | 1800 | JButton fontButton = getJbtnDiagramFont(); |
181 | 1800 | jlblDiagramFont.setLabelFor(fontButton); |
182 | 1800 | fontButtonPanel.add(jlblDiagramFont); |
183 | 1800 | fontButtonPanel.add(fontButton); |
184 | 1800 | settings.add(fontButtonPanel, constraints); |
185 | |
|
186 | 1800 | top.add(settings, BorderLayout.CENTER); |
187 | |
|
188 | 1800 | this.add(top, BorderLayout.NORTH); |
189 | 1800 | this.setSize(new Dimension(296, 169)); |
190 | |
|
191 | 1800 | } |
192 | |
|
193 | |
private JButton getJbtnDiagramFont() { |
194 | 1800 | if (jbtnDiagramFont == null) { |
195 | 1800 | jbtnDiagramFont = new JButton( |
196 | |
Translator.localize("label.diagramappearance.changefont")); |
197 | |
|
198 | 1800 | jbtnDiagramFont.addActionListener(new ActionListener() { |
199 | |
public void actionPerformed(ActionEvent e) { |
200 | 11 | ArgoJFontChooser jFontChooser = new ArgoJFontChooser( |
201 | |
ArgoFrame.getFrame(), jbtnDiagramFont, |
202 | |
selectedDiagramFontName, selectedDiagramFontSize); |
203 | 11 | jFontChooser.setVisible(true); |
204 | |
|
205 | 10 | if (jFontChooser.isOk()) { |
206 | 9 | selectedDiagramFontName = jFontChooser.getResultName(); |
207 | 9 | selectedDiagramFontSize = jFontChooser.getResultSize(); |
208 | |
} |
209 | 10 | } |
210 | |
}); |
211 | |
|
212 | |
} |
213 | 1800 | return jbtnDiagramFont; |
214 | |
} |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public void handleSettingsTabRefresh() { |
220 | 143 | if (scope == Argo.SCOPE_APPLICATION) { |
221 | 19 | showBoldNames.setSelected(getBoolean( |
222 | |
DiagramAppearance.KEY_SHOW_BOLD_NAMES)); |
223 | 19 | selectedDiagramFontName = DiagramAppearance.getInstance() |
224 | |
.getConfiguredFontName(); |
225 | 19 | selectedDiagramFontSize = Configuration |
226 | |
.getInteger(DiagramAppearance.KEY_FONT_SIZE); |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | 19 | hideBidirectionalArrows.setSelected(Configuration.getBoolean( |
234 | |
DiagramAppearance.KEY_HIDE_BIDIRECTIONAL_ARROWS, true)); |
235 | 19 | defaultShadowWidth.setSelectedIndex(Configuration.getInteger( |
236 | |
DiagramAppearance.KEY_DEFAULT_SHADOW_WIDTH, 1)); |
237 | |
} |
238 | 143 | if (scope == Argo.SCOPE_PROJECT) { |
239 | 124 | assert p != null; |
240 | 124 | ProjectSettings ps = p.getProjectSettings(); |
241 | 124 | DiagramSettings ds = ps.getDefaultDiagramSettings(); |
242 | |
|
243 | 124 | showBoldNames.setSelected(ds.isShowBoldNames()); |
244 | 124 | selectedDiagramFontName = ds.getFontName(); |
245 | 124 | selectedDiagramFontSize = ds.getFontSize(); |
246 | 124 | hideBidirectionalArrows.setSelected(! |
247 | |
ds.isShowBidirectionalArrows()); |
248 | 124 | defaultShadowWidth.setSelectedIndex( |
249 | |
ds.getDefaultShadowWidth()); |
250 | |
} |
251 | 143 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
protected static boolean getBoolean(ConfigurationKey key) { |
260 | 25 | return Configuration.getBoolean(key, false); |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public void handleSettingsTabSave() { |
267 | 12 | if (scope == Argo.SCOPE_APPLICATION) { |
268 | 0 | Configuration.setBoolean(DiagramAppearance.KEY_SHOW_BOLD_NAMES, |
269 | |
showBoldNames.isSelected()); |
270 | 0 | Configuration.setString(DiagramAppearance.KEY_FONT_NAME, |
271 | |
selectedDiagramFontName); |
272 | 0 | Configuration.setInteger(DiagramAppearance.KEY_FONT_SIZE, |
273 | |
selectedDiagramFontSize); |
274 | 0 | Configuration.setBoolean(DiagramAppearance.KEY_HIDE_BIDIRECTIONAL_ARROWS, |
275 | |
hideBidirectionalArrows.isSelected()); |
276 | 0 | Configuration.setInteger(DiagramAppearance.KEY_DEFAULT_SHADOW_WIDTH, |
277 | |
defaultShadowWidth.getSelectedIndex()); |
278 | |
} |
279 | 12 | if (scope == Argo.SCOPE_PROJECT) { |
280 | 12 | assert p != null; |
281 | 12 | ProjectSettings ps = p.getProjectSettings(); |
282 | 12 | final DiagramSettings ds = ps.getDefaultDiagramSettings(); |
283 | |
|
284 | 12 | ds.setShowBoldNames(showBoldNames.isSelected()); |
285 | 12 | ds.setFontName(selectedDiagramFontName); |
286 | 12 | ds.setFontSize(selectedDiagramFontSize); |
287 | 12 | ds.setDefaultShadowWidth(defaultShadowWidth.getSelectedIndex()); |
288 | 12 | ds.setShowBidirectionalArrows(!hideBidirectionalArrows.isSelected()); |
289 | |
|
290 | |
|
291 | 12 | Memento memento = new Memento() { |
292 | |
public void redo() { |
293 | 12 | ds.notifyOfChangedSettings(); |
294 | 12 | } |
295 | |
|
296 | |
public void undo() { |
297 | 0 | ds.notifyOfChangedSettings(); |
298 | 0 | } |
299 | |
}; |
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | 12 | memento.redo(); |
306 | |
} |
307 | 12 | } |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
public void handleSettingsTabCancel() { |
313 | 6 | handleSettingsTabRefresh(); |
314 | 6 | } |
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
public void handleResetToDefault() { |
320 | 6 | if (scope == Argo.SCOPE_PROJECT) { |
321 | 6 | showBoldNames.setSelected(getBoolean( |
322 | |
DiagramAppearance.KEY_SHOW_BOLD_NAMES)); |
323 | 6 | selectedDiagramFontName = DiagramAppearance.getInstance() |
324 | |
.getConfiguredFontName(); |
325 | 6 | selectedDiagramFontSize = Configuration |
326 | |
.getInteger(DiagramAppearance.KEY_FONT_SIZE); |
327 | 6 | hideBidirectionalArrows.setSelected(Configuration.getBoolean( |
328 | |
DiagramAppearance.KEY_HIDE_BIDIRECTIONAL_ARROWS, true)); |
329 | 6 | defaultShadowWidth.setSelectedIndex(Configuration.getInteger( |
330 | |
DiagramAppearance.KEY_DEFAULT_SHADOW_WIDTH, 1)); |
331 | |
} |
332 | 6 | } |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
public String getTabKey() { |
338 | 119 | return "tab.diagramappearance"; |
339 | |
} |
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
public JPanel getTabPanel() { |
345 | 119 | return this; |
346 | |
} |
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
protected JCheckBox createCheckBox(String key) { |
355 | 3600 | JCheckBox j = new JCheckBox(Translator.localize(key)); |
356 | 3600 | return j; |
357 | |
} |
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
protected JLabel createLabel(String key) { |
366 | 1800 | return new JLabel(Translator.localize(key)); |
367 | |
} |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
protected JButton createButton(String key) { |
376 | 0 | return new JButton(Translator.localize(key)); |
377 | |
} |
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
public void setVisible(boolean arg0) { |
383 | 140 | super.setVisible(arg0); |
384 | 140 | if (arg0) handleSettingsTabRefresh(); |
385 | 140 | } |
386 | |
|
387 | |
public void setProject(Project project) { |
388 | 100 | assert project != null; |
389 | 100 | p = project; |
390 | 100 | } |
391 | |
} |