author | darcy |
Sun, 23 Mar 2014 13:49:48 -0700 | |
changeset 23697 | e556a715949f |
parent 23010 | 6dadb192ad81 |
child 25765 | 88051e6ecdc7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 1997, 2014, 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 |
||
26 |
package javax.swing.plaf.basic; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import javax.swing.border.*; |
|
30 |
import javax.swing.plaf.*; |
|
31 |
import javax.swing.text.JTextComponent; |
|
32 |
||
33 |
import java.awt.Component; |
|
34 |
import java.awt.Insets; |
|
35 |
import java.awt.Dimension; |
|
36 |
import java.awt.Rectangle; |
|
37 |
import java.awt.Color; |
|
38 |
import java.awt.Graphics; |
|
39 |
||
40 |
/** |
|
20169 | 41 |
* Factory object that can vend Borders appropriate for the basic L & F. |
2 | 42 |
* @author Georges Saab |
43 |
* @author Amy Fowler |
|
44 |
*/ |
|
45 |
||
46 |
public class BasicBorders { |
|
47 |
||
48 |
public static Border getButtonBorder() { |
|
49 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
50 |
Border buttonBorder = new BorderUIResource.CompoundBorderUIResource( |
|
51 |
new BasicBorders.ButtonBorder( |
|
52 |
table.getColor("Button.shadow"), |
|
53 |
table.getColor("Button.darkShadow"), |
|
54 |
table.getColor("Button.light"), |
|
55 |
table.getColor("Button.highlight")), |
|
56 |
new MarginBorder()); |
|
57 |
return buttonBorder; |
|
58 |
} |
|
59 |
||
60 |
public static Border getRadioButtonBorder() { |
|
61 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
62 |
Border radioButtonBorder = new BorderUIResource.CompoundBorderUIResource( |
|
63 |
new BasicBorders.RadioButtonBorder( |
|
64 |
table.getColor("RadioButton.shadow"), |
|
65 |
table.getColor("RadioButton.darkShadow"), |
|
66 |
table.getColor("RadioButton.light"), |
|
67 |
table.getColor("RadioButton.highlight")), |
|
68 |
new MarginBorder()); |
|
69 |
return radioButtonBorder; |
|
70 |
} |
|
71 |
||
72 |
public static Border getToggleButtonBorder() { |
|
73 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
74 |
Border toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource( |
|
75 |
new BasicBorders.ToggleButtonBorder( |
|
76 |
table.getColor("ToggleButton.shadow"), |
|
77 |
table.getColor("ToggleButton.darkShadow"), |
|
78 |
table.getColor("ToggleButton.light"), |
|
79 |
table.getColor("ToggleButton.highlight")), |
|
80 |
new MarginBorder()); |
|
81 |
return toggleButtonBorder; |
|
82 |
} |
|
83 |
||
84 |
public static Border getMenuBarBorder() { |
|
85 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
86 |
Border menuBarBorder = new BasicBorders.MenuBarBorder( |
|
87 |
table.getColor("MenuBar.shadow"), |
|
88 |
table.getColor("MenuBar.highlight") |
|
89 |
); |
|
90 |
return menuBarBorder; |
|
91 |
} |
|
92 |
||
93 |
public static Border getSplitPaneBorder() { |
|
94 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
95 |
Border splitPaneBorder = new BasicBorders.SplitPaneBorder( |
|
96 |
table.getColor("SplitPane.highlight"), |
|
97 |
table.getColor("SplitPane.darkShadow")); |
|
98 |
return splitPaneBorder; |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* Returns a border instance for a JSplitPane divider |
|
103 |
* @since 1.3 |
|
104 |
*/ |
|
105 |
public static Border getSplitPaneDividerBorder() { |
|
106 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
107 |
Border splitPaneBorder = new BasicBorders.SplitPaneDividerBorder( |
|
108 |
table.getColor("SplitPane.highlight"), |
|
109 |
table.getColor("SplitPane.darkShadow")); |
|
110 |
return splitPaneBorder; |
|
111 |
} |
|
112 |
||
113 |
public static Border getTextFieldBorder() { |
|
114 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
115 |
Border textFieldBorder = new BasicBorders.FieldBorder( |
|
116 |
table.getColor("TextField.shadow"), |
|
117 |
table.getColor("TextField.darkShadow"), |
|
118 |
table.getColor("TextField.light"), |
|
119 |
table.getColor("TextField.highlight")); |
|
120 |
return textFieldBorder; |
|
121 |
} |
|
122 |
||
123 |
public static Border getProgressBarBorder() { |
|
124 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
125 |
Border progressBarBorder = new BorderUIResource.LineBorderUIResource(Color.green, 2); |
|
126 |
return progressBarBorder; |
|
127 |
} |
|
128 |
||
129 |
public static Border getInternalFrameBorder() { |
|
130 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
131 |
Border internalFrameBorder = new BorderUIResource.CompoundBorderUIResource( |
|
132 |
new BevelBorder(BevelBorder.RAISED, |
|
133 |
table.getColor("InternalFrame.borderLight"), |
|
134 |
table.getColor("InternalFrame.borderHighlight"), |
|
135 |
table.getColor("InternalFrame.borderDarkShadow"), |
|
136 |
table.getColor("InternalFrame.borderShadow")), |
|
137 |
BorderFactory.createLineBorder( |
|
138 |
table.getColor("InternalFrame.borderColor"), 1)); |
|
139 |
||
140 |
return internalFrameBorder; |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Special thin border for rollover toolbar buttons. |
|
145 |
* @since 1.4 |
|
146 |
*/ |
|
23697 | 147 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 148 |
public static class RolloverButtonBorder extends ButtonBorder { |
149 |
||
150 |
public RolloverButtonBorder(Color shadow, Color darkShadow, |
|
151 |
Color highlight, Color lightHighlight) { |
|
152 |
super(shadow, darkShadow, highlight, lightHighlight); |
|
153 |
} |
|
154 |
||
155 |
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { |
|
156 |
AbstractButton b = (AbstractButton) c; |
|
157 |
ButtonModel model = b.getModel(); |
|
158 |
||
159 |
Color shade = shadow; |
|
160 |
Component p = b.getParent(); |
|
161 |
if (p != null && p.getBackground().equals(shadow)) { |
|
162 |
shade = darkShadow; |
|
163 |
} |
|
164 |
||
165 |
if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) || |
|
166 |
model.isSelected()) { |
|
167 |
||
168 |
Color oldColor = g.getColor(); |
|
169 |
g.translate(x, y); |
|
170 |
||
171 |
if (model.isPressed() && model.isArmed() || model.isSelected()) { |
|
172 |
// Draw the pressd button |
|
173 |
g.setColor(shade); |
|
174 |
g.drawRect(0, 0, w-1, h-1); |
|
175 |
g.setColor(lightHighlight); |
|
176 |
g.drawLine(w-1, 0, w-1, h-1); |
|
177 |
g.drawLine(0, h-1, w-1, h-1); |
|
178 |
} else { |
|
179 |
// Draw a rollover button |
|
180 |
g.setColor(lightHighlight); |
|
181 |
g.drawRect(0, 0, w-1, h-1); |
|
182 |
g.setColor(shade); |
|
183 |
g.drawLine(w-1, 0, w-1, h-1); |
|
184 |
g.drawLine(0, h-1, w-1, h-1); |
|
185 |
} |
|
186 |
g.translate(-x, -y); |
|
187 |
g.setColor(oldColor); |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
||
193 |
/** |
|
194 |
* A border which is like a Margin border but it will only honor the margin |
|
195 |
* if the margin has been explicitly set by the developer. |
|
196 |
* |
|
197 |
* Note: This is identical to the package private class |
|
198 |
* MetalBorders.RolloverMarginBorder and should probably be consolidated. |
|
199 |
*/ |
|
23697 | 200 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 201 |
static class RolloverMarginBorder extends EmptyBorder { |
202 |
||
203 |
public RolloverMarginBorder() { |
|
204 |
super(3,3,3,3); // hardcoded margin for JLF requirements. |
|
205 |
} |
|
206 |
||
207 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
208 |
Insets margin = null; |
|
209 |
||
210 |
if (c instanceof AbstractButton) { |
|
211 |
margin = ((AbstractButton)c).getMargin(); |
|
212 |
} |
|
213 |
if (margin == null || margin instanceof UIResource) { |
|
214 |
// default margin so replace |
|
215 |
insets.left = left; |
|
216 |
insets.top = top; |
|
217 |
insets.right = right; |
|
218 |
insets.bottom = bottom; |
|
219 |
} else { |
|
220 |
// Margin which has been explicitly set by the user. |
|
221 |
insets.left = margin.left; |
|
222 |
insets.top = margin.top; |
|
223 |
insets.right = margin.right; |
|
224 |
insets.bottom = margin.bottom; |
|
225 |
} |
|
226 |
return insets; |
|
227 |
} |
|
228 |
} |
|
229 |
||
23697 | 230 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 231 |
public static class ButtonBorder extends AbstractBorder implements UIResource { |
232 |
protected Color shadow; |
|
233 |
protected Color darkShadow; |
|
234 |
protected Color highlight; |
|
235 |
protected Color lightHighlight; |
|
236 |
||
237 |
public ButtonBorder(Color shadow, Color darkShadow, |
|
238 |
Color highlight, Color lightHighlight) { |
|
239 |
this.shadow = shadow; |
|
240 |
this.darkShadow = darkShadow; |
|
241 |
this.highlight = highlight; |
|
242 |
this.lightHighlight = lightHighlight; |
|
243 |
} |
|
244 |
||
245 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
246 |
int width, int height) { |
|
247 |
boolean isPressed = false; |
|
248 |
boolean isDefault = false; |
|
249 |
||
250 |
if (c instanceof AbstractButton) { |
|
251 |
AbstractButton b = (AbstractButton)c; |
|
252 |
ButtonModel model = b.getModel(); |
|
253 |
||
254 |
isPressed = model.isPressed() && model.isArmed(); |
|
255 |
||
256 |
if (c instanceof JButton) { |
|
257 |
isDefault = ((JButton)c).isDefaultButton(); |
|
258 |
} |
|
259 |
} |
|
260 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, |
|
261 |
isPressed, isDefault, shadow, |
|
262 |
darkShadow, highlight, lightHighlight); |
|
263 |
} |
|
264 |
||
265 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
266 |
// leave room for default visual |
|
267 |
insets.set(2, 3, 3, 3); |
|
268 |
return insets; |
|
269 |
} |
|
270 |
||
271 |
} |
|
272 |
||
23697 | 273 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 274 |
public static class ToggleButtonBorder extends ButtonBorder { |
275 |
||
276 |
public ToggleButtonBorder(Color shadow, Color darkShadow, |
|
277 |
Color highlight, Color lightHighlight) { |
|
278 |
super(shadow, darkShadow, highlight, lightHighlight); |
|
279 |
} |
|
280 |
||
281 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
282 |
int width, int height) { |
|
283 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, |
|
284 |
false, false, |
|
285 |
shadow, darkShadow, |
|
286 |
highlight, lightHighlight); |
|
287 |
} |
|
288 |
||
289 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
290 |
insets.set(2, 2, 2, 2); |
|
291 |
return insets; |
|
292 |
} |
|
293 |
} |
|
294 |
||
23697 | 295 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 296 |
public static class RadioButtonBorder extends ButtonBorder { |
297 |
||
298 |
public RadioButtonBorder(Color shadow, Color darkShadow, |
|
299 |
Color highlight, Color lightHighlight) { |
|
300 |
super(shadow, darkShadow, highlight, lightHighlight); |
|
301 |
} |
|
302 |
||
303 |
||
304 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
305 |
||
306 |
if (c instanceof AbstractButton) { |
|
307 |
AbstractButton b = (AbstractButton)c; |
|
308 |
ButtonModel model = b.getModel(); |
|
309 |
||
310 |
if (model.isArmed() && model.isPressed() || model.isSelected()) { |
|
311 |
BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height, |
|
312 |
shadow, darkShadow, |
|
313 |
highlight, lightHighlight); |
|
314 |
} else { |
|
315 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, |
|
316 |
false, b.isFocusPainted() && b.hasFocus(), |
|
317 |
shadow, darkShadow, |
|
318 |
highlight, lightHighlight); |
|
319 |
} |
|
320 |
} else { |
|
321 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false, |
|
322 |
shadow, darkShadow, highlight, lightHighlight); |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
327 |
insets.set(2, 2, 2, 2); |
|
328 |
return insets; |
|
329 |
} |
|
330 |
} |
|
331 |
||
23697 | 332 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 333 |
public static class MenuBarBorder extends AbstractBorder implements UIResource { |
334 |
private Color shadow; |
|
335 |
private Color highlight; |
|
336 |
||
337 |
public MenuBarBorder(Color shadow, Color highlight) { |
|
338 |
this.shadow = shadow; |
|
339 |
this.highlight = highlight; |
|
340 |
} |
|
341 |
||
342 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
343 |
Color oldColor = g.getColor(); |
|
344 |
g.translate(x, y); |
|
345 |
g.setColor(shadow); |
|
346 |
g.drawLine(0, height-2, width, height-2); |
|
347 |
g.setColor(highlight); |
|
348 |
g.drawLine(0, height-1, width, height-1); |
|
349 |
g.translate(-x,-y); |
|
350 |
g.setColor(oldColor); |
|
351 |
} |
|
352 |
||
353 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
354 |
insets.set(0, 0, 2, 0); |
|
355 |
return insets; |
|
356 |
} |
|
357 |
} |
|
358 |
||
23697 | 359 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 360 |
public static class MarginBorder extends AbstractBorder implements UIResource { |
361 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
362 |
Insets margin = null; |
|
363 |
// |
|
364 |
// Ideally we'd have an interface defined for classes which |
|
365 |
// support margins (to avoid this hackery), but we've |
|
366 |
// decided against it for simplicity |
|
367 |
// |
|
368 |
if (c instanceof AbstractButton) { |
|
369 |
AbstractButton b = (AbstractButton)c; |
|
370 |
margin = b.getMargin(); |
|
371 |
} else if (c instanceof JToolBar) { |
|
372 |
JToolBar t = (JToolBar)c; |
|
373 |
margin = t.getMargin(); |
|
374 |
} else if (c instanceof JTextComponent) { |
|
375 |
JTextComponent t = (JTextComponent)c; |
|
376 |
margin = t.getMargin(); |
|
377 |
} |
|
378 |
insets.top = margin != null? margin.top : 0; |
|
379 |
insets.left = margin != null? margin.left : 0; |
|
380 |
insets.bottom = margin != null? margin.bottom : 0; |
|
381 |
insets.right = margin != null? margin.right : 0; |
|
382 |
||
383 |
return insets; |
|
384 |
} |
|
385 |
} |
|
386 |
||
23697 | 387 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 388 |
public static class FieldBorder extends AbstractBorder implements UIResource { |
389 |
protected Color shadow; |
|
390 |
protected Color darkShadow; |
|
391 |
protected Color highlight; |
|
392 |
protected Color lightHighlight; |
|
393 |
||
394 |
public FieldBorder(Color shadow, Color darkShadow, |
|
395 |
Color highlight, Color lightHighlight) { |
|
396 |
this.shadow = shadow; |
|
397 |
this.highlight = highlight; |
|
398 |
this.darkShadow = darkShadow; |
|
399 |
this.lightHighlight = lightHighlight; |
|
400 |
} |
|
401 |
||
402 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
403 |
int width, int height) { |
|
404 |
BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height, |
|
405 |
shadow, darkShadow, |
|
406 |
highlight, lightHighlight); |
|
407 |
} |
|
408 |
||
409 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
410 |
Insets margin = null; |
|
411 |
if (c instanceof JTextComponent) { |
|
412 |
margin = ((JTextComponent)c).getMargin(); |
|
413 |
} |
|
414 |
insets.top = margin != null? 2+margin.top : 2; |
|
415 |
insets.left = margin != null? 2+margin.left : 2; |
|
416 |
insets.bottom = margin != null? 2+margin.bottom : 2; |
|
417 |
insets.right = margin != null? 2+margin.right : 2; |
|
418 |
||
419 |
return insets; |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
||
424 |
/** |
|
425 |
* Draws the border around the divider in a splitpane |
|
426 |
* (when BasicSplitPaneUI is used). To get the appropriate effect, this |
|
427 |
* needs to be used with a SplitPaneBorder. |
|
428 |
*/ |
|
429 |
static class SplitPaneDividerBorder implements Border, UIResource { |
|
430 |
Color highlight; |
|
431 |
Color shadow; |
|
432 |
||
433 |
SplitPaneDividerBorder(Color highlight, Color shadow) { |
|
434 |
this.highlight = highlight; |
|
435 |
this.shadow = shadow; |
|
436 |
} |
|
437 |
||
438 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
439 |
int width, int height) { |
|
6510
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
440 |
if (!(c instanceof BasicSplitPaneDivider)) { |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
441 |
return; |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
442 |
} |
2 | 443 |
Component child; |
444 |
Rectangle cBounds; |
|
445 |
JSplitPane splitPane = ((BasicSplitPaneDivider)c). |
|
446 |
getBasicSplitPaneUI().getSplitPane(); |
|
447 |
Dimension size = c.getSize(); |
|
448 |
||
449 |
child = splitPane.getLeftComponent(); |
|
450 |
// This is needed for the space between the divider and end of |
|
451 |
// splitpane. |
|
452 |
g.setColor(c.getBackground()); |
|
453 |
g.drawRect(x, y, width - 1, height - 1); |
|
454 |
if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { |
|
455 |
if(child != null) { |
|
456 |
g.setColor(highlight); |
|
457 |
g.drawLine(0, 0, 0, size.height); |
|
458 |
} |
|
459 |
child = splitPane.getRightComponent(); |
|
460 |
if(child != null) { |
|
461 |
g.setColor(shadow); |
|
462 |
g.drawLine(size.width - 1, 0, size.width - 1, size.height); |
|
463 |
} |
|
464 |
} else { |
|
465 |
if(child != null) { |
|
466 |
g.setColor(highlight); |
|
467 |
g.drawLine(0, 0, size.width, 0); |
|
468 |
} |
|
469 |
child = splitPane.getRightComponent(); |
|
470 |
if(child != null) { |
|
471 |
g.setColor(shadow); |
|
472 |
g.drawLine(0, size.height - 1, size.width, |
|
473 |
size.height - 1); |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
public Insets getBorderInsets(Component c) { |
|
478 |
Insets insets = new Insets(0,0,0,0); |
|
479 |
if (c instanceof BasicSplitPaneDivider) { |
|
480 |
BasicSplitPaneUI bspui = ((BasicSplitPaneDivider)c). |
|
481 |
getBasicSplitPaneUI(); |
|
482 |
||
483 |
if (bspui != null) { |
|
484 |
JSplitPane splitPane = bspui.getSplitPane(); |
|
485 |
||
486 |
if (splitPane != null) { |
|
487 |
if (splitPane.getOrientation() == |
|
488 |
JSplitPane.HORIZONTAL_SPLIT) { |
|
489 |
insets.top = insets.bottom = 0; |
|
490 |
insets.left = insets.right = 1; |
|
491 |
return insets; |
|
492 |
} |
|
493 |
// VERTICAL_SPLIT |
|
494 |
insets.top = insets.bottom = 1; |
|
495 |
insets.left = insets.right = 0; |
|
496 |
return insets; |
|
497 |
} |
|
498 |
} |
|
499 |
} |
|
500 |
insets.top = insets.bottom = insets.left = insets.right = 1; |
|
501 |
return insets; |
|
502 |
} |
|
503 |
public boolean isBorderOpaque() { return true; } |
|
504 |
} |
|
505 |
||
506 |
||
507 |
/** |
|
21278 | 508 |
* Draws the border around the splitpane. To work correctly you should |
2 | 509 |
* also install a border on the divider (property SplitPaneDivider.border). |
510 |
*/ |
|
511 |
public static class SplitPaneBorder implements Border, UIResource { |
|
512 |
protected Color highlight; |
|
513 |
protected Color shadow; |
|
514 |
||
515 |
public SplitPaneBorder(Color highlight, Color shadow) { |
|
516 |
this.highlight = highlight; |
|
517 |
this.shadow = shadow; |
|
518 |
} |
|
519 |
||
520 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
521 |
int width, int height) { |
|
6510
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
522 |
if (!(c instanceof JSplitPane)) { |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
523 |
return; |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
524 |
} |
2 | 525 |
// The only tricky part with this border is that the divider is |
526 |
// not positioned at the top (for horizontal) or left (for vert), |
|
527 |
// so this border draws to where the divider is: |
|
528 |
// ----------------- |
|
529 |
// |xxxxxxx xxxxxxx| |
|
530 |
// |x --- x| |
|
531 |
// |x | | x| |
|
532 |
// |x |D| x| |
|
533 |
// |x | | x| |
|
534 |
// |x --- x| |
|
535 |
// |xxxxxxx xxxxxxx| |
|
536 |
// ----------------- |
|
537 |
// The above shows (rather excessively) what this looks like for |
|
538 |
// a horizontal orientation. This border then draws the x's, with |
|
539 |
// the SplitPaneDividerBorder drawing its own border. |
|
540 |
||
541 |
Component child; |
|
542 |
Rectangle cBounds; |
|
543 |
||
544 |
JSplitPane splitPane = (JSplitPane)c; |
|
545 |
||
546 |
child = splitPane.getLeftComponent(); |
|
547 |
// This is needed for the space between the divider and end of |
|
548 |
// splitpane. |
|
549 |
g.setColor(c.getBackground()); |
|
550 |
g.drawRect(x, y, width - 1, height - 1); |
|
551 |
if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { |
|
552 |
if(child != null) { |
|
553 |
cBounds = child.getBounds(); |
|
554 |
g.setColor(shadow); |
|
555 |
g.drawLine(0, 0, cBounds.width + 1, 0); |
|
556 |
g.drawLine(0, 1, 0, cBounds.height + 1); |
|
557 |
||
558 |
g.setColor(highlight); |
|
559 |
g.drawLine(0, cBounds.height + 1, cBounds.width + 1, |
|
560 |
cBounds.height + 1); |
|
561 |
} |
|
562 |
child = splitPane.getRightComponent(); |
|
563 |
if(child != null) { |
|
564 |
cBounds = child.getBounds(); |
|
565 |
||
566 |
int maxX = cBounds.x + cBounds.width; |
|
567 |
int maxY = cBounds.y + cBounds.height; |
|
568 |
||
569 |
g.setColor(shadow); |
|
570 |
g.drawLine(cBounds.x - 1, 0, maxX, 0); |
|
571 |
g.setColor(highlight); |
|
572 |
g.drawLine(cBounds.x - 1, maxY, maxX, maxY); |
|
573 |
g.drawLine(maxX, 0, maxX, maxY + 1); |
|
574 |
} |
|
575 |
} else { |
|
576 |
if(child != null) { |
|
577 |
cBounds = child.getBounds(); |
|
578 |
g.setColor(shadow); |
|
579 |
g.drawLine(0, 0, cBounds.width + 1, 0); |
|
580 |
g.drawLine(0, 1, 0, cBounds.height); |
|
581 |
g.setColor(highlight); |
|
582 |
g.drawLine(1 + cBounds.width, 0, 1 + cBounds.width, |
|
583 |
cBounds.height + 1); |
|
584 |
g.drawLine(0, cBounds.height + 1, 0, cBounds.height + 1); |
|
585 |
} |
|
586 |
child = splitPane.getRightComponent(); |
|
587 |
if(child != null) { |
|
588 |
cBounds = child.getBounds(); |
|
589 |
||
590 |
int maxX = cBounds.x + cBounds.width; |
|
591 |
int maxY = cBounds.y + cBounds.height; |
|
592 |
||
593 |
g.setColor(shadow); |
|
594 |
g.drawLine(0, cBounds.y - 1, 0, maxY); |
|
595 |
g.drawLine(maxX, cBounds.y - 1, maxX, cBounds.y - 1); |
|
596 |
g.setColor(highlight); |
|
597 |
g.drawLine(0, maxY, cBounds.width + 1, maxY); |
|
598 |
g.drawLine(maxX, cBounds.y, maxX, maxY); |
|
599 |
} |
|
600 |
} |
|
601 |
} |
|
602 |
public Insets getBorderInsets(Component c) { |
|
603 |
return new Insets(1, 1, 1, 1); |
|
604 |
} |
|
605 |
public boolean isBorderOpaque() { return true; } |
|
606 |
} |
|
607 |
||
608 |
} |