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.Font; |
43 | |
import java.awt.Frame; |
44 | |
import java.awt.GraphicsEnvironment; |
45 | |
import java.awt.GridBagConstraints; |
46 | |
import java.awt.GridBagLayout; |
47 | |
import java.awt.Insets; |
48 | |
import java.awt.event.ActionEvent; |
49 | |
import java.awt.event.ActionListener; |
50 | |
|
51 | |
import javax.swing.DefaultListModel; |
52 | |
import javax.swing.JButton; |
53 | |
import javax.swing.JComponent; |
54 | |
import javax.swing.JDialog; |
55 | |
import javax.swing.JLabel; |
56 | |
import javax.swing.JList; |
57 | |
import javax.swing.JPanel; |
58 | |
import javax.swing.JScrollPane; |
59 | |
import javax.swing.event.ListSelectionEvent; |
60 | |
import javax.swing.event.ListSelectionListener; |
61 | |
|
62 | |
import org.argouml.i18n.Translator; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | 10 | public class ArgoJFontChooser extends JDialog { |
70 | |
|
71 | 11 | private JPanel jContentPane = null; |
72 | |
|
73 | 11 | private JList jlstFamilies = null; |
74 | |
|
75 | 11 | private JList jlstSizes = null; |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | 11 | private JLabel jlblFamilies = null; |
82 | |
|
83 | 11 | private JLabel jlblSize = null; |
84 | |
|
85 | 11 | private JLabel jlblPreview = null; |
86 | |
|
87 | 11 | private JButton jbtnOk = null; |
88 | |
|
89 | 11 | private JButton jbtnCancel = null; |
90 | |
|
91 | |
private int resultSize; |
92 | |
|
93 | |
private String resultName; |
94 | |
|
95 | 11 | private boolean isOk = false; |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public ArgoJFontChooser(Frame owner, JComponent parent, String name, |
104 | |
int size) { |
105 | 11 | super(owner, true); |
106 | 11 | setLocationRelativeTo(parent); |
107 | |
|
108 | 11 | this.resultName = name; |
109 | 11 | this.resultSize = size; |
110 | |
|
111 | 11 | initialize(); |
112 | 11 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
private void initialize() { |
118 | 11 | this.setSize(299, 400); |
119 | 11 | this.setTitle(Translator.localize("dialog.fontchooser")); |
120 | 11 | this.setContentPane(getJContentPane()); |
121 | |
|
122 | 11 | updatePreview(); |
123 | 11 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
private JPanel getJContentPane() { |
131 | 11 | if (jContentPane == null) { |
132 | 11 | GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
133 | 11 | gridBagConstraints8.gridx = 4; |
134 | 11 | gridBagConstraints8.anchor = GridBagConstraints.NORTHEAST; |
135 | 11 | gridBagConstraints8.insets = new Insets(0, 0, 5, 5); |
136 | 11 | gridBagConstraints8.weightx = 0.0; |
137 | 11 | gridBagConstraints8.ipadx = 0; |
138 | 11 | gridBagConstraints8.gridy = 5; |
139 | 11 | GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
140 | 11 | gridBagConstraints7.gridx = 3; |
141 | 11 | gridBagConstraints7.fill = GridBagConstraints.NONE; |
142 | 11 | gridBagConstraints7.weightx = 1.0; |
143 | 11 | gridBagConstraints7.anchor = GridBagConstraints.NORTHEAST; |
144 | 11 | gridBagConstraints7.insets = new Insets(0, 0, 5, 5); |
145 | 11 | gridBagConstraints7.weighty = 0.0; |
146 | 11 | gridBagConstraints7.gridwidth = 1; |
147 | 11 | gridBagConstraints7.ipadx = 0; |
148 | 11 | gridBagConstraints7.gridy = 5; |
149 | 11 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
150 | 11 | gridBagConstraints6.gridx = 0; |
151 | 11 | gridBagConstraints6.gridwidth = 5; |
152 | 11 | gridBagConstraints6.fill = GridBagConstraints.HORIZONTAL; |
153 | 11 | gridBagConstraints6.weightx = 1.0; |
154 | 11 | gridBagConstraints6.insets = new Insets(5, 5, 5, 5); |
155 | 11 | gridBagConstraints6.anchor = GridBagConstraints.NORTHWEST; |
156 | 11 | gridBagConstraints6.gridy = 4; |
157 | 11 | jlblPreview = new JLabel(); |
158 | 11 | jlblPreview.setText(Translator |
159 | |
.localize("label.diagramappearance.preview")); |
160 | 11 | jlblPreview.setPreferredSize(new Dimension(52, 50)); |
161 | 11 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
162 | 11 | gridBagConstraints5.gridx = 4; |
163 | 11 | gridBagConstraints5.anchor = GridBagConstraints.NORTHWEST; |
164 | 11 | gridBagConstraints5.insets = new Insets(5, 5, 0, 0); |
165 | 11 | gridBagConstraints5.gridy = 0; |
166 | 11 | jlblSize = new JLabel(); |
167 | 11 | jlblSize.setText(Translator |
168 | |
.localize("label.diagramappearance.fontsize")); |
169 | 11 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
170 | 11 | gridBagConstraints4.gridx = 0; |
171 | 11 | gridBagConstraints4.anchor = GridBagConstraints.NORTHWEST; |
172 | 11 | gridBagConstraints4.insets = new Insets(5, 5, 0, 0); |
173 | 11 | gridBagConstraints4.gridy = 0; |
174 | 11 | jlblFamilies = new JLabel(); |
175 | 11 | jlblFamilies.setText(Translator |
176 | |
.localize("label.diagramappearance.fontlist")); |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | 11 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
188 | 11 | gridBagConstraints1.fill = GridBagConstraints.BOTH; |
189 | 11 | gridBagConstraints1.gridy = 2; |
190 | 11 | gridBagConstraints1.weightx = 0.0; |
191 | 11 | gridBagConstraints1.weighty = 1.0; |
192 | 11 | gridBagConstraints1.insets = new Insets(5, 0, 0, 5); |
193 | 11 | gridBagConstraints1.anchor = GridBagConstraints.NORTHWEST; |
194 | 11 | gridBagConstraints1.gridwidth = 2; |
195 | 11 | gridBagConstraints1.gridx = 4; |
196 | 11 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
197 | 11 | gridBagConstraints.fill = GridBagConstraints.BOTH; |
198 | 11 | gridBagConstraints.gridy = 2; |
199 | 11 | gridBagConstraints.weightx = 1.0; |
200 | 11 | gridBagConstraints.weighty = 1.0; |
201 | 11 | gridBagConstraints.insets = new Insets(5, 5, 0, 5); |
202 | 11 | gridBagConstraints.gridwidth = 4; |
203 | 11 | gridBagConstraints.gridheight = 1; |
204 | 11 | gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; |
205 | 11 | gridBagConstraints.gridx = 0; |
206 | 11 | jContentPane = new JPanel(); |
207 | 11 | jContentPane.setLayout(new GridBagLayout()); |
208 | |
|
209 | 11 | JScrollPane jscpFamilies = new JScrollPane(); |
210 | 11 | jscpFamilies.setViewportView(getJlstFamilies()); |
211 | 11 | JScrollPane jscpSizes = new JScrollPane(); |
212 | 11 | jscpSizes.setViewportView(getJlstSizes()); |
213 | 11 | jContentPane.add(jscpFamilies, gridBagConstraints); |
214 | 11 | jContentPane.add(jscpSizes, gridBagConstraints1); |
215 | |
|
216 | |
|
217 | 11 | jContentPane.add(jlblFamilies, gridBagConstraints4); |
218 | 11 | jContentPane.add(jlblSize, gridBagConstraints5); |
219 | 11 | jContentPane.add(jlblPreview, gridBagConstraints6); |
220 | 11 | jContentPane.add(getJbtnOk(), gridBagConstraints7); |
221 | 11 | jContentPane.add(getJbtnCancel(), gridBagConstraints8); |
222 | |
} |
223 | 11 | return jContentPane; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
private JList getJlstFamilies() { |
232 | 11 | if (jlstFamilies == null) { |
233 | 11 | jlstFamilies = new JList(); |
234 | 11 | jlstFamilies.setModel(new DefaultListModel()); |
235 | |
|
236 | 11 | String[] fontNames = GraphicsEnvironment |
237 | |
.getLocalGraphicsEnvironment() |
238 | |
.getAvailableFontFamilyNames(); |
239 | 792 | for (String fontName : fontNames) { |
240 | 781 | ((DefaultListModel) jlstFamilies.getModel()) |
241 | |
.addElement(fontName); |
242 | |
} |
243 | 11 | jlstFamilies.setSelectedValue(resultName, true); |
244 | |
|
245 | 11 | jlstFamilies.getSelectionModel().addListSelectionListener( |
246 | 11 | new ListSelectionListener() { |
247 | |
public void valueChanged(ListSelectionEvent e) { |
248 | 0 | if (jlstFamilies.getSelectedValue() != null) { |
249 | 0 | resultName = (String) jlstFamilies |
250 | |
.getSelectedValue(); |
251 | 0 | updatePreview(); |
252 | |
} |
253 | 0 | } |
254 | |
}); |
255 | |
} |
256 | 11 | return jlstFamilies; |
257 | |
} |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
private JList getJlstSizes() { |
265 | 11 | if (jlstSizes == null) { |
266 | 11 | jlstSizes = new JList(new Integer[] {Integer.valueOf(8), |
267 | |
Integer.valueOf(9), Integer.valueOf(10), Integer.valueOf(11), |
268 | |
Integer.valueOf(12), Integer.valueOf(14), Integer.valueOf(16), |
269 | |
Integer.valueOf(18), Integer.valueOf(20), Integer.valueOf(22), |
270 | |
Integer.valueOf(24), Integer.valueOf(26), Integer.valueOf(28), |
271 | |
Integer.valueOf(36), Integer.valueOf(48), Integer.valueOf(72) |
272 | |
}); |
273 | 11 | jlstSizes.setSelectedValue(resultSize, true); |
274 | |
|
275 | 11 | jlstSizes.getSelectionModel().addListSelectionListener( |
276 | 11 | new ListSelectionListener() { |
277 | |
public void valueChanged(ListSelectionEvent e) { |
278 | 0 | if (jlstSizes.getSelectedValue() != null) { |
279 | 0 | resultSize = (Integer) jlstSizes |
280 | |
.getSelectedValue(); |
281 | 0 | updatePreview(); |
282 | |
} |
283 | 0 | } |
284 | |
}); |
285 | |
} |
286 | 11 | return jlstSizes; |
287 | |
} |
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
private void updatePreview() { |
294 | 11 | int style = 0; |
295 | |
|
296 | 11 | Font previewFont = new Font(resultName, style, resultSize); |
297 | 11 | jlblPreview.setFont(previewFont); |
298 | 11 | } |
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
private JButton getJbtnOk() { |
306 | 11 | if (jbtnOk == null) { |
307 | 11 | jbtnOk = new JButton(); |
308 | 11 | jbtnOk.setText(Translator.localize("button.ok")); |
309 | |
|
310 | 11 | jbtnOk.addActionListener(new ActionListener() { |
311 | |
public void actionPerformed(ActionEvent e) { |
312 | 9 | isOk = true; |
313 | 9 | dispose(); |
314 | 9 | setVisible(false); |
315 | 9 | } |
316 | |
}); |
317 | |
} |
318 | 11 | return jbtnOk; |
319 | |
} |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
private JButton getJbtnCancel() { |
327 | 11 | if (jbtnCancel == null) { |
328 | 11 | jbtnCancel = new JButton(); |
329 | 11 | jbtnCancel.setText(Translator.localize("button.cancel")); |
330 | |
|
331 | 11 | jbtnCancel.addActionListener(new ActionListener() { |
332 | |
public void actionPerformed(ActionEvent e) { |
333 | 1 | isOk = false; |
334 | 1 | dispose(); |
335 | 1 | setVisible(false); |
336 | 1 | } |
337 | |
}); |
338 | |
} |
339 | 11 | return jbtnCancel; |
340 | |
} |
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
public boolean isOk() { |
348 | 10 | return isOk; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
public String getResultName() { |
357 | 9 | return resultName; |
358 | |
} |
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
public int getResultSize() { |
366 | 9 | return resultSize; |
367 | |
} |
368 | |
} |