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.Color; |
42 | |
import java.awt.event.ItemEvent; |
43 | |
|
44 | |
import javax.swing.JComboBox; |
45 | |
import javax.swing.JLabel; |
46 | |
|
47 | |
import org.argouml.i18n.Translator; |
48 | |
import org.argouml.ui.targetmanager.TargetManager; |
49 | |
import org.tigris.gef.presentation.Fig; |
50 | |
import org.tigris.gef.presentation.FigText; |
51 | |
import org.tigris.gef.ui.ColorRenderer; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public class StylePanelFigText extends StylePanelFig { |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 0 | private static final String[] FONT_NAMES = { |
64 | |
"dialog", "serif", "sanserif", |
65 | |
"monospaced", |
66 | |
}; |
67 | |
|
68 | 0 | private static final Integer[] COMMON_SIZES = { |
69 | |
Integer.valueOf(8), Integer.valueOf(9), |
70 | |
Integer.valueOf(10), Integer.valueOf(12), |
71 | |
Integer.valueOf(16), Integer.valueOf(18), |
72 | |
Integer.valueOf(24), Integer.valueOf(36), |
73 | |
Integer.valueOf(48), Integer.valueOf(72), |
74 | |
Integer.valueOf(96), |
75 | |
}; |
76 | |
|
77 | 0 | private static final String[] STYLES = { |
78 | |
"Plain", "Bold", "Italic", |
79 | |
"Bold-Italic", |
80 | |
}; |
81 | |
|
82 | 0 | private static final String[] JUSTIFIES = { |
83 | |
"Left", "Right", "Center", |
84 | |
}; |
85 | |
|
86 | 0 | private JLabel fontLabel = new JLabel( |
87 | |
Translator.localize("label.stylepane.font") + ": "); |
88 | |
|
89 | 0 | private JComboBox fontField = new JComboBox(FONT_NAMES); |
90 | |
|
91 | 0 | private JLabel sizeLabel = new JLabel( |
92 | |
Translator.localize("label.stylepane.size") + ": "); |
93 | |
|
94 | 0 | private JComboBox sizeField = new JComboBox(COMMON_SIZES); |
95 | |
|
96 | 0 | private JLabel styleLabel = new JLabel( |
97 | |
Translator.localize("label.stylepane.style") + ": "); |
98 | |
|
99 | 0 | private JComboBox styleField = new JComboBox(STYLES); |
100 | |
|
101 | 0 | private JLabel justLabel = new JLabel( |
102 | |
Translator.localize("label.stylepane.justify") + ": "); |
103 | |
|
104 | 0 | private JComboBox justField = new JComboBox(JUSTIFIES); |
105 | |
|
106 | 0 | private JLabel textColorLabel = new JLabel( |
107 | |
Translator.localize("label.stylepane.text-color") + ": "); |
108 | |
|
109 | 0 | private JComboBox textColorField = new JComboBox(); |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public StylePanelFigText() { |
115 | 0 | super(); |
116 | |
|
117 | 0 | fontField.addItemListener(this); |
118 | 0 | sizeField.addItemListener(this); |
119 | 0 | styleField.addItemListener(this); |
120 | 0 | justField.addItemListener(this); |
121 | 0 | textColorField.addItemListener(this); |
122 | |
|
123 | 0 | textColorField.setRenderer(new ColorRenderer()); |
124 | |
|
125 | 0 | textColorLabel.setLabelFor(textColorField); |
126 | 0 | add(textColorLabel); |
127 | 0 | add(textColorField); |
128 | |
|
129 | 0 | addSeperator(); |
130 | |
|
131 | 0 | fontLabel.setLabelFor(fontField); |
132 | 0 | add(fontLabel); |
133 | 0 | add(fontField); |
134 | |
|
135 | 0 | sizeLabel.setLabelFor(sizeField); |
136 | 0 | add(sizeLabel); |
137 | 0 | add(sizeField); |
138 | |
|
139 | 0 | styleLabel.setLabelFor(styleField); |
140 | 0 | add(styleLabel); |
141 | 0 | add(styleField); |
142 | |
|
143 | 0 | justLabel.setLabelFor(justField); |
144 | 0 | add(justLabel); |
145 | 0 | add(justField); |
146 | |
|
147 | 0 | initChoices2(); |
148 | 0 | } |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
protected void initChoices2() { |
154 | 0 | textColorField.addItem(Color.black); |
155 | 0 | textColorField.addItem(Color.white); |
156 | 0 | textColorField.addItem(Color.gray); |
157 | 0 | textColorField.addItem(Color.lightGray); |
158 | 0 | textColorField.addItem(Color.darkGray); |
159 | 0 | textColorField.addItem(Color.red); |
160 | 0 | textColorField.addItem(Color.blue); |
161 | 0 | textColorField.addItem(Color.green); |
162 | 0 | textColorField.addItem(Color.orange); |
163 | 0 | textColorField.addItem(Color.pink); |
164 | 0 | textColorField.addItem(getCustomItemName()); |
165 | |
|
166 | 0 | } |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public void refresh() { |
174 | 0 | if (TargetManager.getInstance().getTargets().size() > 1) { |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | 0 | return; |
180 | |
} |
181 | 0 | super.refresh(); |
182 | 0 | FigText ft = (FigText) getPanelTarget(); |
183 | 0 | if (ft == null) { |
184 | 0 | return; |
185 | |
} |
186 | 0 | String fontName = ft.getFontFamily().toLowerCase(); |
187 | 0 | int size = ft.getFontSize(); |
188 | 0 | String styleName = STYLES[0]; |
189 | |
|
190 | 0 | fontField.setSelectedItem(fontName); |
191 | 0 | sizeField.setSelectedItem(Integer.valueOf(size)); |
192 | 0 | if (ft.getBold()) { |
193 | 0 | styleName = STYLES[1]; |
194 | |
} |
195 | 0 | if (ft.getItalic()) { |
196 | 0 | styleName = STYLES[2]; |
197 | |
} |
198 | 0 | if (ft.getBold() && ft.getItalic()) { |
199 | 0 | styleName = STYLES[3]; |
200 | |
} |
201 | 0 | styleField.setSelectedItem(styleName); |
202 | |
|
203 | 0 | String justName = JUSTIFIES[0]; |
204 | 0 | int justCode = ft.getJustification(); |
205 | 0 | if (justCode >= 0 && justCode <= JUSTIFIES.length) { |
206 | 0 | justName = JUSTIFIES[justCode]; |
207 | |
} |
208 | 0 | justField.setSelectedItem(justName); |
209 | |
|
210 | 0 | Color c = ft.getTextColor(); |
211 | 0 | textColorField.setSelectedItem(c); |
212 | 0 | if (c != null && !textColorField.getSelectedItem().equals(c)) { |
213 | 0 | textColorField.insertItemAt(c, textColorField.getItemCount() - 1); |
214 | 0 | textColorField.setSelectedItem(c); |
215 | |
} |
216 | |
|
217 | 0 | if (ft.isFilled()) { |
218 | 0 | Color fc = ft.getFillColor(); |
219 | 0 | getFillField().setSelectedItem(fc); |
220 | 0 | if (fc != null && !getFillField().getSelectedItem().equals(fc)) { |
221 | 0 | getFillField().insertItemAt(fc, |
222 | |
getFillField().getItemCount() - 1); |
223 | 0 | getFillField().setSelectedItem(fc); |
224 | |
} |
225 | 0 | } else { |
226 | 0 | getFillField().setSelectedIndex(0); |
227 | |
} |
228 | 0 | } |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
protected void setTargetFont() { |
234 | 0 | if (getPanelTarget() == null) { |
235 | 0 | return; |
236 | |
} |
237 | 0 | String fontStr = (String) fontField.getSelectedItem(); |
238 | 0 | if (fontStr.length() == 0) { |
239 | 0 | return; |
240 | |
} |
241 | 0 | ((FigText) getPanelTarget()).setFontFamily(fontStr); |
242 | 0 | getPanelTarget().endTrans(); |
243 | 0 | } |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
protected void setTargetSize() { |
249 | 0 | if (getPanelTarget() == null) { |
250 | 0 | return; |
251 | |
} |
252 | 0 | Integer size = (Integer) sizeField.getSelectedItem(); |
253 | 0 | ((FigText) getPanelTarget()).setFontSize(size.intValue()); |
254 | 0 | getPanelTarget().endTrans(); |
255 | 0 | } |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
protected void setTargetStyle() { |
262 | 0 | if (getPanelTarget() == null) { |
263 | 0 | return; |
264 | |
} |
265 | 0 | String styleStr = (String) styleField.getSelectedItem(); |
266 | 0 | if (styleStr == null) { |
267 | 0 | return; |
268 | |
} |
269 | 0 | boolean bold = (styleStr.indexOf("Bold") != -1); |
270 | 0 | boolean italic = (styleStr.indexOf("Italic") != -1); |
271 | 0 | ((FigText) getPanelTarget()).setBold(bold); |
272 | 0 | ((FigText) getPanelTarget()).setItalic(italic); |
273 | 0 | getPanelTarget().endTrans(); |
274 | 0 | } |
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
protected void setTargetJustification() { |
280 | 0 | if (getPanelTarget() == null) { |
281 | 0 | return; |
282 | |
} |
283 | 0 | String justStr = (String) justField.getSelectedItem(); |
284 | 0 | if (justStr == null) { |
285 | 0 | return; |
286 | |
} |
287 | 0 | ((FigText) getPanelTarget()).setJustificationByName(justStr); |
288 | 0 | getPanelTarget().endTrans(); |
289 | 0 | } |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
protected void setTargetTextColor() { |
297 | 0 | if (getPanelTarget() == null) { |
298 | 0 | return; |
299 | |
} |
300 | 0 | Object c = textColorField.getSelectedItem(); |
301 | 0 | if (c instanceof Color) { |
302 | 0 | ((FigText) getPanelTarget()).setTextColor((Color) c); |
303 | |
} |
304 | 0 | getPanelTarget().endTrans(); |
305 | 0 | } |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
public void itemStateChanged(ItemEvent e) { |
311 | 0 | Object src = e.getSource(); |
312 | 0 | Fig target = getPanelTarget(); |
313 | 0 | if (e.getStateChange() == ItemEvent.SELECTED |
314 | |
&& target instanceof FigText) { |
315 | 0 | if (src == fontField) { |
316 | 0 | setTargetFont(); |
317 | 0 | } else if (src == sizeField) { |
318 | 0 | setTargetSize(); |
319 | 0 | } else if (src == styleField) { |
320 | 0 | setTargetStyle(); |
321 | 0 | } else if (src == justField) { |
322 | 0 | setTargetJustification(); |
323 | 0 | } else if (src == textColorField) { |
324 | 0 | if (e.getItem() == getCustomItemName()) { |
325 | 0 | handleCustomColor(textColorField, |
326 | |
"label.stylepane.custom-text-color", |
327 | |
((FigText) target).getTextColor()); |
328 | |
} |
329 | 0 | setTargetTextColor(); |
330 | |
} else { |
331 | 0 | super.itemStateChanged(e); |
332 | |
} |
333 | |
} |
334 | 0 | } |
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
private static final long serialVersionUID = 2019248527481196634L; |
341 | |
} |