author | alexsch |
Wed, 25 Sep 2013 17:08:31 +0400 | |
changeset 20168 | 137788883a22 |
parent 9035 | 1255eb81cc2f |
child 25173 | 4f093fa54fa1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8376
diff
changeset
|
2 |
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing.plaf.synth; |
|
26 |
||
27 |
import sun.swing.SwingUtilities2; |
|
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
28 |
import sun.swing.MenuItemLayoutHelper; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
29 |
|
2 | 30 |
import java.awt.*; |
31 |
import javax.swing.*; |
|
32 |
import javax.swing.plaf.basic.BasicHTML; |
|
33 |
import javax.swing.text.*; |
|
34 |
import sun.swing.plaf.synth.*; |
|
35 |
||
36 |
/** |
|
37 |
* Wrapper for primitive graphics calls. |
|
38 |
* |
|
39 |
* @since 1.5 |
|
40 |
* @author Scott Violet |
|
41 |
*/ |
|
42 |
public class SynthGraphicsUtils { |
|
43 |
// These are used in the text painting code to avoid allocating a bunch of |
|
44 |
// garbage. |
|
45 |
private Rectangle paintIconR = new Rectangle(); |
|
46 |
private Rectangle paintTextR = new Rectangle(); |
|
47 |
private Rectangle paintViewR = new Rectangle(); |
|
48 |
private Insets paintInsets = new Insets(0, 0, 0, 0); |
|
49 |
||
50 |
// These Rectangles/Insets are used in the text size calculation to avoid a |
|
51 |
// a bunch of garbage. |
|
52 |
private Rectangle iconR = new Rectangle(); |
|
53 |
private Rectangle textR = new Rectangle(); |
|
54 |
private Rectangle viewR = new Rectangle(); |
|
55 |
private Insets viewSizingInsets = new Insets(0, 0, 0, 0); |
|
56 |
||
57 |
/** |
|
58 |
* Creates a <code>SynthGraphicsUtils</code>. |
|
59 |
*/ |
|
60 |
public SynthGraphicsUtils() { |
|
61 |
} |
|
62 |
||
63 |
/** |
|
64 |
* Draws a line between the two end points. |
|
65 |
* |
|
66 |
* @param context Identifies hosting region. |
|
67 |
* @param paintKey Identifies the portion of the component being asked |
|
68 |
* to paint, may be null. |
|
69 |
* @param g Graphics object to paint to |
|
70 |
* @param x1 x origin |
|
71 |
* @param y1 y origin |
|
72 |
* @param x2 x destination |
|
73 |
* @param y2 y destination |
|
74 |
*/ |
|
75 |
public void drawLine(SynthContext context, Object paintKey, |
|
76 |
Graphics g, int x1, int y1, int x2, int y2) { |
|
77 |
g.drawLine(x1, y1, x2, y2); |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Draws a line between the two end points. |
|
82 |
* <p>This implementation supports only one line style key, |
|
83 |
* <code>"dashed"</code>. The <code>"dashed"</code> line style is applied |
|
84 |
* only to vertical and horizontal lines. |
|
85 |
* <p>Specifying <code>null</code> or any key different from |
|
86 |
* <code>"dashed"</code> will draw solid lines. |
|
87 |
* |
|
88 |
* @param context identifies hosting region |
|
89 |
* @param paintKey identifies the portion of the component being asked |
|
90 |
* to paint, may be null |
|
91 |
* @param g Graphics object to paint to |
|
92 |
* @param x1 x origin |
|
93 |
* @param y1 y origin |
|
94 |
* @param x2 x destination |
|
95 |
* @param y2 y destination |
|
96 |
* @param styleKey identifies the requested style of the line (e.g. "dashed") |
|
97 |
* @since 1.6 |
|
98 |
*/ |
|
99 |
public void drawLine(SynthContext context, Object paintKey, |
|
100 |
Graphics g, int x1, int y1, int x2, int y2, |
|
101 |
Object styleKey) { |
|
102 |
if ("dashed".equals(styleKey)) { |
|
103 |
// draw vertical line |
|
104 |
if (x1 == x2) { |
|
105 |
y1 += (y1 % 2); |
|
106 |
||
107 |
for (int y = y1; y <= y2; y+=2) { |
|
108 |
g.drawLine(x1, y, x2, y); |
|
109 |
} |
|
110 |
// draw horizontal line |
|
111 |
} else if (y1 == y2) { |
|
112 |
x1 += (x1 % 2); |
|
113 |
||
114 |
for (int x = x1; x <= x2; x+=2) { |
|
115 |
g.drawLine(x, y1, x, y2); |
|
116 |
} |
|
117 |
// oblique lines are not supported |
|
118 |
} |
|
119 |
} else { |
|
120 |
drawLine(context, paintKey, g, x1, y1, x2, y2); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Lays out text and an icon returning, by reference, the location to |
|
126 |
* place the icon and text. |
|
127 |
* |
|
128 |
* @param ss SynthContext |
|
129 |
* @param fm FontMetrics for the Font to use, this may be ignored |
|
130 |
* @param text Text to layout |
|
131 |
* @param icon Icon to layout |
|
132 |
* @param hAlign horizontal alignment |
|
133 |
* @param vAlign vertical alignment |
|
134 |
* @param hTextPosition horizontal text position |
|
135 |
* @param vTextPosition vertical text position |
|
136 |
* @param viewR Rectangle to layout text and icon in. |
|
137 |
* @param iconR Rectangle to place icon bounds in |
|
138 |
* @param textR Rectangle to place text in |
|
139 |
* @param iconTextGap gap between icon and text |
|
140 |
*/ |
|
141 |
public String layoutText(SynthContext ss, FontMetrics fm, |
|
142 |
String text, Icon icon, int hAlign, |
|
143 |
int vAlign, int hTextPosition, |
|
144 |
int vTextPosition, Rectangle viewR, |
|
145 |
Rectangle iconR, Rectangle textR, int iconTextGap) { |
|
146 |
if (icon instanceof SynthIcon) { |
|
147 |
SynthIconWrapper wrapper = SynthIconWrapper.get((SynthIcon)icon, |
|
148 |
ss); |
|
149 |
String formattedText = SwingUtilities.layoutCompoundLabel( |
|
150 |
ss.getComponent(), fm, text, wrapper, vAlign, hAlign, |
|
151 |
vTextPosition, hTextPosition, viewR, iconR, textR, |
|
152 |
iconTextGap); |
|
153 |
SynthIconWrapper.release(wrapper); |
|
154 |
return formattedText; |
|
155 |
} |
|
156 |
return SwingUtilities.layoutCompoundLabel( |
|
157 |
ss.getComponent(), fm, text, icon, vAlign, hAlign, |
|
158 |
vTextPosition, hTextPosition, viewR, iconR, textR, |
|
159 |
iconTextGap); |
|
160 |
} |
|
161 |
||
162 |
/** |
|
163 |
* Returns the size of the passed in string. |
|
164 |
* |
|
165 |
* @param ss SynthContext |
|
166 |
* @param font Font to use |
|
167 |
* @param metrics FontMetrics, may be ignored |
|
168 |
* @param text Text to get size of. |
|
169 |
*/ |
|
170 |
public int computeStringWidth(SynthContext ss, Font font, |
|
171 |
FontMetrics metrics, String text) { |
|
172 |
return SwingUtilities2.stringWidth(ss.getComponent(), metrics, |
|
173 |
text); |
|
174 |
} |
|
175 |
||
176 |
/** |
|
177 |
* Returns the minimum size needed to properly render an icon and text. |
|
178 |
* |
|
179 |
* @param ss SynthContext |
|
180 |
* @param font Font to use |
|
181 |
* @param text Text to layout |
|
182 |
* @param icon Icon to layout |
|
183 |
* @param hAlign horizontal alignment |
|
184 |
* @param vAlign vertical alignment |
|
185 |
* @param hTextPosition horizontal text position |
|
186 |
* @param vTextPosition vertical text position |
|
187 |
* @param iconTextGap gap between icon and text |
|
188 |
* @param mnemonicIndex Index into text to render the mnemonic at, -1 |
|
189 |
* indicates no mnemonic. |
|
190 |
*/ |
|
191 |
public Dimension getMinimumSize(SynthContext ss, Font font, String text, |
|
192 |
Icon icon, int hAlign, int vAlign, int hTextPosition, |
|
193 |
int vTextPosition, int iconTextGap, int mnemonicIndex) { |
|
194 |
JComponent c = ss.getComponent(); |
|
195 |
Dimension size = getPreferredSize(ss, font, text, icon, hAlign, |
|
196 |
vAlign, hTextPosition, vTextPosition, |
|
197 |
iconTextGap, mnemonicIndex); |
|
198 |
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
|
199 |
||
200 |
if (v != null) { |
|
201 |
size.width -= v.getPreferredSpan(View.X_AXIS) - |
|
202 |
v.getMinimumSpan(View.X_AXIS); |
|
203 |
} |
|
204 |
return size; |
|
205 |
} |
|
206 |
||
207 |
/** |
|
208 |
* Returns the maximum size needed to properly render an icon and text. |
|
209 |
* |
|
210 |
* @param ss SynthContext |
|
211 |
* @param font Font to use |
|
212 |
* @param text Text to layout |
|
213 |
* @param icon Icon to layout |
|
214 |
* @param hAlign horizontal alignment |
|
215 |
* @param vAlign vertical alignment |
|
216 |
* @param hTextPosition horizontal text position |
|
217 |
* @param vTextPosition vertical text position |
|
218 |
* @param iconTextGap gap between icon and text |
|
219 |
* @param mnemonicIndex Index into text to render the mnemonic at, -1 |
|
220 |
* indicates no mnemonic. |
|
221 |
*/ |
|
222 |
public Dimension getMaximumSize(SynthContext ss, Font font, String text, |
|
223 |
Icon icon, int hAlign, int vAlign, int hTextPosition, |
|
224 |
int vTextPosition, int iconTextGap, int mnemonicIndex) { |
|
225 |
JComponent c = ss.getComponent(); |
|
226 |
Dimension size = getPreferredSize(ss, font, text, icon, hAlign, |
|
227 |
vAlign, hTextPosition, vTextPosition, |
|
228 |
iconTextGap, mnemonicIndex); |
|
229 |
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
|
230 |
||
231 |
if (v != null) { |
|
232 |
size.width += v.getMaximumSpan(View.X_AXIS) - |
|
233 |
v.getPreferredSpan(View.X_AXIS); |
|
234 |
} |
|
235 |
return size; |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Returns the maximum height of the the Font from the passed in |
|
240 |
* SynthContext. |
|
241 |
* |
|
242 |
* @param context SynthContext used to determine font. |
|
243 |
* @return maximum height of the characters for the font from the passed |
|
244 |
* in context. |
|
245 |
*/ |
|
246 |
public int getMaximumCharHeight(SynthContext context) { |
|
247 |
FontMetrics fm = context.getComponent().getFontMetrics( |
|
248 |
context.getStyle().getFont(context)); |
|
249 |
return (fm.getAscent() + fm.getDescent()); |
|
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* Returns the preferred size needed to properly render an icon and text. |
|
254 |
* |
|
255 |
* @param ss SynthContext |
|
256 |
* @param font Font to use |
|
257 |
* @param text Text to layout |
|
258 |
* @param icon Icon to layout |
|
259 |
* @param hAlign horizontal alignment |
|
260 |
* @param vAlign vertical alignment |
|
261 |
* @param hTextPosition horizontal text position |
|
262 |
* @param vTextPosition vertical text position |
|
263 |
* @param iconTextGap gap between icon and text |
|
264 |
* @param mnemonicIndex Index into text to render the mnemonic at, -1 |
|
265 |
* indicates no mnemonic. |
|
266 |
*/ |
|
267 |
public Dimension getPreferredSize(SynthContext ss, Font font, String text, |
|
268 |
Icon icon, int hAlign, int vAlign, int hTextPosition, |
|
269 |
int vTextPosition, int iconTextGap, int mnemonicIndex) { |
|
270 |
JComponent c = ss.getComponent(); |
|
271 |
Insets insets = c.getInsets(viewSizingInsets); |
|
272 |
int dx = insets.left + insets.right; |
|
273 |
int dy = insets.top + insets.bottom; |
|
274 |
||
275 |
if (icon == null && (text == null || font == null)) { |
|
276 |
return new Dimension(dx, dy); |
|
277 |
} |
|
278 |
else if ((text == null) || ((icon != null) && (font == null))) { |
|
279 |
return new Dimension(SynthIcon.getIconWidth(icon, ss) + dx, |
|
280 |
SynthIcon.getIconHeight(icon, ss) + dy); |
|
281 |
} |
|
282 |
else { |
|
283 |
FontMetrics fm = c.getFontMetrics(font); |
|
284 |
||
285 |
iconR.x = iconR.y = iconR.width = iconR.height = 0; |
|
286 |
textR.x = textR.y = textR.width = textR.height = 0; |
|
287 |
viewR.x = dx; |
|
288 |
viewR.y = dy; |
|
289 |
viewR.width = viewR.height = Short.MAX_VALUE; |
|
290 |
||
291 |
layoutText(ss, fm, text, icon, hAlign, vAlign, |
|
292 |
hTextPosition, vTextPosition, viewR, iconR, textR, |
|
293 |
iconTextGap); |
|
294 |
int x1 = Math.min(iconR.x, textR.x); |
|
295 |
int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width); |
|
296 |
int y1 = Math.min(iconR.y, textR.y); |
|
297 |
int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height); |
|
298 |
Dimension rv = new Dimension(x2 - x1, y2 - y1); |
|
299 |
||
300 |
rv.width += dx; |
|
301 |
rv.height += dy; |
|
302 |
return rv; |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
/** |
|
307 |
* Paints text at the specified location. This will not attempt to |
|
308 |
* render the text as html nor will it offset by the insets of the |
|
309 |
* component. |
|
310 |
* |
|
311 |
* @param ss SynthContext |
|
312 |
* @param g Graphics used to render string in. |
|
313 |
* @param text Text to render |
|
314 |
* @param bounds Bounds of the text to be drawn. |
|
315 |
* @param mnemonicIndex Index to draw string at. |
|
316 |
*/ |
|
317 |
public void paintText(SynthContext ss, Graphics g, String text, |
|
318 |
Rectangle bounds, int mnemonicIndex) { |
|
319 |
paintText(ss, g, text, bounds.x, bounds.y, mnemonicIndex); |
|
320 |
} |
|
321 |
||
322 |
/** |
|
323 |
* Paints text at the specified location. This will not attempt to |
|
324 |
* render the text as html nor will it offset by the insets of the |
|
325 |
* component. |
|
326 |
* |
|
327 |
* @param ss SynthContext |
|
328 |
* @param g Graphics used to render string in. |
|
329 |
* @param text Text to render |
|
330 |
* @param x X location to draw text at. |
|
331 |
* @param y Upper left corner to draw text at. |
|
332 |
* @param mnemonicIndex Index to draw string at. |
|
333 |
*/ |
|
334 |
public void paintText(SynthContext ss, Graphics g, String text, |
|
335 |
int x, int y, int mnemonicIndex) { |
|
336 |
if (text != null) { |
|
337 |
JComponent c = ss.getComponent(); |
|
338 |
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); |
|
339 |
y += fm.getAscent(); |
|
340 |
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, |
|
341 |
mnemonicIndex, x, y); |
|
342 |
} |
|
343 |
} |
|
344 |
||
345 |
/** |
|
346 |
* Paints an icon and text. This will render the text as html, if |
|
347 |
* necessary, and offset the location by the insets of the component. |
|
348 |
* |
|
349 |
* @param ss SynthContext |
|
350 |
* @param g Graphics to render string and icon into |
|
351 |
* @param text Text to layout |
|
352 |
* @param icon Icon to layout |
|
353 |
* @param hAlign horizontal alignment |
|
354 |
* @param vAlign vertical alignment |
|
355 |
* @param hTextPosition horizontal text position |
|
356 |
* @param vTextPosition vertical text position |
|
357 |
* @param iconTextGap gap between icon and text |
|
358 |
* @param mnemonicIndex Index into text to render the mnemonic at, -1 |
|
359 |
* indicates no mnemonic. |
|
360 |
* @param textOffset Amount to offset the text when painting |
|
361 |
*/ |
|
362 |
public void paintText(SynthContext ss, Graphics g, String text, |
|
363 |
Icon icon, int hAlign, int vAlign, int hTextPosition, |
|
364 |
int vTextPosition, int iconTextGap, int mnemonicIndex, |
|
365 |
int textOffset) { |
|
366 |
if ((icon == null) && (text == null)) { |
|
367 |
return; |
|
368 |
} |
|
369 |
JComponent c = ss.getComponent(); |
|
370 |
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); |
|
371 |
Insets insets = SynthLookAndFeel.getPaintingInsets(ss, paintInsets); |
|
372 |
||
373 |
paintViewR.x = insets.left; |
|
374 |
paintViewR.y = insets.top; |
|
375 |
paintViewR.width = c.getWidth() - (insets.left + insets.right); |
|
376 |
paintViewR.height = c.getHeight() - (insets.top + insets.bottom); |
|
377 |
||
378 |
paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; |
|
379 |
paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; |
|
380 |
||
381 |
String clippedText = |
|
382 |
layoutText(ss, fm, text, icon, hAlign, vAlign, |
|
383 |
hTextPosition, vTextPosition, paintViewR, paintIconR, |
|
384 |
paintTextR, iconTextGap); |
|
385 |
||
386 |
if (icon != null) { |
|
387 |
Color color = g.getColor(); |
|
388 |
||
389 |
if (ss.getStyle().getBoolean(ss, "TableHeader.alignSorterArrow", false) && |
|
390 |
"TableHeader.renderer".equals(c.getName())) { |
|
391 |
paintIconR.x = paintViewR.width - paintIconR.width; |
|
392 |
} else { |
|
393 |
paintIconR.x += textOffset; |
|
394 |
} |
|
395 |
paintIconR.y += textOffset; |
|
396 |
SynthIcon.paintIcon(icon, ss, g, paintIconR.x, paintIconR.y, |
|
397 |
paintIconR.width, paintIconR.height); |
|
398 |
g.setColor(color); |
|
399 |
} |
|
400 |
||
401 |
if (text != null) { |
|
402 |
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
|
403 |
||
404 |
if (v != null) { |
|
405 |
v.paint(g, paintTextR); |
|
406 |
} else { |
|
407 |
paintTextR.x += textOffset; |
|
408 |
paintTextR.y += textOffset; |
|
409 |
||
410 |
paintText(ss, g, clippedText, paintTextR, mnemonicIndex); |
|
411 |
} |
|
412 |
} |
|
413 |
} |
|
414 |
||
415 |
||
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
416 |
/** |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
417 |
* A quick note about how preferred sizes are calculated... Generally |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
418 |
* speaking, SynthPopupMenuUI will run through the list of its children |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
419 |
* (from top to bottom) and ask each for its preferred size. Each menu |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
420 |
* item will add up the max width of each element (icons, text, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
421 |
* accelerator spacing, accelerator text or arrow icon) encountered thus |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
422 |
* far, so by the time all menu items have been calculated, we will |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
423 |
* know the maximum (preferred) menu item size for that popup menu. |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
424 |
* Later when it comes time to paint each menu item, we can use those |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
425 |
* same accumulated max element sizes in order to layout the item. |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
426 |
*/ |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
427 |
static Dimension getPreferredMenuItemSize(SynthContext context, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
428 |
SynthContext accContext, JComponent c, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
429 |
Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
430 |
String acceleratorDelimiter, boolean useCheckAndArrow, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
431 |
String propertyPrefix) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
432 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
433 |
JMenuItem mi = (JMenuItem) c; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
434 |
SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper( |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
435 |
context, accContext, mi, checkIcon, arrowIcon, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
436 |
MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
437 |
acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi), |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
438 |
useCheckAndArrow, propertyPrefix); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
439 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
440 |
Dimension result = new Dimension(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
441 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
442 |
// Calculate the result width |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
443 |
int gap = lh.getGap(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
444 |
result.width = 0; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
445 |
MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
446 |
MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
447 |
MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
448 |
// The last gap is unnecessary |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
449 |
result.width -= gap; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
450 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
451 |
// Calculate the result height |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
452 |
result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(), |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
453 |
lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(), |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
454 |
lh.getArrowSize().getHeight()); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
455 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
456 |
// Take into account menu item insets |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
457 |
Insets insets = lh.getMenuItem().getInsets(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
458 |
if (insets != null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
459 |
result.width += insets.left + insets.right; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
460 |
result.height += insets.top + insets.bottom; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
461 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
462 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
463 |
// if the width is even, bump it up one. This is critical |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
464 |
// for the focus dash lhne to draw properly |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
465 |
if (result.width % 2 == 0) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
466 |
result.width++; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
467 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
468 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
469 |
// if the height is even, bump it up one. This is critical |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
470 |
// for the text to center properly |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
471 |
if (result.height % 2 == 0) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
472 |
result.height++; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
473 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
474 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
475 |
return result; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
476 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
477 |
|
3981
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
478 |
static void applyInsets(Rectangle rect, Insets insets, boolean leftToRight) { |
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
479 |
if (insets != null) { |
3981
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
480 |
rect.x += (leftToRight ? insets.left : insets.right); |
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
481 |
rect.y += insets.top; |
3981
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
482 |
rect.width -= (leftToRight ? insets.right : insets.left) + rect.x; |
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
483 |
rect.height -= (insets.bottom + rect.y); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
484 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
485 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
486 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
487 |
static void paint(SynthContext context, SynthContext accContext, Graphics g, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
488 |
Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
489 |
int defaultTextIconGap, String propertyPrefix) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
490 |
JMenuItem mi = (JMenuItem) context.getComponent(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
491 |
SynthStyle style = context.getStyle(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
492 |
g.setFont(style.getFont(context)); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
493 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
494 |
Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); |
3981
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
495 |
boolean leftToRight = SynthLookAndFeel.isLeftToRight(mi); |
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
496 |
applyInsets(viewRect, mi.getInsets(), leftToRight); |
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
497 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
498 |
SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper( |
3981
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
499 |
context, accContext, mi, checkIcon, arrowIcon, viewRect, |
a219cd45863d
6857888: closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
peterz
parents:
1295
diff
changeset
|
500 |
defaultTextIconGap, acceleratorDelimiter, leftToRight, |
1295
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
501 |
MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
502 |
MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
503 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
504 |
paintMenuItem(g, lh, lr); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
505 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
506 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
507 |
static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
508 |
MenuItemLayoutHelper.LayoutResult lr) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
509 |
// Save original graphics font and color |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
510 |
Font holdf = g.getFont(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
511 |
Color holdc = g.getColor(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
512 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
513 |
paintCheckIcon(g, lh, lr); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
514 |
paintIcon(g, lh, lr); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
515 |
paintText(g, lh, lr); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
516 |
paintAccText(g, lh, lr); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
517 |
paintArrowIcon(g, lh, lr); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
518 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
519 |
// Restore original graphics font and color |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
520 |
g.setColor(holdc); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
521 |
g.setFont(holdf); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
522 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
523 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
524 |
static void paintBackground(Graphics g, SynthMenuItemLayoutHelper lh) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
525 |
paintBackground(lh.getContext(), g, lh.getMenuItem()); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
526 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
527 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
528 |
static void paintBackground(SynthContext context, Graphics g, JComponent c) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
529 |
context.getPainter().paintMenuItemBackground(context, g, 0, 0, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
530 |
c.getWidth(), c.getHeight()); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
531 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
532 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
533 |
static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
534 |
MenuItemLayoutHelper.LayoutResult lr) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
535 |
if (lh.getIcon() != null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
536 |
Icon icon; |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
537 |
JMenuItem mi = lh.getMenuItem(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
538 |
ButtonModel model = mi.getModel(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
539 |
if (!model.isEnabled()) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
540 |
icon = mi.getDisabledIcon(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
541 |
} else if (model.isPressed() && model.isArmed()) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
542 |
icon = mi.getPressedIcon(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
543 |
if (icon == null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
544 |
// Use default icon |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
545 |
icon = mi.getIcon(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
546 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
547 |
} else { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
548 |
icon = mi.getIcon(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
549 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
550 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
551 |
if (icon != null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
552 |
Rectangle iconRect = lr.getIconRect(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
553 |
SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
554 |
iconRect.y, iconRect.width, iconRect.height); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
555 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
556 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
557 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
558 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
559 |
static void paintCheckIcon(Graphics g, SynthMenuItemLayoutHelper lh, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
560 |
MenuItemLayoutHelper.LayoutResult lr) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
561 |
if (lh.getCheckIcon() != null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
562 |
Rectangle checkRect = lr.getCheckRect(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
563 |
SynthIcon.paintIcon(lh.getCheckIcon(), lh.getContext(), g, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
564 |
checkRect.x, checkRect.y, checkRect.width, checkRect.height); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
565 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
566 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
567 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
568 |
static void paintAccText(Graphics g, SynthMenuItemLayoutHelper lh, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
569 |
MenuItemLayoutHelper.LayoutResult lr) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
570 |
String accText = lh.getAccText(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
571 |
if (accText != null && !accText.equals("")) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
572 |
g.setColor(lh.getAccStyle().getColor(lh.getAccContext(), |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
573 |
ColorType.TEXT_FOREGROUND)); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
574 |
g.setFont(lh.getAccStyle().getFont(lh.getAccContext())); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
575 |
lh.getAccGraphicsUtils().paintText(lh.getAccContext(), g, accText, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
576 |
lr.getAccRect().x, lr.getAccRect().y, -1); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
577 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
578 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
579 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
580 |
static void paintText(Graphics g, SynthMenuItemLayoutHelper lh, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
581 |
MenuItemLayoutHelper.LayoutResult lr) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
582 |
if (!lh.getText().equals("")) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
583 |
if (lh.getHtmlView() != null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
584 |
// Text is HTML |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
585 |
lh.getHtmlView().paint(g, lr.getTextRect()); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
586 |
} else { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
587 |
// Text isn't HTML |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
588 |
g.setColor(lh.getStyle().getColor( |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
589 |
lh.getContext(), ColorType.TEXT_FOREGROUND)); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
590 |
g.setFont(lh.getStyle().getFont(lh.getContext())); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
591 |
lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(), |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
592 |
lr.getTextRect().x, lr.getTextRect().y, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
593 |
lh.getMenuItem().getDisplayedMnemonicIndex()); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
594 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
595 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
596 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
597 |
|
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
598 |
static void paintArrowIcon(Graphics g, SynthMenuItemLayoutHelper lh, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
599 |
MenuItemLayoutHelper.LayoutResult lr) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
600 |
if (lh.getArrowIcon() != null) { |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
601 |
Rectangle arrowRect = lr.getArrowRect(); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
602 |
SynthIcon.paintIcon(lh.getArrowIcon(), lh.getContext(), g, |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
603 |
arrowRect.x, arrowRect.y, arrowRect.width, arrowRect.height); |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
604 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
605 |
} |
3cf2264a5743
6584657: GTK Look and Feel: Bugs in menu item layout
mlapshin
parents:
1290
diff
changeset
|
606 |
|
2 | 607 |
/** |
608 |
* Wraps a SynthIcon around the Icon interface, forwarding calls to |
|
609 |
* the SynthIcon with a given SynthContext. |
|
610 |
*/ |
|
611 |
private static class SynthIconWrapper implements Icon { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
612 |
private static final java.util.List<SynthIconWrapper> CACHE = new java.util.ArrayList<SynthIconWrapper>(1); |
2 | 613 |
|
614 |
private SynthIcon synthIcon; |
|
615 |
private SynthContext context; |
|
616 |
||
617 |
static SynthIconWrapper get(SynthIcon icon, SynthContext context) { |
|
618 |
synchronized(CACHE) { |
|
619 |
int size = CACHE.size(); |
|
620 |
if (size > 0) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
2
diff
changeset
|
621 |
SynthIconWrapper wrapper = CACHE.remove(size - 1); |
2 | 622 |
wrapper.reset(icon, context); |
623 |
return wrapper; |
|
624 |
} |
|
625 |
} |
|
626 |
return new SynthIconWrapper(icon, context); |
|
627 |
} |
|
628 |
||
629 |
static void release(SynthIconWrapper wrapper) { |
|
630 |
wrapper.reset(null, null); |
|
631 |
synchronized(CACHE) { |
|
632 |
CACHE.add(wrapper); |
|
633 |
} |
|
634 |
} |
|
635 |
||
636 |
SynthIconWrapper(SynthIcon icon, SynthContext context) { |
|
637 |
reset(icon, context); |
|
638 |
} |
|
639 |
||
640 |
void reset(SynthIcon icon, SynthContext context) { |
|
641 |
synthIcon = icon; |
|
642 |
this.context = context; |
|
643 |
} |
|
644 |
||
645 |
public void paintIcon(Component c, Graphics g, int x, int y) { |
|
646 |
// This is a noop as this should only be for sizing calls. |
|
647 |
} |
|
648 |
||
649 |
public int getIconWidth() { |
|
650 |
return synthIcon.getIconWidth(context); |
|
651 |
} |
|
652 |
||
653 |
public int getIconHeight() { |
|
654 |
return synthIcon.getIconHeight(context); |
|
655 |
} |
|
656 |
} |
|
657 |
} |