2
|
1 |
/*
|
|
2 |
* Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
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
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
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 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package com.sun.java.swing.plaf.gtk;
|
|
26 |
|
|
27 |
import sun.swing.plaf.synth.SynthUI;
|
|
28 |
import sun.awt.UNIXToolkit;
|
|
29 |
|
|
30 |
import javax.swing.plaf.synth.*;
|
|
31 |
import java.awt.*;
|
|
32 |
import javax.swing.*;
|
|
33 |
import javax.swing.border.*;
|
|
34 |
import javax.swing.plaf.*;
|
|
35 |
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
|
|
36 |
import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
|
|
37 |
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
|
|
38 |
import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType;
|
|
39 |
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
|
|
40 |
import java.lang.reflect.InvocationTargetException;
|
|
41 |
import java.lang.reflect.Method;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* @author Joshua Outwater
|
|
45 |
* @author Scott Violet
|
|
46 |
*/
|
|
47 |
// Need to support:
|
|
48 |
// default_outside_border: Insets when default.
|
|
49 |
// interior_focus: Indicates if focus should appear inside border, or
|
|
50 |
// outside border.
|
|
51 |
// focus-line-width: Integer giving size of focus border
|
|
52 |
// focus-padding: Integer giving padding between border and focus
|
|
53 |
// indicator.
|
|
54 |
// focus-line-pattern:
|
|
55 |
//
|
|
56 |
class GTKPainter extends SynthPainter {
|
|
57 |
private static final PositionType[] POSITIONS = {
|
|
58 |
PositionType.BOTTOM, PositionType.RIGHT,
|
|
59 |
PositionType.TOP, PositionType.LEFT
|
|
60 |
};
|
|
61 |
|
|
62 |
private static final ShadowType SHADOWS[] = {
|
|
63 |
ShadowType.NONE, ShadowType.IN, ShadowType.OUT,
|
|
64 |
ShadowType.ETCHED_IN, ShadowType.OUT
|
|
65 |
};
|
|
66 |
|
|
67 |
private final static GTKEngine ENGINE = GTKEngine.INSTANCE;
|
|
68 |
final static GTKPainter INSTANCE = new GTKPainter();
|
|
69 |
|
|
70 |
private GTKPainter() {
|
|
71 |
}
|
|
72 |
|
|
73 |
private String getName(SynthContext context) {
|
|
74 |
return (context.getRegion().isSubregion()) ? null :
|
|
75 |
context.getComponent().getName();
|
|
76 |
}
|
|
77 |
|
|
78 |
public void paintCheckBoxBackground(SynthContext context,
|
|
79 |
Graphics g, int x, int y, int w, int h) {
|
|
80 |
paintRadioButtonBackground(context, g, x, y, w, h);
|
|
81 |
}
|
|
82 |
|
|
83 |
public void paintCheckBoxMenuItemBackground(SynthContext context,
|
|
84 |
Graphics g, int x, int y, int w, int h) {
|
|
85 |
paintRadioButtonMenuItemBackground(context, g, x, y, w, h);
|
|
86 |
}
|
|
87 |
|
|
88 |
// FORMATTED_TEXT_FIELD
|
|
89 |
public void paintFormattedTextFieldBackground(SynthContext context,
|
|
90 |
Graphics g, int x, int y,
|
|
91 |
int w, int h) {
|
|
92 |
paintTextBackground(context, g, x, y, w, h);
|
|
93 |
}
|
|
94 |
|
|
95 |
//
|
|
96 |
// TOOL_BAR_DRAG_WINDOW
|
|
97 |
//
|
|
98 |
public void paintToolBarDragWindowBackground(SynthContext context,
|
|
99 |
Graphics g, int x, int y,
|
|
100 |
int w, int h) {
|
|
101 |
paintToolBarBackground(context, g, x, y, w, h);
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
//
|
|
106 |
// TOOL_BAR
|
|
107 |
//
|
|
108 |
public void paintToolBarBackground(SynthContext context,
|
|
109 |
Graphics g, int x, int y,
|
|
110 |
int w, int h) {
|
|
111 |
Region id = context.getRegion();
|
|
112 |
int state = context.getComponentState();
|
|
113 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
114 |
int orientation = ((JToolBar)context.getComponent()).getOrientation();
|
|
115 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
116 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id,
|
|
117 |
state, orientation))
|
|
118 |
{
|
|
119 |
ENGINE.startPainting(g, x, y, w, h, id, state, orientation);
|
|
120 |
ENGINE.paintBox(g, context, id, gtkState, ShadowType.OUT,
|
|
121 |
"handlebox_bin", x, y, w, h);
|
|
122 |
ENGINE.finishPainting();
|
|
123 |
}
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
public void paintToolBarContentBackground(SynthContext context,
|
|
128 |
Graphics g,
|
|
129 |
int x, int y, int w, int h) {
|
|
130 |
Region id = context.getRegion();
|
|
131 |
int orientation = ((JToolBar)context.getComponent()).getOrientation();
|
|
132 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
133 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, orientation)) {
|
|
134 |
ENGINE.startPainting(g, x, y, w, h, id, orientation);
|
|
135 |
ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,
|
|
136 |
ShadowType.OUT, "toolbar", x, y, w, h);
|
|
137 |
ENGINE.finishPainting();
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
//
|
|
143 |
// PASSWORD_FIELD
|
|
144 |
//
|
|
145 |
public void paintPasswordFieldBackground(SynthContext context,
|
|
146 |
Graphics g, int x, int y,
|
|
147 |
int w, int h) {
|
|
148 |
paintTextBackground(context, g, x, y, w, h);
|
|
149 |
}
|
|
150 |
|
|
151 |
//
|
|
152 |
// TEXT_FIELD
|
|
153 |
//
|
|
154 |
public void paintTextFieldBackground(SynthContext context, Graphics g,
|
|
155 |
int x, int y, int w, int h) {
|
|
156 |
if (getName(context) == "Tree.cellEditor") {
|
|
157 |
paintTreeCellEditorBackground(context, g, x, y, w, h);
|
|
158 |
} else {
|
|
159 |
paintTextBackground(context, g, x, y, w, h);
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
//
|
|
164 |
// RADIO_BUTTON
|
|
165 |
//
|
|
166 |
// NOTE: this is called for JCheckBox too
|
|
167 |
public void paintRadioButtonBackground(SynthContext context,
|
|
168 |
Graphics g, int x, int y,
|
|
169 |
int w, int h) {
|
|
170 |
Region id = context.getRegion();
|
|
171 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
172 |
id, context.getComponentState());
|
|
173 |
if (gtkState == SynthConstants.MOUSE_OVER) {
|
|
174 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
175 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
176 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
177 |
ENGINE.paintFlatBox(g, context, id,
|
|
178 |
SynthConstants.MOUSE_OVER, ShadowType.ETCHED_OUT,
|
|
179 |
"checkbutton", x, y, w, h, ColorType.BACKGROUND);
|
|
180 |
ENGINE.finishPainting();
|
|
181 |
}
|
|
182 |
}
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
//
|
|
187 |
// RADIO_BUTTON_MENU_ITEM
|
|
188 |
//
|
|
189 |
// NOTE: this is called for JCheckBoxMenuItem too
|
|
190 |
public void paintRadioButtonMenuItemBackground(SynthContext context,
|
|
191 |
Graphics g, int x, int y,
|
|
192 |
int w, int h) {
|
|
193 |
Region id = context.getRegion();
|
|
194 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
195 |
id, context.getComponentState());
|
|
196 |
if (gtkState == SynthConstants.MOUSE_OVER) {
|
|
197 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
198 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
199 |
ShadowType shadow = (GTKLookAndFeel.is2_2() ?
|
|
200 |
ShadowType.NONE : ShadowType.OUT);
|
|
201 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
202 |
ENGINE.paintBox(g, context, id, gtkState,
|
|
203 |
shadow, "menuitem", x, y, w, h);
|
|
204 |
ENGINE.finishPainting();
|
|
205 |
}
|
|
206 |
}
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
//
|
|
211 |
// LABEL
|
|
212 |
//
|
|
213 |
public void paintLabelBackground(SynthContext context,
|
|
214 |
Graphics g, int x, int y,
|
|
215 |
int w, int h) {
|
|
216 |
String name = getName(context);
|
|
217 |
JComponent c = context.getComponent();
|
|
218 |
Container container = c.getParent();
|
|
219 |
|
|
220 |
if (name == "TableHeader.renderer" ||
|
|
221 |
name == "GTKFileChooser.directoryListLabel" ||
|
|
222 |
name == "GTKFileChooser.fileListLabel") {
|
|
223 |
|
|
224 |
paintButtonBackgroundImpl(context, g, Region.BUTTON, "button",
|
|
225 |
x, y, w, h, true, false, false, false);
|
|
226 |
}
|
|
227 |
/*
|
|
228 |
* If the label is a ListCellRenderer and it's in a container
|
|
229 |
* (CellRendererPane) which is in a JComboBox then we paint the label
|
|
230 |
* as a TextField like a gtk_entry for a combobox.
|
|
231 |
*/
|
|
232 |
else if (c instanceof ListCellRenderer &&
|
|
233 |
container != null &&
|
|
234 |
container.getParent() instanceof JComboBox ) {
|
|
235 |
paintTextBackground(context, g, x, y, w, h);
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
//
|
|
240 |
// INTERNAL_FRAME
|
|
241 |
//
|
|
242 |
public void paintInternalFrameBorder(SynthContext context,
|
|
243 |
Graphics g, int x, int y,
|
|
244 |
int w, int h) {
|
|
245 |
Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);
|
|
246 |
}
|
|
247 |
|
|
248 |
//
|
|
249 |
// DESKTOP_PANE
|
|
250 |
//
|
|
251 |
public void paintDesktopPaneBackground(SynthContext context,
|
|
252 |
Graphics g, int x, int y,
|
|
253 |
int w, int h) {
|
|
254 |
// Does not call into ENGINE for better performance
|
|
255 |
fillArea(context, g, x, y, w, h, ColorType.BACKGROUND);
|
|
256 |
}
|
|
257 |
|
|
258 |
//
|
|
259 |
// DESKTOP_ICON
|
|
260 |
//
|
|
261 |
public void paintDesktopIconBorder(SynthContext context,
|
|
262 |
Graphics g, int x, int y,
|
|
263 |
int w, int h) {
|
|
264 |
Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);
|
|
265 |
}
|
|
266 |
|
|
267 |
public void paintButtonBackground(SynthContext context, Graphics g,
|
|
268 |
int x, int y, int w, int h) {
|
|
269 |
String name = getName(context);
|
|
270 |
if (name != null && name.startsWith("InternalFrameTitlePane.")) {
|
|
271 |
Metacity.INSTANCE.paintButtonBackground(context, g, x, y, w, h);
|
|
272 |
|
|
273 |
} else {
|
|
274 |
AbstractButton button = (AbstractButton)context.getComponent();
|
|
275 |
boolean paintBG = button.isContentAreaFilled() &&
|
|
276 |
button.isBorderPainted();
|
|
277 |
boolean paintFocus = button.isFocusPainted();
|
|
278 |
boolean defaultCapable = (button instanceof JButton) &&
|
|
279 |
((JButton)button).isDefaultCapable();
|
|
280 |
boolean toolButton = (button.getParent() instanceof JToolBar);
|
|
281 |
paintButtonBackgroundImpl(context, g, Region.BUTTON, "button",
|
|
282 |
x, y, w, h, paintBG, paintFocus, defaultCapable, toolButton);
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
private void paintButtonBackgroundImpl(SynthContext context, Graphics g,
|
|
287 |
Region id, String detail, int x, int y, int w, int h,
|
|
288 |
boolean paintBackground, boolean paintFocus,
|
|
289 |
boolean defaultCapable, boolean toolButton) {
|
|
290 |
int state = context.getComponentState();
|
|
291 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
292 |
if (ENGINE.paintCachedImage(g, x, y, w, h, id, state, detail,
|
|
293 |
paintBackground, paintFocus, defaultCapable, toolButton)) {
|
|
294 |
return;
|
|
295 |
}
|
|
296 |
ENGINE.startPainting(g, x, y, w, h, id, state, detail,
|
|
297 |
paintBackground, paintFocus, defaultCapable, toolButton);
|
|
298 |
|
|
299 |
// Paint the default indicator
|
|
300 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
301 |
if (defaultCapable && !toolButton) {
|
|
302 |
Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(
|
|
303 |
context, "default-border",
|
|
304 |
GTKStyle.BUTTON_DEFAULT_BORDER_INSETS);
|
|
305 |
|
|
306 |
if (paintBackground && (state & SynthConstants.DEFAULT) != 0) {
|
|
307 |
ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,
|
|
308 |
ShadowType.IN, "buttondefault", x, y, w, h);
|
|
309 |
}
|
|
310 |
x += defaultInsets.left;
|
|
311 |
y += defaultInsets.top;
|
|
312 |
w -= (defaultInsets.left + defaultInsets.right);
|
|
313 |
h -= (defaultInsets.top + defaultInsets.bottom);
|
|
314 |
}
|
|
315 |
|
|
316 |
boolean interiorFocus = style.getClassSpecificBoolValue(
|
|
317 |
context, "interior-focus", true);
|
|
318 |
int focusSize = style.getClassSpecificIntValue(
|
|
319 |
context, "focus-line-width",1);
|
|
320 |
int focusPad = style.getClassSpecificIntValue(
|
|
321 |
context, "focus-padding", 1);
|
|
322 |
|
|
323 |
int totalFocusSize = focusSize + focusPad;
|
|
324 |
int xThickness = style.getXThickness();
|
|
325 |
int yThickness = style.getYThickness();
|
|
326 |
|
|
327 |
// Render the box.
|
|
328 |
if (!interiorFocus &&
|
|
329 |
(state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {
|
|
330 |
x += totalFocusSize;
|
|
331 |
y += totalFocusSize;
|
|
332 |
w -= 2 * totalFocusSize;
|
|
333 |
h -= 2 * totalFocusSize;
|
|
334 |
}
|
|
335 |
|
|
336 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
337 |
boolean paintBg;
|
|
338 |
if (toolButton) {
|
|
339 |
// Toolbar buttons should only have their background painted
|
|
340 |
// in the PRESSED, SELECTED, or MOUSE_OVER states.
|
|
341 |
paintBg =
|
|
342 |
(gtkState != SynthConstants.ENABLED) &&
|
|
343 |
(gtkState != SynthConstants.DISABLED);
|
|
344 |
} else {
|
|
345 |
// Otherwise, always paint the button's background, unless
|
|
346 |
// the user has overridden it and we're in the ENABLED state.
|
|
347 |
paintBg =
|
|
348 |
paintBackground ||
|
|
349 |
(gtkState != SynthConstants.ENABLED);
|
|
350 |
}
|
|
351 |
if (paintBg) {
|
|
352 |
ShadowType shadowType = ShadowType.OUT;
|
|
353 |
if ((state & (SynthConstants.PRESSED |
|
|
354 |
SynthConstants.SELECTED)) != 0) {
|
|
355 |
shadowType = ShadowType.IN;
|
|
356 |
}
|
|
357 |
ENGINE.paintBox(g, context, id, gtkState,
|
|
358 |
shadowType, detail, x, y, w, h);
|
|
359 |
}
|
|
360 |
|
|
361 |
// focus
|
|
362 |
if (paintFocus && (state & SynthConstants.FOCUSED) != 0) {
|
|
363 |
if (interiorFocus) {
|
|
364 |
x += xThickness + focusPad;
|
|
365 |
y += yThickness + focusPad;
|
|
366 |
w -= 2 * (xThickness + focusPad);
|
|
367 |
h -= 2 * (yThickness + focusPad);
|
|
368 |
} else {
|
|
369 |
x -= totalFocusSize;
|
|
370 |
y -= totalFocusSize;
|
|
371 |
w += 2 * totalFocusSize;
|
|
372 |
h += 2 * totalFocusSize;
|
|
373 |
}
|
|
374 |
ENGINE.paintFocus(g, context, id, gtkState, detail, x, y, w, h);
|
|
375 |
}
|
|
376 |
ENGINE.finishPainting();
|
|
377 |
}
|
|
378 |
}
|
|
379 |
|
|
380 |
//
|
|
381 |
// ARROW_BUTTON
|
|
382 |
//
|
|
383 |
public void paintArrowButtonForeground(SynthContext context, Graphics g,
|
|
384 |
int x, int y, int w, int h,
|
|
385 |
int direction) {
|
|
386 |
Region id = context.getRegion();
|
|
387 |
Component c = context.getComponent();
|
|
388 |
String name = c.getName();
|
|
389 |
|
|
390 |
ArrowType arrowType = null;
|
|
391 |
switch (direction) {
|
|
392 |
case SwingConstants.NORTH:
|
|
393 |
arrowType = ArrowType.UP; break;
|
|
394 |
case SwingConstants.SOUTH:
|
|
395 |
arrowType = ArrowType.DOWN; break;
|
|
396 |
case SwingConstants.EAST:
|
|
397 |
arrowType = ArrowType.RIGHT; break;
|
|
398 |
case SwingConstants.WEST:
|
|
399 |
arrowType = ArrowType.LEFT; break;
|
|
400 |
}
|
|
401 |
|
|
402 |
String detail = "arrow";
|
|
403 |
if (name == "ScrollBar.button") {
|
|
404 |
if (arrowType == ArrowType.UP || arrowType == ArrowType.DOWN) {
|
|
405 |
detail = "vscrollbar";
|
|
406 |
} else {
|
|
407 |
detail = "hscrollbar";
|
|
408 |
}
|
|
409 |
} else if (name == "Spinner.nextButton" ||
|
|
410 |
name == "Spinner.previousButton") {
|
|
411 |
detail = "spinbutton";
|
|
412 |
} else if (name != "ComboBox.arrowButton") {
|
|
413 |
assert false;
|
|
414 |
}
|
|
415 |
|
|
416 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
417 |
id, context.getComponentState());
|
|
418 |
ShadowType shadowType = (gtkState == SynthConstants.PRESSED ?
|
|
419 |
ShadowType.IN : ShadowType.OUT);
|
|
420 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
421 |
if (ENGINE.paintCachedImage(g, x, y, w, h,
|
|
422 |
gtkState, name, direction)) {
|
|
423 |
return;
|
|
424 |
}
|
|
425 |
ENGINE.startPainting(g, x, y, w, h, gtkState, name, direction);
|
|
426 |
ENGINE.paintArrow(g, context, id, gtkState,
|
|
427 |
shadowType, arrowType, detail, x, y, w, h);
|
|
428 |
ENGINE.finishPainting();
|
|
429 |
}
|
|
430 |
}
|
|
431 |
|
|
432 |
public void paintArrowButtonBackground(SynthContext context,
|
|
433 |
Graphics g, int x, int y, int w, int h) {
|
|
434 |
Region id = context.getRegion();
|
|
435 |
AbstractButton button = (AbstractButton)context.getComponent();
|
|
436 |
|
|
437 |
String name = button.getName();
|
|
438 |
String detail = "button";
|
|
439 |
int direction = SwingConstants.CENTER;
|
|
440 |
if (name == "ScrollBar.button") {
|
|
441 |
Integer prop = (Integer)
|
|
442 |
button.getClientProperty("__arrow_direction__");
|
|
443 |
direction = (prop != null) ?
|
|
444 |
prop.intValue() : SwingConstants.WEST;
|
|
445 |
switch (direction) {
|
|
446 |
default:
|
|
447 |
case SwingConstants.EAST:
|
|
448 |
case SwingConstants.WEST:
|
|
449 |
detail = "hscrollbar";
|
|
450 |
break;
|
|
451 |
case SwingConstants.NORTH:
|
|
452 |
case SwingConstants.SOUTH:
|
|
453 |
detail = "vscrollbar";
|
|
454 |
break;
|
|
455 |
}
|
|
456 |
} else if (name == "Spinner.previousButton") {
|
|
457 |
detail = "spinbutton_down";
|
|
458 |
} else if (name == "Spinner.nextButton") {
|
|
459 |
detail = "spinbutton_up";
|
|
460 |
} else if (name != "ComboBox.arrowButton") {
|
|
461 |
assert false;
|
|
462 |
}
|
|
463 |
|
|
464 |
int state = context.getComponentState();
|
|
465 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
466 |
if (ENGINE.paintCachedImage(g, x, y, w, h, id,
|
|
467 |
state, detail, direction))
|
|
468 |
{
|
|
469 |
return;
|
|
470 |
}
|
|
471 |
ENGINE.startPainting(g, x, y, w, h, id,
|
|
472 |
state, detail, direction);
|
|
473 |
|
|
474 |
if (detail.startsWith("spin")) {
|
|
475 |
/*
|
|
476 |
* The ubuntulooks engine (and presumably others) expect us to
|
|
477 |
* first draw the full "spinbutton" background, and then draw
|
|
478 |
* the individual "spinbutton_up/down" buttons on top of that.
|
|
479 |
* Note that it is the state of the JSpinner (not its arrow
|
|
480 |
* button) that determines how we draw this background.
|
|
481 |
*/
|
|
482 |
int spinState = button.getParent().isEnabled() ?
|
|
483 |
SynthConstants.ENABLED : SynthConstants.DISABLED;
|
|
484 |
int mody = (detail == "spinbutton_up") ? y : y-h;
|
|
485 |
int modh = h*2;
|
|
486 |
ENGINE.paintBox(g, context, id, spinState,
|
|
487 |
ShadowType.IN, "spinbutton",
|
|
488 |
x, mody, w, modh);
|
|
489 |
}
|
|
490 |
|
|
491 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
492 |
ShadowType shadowType = ShadowType.OUT;
|
|
493 |
if ((gtkState & (SynthConstants.PRESSED |
|
|
494 |
SynthConstants.SELECTED)) != 0)
|
|
495 |
{
|
|
496 |
shadowType = ShadowType.IN;
|
|
497 |
}
|
|
498 |
ENGINE.paintBox(g, context, id, gtkState,
|
|
499 |
shadowType, detail,
|
|
500 |
x, y, w, h);
|
|
501 |
|
|
502 |
ENGINE.finishPainting();
|
|
503 |
}
|
|
504 |
}
|
|
505 |
|
|
506 |
|
|
507 |
//
|
|
508 |
// LIST
|
|
509 |
//
|
|
510 |
public void paintListBackground(SynthContext context, Graphics g,
|
|
511 |
int x, int y, int w, int h) {
|
|
512 |
// Does not call into ENGINE for better performance
|
|
513 |
fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
|
|
514 |
}
|
|
515 |
|
|
516 |
public void paintMenuBarBackground(SynthContext context, Graphics g,
|
|
517 |
int x, int y, int w, int h) {
|
|
518 |
Region id = context.getRegion();
|
|
519 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
520 |
if (ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
521 |
return;
|
|
522 |
}
|
|
523 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
524 |
int shadow = style.getClassSpecificIntValue(
|
|
525 |
context, "shadow-type", 2);
|
|
526 |
ShadowType shadowType = SHADOWS[shadow];
|
|
527 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
528 |
id, context.getComponentState());
|
|
529 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
530 |
ENGINE.paintBox(g, context, id, gtkState,
|
|
531 |
shadowType, "menubar", x, y, w, h);
|
|
532 |
ENGINE.finishPainting();
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
//
|
|
537 |
// MENU
|
|
538 |
//
|
|
539 |
public void paintMenuBackground(SynthContext context,
|
|
540 |
Graphics g,
|
|
541 |
int x, int y, int w, int h) {
|
|
542 |
paintMenuItemBackground(context, g, x, y, w, h);
|
|
543 |
}
|
|
544 |
|
|
545 |
// This is called for both MENU and MENU_ITEM
|
|
546 |
public void paintMenuItemBackground(SynthContext context,
|
|
547 |
Graphics g,
|
|
548 |
int x, int y, int w, int h) {
|
|
549 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
550 |
context.getRegion(), context.getComponentState());
|
|
551 |
if (gtkState == SynthConstants.MOUSE_OVER) {
|
|
552 |
Region id = Region.MENU_ITEM;
|
|
553 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
554 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
555 |
ShadowType shadow = (GTKLookAndFeel.is2_2() ?
|
|
556 |
ShadowType.NONE : ShadowType.OUT);
|
|
557 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
558 |
ENGINE.paintBox(g, context, id, gtkState, shadow,
|
|
559 |
"menuitem", x, y, w, h);
|
|
560 |
ENGINE.finishPainting();
|
|
561 |
}
|
|
562 |
}
|
|
563 |
}
|
|
564 |
}
|
|
565 |
|
|
566 |
public void paintPopupMenuBackground(SynthContext context, Graphics g,
|
|
567 |
int x, int y, int w, int h) {
|
|
568 |
Region id = context.getRegion();
|
|
569 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
570 |
id, context.getComponentState());
|
|
571 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
572 |
if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
|
|
573 |
return;
|
|
574 |
}
|
|
575 |
ENGINE.startPainting(g, x, y, w, h, id, gtkState);
|
|
576 |
ENGINE.paintBox(g, context, id, gtkState,
|
|
577 |
ShadowType.OUT, "menu", x, y, w, h);
|
|
578 |
|
|
579 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
580 |
int xThickness = style.getXThickness();
|
|
581 |
int yThickness = style.getYThickness();
|
|
582 |
ENGINE.paintBackground(g, context, id, gtkState,
|
|
583 |
style.getGTKColor(context, gtkState, GTKColorType.BACKGROUND),
|
|
584 |
x + xThickness, y + yThickness,
|
|
585 |
w - xThickness - xThickness, h - yThickness - yThickness);
|
|
586 |
ENGINE.finishPainting();
|
|
587 |
}
|
|
588 |
}
|
|
589 |
|
|
590 |
public void paintProgressBarBackground(SynthContext context,
|
|
591 |
Graphics g,
|
|
592 |
int x, int y, int w, int h) {
|
|
593 |
Region id = context.getRegion();
|
|
594 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
595 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
596 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
597 |
ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,
|
|
598 |
ShadowType.IN, "trough", x, y, w, h);
|
|
599 |
ENGINE.finishPainting();
|
|
600 |
}
|
|
601 |
}
|
|
602 |
}
|
|
603 |
|
|
604 |
public void paintProgressBarForeground(SynthContext context, Graphics g,
|
|
605 |
int x, int y, int w, int h,
|
|
606 |
int orientation) {
|
|
607 |
Region id = context.getRegion();
|
|
608 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
609 |
// Note that we don't call paintCachedImage() here. Since the
|
|
610 |
// progress bar foreground is painted differently for each value
|
|
611 |
// it would be wasteful to try to cache an image for each state,
|
|
612 |
// so instead we simply avoid caching in this case.
|
|
613 |
if (w <= 0 || h <= 0) {
|
|
614 |
return;
|
|
615 |
}
|
|
616 |
ENGINE.startPainting(g, x, y, w, h, id, "fg");
|
|
617 |
ENGINE.paintBox(g, context, id, SynthConstants.MOUSE_OVER,
|
|
618 |
ShadowType.OUT, "bar", x, y, w, h);
|
|
619 |
ENGINE.finishPainting(false); // don't bother caching the image
|
|
620 |
}
|
|
621 |
}
|
|
622 |
|
|
623 |
public void paintViewportBorder(SynthContext context, Graphics g,
|
|
624 |
int x, int y, int w, int h) {
|
|
625 |
Region id = context.getRegion();
|
|
626 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
627 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
628 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
629 |
ENGINE.paintShadow(g, context, id, SynthConstants.ENABLED,
|
|
630 |
ShadowType.IN, "scrolled_window", x, y, w, h);
|
|
631 |
ENGINE.finishPainting();
|
|
632 |
}
|
|
633 |
}
|
|
634 |
}
|
|
635 |
|
|
636 |
public void paintSeparatorBackground(SynthContext context,
|
|
637 |
Graphics g,
|
|
638 |
int x, int y, int w, int h,
|
|
639 |
int orientation) {
|
|
640 |
Region id = context.getRegion();
|
|
641 |
int state = context.getComponentState();
|
|
642 |
JComponent c = context.getComponent();
|
|
643 |
|
|
644 |
/*
|
|
645 |
* Note: In theory, the style's x/y thickness values would determine
|
|
646 |
* the width of the separator content. In practice, however, some
|
|
647 |
* engines will render a line that is wider than the corresponding
|
|
648 |
* thickness value. For example, ubuntulooks reports x/y thickness
|
|
649 |
* values of 1 for separators, but always renders a 2-pixel wide line.
|
|
650 |
* As a result of all this, we need to be careful not to restrict
|
|
651 |
* the w/h values below too much, so that the full thickness of the
|
|
652 |
* rendered line will be captured by our image caching code.
|
|
653 |
*/
|
|
654 |
String detail;
|
|
655 |
if (c instanceof JToolBar.Separator) {
|
|
656 |
/*
|
|
657 |
* GTK renders toolbar separators differently in that an
|
|
658 |
* artificial padding is added to each end of the separator.
|
|
659 |
* The value of 0.2f below is derived from the source code of
|
|
660 |
* gtktoolbar.c in the current version of GTK+ (2.8.20 at the
|
|
661 |
* time of this writing). Specifically, the relevant values are:
|
|
662 |
* SPACE_LINE_DIVISION 10.0
|
|
663 |
* SPACE_LINE_START 2.0
|
|
664 |
* SPACE_LINE_END 8.0
|
|
665 |
* These are used to determine the distance from the top (or left)
|
|
666 |
* edge of the toolbar to the other edge. So for example, the
|
|
667 |
* starting/top point of a vertical separator is 2/10 of the
|
|
668 |
* height of a horizontal toolbar away from the top edge, which
|
|
669 |
* is how we arrive at 0.2f below. Likewise, the ending/bottom
|
|
670 |
* point is 8/10 of the height away from the top edge, or in other
|
|
671 |
* words, it is 2/10 away from the bottom edge, which is again
|
|
672 |
* how we arrive at the 0.2f value below.
|
|
673 |
*
|
|
674 |
* The separator is also centered horizontally or vertically,
|
|
675 |
* depending on its orientation. This was determined empirically
|
|
676 |
* and by examining the code referenced above.
|
|
677 |
*/
|
|
678 |
detail = "toolbar";
|
|
679 |
float pct = 0.2f;
|
|
680 |
JToolBar.Separator sep = (JToolBar.Separator)c;
|
|
681 |
Dimension size = sep.getSeparatorSize();
|
|
682 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
683 |
if (orientation == JSeparator.HORIZONTAL) {
|
|
684 |
x += (int)(w * pct);
|
|
685 |
w -= (int)(w * pct * 2);
|
|
686 |
y += (size.height - style.getYThickness()) / 2;
|
|
687 |
} else {
|
|
688 |
y += (int)(h * pct);
|
|
689 |
h -= (int)(h * pct * 2);
|
|
690 |
x += (size.width - style.getXThickness()) / 2;
|
|
691 |
}
|
|
692 |
} else {
|
|
693 |
// For regular/menu separators, we simply subtract out the insets.
|
|
694 |
detail = "separator";
|
|
695 |
Insets insets = c.getInsets();
|
|
696 |
x += insets.left;
|
|
697 |
y += insets.top;
|
|
698 |
if (orientation == JSeparator.HORIZONTAL) {
|
|
699 |
w -= (insets.left + insets.right);
|
|
700 |
} else {
|
|
701 |
h -= (insets.top + insets.bottom);
|
|
702 |
}
|
|
703 |
}
|
|
704 |
|
|
705 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
706 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id,
|
|
707 |
state, detail, orientation)) {
|
|
708 |
ENGINE.startPainting(g, x, y, w, h, id,
|
|
709 |
state, detail, orientation);
|
|
710 |
if (orientation == JSeparator.HORIZONTAL) {
|
|
711 |
ENGINE.paintHline(g, context, id, state,
|
|
712 |
detail, x, y, w, h);
|
|
713 |
} else {
|
|
714 |
ENGINE.paintVline(g, context, id, state,
|
|
715 |
detail, x, y, w, h);
|
|
716 |
}
|
|
717 |
ENGINE.finishPainting();
|
|
718 |
}
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
public void paintSliderTrackBackground(SynthContext context,
|
|
723 |
Graphics g,
|
|
724 |
int x, int y, int w,int h) {
|
|
725 |
Region id = context.getRegion();
|
|
726 |
int state = context.getComponentState();
|
|
727 |
|
|
728 |
// For focused sliders, we paint focus rect outside the bounds passed.
|
|
729 |
// Need to adjust for that.
|
|
730 |
boolean focused = ((state & SynthConstants.FOCUSED) != 0);
|
|
731 |
int focusSize = 0;
|
|
732 |
if (focused) {
|
|
733 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
734 |
focusSize = style.getClassSpecificIntValue(
|
|
735 |
context, "focus-line-width", 1) +
|
|
736 |
style.getClassSpecificIntValue(
|
|
737 |
context, "focus-padding", 1);
|
|
738 |
x -= focusSize;
|
|
739 |
y -= focusSize;
|
|
740 |
w += focusSize * 2;
|
|
741 |
h += focusSize * 2;
|
|
742 |
}
|
|
743 |
|
|
744 |
// The ubuntulooks engine paints slider troughs differently depending
|
|
745 |
// on the current slider value and its component orientation.
|
|
746 |
JSlider slider = (JSlider)context.getComponent();
|
|
747 |
double value = slider.getValue();
|
|
748 |
double min = slider.getMinimum();
|
|
749 |
double max = slider.getMaximum();
|
|
750 |
double visible = 20; // not used for sliders; any value will work
|
|
751 |
|
|
752 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
753 |
// Note that we don't call paintCachedImage() here. Since some
|
|
754 |
// engines (e.g. ubuntulooks) paint the slider background
|
|
755 |
// differently for any given slider value, it would be wasteful
|
|
756 |
// to try to cache an image for each state, so instead we simply
|
|
757 |
// avoid caching in this case.
|
|
758 |
if (w <= 0 || h <= 0) {
|
|
759 |
return;
|
|
760 |
}
|
|
761 |
ENGINE.startPainting(g, x, y, w, h, id, state, value);
|
|
762 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
763 |
ENGINE.setRangeValue(context, id, value, min, max, visible);
|
|
764 |
ENGINE.paintBox(g, context, id, gtkState, ShadowType.IN,
|
|
765 |
"trough", x + focusSize, y + focusSize,
|
|
766 |
w - 2 * focusSize, h - 2 * focusSize);
|
|
767 |
if (focused) {
|
|
768 |
ENGINE.paintFocus(g, context, id, SynthConstants.ENABLED,
|
|
769 |
"trough", x, y, w, h);
|
|
770 |
}
|
|
771 |
ENGINE.finishPainting(false); // don't bother caching the image
|
|
772 |
}
|
|
773 |
}
|
|
774 |
|
|
775 |
public void paintSliderThumbBackground(SynthContext context,
|
|
776 |
Graphics g, int x, int y, int w, int h, int dir) {
|
|
777 |
Region id = context.getRegion();
|
|
778 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
779 |
id, context.getComponentState());
|
|
780 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
781 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, dir)) {
|
|
782 |
Orientation orientation = (dir == JSlider.HORIZONTAL ?
|
|
783 |
Orientation.HORIZONTAL : Orientation.VERTICAL);
|
|
784 |
String detail = (dir == JSlider.HORIZONTAL ?
|
|
785 |
"hscale" : "vscale");
|
|
786 |
ENGINE.startPainting(g, x, y, w, h, id, gtkState, dir);
|
|
787 |
ENGINE.paintSlider(g, context, id, gtkState,
|
|
788 |
ShadowType.OUT, detail, x, y, w, h, orientation);
|
|
789 |
ENGINE.finishPainting();
|
|
790 |
}
|
|
791 |
}
|
|
792 |
}
|
|
793 |
|
|
794 |
//
|
|
795 |
// SPINNER
|
|
796 |
//
|
|
797 |
public void paintSpinnerBackground(SynthContext context,
|
|
798 |
Graphics g,
|
|
799 |
int x, int y, int w, int h) {
|
|
800 |
// This is handled in paintTextFieldBackground
|
|
801 |
}
|
|
802 |
|
|
803 |
//
|
|
804 |
// SPLIT_PANE_DIVIDER
|
|
805 |
//
|
|
806 |
public void paintSplitPaneDividerBackground(SynthContext context,
|
|
807 |
Graphics g,
|
|
808 |
int x, int y, int w, int h) {
|
|
809 |
Region id = context.getRegion();
|
|
810 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
811 |
id, context.getComponentState());
|
|
812 |
JSplitPane splitPane = (JSplitPane)context.getComponent();
|
|
813 |
Orientation orientation =
|
|
814 |
(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT ?
|
|
815 |
Orientation.VERTICAL : Orientation.HORIZONTAL);
|
|
816 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
817 |
if (! ENGINE.paintCachedImage(g, x, y, w, h,
|
|
818 |
id, gtkState, orientation)) {
|
|
819 |
ENGINE.startPainting(g, x, y, w, h, id, gtkState, orientation);
|
|
820 |
ENGINE.paintHandle(g, context, id, gtkState,
|
|
821 |
ShadowType.OUT, "paned", x, y, w, h, orientation);
|
|
822 |
ENGINE.finishPainting();
|
|
823 |
}
|
|
824 |
}
|
|
825 |
}
|
|
826 |
|
|
827 |
public void paintSplitPaneDragDivider(SynthContext context,
|
|
828 |
Graphics g,int x, int y, int w, int h,
|
|
829 |
int orientation) {
|
|
830 |
paintSplitPaneDividerForeground(context, g, x, y, w, h, orientation);
|
|
831 |
}
|
|
832 |
|
|
833 |
public void paintTabbedPaneContentBackground(SynthContext context,
|
|
834 |
Graphics g, int x, int y, int w, int h) {
|
|
835 |
JTabbedPane pane = (JTabbedPane)context.getComponent();
|
|
836 |
int selectedIndex = pane.getSelectedIndex();
|
|
837 |
PositionType placement = GTKLookAndFeel.SwingOrientationConstantToGTK(
|
|
838 |
pane.getTabPlacement());
|
|
839 |
|
|
840 |
int gapStart = 0;
|
|
841 |
int gapSize = 0;
|
|
842 |
if (selectedIndex != -1) {
|
|
843 |
Rectangle tabBounds = pane.getBoundsAt(selectedIndex);
|
|
844 |
|
|
845 |
if (placement == PositionType.TOP ||
|
|
846 |
placement == PositionType.BOTTOM) {
|
|
847 |
|
|
848 |
gapStart = tabBounds.x - x;
|
|
849 |
gapSize = tabBounds.width;
|
|
850 |
}
|
|
851 |
else {
|
|
852 |
gapStart = tabBounds.y - y;
|
|
853 |
gapSize = tabBounds.height;
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
Region id = context.getRegion();
|
|
858 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
859 |
id, context.getComponentState());
|
|
860 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
861 |
if (! ENGINE.paintCachedImage(g, x, y, w, h,
|
|
862 |
id, gtkState, placement, gapStart, gapSize)) {
|
|
863 |
ENGINE.startPainting(g, x, y, w, h,
|
|
864 |
id, gtkState, placement, gapStart, gapSize);
|
|
865 |
ENGINE.paintBoxGap(g, context, id, gtkState, ShadowType.OUT,
|
|
866 |
"notebook", x, y, w, h, placement, gapStart, gapSize);
|
|
867 |
ENGINE.finishPainting();
|
|
868 |
}
|
|
869 |
}
|
|
870 |
}
|
|
871 |
|
|
872 |
public void paintTabbedPaneTabBackground(SynthContext context,
|
|
873 |
Graphics g,
|
|
874 |
int x, int y, int w, int h,
|
|
875 |
int tabIndex) {
|
|
876 |
Region id = context.getRegion();
|
|
877 |
int state = context.getComponentState();
|
|
878 |
int gtkState = ((state & SynthConstants.SELECTED) != 0 ?
|
|
879 |
SynthConstants.ENABLED : SynthConstants.PRESSED);
|
|
880 |
JTabbedPane pane = (JTabbedPane)context.getComponent();
|
|
881 |
int placement = pane.getTabPlacement();
|
|
882 |
|
|
883 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
884 |
if (! ENGINE.paintCachedImage(g, x, y, w, h,
|
|
885 |
id, gtkState, placement, tabIndex)) {
|
|
886 |
PositionType side = POSITIONS[placement - 1];
|
|
887 |
ENGINE.startPainting(g, x, y, w, h,
|
|
888 |
id, gtkState, placement, tabIndex);
|
|
889 |
ENGINE.paintExtension(g, context, id, gtkState,
|
|
890 |
ShadowType.OUT, "tab", x, y, w, h, side, tabIndex);
|
|
891 |
ENGINE.finishPainting();
|
|
892 |
}
|
|
893 |
}
|
|
894 |
}
|
|
895 |
|
|
896 |
//
|
|
897 |
// TEXT_PANE
|
|
898 |
//
|
|
899 |
public void paintTextPaneBackground(SynthContext context, Graphics g,
|
|
900 |
int x, int y, int w, int h) {
|
|
901 |
paintTextAreaBackground(context, g, x, y, w, h);
|
|
902 |
}
|
|
903 |
|
|
904 |
//
|
|
905 |
// EDITOR_PANE
|
|
906 |
//
|
|
907 |
public void paintEditorPaneBackground(SynthContext context, Graphics g,
|
|
908 |
int x, int y, int w, int h) {
|
|
909 |
paintTextAreaBackground(context, g, x, y, w, h);
|
|
910 |
}
|
|
911 |
|
|
912 |
//
|
|
913 |
// TEXT_AREA
|
|
914 |
//
|
|
915 |
public void paintTextAreaBackground(SynthContext context, Graphics g,
|
|
916 |
int x, int y, int w, int h) {
|
|
917 |
// Does not call into ENGINE for better performance
|
|
918 |
fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
|
|
919 |
}
|
|
920 |
|
|
921 |
//
|
|
922 |
// TEXT_FIELD
|
|
923 |
//
|
|
924 |
// NOTE: Combobox and Label, Password and FormattedTextField calls this
|
|
925 |
// too.
|
|
926 |
private void paintTextBackground(SynthContext context, Graphics g,
|
|
927 |
int x, int y, int w, int h) {
|
|
928 |
// Text is odd in that it uses the TEXT_BACKGROUND vs BACKGROUND.
|
|
929 |
JComponent c = context.getComponent();
|
|
930 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
931 |
Region id = context.getRegion();
|
|
932 |
int state = context.getComponentState();
|
|
933 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
934 |
if (ENGINE.paintCachedImage(g, x, y, w, h, id, state)) {
|
|
935 |
return;
|
|
936 |
}
|
|
937 |
|
|
938 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
939 |
int focusSize = 0;
|
|
940 |
boolean interiorFocus = style.getClassSpecificBoolValue(
|
|
941 |
context, "interior-focus", true);
|
|
942 |
if (!interiorFocus && (state & SynthConstants.FOCUSED) != 0) {
|
|
943 |
focusSize = style.getClassSpecificIntValue(context,
|
|
944 |
"focus-line-width",1);
|
|
945 |
x += focusSize;
|
|
946 |
y += focusSize;
|
|
947 |
w -= 2 * focusSize;
|
|
948 |
h -= 2 * focusSize;
|
|
949 |
}
|
|
950 |
|
|
951 |
int xThickness = style.getXThickness();
|
|
952 |
int yThickness = style.getYThickness();
|
|
953 |
|
|
954 |
ENGINE.startPainting(g, x, y, w, h, id, state);
|
|
955 |
ENGINE.paintShadow(g, context, id, gtkState,
|
|
956 |
ShadowType.IN, "entry", x, y, w, h);
|
|
957 |
ENGINE.paintFlatBox(g, context, id,
|
|
958 |
gtkState, ShadowType.NONE, "entry_bg",
|
|
959 |
x + xThickness,
|
|
960 |
y + yThickness,
|
|
961 |
w - (2 * xThickness),
|
|
962 |
h - (2 * yThickness),
|
|
963 |
ColorType.TEXT_BACKGROUND);
|
|
964 |
|
|
965 |
if (focusSize > 0) {
|
|
966 |
x -= focusSize;
|
|
967 |
y -= focusSize;
|
|
968 |
w += 2 * focusSize;
|
|
969 |
h += 2 * focusSize;
|
|
970 |
ENGINE.paintFocus(g, context, id, gtkState,
|
|
971 |
"entry", x, y, w, h);
|
|
972 |
}
|
|
973 |
ENGINE.finishPainting();
|
|
974 |
}
|
|
975 |
}
|
|
976 |
|
|
977 |
private void paintTreeCellEditorBackground(SynthContext context, Graphics g,
|
|
978 |
int x, int y, int w, int h) {
|
|
979 |
Region id = context.getRegion();
|
|
980 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
981 |
id, context.getComponentState());
|
|
982 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
983 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
|
|
984 |
ENGINE.startPainting(g, x, y, w, h, id, gtkState);
|
|
985 |
ENGINE.paintFlatBox(g, context, id, gtkState, ShadowType.NONE,
|
|
986 |
"entry_bg", x, y, w, h, ColorType.TEXT_BACKGROUND);
|
|
987 |
ENGINE.finishPainting();
|
|
988 |
}
|
|
989 |
}
|
|
990 |
}
|
|
991 |
|
|
992 |
|
|
993 |
//
|
|
994 |
// ROOT_PANE
|
|
995 |
//
|
|
996 |
public void paintRootPaneBackground(SynthContext context, Graphics g,
|
|
997 |
int x, int y, int w, int h) {
|
|
998 |
// Does not call into ENGINE for better performance
|
|
999 |
fillArea(context, g, x, y, w, h, GTKColorType.BACKGROUND);
|
|
1000 |
}
|
|
1001 |
|
|
1002 |
//
|
|
1003 |
// TOGGLE_BUTTON
|
|
1004 |
//
|
|
1005 |
public void paintToggleButtonBackground(SynthContext context,
|
|
1006 |
Graphics g,
|
|
1007 |
int x, int y, int w, int h) {
|
|
1008 |
Region id = context.getRegion();
|
|
1009 |
JToggleButton toggleButton = (JToggleButton)context.getComponent();
|
|
1010 |
boolean paintBG = toggleButton.isContentAreaFilled() &&
|
|
1011 |
toggleButton.isBorderPainted();
|
|
1012 |
boolean paintFocus = toggleButton.isFocusPainted();
|
|
1013 |
boolean toolButton = (toggleButton.getParent() instanceof JToolBar);
|
|
1014 |
paintButtonBackgroundImpl(context, g, id, "button",
|
|
1015 |
x, y, w, h,
|
|
1016 |
paintBG, paintFocus, false, toolButton);
|
|
1017 |
}
|
|
1018 |
|
|
1019 |
|
|
1020 |
//
|
|
1021 |
// SCROLL_BAR
|
|
1022 |
//
|
|
1023 |
public void paintScrollBarBackground(SynthContext context,
|
|
1024 |
Graphics g,
|
|
1025 |
int x, int y, int w,int h) {
|
|
1026 |
Region id = context.getRegion();
|
|
1027 |
boolean focused =
|
|
1028 |
(context.getComponentState() & SynthConstants.FOCUSED) != 0;
|
|
1029 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1030 |
if (ENGINE.paintCachedImage(g, x, y, w, h, id, focused)) {
|
|
1031 |
return;
|
|
1032 |
}
|
|
1033 |
ENGINE.startPainting(g, x, y, w, h, id, focused);
|
|
1034 |
|
|
1035 |
// Note: the scrollbar insets already include the "trough-border",
|
|
1036 |
// which is needed to position the scrollbar buttons properly.
|
|
1037 |
// But when we render, we need to take the trough border out
|
|
1038 |
// of the equation so that we paint the entire area covered by
|
|
1039 |
// the trough border and the scrollbar content itself.
|
|
1040 |
Insets insets = context.getComponent().getInsets();
|
|
1041 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
1042 |
int troughBorder =
|
|
1043 |
style.getClassSpecificIntValue(context, "trough-border", 1);
|
|
1044 |
insets.left -= troughBorder;
|
|
1045 |
insets.right -= troughBorder;
|
|
1046 |
insets.top -= troughBorder;
|
|
1047 |
insets.bottom -= troughBorder;
|
|
1048 |
|
|
1049 |
ENGINE.paintBox(g, context, id, SynthConstants.PRESSED,
|
|
1050 |
ShadowType.IN, "trough",
|
|
1051 |
x + insets.left,
|
|
1052 |
y + insets.top,
|
|
1053 |
w - insets.left - insets.right,
|
|
1054 |
h - insets.top - insets.bottom);
|
|
1055 |
|
|
1056 |
if (focused) {
|
|
1057 |
ENGINE.paintFocus(g, context, id,
|
|
1058 |
SynthConstants.ENABLED, "trough", x, y, w, h);
|
|
1059 |
}
|
|
1060 |
ENGINE.finishPainting();
|
|
1061 |
}
|
|
1062 |
}
|
|
1063 |
|
|
1064 |
|
|
1065 |
//
|
|
1066 |
// SCROLL_BAR_THUMB
|
|
1067 |
//
|
|
1068 |
public void paintScrollBarThumbBackground(SynthContext context,
|
|
1069 |
Graphics g, int x, int y, int w, int h, int dir) {
|
|
1070 |
Region id = context.getRegion();
|
|
1071 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
1072 |
id, context.getComponentState());
|
|
1073 |
|
|
1074 |
// The clearlooks engine paints scrollbar thumbs differently
|
|
1075 |
// depending on the current scroll value (specifically, it will avoid
|
|
1076 |
// rendering a certain line when the thumb is at the starting or
|
|
1077 |
// ending position). Therefore, we normalize the current value to
|
|
1078 |
// the range [0,100] here and then pass it down to setRangeValue()
|
|
1079 |
// so that the native widget is configured appropriately. Note that
|
|
1080 |
// there are really only four values that matter (min, middle, max,
|
|
1081 |
// or fill) so we restrict to one of those four values to avoid
|
|
1082 |
// blowing out the image cache.
|
|
1083 |
JScrollBar sb = (JScrollBar)context.getComponent();
|
|
1084 |
boolean rtl =
|
|
1085 |
sb.getOrientation() == JScrollBar.HORIZONTAL &&
|
|
1086 |
!sb.getComponentOrientation().isLeftToRight();
|
|
1087 |
double min = 0;
|
|
1088 |
double max = 100;
|
|
1089 |
double visible = 20;
|
|
1090 |
double value;
|
|
1091 |
if (sb.getMaximum() - sb.getMinimum() == sb.getVisibleAmount()) {
|
|
1092 |
// In this case, the thumb fills the entire track, so it is
|
|
1093 |
// touching both ends at the same time
|
|
1094 |
value = 0;
|
|
1095 |
visible = 100;
|
|
1096 |
} else if (sb.getValue() == sb.getMinimum()) {
|
|
1097 |
// At minimum
|
|
1098 |
value = rtl ? 100 : 0;
|
|
1099 |
} else if (sb.getValue() >= sb.getMaximum() - sb.getVisibleAmount()) {
|
|
1100 |
// At maximum
|
|
1101 |
value = rtl ? 0 : 100;
|
|
1102 |
} else {
|
|
1103 |
// Somewhere in between
|
|
1104 |
value = 50;
|
|
1105 |
}
|
|
1106 |
|
|
1107 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1108 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState,
|
|
1109 |
dir, value, visible, rtl))
|
|
1110 |
{
|
|
1111 |
ENGINE.startPainting(g, x, y, w, h, id, gtkState,
|
|
1112 |
dir, value, visible, rtl);
|
|
1113 |
Orientation orientation = (dir == JScrollBar.HORIZONTAL ?
|
|
1114 |
Orientation.HORIZONTAL : Orientation.VERTICAL);
|
|
1115 |
ENGINE.setRangeValue(context, id, value, min, max, visible);
|
|
1116 |
ENGINE.paintSlider(g, context, id, gtkState,
|
|
1117 |
ShadowType.OUT, "slider", x, y, w, h, orientation);
|
|
1118 |
ENGINE.finishPainting();
|
|
1119 |
}
|
|
1120 |
}
|
|
1121 |
}
|
|
1122 |
|
|
1123 |
//
|
|
1124 |
// TOOL_TIP
|
|
1125 |
//
|
|
1126 |
public void paintToolTipBackground(SynthContext context, Graphics g,
|
|
1127 |
int x, int y, int w,int h) {
|
|
1128 |
Region id = context.getRegion();
|
|
1129 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1130 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
1131 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
1132 |
ENGINE.paintFlatBox(g, context, id, SynthConstants.ENABLED,
|
|
1133 |
ShadowType.OUT, "tooltip", x, y, w, h,
|
|
1134 |
ColorType.BACKGROUND);
|
|
1135 |
ENGINE.finishPainting();
|
|
1136 |
}
|
|
1137 |
}
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
|
|
1141 |
//
|
|
1142 |
// TREE_CELL
|
|
1143 |
//
|
|
1144 |
public void paintTreeCellBackground(SynthContext context, Graphics g,
|
|
1145 |
int x, int y, int w, int h) {
|
|
1146 |
Region id = context.getRegion();
|
|
1147 |
int state = context.getComponentState();
|
|
1148 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
1149 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1150 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, state)) {
|
|
1151 |
ENGINE.startPainting(g, x, y, w, h, id, state);
|
|
1152 |
// the string arg should alternate based on row being painted,
|
|
1153 |
// but we currently don't pass that in.
|
|
1154 |
ENGINE.paintFlatBox(g, context, id, gtkState, ShadowType.NONE,
|
|
1155 |
"cell_odd", x, y, w, h, ColorType.TEXT_BACKGROUND);
|
|
1156 |
ENGINE.finishPainting();
|
|
1157 |
}
|
|
1158 |
}
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
public void paintTreeCellFocus(SynthContext context, Graphics g,
|
|
1162 |
int x, int y, int w, int h) {
|
|
1163 |
Region id = Region.TREE_CELL;
|
|
1164 |
int state = context.getComponentState();
|
|
1165 |
paintFocus(context, g, id, state, "treeview", x, y, w, h);
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
|
|
1169 |
//
|
|
1170 |
// TREE
|
|
1171 |
//
|
|
1172 |
public void paintTreeBackground(SynthContext context, Graphics g,
|
|
1173 |
int x, int y, int w, int h) {
|
|
1174 |
// As far as I can tell, these don't call into the ENGINE.
|
|
1175 |
fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
|
|
1176 |
}
|
|
1177 |
|
|
1178 |
|
|
1179 |
//
|
|
1180 |
// VIEWPORT
|
|
1181 |
//
|
|
1182 |
public void paintViewportBackground(SynthContext context, Graphics g,
|
|
1183 |
int x, int y, int w, int h) {
|
|
1184 |
// As far as I can tell, these don't call into the ENGINE.
|
|
1185 |
// Also note that you don't want this to call into the ENGINE
|
|
1186 |
// as if it where to paint a background JViewport wouldn't scroll
|
|
1187 |
// correctly.
|
|
1188 |
fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
|
|
1189 |
}
|
|
1190 |
|
|
1191 |
void paintFocus(SynthContext context, Graphics g, Region id,
|
|
1192 |
int state, String detail, int x, int y, int w, int h) {
|
|
1193 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
1194 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1195 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, "focus")) {
|
|
1196 |
ENGINE.startPainting(g, x, y, w, h, id, gtkState, "focus");
|
|
1197 |
ENGINE.paintFocus(g, context, id, gtkState, detail, x, y, w, h);
|
|
1198 |
ENGINE.finishPainting();
|
|
1199 |
}
|
|
1200 |
}
|
|
1201 |
}
|
|
1202 |
|
|
1203 |
void paintMetacityElement(SynthContext context, Graphics g,
|
|
1204 |
int gtkState, String detail, int x, int y, int w, int h,
|
|
1205 |
ShadowType shadow, ArrowType direction) {
|
|
1206 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1207 |
if (! ENGINE.paintCachedImage(
|
|
1208 |
g, x, y, w, h, gtkState, detail, shadow, direction)) {
|
|
1209 |
ENGINE.startPainting(
|
|
1210 |
g, x, y, w, h, gtkState, detail, shadow, direction);
|
|
1211 |
if (detail == "metacity-arrow") {
|
|
1212 |
ENGINE.paintArrow(g, context, Region.INTERNAL_FRAME_TITLE_PANE,
|
|
1213 |
gtkState, shadow, direction, "", x, y, w, h);
|
|
1214 |
|
|
1215 |
} else if (detail == "metacity-box") {
|
|
1216 |
ENGINE.paintBox(g, context, Region.INTERNAL_FRAME_TITLE_PANE,
|
|
1217 |
gtkState, shadow, "", x, y, w, h);
|
|
1218 |
|
|
1219 |
} else if (detail == "metacity-vline") {
|
|
1220 |
ENGINE.paintVline(g, context, Region.INTERNAL_FRAME_TITLE_PANE,
|
|
1221 |
gtkState, "", x, y, w, h);
|
|
1222 |
}
|
|
1223 |
ENGINE.finishPainting();
|
|
1224 |
}
|
|
1225 |
}
|
|
1226 |
}
|
|
1227 |
|
|
1228 |
void paintIcon(SynthContext context, Graphics g,
|
|
1229 |
Method paintMethod, int x, int y, int w, int h) {
|
|
1230 |
int state = context.getComponentState();
|
|
1231 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1232 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, state, paintMethod)) {
|
|
1233 |
ENGINE.startPainting(g, x, y, w, h, state, paintMethod);
|
|
1234 |
try {
|
|
1235 |
paintMethod.invoke(this, context, g, state, x, y, w, h);
|
|
1236 |
} catch (IllegalAccessException iae) {
|
|
1237 |
assert false;
|
|
1238 |
} catch (InvocationTargetException ite) {
|
|
1239 |
assert false;
|
|
1240 |
}
|
|
1241 |
ENGINE.finishPainting();
|
|
1242 |
}
|
|
1243 |
}
|
|
1244 |
}
|
|
1245 |
|
|
1246 |
void paintIcon(SynthContext context, Graphics g,
|
|
1247 |
Method paintMethod, int x, int y, int w, int h, Object direction) {
|
|
1248 |
int state = context.getComponentState();
|
|
1249 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1250 |
if (! ENGINE.paintCachedImage(g,
|
|
1251 |
x, y, w, h, state, paintMethod, direction)) {
|
|
1252 |
ENGINE.startPainting(g,
|
|
1253 |
x, y, w, h, state, paintMethod, direction);
|
|
1254 |
try {
|
|
1255 |
paintMethod.invoke(this, context,
|
|
1256 |
g, state, x, y, w, h, direction);
|
|
1257 |
} catch (IllegalAccessException iae) {
|
|
1258 |
assert false;
|
|
1259 |
} catch (InvocationTargetException ite) {
|
|
1260 |
assert false;
|
|
1261 |
}
|
|
1262 |
ENGINE.finishPainting();
|
|
1263 |
}
|
|
1264 |
}
|
|
1265 |
}
|
|
1266 |
|
|
1267 |
// All icon painting methods are called from under GTK_LOCK
|
|
1268 |
|
|
1269 |
public void paintTreeExpandedIcon(SynthContext context,
|
|
1270 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1271 |
ENGINE.paintExpander(g, context, Region.TREE,
|
|
1272 |
GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state),
|
|
1273 |
ExpanderStyle.EXPANDED, "treeview", x, y, w, h);
|
|
1274 |
}
|
|
1275 |
|
|
1276 |
public void paintTreeCollapsedIcon(SynthContext context,
|
|
1277 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1278 |
ENGINE.paintExpander(g, context, Region.TREE,
|
|
1279 |
GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state),
|
|
1280 |
ExpanderStyle.COLLAPSED, "treeview", x, y, w, h);
|
|
1281 |
}
|
|
1282 |
|
|
1283 |
public void paintCheckBoxIcon(SynthContext context,
|
|
1284 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1285 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
1286 |
int size = style.getClassSpecificIntValue(context,
|
|
1287 |
"indicator-size", GTKIconFactory.DEFAULT_ICON_SIZE);
|
|
1288 |
int offset = style.getClassSpecificIntValue(context,
|
|
1289 |
"indicator-spacing", GTKIconFactory.DEFAULT_ICON_SPACING);
|
|
1290 |
|
|
1291 |
ENGINE.paintCheck(g, context, Region.CHECK_BOX, "checkbutton",
|
|
1292 |
x+offset, y+offset, size, size);
|
|
1293 |
}
|
|
1294 |
|
|
1295 |
public void paintRadioButtonIcon(SynthContext context,
|
|
1296 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1297 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
1298 |
int size = style.getClassSpecificIntValue(context,
|
|
1299 |
"indicator-size", GTKIconFactory.DEFAULT_ICON_SIZE);
|
|
1300 |
int offset = style.getClassSpecificIntValue(context,
|
|
1301 |
"indicator-spacing", GTKIconFactory.DEFAULT_ICON_SPACING);
|
|
1302 |
|
|
1303 |
ENGINE.paintOption(g, context, Region.RADIO_BUTTON, "radiobutton",
|
|
1304 |
x+offset, y+offset, size, size);
|
|
1305 |
}
|
|
1306 |
|
|
1307 |
public void paintMenuArrowIcon(SynthContext context, Graphics g,
|
|
1308 |
int state, int x, int y, int w, int h, ArrowType dir) {
|
|
1309 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
1310 |
context.getRegion(), state);
|
|
1311 |
ShadowType shadow = ShadowType.OUT;
|
|
1312 |
if (gtkState == SynthConstants.MOUSE_OVER) {
|
|
1313 |
shadow = ShadowType.IN;
|
|
1314 |
}
|
|
1315 |
ENGINE.paintArrow(g, context, Region.MENU_ITEM, gtkState, shadow,
|
|
1316 |
dir, "menuitem", x + 3, y + 3, 7, 7);
|
|
1317 |
}
|
|
1318 |
|
|
1319 |
public void paintCheckBoxMenuItemCheckIcon(SynthContext context,
|
|
1320 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1321 |
|
|
1322 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
1323 |
int size = style.getClassSpecificIntValue(context,"indicator-size",
|
|
1324 |
GTKIconFactory.DEFAULT_TOGGLE_MENU_ITEM_SIZE);
|
|
1325 |
|
|
1326 |
ENGINE.paintCheck(g, context, Region.CHECK_BOX_MENU_ITEM, "check",
|
|
1327 |
x + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
|
|
1328 |
y + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
|
|
1329 |
size, size);
|
|
1330 |
}
|
|
1331 |
|
|
1332 |
public void paintRadioButtonMenuItemCheckIcon(SynthContext context,
|
|
1333 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1334 |
|
|
1335 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
1336 |
int size = style.getClassSpecificIntValue(context,"indicator-size",
|
|
1337 |
GTKIconFactory.DEFAULT_TOGGLE_MENU_ITEM_SIZE);
|
|
1338 |
|
|
1339 |
ENGINE.paintOption(g, context, Region.RADIO_BUTTON_MENU_ITEM, "option",
|
|
1340 |
x + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
|
|
1341 |
y + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
|
|
1342 |
size, size);
|
|
1343 |
}
|
|
1344 |
|
|
1345 |
public void paintToolBarHandleIcon(SynthContext context, Graphics g,
|
|
1346 |
int state, int x, int y, int w, int h, Orientation orientation) {
|
|
1347 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(
|
|
1348 |
context.getRegion(), state);
|
|
1349 |
|
|
1350 |
// The orientation parameter passed down by Synth refers to the
|
|
1351 |
// orientation of the toolbar, but the one we pass to GTK refers
|
|
1352 |
// to the orientation of the handle. Therefore, we need to swap
|
|
1353 |
// the value here: horizontal toolbars have vertical handles, and
|
|
1354 |
// vice versa.
|
|
1355 |
orientation = (orientation == Orientation.HORIZONTAL) ?
|
|
1356 |
Orientation.VERTICAL : Orientation.HORIZONTAL;
|
|
1357 |
|
|
1358 |
ENGINE.paintHandle(g, context, Region.TOOL_BAR, gtkState,
|
|
1359 |
ShadowType.OUT, "handlebox", x, y, w, h, orientation);
|
|
1360 |
}
|
|
1361 |
|
|
1362 |
public void paintAscendingSortIcon(SynthContext context,
|
|
1363 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1364 |
ENGINE.paintArrow(g, context, Region.TABLE, SynthConstants.ENABLED,
|
|
1365 |
ShadowType.IN, ArrowType.UP, "arrow", x, y, w, h);
|
|
1366 |
}
|
|
1367 |
|
|
1368 |
public void paintDescendingSortIcon(SynthContext context,
|
|
1369 |
Graphics g, int state, int x, int y, int w, int h) {
|
|
1370 |
ENGINE.paintArrow(g, context, Region.TABLE, SynthConstants.ENABLED,
|
|
1371 |
ShadowType.IN, ArrowType.DOWN, "arrow", x, y, w, h);
|
|
1372 |
}
|
|
1373 |
|
|
1374 |
/*
|
|
1375 |
* Fill an area with color determined from this context's Style using the
|
|
1376 |
* specified GTKColorType
|
|
1377 |
*/
|
|
1378 |
private void fillArea(SynthContext context, Graphics g,
|
|
1379 |
int x, int y, int w, int h, ColorType colorType) {
|
|
1380 |
if (context.getComponent().isOpaque()) {
|
|
1381 |
Region id = context.getRegion();
|
|
1382 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id,
|
|
1383 |
context.getComponentState());
|
|
1384 |
GTKStyle style = (GTKStyle)context.getStyle();
|
|
1385 |
|
|
1386 |
g.setColor(style.getGTKColor(context, gtkState, colorType));
|
|
1387 |
g.fillRect(x, y, w, h);
|
|
1388 |
}
|
|
1389 |
}
|
|
1390 |
|
|
1391 |
// Refer to GTKLookAndFeel for details on this.
|
|
1392 |
static class ListTableFocusBorder extends AbstractBorder implements
|
|
1393 |
UIResource {
|
|
1394 |
|
|
1395 |
private boolean selectedCell;
|
|
1396 |
private boolean focusedCell;
|
|
1397 |
|
|
1398 |
public static ListTableFocusBorder getSelectedCellBorder() {
|
|
1399 |
return new ListTableFocusBorder(true, true);
|
|
1400 |
}
|
|
1401 |
|
|
1402 |
public static ListTableFocusBorder getUnselectedCellBorder() {
|
|
1403 |
return new ListTableFocusBorder(false, true);
|
|
1404 |
}
|
|
1405 |
|
|
1406 |
public static ListTableFocusBorder getNoFocusCellBorder() {
|
|
1407 |
return new ListTableFocusBorder(false, false);
|
|
1408 |
}
|
|
1409 |
|
|
1410 |
public ListTableFocusBorder(boolean selectedCell, boolean focusedCell) {
|
|
1411 |
this.selectedCell = selectedCell;
|
|
1412 |
this.focusedCell = focusedCell;
|
|
1413 |
}
|
|
1414 |
|
|
1415 |
private SynthContext getContext(Component c) {
|
|
1416 |
SynthContext context = null;
|
|
1417 |
|
|
1418 |
ComponentUI ui = null;
|
|
1419 |
if (c instanceof JLabel) {
|
|
1420 |
ui = ((JLabel)c).getUI();
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
if (ui instanceof SynthUI) {
|
|
1424 |
context = ((SynthUI)ui).getContext((JComponent)c);
|
|
1425 |
}
|
|
1426 |
|
|
1427 |
return context;
|
|
1428 |
}
|
|
1429 |
|
|
1430 |
public void paintBorder(Component c, Graphics g, int x, int y,
|
|
1431 |
int w, int h) {
|
|
1432 |
if (focusedCell) {
|
|
1433 |
SynthContext context = getContext(c);
|
|
1434 |
int state = (selectedCell? SynthConstants.SELECTED:
|
|
1435 |
SynthConstants.FOCUSED | SynthConstants.ENABLED);
|
|
1436 |
|
|
1437 |
if (context != null) {
|
|
1438 |
GTKPainter.INSTANCE.paintFocus(context, g,
|
|
1439 |
Region.TABLE, state, "", x, y, w, h);
|
|
1440 |
}
|
|
1441 |
}
|
|
1442 |
}
|
|
1443 |
|
|
1444 |
public Insets getBorderInsets(Component c) {
|
|
1445 |
return getBorderInsets(c, null);
|
|
1446 |
}
|
|
1447 |
|
|
1448 |
public Insets getBorderInsets(Component c, Insets i) {
|
|
1449 |
SynthContext context = getContext(c);
|
|
1450 |
|
|
1451 |
if (context != null) {
|
|
1452 |
i = context.getStyle().getInsets(context, i);
|
|
1453 |
}
|
|
1454 |
|
|
1455 |
return i;
|
|
1456 |
}
|
|
1457 |
|
|
1458 |
public boolean isBorderOpaque() {
|
|
1459 |
return true;
|
|
1460 |
}
|
|
1461 |
}
|
|
1462 |
|
|
1463 |
// TitledBorder implementation for GTK L&F
|
|
1464 |
static class TitledBorder extends AbstractBorder implements UIResource {
|
|
1465 |
|
|
1466 |
public void paintBorder(Component c, Graphics g, int x, int y,
|
|
1467 |
int w, int h) {
|
|
1468 |
SynthContext context = getContext((JComponent)c);
|
|
1469 |
Region id = context.getRegion();
|
|
1470 |
int state = context.getComponentState();
|
|
1471 |
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
|
1472 |
|
|
1473 |
synchronized (UNIXToolkit.GTK_LOCK) {
|
|
1474 |
if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
|
|
1475 |
ENGINE.startPainting(g, x, y, w, h, id);
|
|
1476 |
ENGINE.paintShadow(g, context, id, gtkState, ShadowType.ETCHED_IN,
|
|
1477 |
"frame", x, y, w, h);
|
|
1478 |
ENGINE.finishPainting();
|
|
1479 |
}
|
|
1480 |
}
|
|
1481 |
}
|
|
1482 |
|
|
1483 |
public Insets getBorderInsets(Component c, Insets i) {
|
|
1484 |
SynthContext context = getContext((JComponent)c);
|
|
1485 |
return context.getStyle().getInsets(context, i);
|
|
1486 |
}
|
|
1487 |
|
|
1488 |
public boolean isBorderOpaque() {
|
|
1489 |
return true;
|
|
1490 |
}
|
|
1491 |
|
|
1492 |
private SynthStyle getStyle(JComponent c) {
|
|
1493 |
return SynthLookAndFeel.getStyle(c, GTKEngine.CustomRegion.TITLED_BORDER);
|
|
1494 |
}
|
|
1495 |
|
|
1496 |
private SynthContext getContext(JComponent c) {
|
|
1497 |
int state = SynthConstants.DEFAULT;
|
|
1498 |
return new SynthContext(c, GTKEngine.CustomRegion.TITLED_BORDER,
|
|
1499 |
getStyle(c), state);
|
|
1500 |
}
|
|
1501 |
}
|
|
1502 |
}
|