author | weijun |
Thu, 11 Dec 2014 15:19:12 +0800 | |
changeset 28228 | be83f404724d |
parent 25859 | 3317bb8137f4 |
child 29507 | f16389ada5f3 |
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 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
48 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
49 |
* Returns a border instance for a {@code JButton}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
50 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
51 |
* @return a border instance for a {@code JButton} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
52 |
*/ |
2 | 53 |
public static Border getButtonBorder() { |
54 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
55 |
Border buttonBorder = new BorderUIResource.CompoundBorderUIResource( |
|
56 |
new BasicBorders.ButtonBorder( |
|
57 |
table.getColor("Button.shadow"), |
|
58 |
table.getColor("Button.darkShadow"), |
|
59 |
table.getColor("Button.light"), |
|
60 |
table.getColor("Button.highlight")), |
|
61 |
new MarginBorder()); |
|
62 |
return buttonBorder; |
|
63 |
} |
|
64 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
65 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
66 |
* Returns a border instance for a {@code JRadioButton}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
67 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
68 |
* @return a border instance for a {@code JRadioButton} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
69 |
*/ |
2 | 70 |
public static Border getRadioButtonBorder() { |
71 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
72 |
Border radioButtonBorder = new BorderUIResource.CompoundBorderUIResource( |
|
73 |
new BasicBorders.RadioButtonBorder( |
|
74 |
table.getColor("RadioButton.shadow"), |
|
75 |
table.getColor("RadioButton.darkShadow"), |
|
76 |
table.getColor("RadioButton.light"), |
|
77 |
table.getColor("RadioButton.highlight")), |
|
78 |
new MarginBorder()); |
|
79 |
return radioButtonBorder; |
|
80 |
} |
|
81 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
82 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
83 |
* Returns a border instance for a {@code JToggleButton}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
84 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
85 |
* @return a border instance for a {@code JToggleButton} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
86 |
*/ |
2 | 87 |
public static Border getToggleButtonBorder() { |
88 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
89 |
Border toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource( |
|
90 |
new BasicBorders.ToggleButtonBorder( |
|
91 |
table.getColor("ToggleButton.shadow"), |
|
92 |
table.getColor("ToggleButton.darkShadow"), |
|
93 |
table.getColor("ToggleButton.light"), |
|
94 |
table.getColor("ToggleButton.highlight")), |
|
95 |
new MarginBorder()); |
|
96 |
return toggleButtonBorder; |
|
97 |
} |
|
98 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
99 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
100 |
* Returns a border instance for a {@code JMenuBar}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
101 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
102 |
* @return a border instance for a {@code JMenuBar} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
103 |
*/ |
2 | 104 |
public static Border getMenuBarBorder() { |
105 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
106 |
Border menuBarBorder = new BasicBorders.MenuBarBorder( |
|
107 |
table.getColor("MenuBar.shadow"), |
|
108 |
table.getColor("MenuBar.highlight") |
|
109 |
); |
|
110 |
return menuBarBorder; |
|
111 |
} |
|
112 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
113 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
114 |
* Returns a border instance for a {@code JSplitPane}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
115 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
116 |
* @return a border instance for a {@code JSplitPane} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
117 |
*/ |
2 | 118 |
public static Border getSplitPaneBorder() { |
119 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
120 |
Border splitPaneBorder = new BasicBorders.SplitPaneBorder( |
|
121 |
table.getColor("SplitPane.highlight"), |
|
122 |
table.getColor("SplitPane.darkShadow")); |
|
123 |
return splitPaneBorder; |
|
124 |
} |
|
125 |
||
126 |
/** |
|
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
127 |
* Returns a border instance for a {@code JSplitPane} divider. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
128 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
129 |
* @return a border instance for a {@code JSplitPane} divider |
2 | 130 |
* @since 1.3 |
131 |
*/ |
|
132 |
public static Border getSplitPaneDividerBorder() { |
|
133 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
134 |
Border splitPaneBorder = new BasicBorders.SplitPaneDividerBorder( |
|
135 |
table.getColor("SplitPane.highlight"), |
|
136 |
table.getColor("SplitPane.darkShadow")); |
|
137 |
return splitPaneBorder; |
|
138 |
} |
|
139 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
140 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
141 |
* Returns a border instance for a {@code JTextField}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
142 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
143 |
* @return a border instance for a {@code JTextField} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
144 |
*/ |
2 | 145 |
public static Border getTextFieldBorder() { |
146 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
147 |
Border textFieldBorder = new BasicBorders.FieldBorder( |
|
148 |
table.getColor("TextField.shadow"), |
|
149 |
table.getColor("TextField.darkShadow"), |
|
150 |
table.getColor("TextField.light"), |
|
151 |
table.getColor("TextField.highlight")); |
|
152 |
return textFieldBorder; |
|
153 |
} |
|
154 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
155 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
156 |
* Returns a border instance for a {@code JProgressBar}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
157 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
158 |
* @return a border instance for a {@code JProgressBar} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
159 |
*/ |
2 | 160 |
public static Border getProgressBarBorder() { |
161 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
162 |
Border progressBarBorder = new BorderUIResource.LineBorderUIResource(Color.green, 2); |
|
163 |
return progressBarBorder; |
|
164 |
} |
|
165 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
166 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
167 |
* Returns a border instance for a {@code JInternalFrame}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
168 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
169 |
* @return a border instance for a {@code JInternalFrame} |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
170 |
*/ |
2 | 171 |
public static Border getInternalFrameBorder() { |
172 |
UIDefaults table = UIManager.getLookAndFeelDefaults(); |
|
173 |
Border internalFrameBorder = new BorderUIResource.CompoundBorderUIResource( |
|
174 |
new BevelBorder(BevelBorder.RAISED, |
|
175 |
table.getColor("InternalFrame.borderLight"), |
|
176 |
table.getColor("InternalFrame.borderHighlight"), |
|
177 |
table.getColor("InternalFrame.borderDarkShadow"), |
|
178 |
table.getColor("InternalFrame.borderShadow")), |
|
179 |
BorderFactory.createLineBorder( |
|
180 |
table.getColor("InternalFrame.borderColor"), 1)); |
|
181 |
||
182 |
return internalFrameBorder; |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Special thin border for rollover toolbar buttons. |
|
187 |
* @since 1.4 |
|
188 |
*/ |
|
23697 | 189 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 190 |
public static class RolloverButtonBorder extends ButtonBorder { |
191 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
192 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
193 |
* Constructs a new instance of a {@code RolloverButtonBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
194 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
195 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
196 |
* @param darkShadow a color of dark shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
197 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
198 |
* @param lightHighlight a color of light highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
199 |
*/ |
2 | 200 |
public RolloverButtonBorder(Color shadow, Color darkShadow, |
201 |
Color highlight, Color lightHighlight) { |
|
202 |
super(shadow, darkShadow, highlight, lightHighlight); |
|
203 |
} |
|
204 |
||
205 |
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { |
|
206 |
AbstractButton b = (AbstractButton) c; |
|
207 |
ButtonModel model = b.getModel(); |
|
208 |
||
209 |
Color shade = shadow; |
|
210 |
Component p = b.getParent(); |
|
211 |
if (p != null && p.getBackground().equals(shadow)) { |
|
212 |
shade = darkShadow; |
|
213 |
} |
|
214 |
||
215 |
if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) || |
|
216 |
model.isSelected()) { |
|
217 |
||
218 |
Color oldColor = g.getColor(); |
|
219 |
g.translate(x, y); |
|
220 |
||
221 |
if (model.isPressed() && model.isArmed() || model.isSelected()) { |
|
222 |
// Draw the pressd button |
|
223 |
g.setColor(shade); |
|
224 |
g.drawRect(0, 0, w-1, h-1); |
|
225 |
g.setColor(lightHighlight); |
|
226 |
g.drawLine(w-1, 0, w-1, h-1); |
|
227 |
g.drawLine(0, h-1, w-1, h-1); |
|
228 |
} else { |
|
229 |
// Draw a rollover button |
|
230 |
g.setColor(lightHighlight); |
|
231 |
g.drawRect(0, 0, w-1, h-1); |
|
232 |
g.setColor(shade); |
|
233 |
g.drawLine(w-1, 0, w-1, h-1); |
|
234 |
g.drawLine(0, h-1, w-1, h-1); |
|
235 |
} |
|
236 |
g.translate(-x, -y); |
|
237 |
g.setColor(oldColor); |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
||
242 |
||
243 |
/** |
|
244 |
* A border which is like a Margin border but it will only honor the margin |
|
245 |
* if the margin has been explicitly set by the developer. |
|
246 |
* |
|
247 |
* Note: This is identical to the package private class |
|
248 |
* MetalBorders.RolloverMarginBorder and should probably be consolidated. |
|
249 |
*/ |
|
23697 | 250 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 251 |
static class RolloverMarginBorder extends EmptyBorder { |
252 |
||
253 |
public RolloverMarginBorder() { |
|
254 |
super(3,3,3,3); // hardcoded margin for JLF requirements. |
|
255 |
} |
|
256 |
||
257 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
258 |
Insets margin = null; |
|
259 |
||
260 |
if (c instanceof AbstractButton) { |
|
261 |
margin = ((AbstractButton)c).getMargin(); |
|
262 |
} |
|
263 |
if (margin == null || margin instanceof UIResource) { |
|
264 |
// default margin so replace |
|
265 |
insets.left = left; |
|
266 |
insets.top = top; |
|
267 |
insets.right = right; |
|
268 |
insets.bottom = bottom; |
|
269 |
} else { |
|
270 |
// Margin which has been explicitly set by the user. |
|
271 |
insets.left = margin.left; |
|
272 |
insets.top = margin.top; |
|
273 |
insets.right = margin.right; |
|
274 |
insets.bottom = margin.bottom; |
|
275 |
} |
|
276 |
return insets; |
|
277 |
} |
|
278 |
} |
|
279 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
280 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
281 |
* Draws a border around a button. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
282 |
*/ |
23697 | 283 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 284 |
public static class ButtonBorder extends AbstractBorder implements UIResource { |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
285 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
286 |
* The color of shadow. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
287 |
*/ |
2 | 288 |
protected Color shadow; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
289 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
290 |
* The color of dark shadow. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
291 |
*/ |
2 | 292 |
protected Color darkShadow; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
293 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
294 |
* The color of highlight. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
295 |
*/ |
2 | 296 |
protected Color highlight; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
297 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
298 |
* The color of light highlight. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
299 |
*/ |
2 | 300 |
protected Color lightHighlight; |
301 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
302 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
303 |
* Constructs a new instance of a {@code ButtonBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
304 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
305 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
306 |
* @param darkShadow a color of dark shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
307 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
308 |
* @param lightHighlight a color of light highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
309 |
*/ |
2 | 310 |
public ButtonBorder(Color shadow, Color darkShadow, |
311 |
Color highlight, Color lightHighlight) { |
|
312 |
this.shadow = shadow; |
|
313 |
this.darkShadow = darkShadow; |
|
314 |
this.highlight = highlight; |
|
315 |
this.lightHighlight = lightHighlight; |
|
316 |
} |
|
317 |
||
318 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
319 |
int width, int height) { |
|
320 |
boolean isPressed = false; |
|
321 |
boolean isDefault = false; |
|
322 |
||
323 |
if (c instanceof AbstractButton) { |
|
324 |
AbstractButton b = (AbstractButton)c; |
|
325 |
ButtonModel model = b.getModel(); |
|
326 |
||
327 |
isPressed = model.isPressed() && model.isArmed(); |
|
328 |
||
329 |
if (c instanceof JButton) { |
|
330 |
isDefault = ((JButton)c).isDefaultButton(); |
|
331 |
} |
|
332 |
} |
|
333 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, |
|
334 |
isPressed, isDefault, shadow, |
|
335 |
darkShadow, highlight, lightHighlight); |
|
336 |
} |
|
337 |
||
338 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
339 |
// leave room for default visual |
|
340 |
insets.set(2, 3, 3, 3); |
|
341 |
return insets; |
|
342 |
} |
|
343 |
||
344 |
} |
|
345 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
346 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
347 |
* Draws the border around a toggle button. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
348 |
*/ |
23697 | 349 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 350 |
public static class ToggleButtonBorder extends ButtonBorder { |
351 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
352 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
353 |
* Constructs a new instance of a {@code ToggleButtonBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
354 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
355 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
356 |
* @param darkShadow a color of dark shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
357 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
358 |
* @param lightHighlight a color of light highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
359 |
*/ |
2 | 360 |
public ToggleButtonBorder(Color shadow, Color darkShadow, |
361 |
Color highlight, Color lightHighlight) { |
|
362 |
super(shadow, darkShadow, highlight, lightHighlight); |
|
363 |
} |
|
364 |
||
365 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
366 |
int width, int height) { |
|
367 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, |
|
368 |
false, false, |
|
369 |
shadow, darkShadow, |
|
370 |
highlight, lightHighlight); |
|
371 |
} |
|
372 |
||
373 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
374 |
insets.set(2, 2, 2, 2); |
|
375 |
return insets; |
|
376 |
} |
|
377 |
} |
|
378 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
379 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
380 |
* Draws the border around a radio button. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
381 |
*/ |
23697 | 382 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 383 |
public static class RadioButtonBorder extends ButtonBorder { |
384 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
385 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
386 |
* Constructs a new instance of a {@code RadioButtonBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
387 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
388 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
389 |
* @param darkShadow a color of dark shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
390 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
391 |
* @param lightHighlight a color of light highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
392 |
*/ |
2 | 393 |
public RadioButtonBorder(Color shadow, Color darkShadow, |
394 |
Color highlight, Color lightHighlight) { |
|
395 |
super(shadow, darkShadow, highlight, lightHighlight); |
|
396 |
} |
|
397 |
||
398 |
||
399 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
400 |
||
401 |
if (c instanceof AbstractButton) { |
|
402 |
AbstractButton b = (AbstractButton)c; |
|
403 |
ButtonModel model = b.getModel(); |
|
404 |
||
405 |
if (model.isArmed() && model.isPressed() || model.isSelected()) { |
|
406 |
BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height, |
|
407 |
shadow, darkShadow, |
|
408 |
highlight, lightHighlight); |
|
409 |
} else { |
|
410 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, |
|
411 |
false, b.isFocusPainted() && b.hasFocus(), |
|
412 |
shadow, darkShadow, |
|
413 |
highlight, lightHighlight); |
|
414 |
} |
|
415 |
} else { |
|
416 |
BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false, |
|
417 |
shadow, darkShadow, highlight, lightHighlight); |
|
418 |
} |
|
419 |
} |
|
420 |
||
421 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
422 |
insets.set(2, 2, 2, 2); |
|
423 |
return insets; |
|
424 |
} |
|
425 |
} |
|
426 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
427 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
428 |
* Draws the border around a menu bar. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
429 |
*/ |
23697 | 430 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 431 |
public static class MenuBarBorder extends AbstractBorder implements UIResource { |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
432 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
433 |
* The color of shadow. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
434 |
*/ |
2 | 435 |
private Color shadow; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
436 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
437 |
* The color of highlight. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
438 |
*/ |
2 | 439 |
private Color highlight; |
440 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
441 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
442 |
* Constructs a new instance of a {@code MenuBarBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
443 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
444 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
445 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
446 |
*/ |
2 | 447 |
public MenuBarBorder(Color shadow, Color highlight) { |
448 |
this.shadow = shadow; |
|
449 |
this.highlight = highlight; |
|
450 |
} |
|
451 |
||
452 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
453 |
Color oldColor = g.getColor(); |
|
454 |
g.translate(x, y); |
|
455 |
g.setColor(shadow); |
|
456 |
g.drawLine(0, height-2, width, height-2); |
|
457 |
g.setColor(highlight); |
|
458 |
g.drawLine(0, height-1, width, height-1); |
|
459 |
g.translate(-x,-y); |
|
460 |
g.setColor(oldColor); |
|
461 |
} |
|
462 |
||
463 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
464 |
insets.set(0, 0, 2, 0); |
|
465 |
return insets; |
|
466 |
} |
|
467 |
} |
|
468 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
469 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
470 |
* Draws the border around components which support margins. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
471 |
*/ |
23697 | 472 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 473 |
public static class MarginBorder extends AbstractBorder implements UIResource { |
474 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
475 |
Insets margin = null; |
|
476 |
// |
|
477 |
// Ideally we'd have an interface defined for classes which |
|
478 |
// support margins (to avoid this hackery), but we've |
|
479 |
// decided against it for simplicity |
|
480 |
// |
|
481 |
if (c instanceof AbstractButton) { |
|
482 |
AbstractButton b = (AbstractButton)c; |
|
483 |
margin = b.getMargin(); |
|
484 |
} else if (c instanceof JToolBar) { |
|
485 |
JToolBar t = (JToolBar)c; |
|
486 |
margin = t.getMargin(); |
|
487 |
} else if (c instanceof JTextComponent) { |
|
488 |
JTextComponent t = (JTextComponent)c; |
|
489 |
margin = t.getMargin(); |
|
490 |
} |
|
491 |
insets.top = margin != null? margin.top : 0; |
|
492 |
insets.left = margin != null? margin.left : 0; |
|
493 |
insets.bottom = margin != null? margin.bottom : 0; |
|
494 |
insets.right = margin != null? margin.right : 0; |
|
495 |
||
496 |
return insets; |
|
497 |
} |
|
498 |
} |
|
499 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
500 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
501 |
* Draws the border around a field. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
502 |
*/ |
23697 | 503 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 504 |
public static class FieldBorder extends AbstractBorder implements UIResource { |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
505 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
506 |
* The color of shadow. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
507 |
*/ |
2 | 508 |
protected Color shadow; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
509 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
510 |
* The color of dark shadow. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
511 |
*/ |
2 | 512 |
protected Color darkShadow; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
513 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
514 |
* The color of highlight. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
515 |
*/ |
2 | 516 |
protected Color highlight; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
517 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
518 |
* The color of light highlight. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
519 |
*/ |
2 | 520 |
protected Color lightHighlight; |
521 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
522 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
523 |
* Constructs a new instance of a {@code FieldBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
524 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
525 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
526 |
* @param darkShadow a color of dark shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
527 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
528 |
* @param lightHighlight a color of light highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
529 |
*/ |
2 | 530 |
public FieldBorder(Color shadow, Color darkShadow, |
531 |
Color highlight, Color lightHighlight) { |
|
532 |
this.shadow = shadow; |
|
533 |
this.highlight = highlight; |
|
534 |
this.darkShadow = darkShadow; |
|
535 |
this.lightHighlight = lightHighlight; |
|
536 |
} |
|
537 |
||
538 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
539 |
int width, int height) { |
|
540 |
BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height, |
|
541 |
shadow, darkShadow, |
|
542 |
highlight, lightHighlight); |
|
543 |
} |
|
544 |
||
545 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
546 |
Insets margin = null; |
|
547 |
if (c instanceof JTextComponent) { |
|
548 |
margin = ((JTextComponent)c).getMargin(); |
|
549 |
} |
|
550 |
insets.top = margin != null? 2+margin.top : 2; |
|
551 |
insets.left = margin != null? 2+margin.left : 2; |
|
552 |
insets.bottom = margin != null? 2+margin.bottom : 2; |
|
553 |
insets.right = margin != null? 2+margin.right : 2; |
|
554 |
||
555 |
return insets; |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
||
560 |
/** |
|
561 |
* Draws the border around the divider in a splitpane |
|
562 |
* (when BasicSplitPaneUI is used). To get the appropriate effect, this |
|
563 |
* needs to be used with a SplitPaneBorder. |
|
564 |
*/ |
|
565 |
static class SplitPaneDividerBorder implements Border, UIResource { |
|
566 |
Color highlight; |
|
567 |
Color shadow; |
|
568 |
||
569 |
SplitPaneDividerBorder(Color highlight, Color shadow) { |
|
570 |
this.highlight = highlight; |
|
571 |
this.shadow = shadow; |
|
572 |
} |
|
573 |
||
574 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
575 |
int width, int height) { |
|
6510
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
576 |
if (!(c instanceof BasicSplitPaneDivider)) { |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
577 |
return; |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
578 |
} |
2 | 579 |
Component child; |
580 |
Rectangle cBounds; |
|
581 |
JSplitPane splitPane = ((BasicSplitPaneDivider)c). |
|
582 |
getBasicSplitPaneUI().getSplitPane(); |
|
583 |
Dimension size = c.getSize(); |
|
584 |
||
585 |
child = splitPane.getLeftComponent(); |
|
586 |
// This is needed for the space between the divider and end of |
|
587 |
// splitpane. |
|
588 |
g.setColor(c.getBackground()); |
|
589 |
g.drawRect(x, y, width - 1, height - 1); |
|
590 |
if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { |
|
591 |
if(child != null) { |
|
592 |
g.setColor(highlight); |
|
593 |
g.drawLine(0, 0, 0, size.height); |
|
594 |
} |
|
595 |
child = splitPane.getRightComponent(); |
|
596 |
if(child != null) { |
|
597 |
g.setColor(shadow); |
|
598 |
g.drawLine(size.width - 1, 0, size.width - 1, size.height); |
|
599 |
} |
|
600 |
} else { |
|
601 |
if(child != null) { |
|
602 |
g.setColor(highlight); |
|
603 |
g.drawLine(0, 0, size.width, 0); |
|
604 |
} |
|
605 |
child = splitPane.getRightComponent(); |
|
606 |
if(child != null) { |
|
607 |
g.setColor(shadow); |
|
608 |
g.drawLine(0, size.height - 1, size.width, |
|
609 |
size.height - 1); |
|
610 |
} |
|
611 |
} |
|
612 |
} |
|
613 |
public Insets getBorderInsets(Component c) { |
|
614 |
Insets insets = new Insets(0,0,0,0); |
|
615 |
if (c instanceof BasicSplitPaneDivider) { |
|
616 |
BasicSplitPaneUI bspui = ((BasicSplitPaneDivider)c). |
|
617 |
getBasicSplitPaneUI(); |
|
618 |
||
619 |
if (bspui != null) { |
|
620 |
JSplitPane splitPane = bspui.getSplitPane(); |
|
621 |
||
622 |
if (splitPane != null) { |
|
623 |
if (splitPane.getOrientation() == |
|
624 |
JSplitPane.HORIZONTAL_SPLIT) { |
|
625 |
insets.top = insets.bottom = 0; |
|
626 |
insets.left = insets.right = 1; |
|
627 |
return insets; |
|
628 |
} |
|
629 |
// VERTICAL_SPLIT |
|
630 |
insets.top = insets.bottom = 1; |
|
631 |
insets.left = insets.right = 0; |
|
632 |
return insets; |
|
633 |
} |
|
634 |
} |
|
635 |
} |
|
636 |
insets.top = insets.bottom = insets.left = insets.right = 1; |
|
637 |
return insets; |
|
638 |
} |
|
639 |
public boolean isBorderOpaque() { return true; } |
|
640 |
} |
|
641 |
||
642 |
||
643 |
/** |
|
21278 | 644 |
* Draws the border around the splitpane. To work correctly you should |
2 | 645 |
* also install a border on the divider (property SplitPaneDivider.border). |
646 |
*/ |
|
647 |
public static class SplitPaneBorder implements Border, UIResource { |
|
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
648 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
649 |
* The color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
650 |
*/ |
2 | 651 |
protected Color highlight; |
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
652 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
653 |
* The color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
654 |
*/ |
2 | 655 |
protected Color shadow; |
656 |
||
25765
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
657 |
/** |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
658 |
* Constructs a new instance of a {@code SplitPaneBorder}. |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
659 |
* |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
660 |
* @param highlight a color of highlight |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
661 |
* @param shadow a color of shadow |
88051e6ecdc7
8049808: Fix doclint warnings from javax.swing.plaf.basic package, 3 of 7
aeremeev
parents:
23697
diff
changeset
|
662 |
*/ |
2 | 663 |
public SplitPaneBorder(Color highlight, Color shadow) { |
664 |
this.highlight = highlight; |
|
665 |
this.shadow = shadow; |
|
666 |
} |
|
667 |
||
668 |
public void paintBorder(Component c, Graphics g, int x, int y, |
|
669 |
int width, int height) { |
|
6510
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
670 |
if (!(c instanceof JSplitPane)) { |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
671 |
return; |
75e8a4664c38
6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents:
5506
diff
changeset
|
672 |
} |
2 | 673 |
// The only tricky part with this border is that the divider is |
674 |
// not positioned at the top (for horizontal) or left (for vert), |
|
675 |
// so this border draws to where the divider is: |
|
676 |
// ----------------- |
|
677 |
// |xxxxxxx xxxxxxx| |
|
678 |
// |x --- x| |
|
679 |
// |x | | x| |
|
680 |
// |x |D| x| |
|
681 |
// |x | | x| |
|
682 |
// |x --- x| |
|
683 |
// |xxxxxxx xxxxxxx| |
|
684 |
// ----------------- |
|
685 |
// The above shows (rather excessively) what this looks like for |
|
686 |
// a horizontal orientation. This border then draws the x's, with |
|
687 |
// the SplitPaneDividerBorder drawing its own border. |
|
688 |
||
689 |
Component child; |
|
690 |
Rectangle cBounds; |
|
691 |
||
692 |
JSplitPane splitPane = (JSplitPane)c; |
|
693 |
||
694 |
child = splitPane.getLeftComponent(); |
|
695 |
// This is needed for the space between the divider and end of |
|
696 |
// splitpane. |
|
697 |
g.setColor(c.getBackground()); |
|
698 |
g.drawRect(x, y, width - 1, height - 1); |
|
699 |
if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { |
|
700 |
if(child != null) { |
|
701 |
cBounds = child.getBounds(); |
|
702 |
g.setColor(shadow); |
|
703 |
g.drawLine(0, 0, cBounds.width + 1, 0); |
|
704 |
g.drawLine(0, 1, 0, cBounds.height + 1); |
|
705 |
||
706 |
g.setColor(highlight); |
|
707 |
g.drawLine(0, cBounds.height + 1, cBounds.width + 1, |
|
708 |
cBounds.height + 1); |
|
709 |
} |
|
710 |
child = splitPane.getRightComponent(); |
|
711 |
if(child != null) { |
|
712 |
cBounds = child.getBounds(); |
|
713 |
||
714 |
int maxX = cBounds.x + cBounds.width; |
|
715 |
int maxY = cBounds.y + cBounds.height; |
|
716 |
||
717 |
g.setColor(shadow); |
|
718 |
g.drawLine(cBounds.x - 1, 0, maxX, 0); |
|
719 |
g.setColor(highlight); |
|
720 |
g.drawLine(cBounds.x - 1, maxY, maxX, maxY); |
|
721 |
g.drawLine(maxX, 0, maxX, maxY + 1); |
|
722 |
} |
|
723 |
} else { |
|
724 |
if(child != null) { |
|
725 |
cBounds = child.getBounds(); |
|
726 |
g.setColor(shadow); |
|
727 |
g.drawLine(0, 0, cBounds.width + 1, 0); |
|
728 |
g.drawLine(0, 1, 0, cBounds.height); |
|
729 |
g.setColor(highlight); |
|
730 |
g.drawLine(1 + cBounds.width, 0, 1 + cBounds.width, |
|
731 |
cBounds.height + 1); |
|
732 |
g.drawLine(0, cBounds.height + 1, 0, cBounds.height + 1); |
|
733 |
} |
|
734 |
child = splitPane.getRightComponent(); |
|
735 |
if(child != null) { |
|
736 |
cBounds = child.getBounds(); |
|
737 |
||
738 |
int maxX = cBounds.x + cBounds.width; |
|
739 |
int maxY = cBounds.y + cBounds.height; |
|
740 |
||
741 |
g.setColor(shadow); |
|
742 |
g.drawLine(0, cBounds.y - 1, 0, maxY); |
|
743 |
g.drawLine(maxX, cBounds.y - 1, maxX, cBounds.y - 1); |
|
744 |
g.setColor(highlight); |
|
745 |
g.drawLine(0, maxY, cBounds.width + 1, maxY); |
|
746 |
g.drawLine(maxX, cBounds.y, maxX, maxY); |
|
747 |
} |
|
748 |
} |
|
749 |
} |
|
750 |
public Insets getBorderInsets(Component c) { |
|
751 |
return new Insets(1, 1, 1, 1); |
|
752 |
} |
|
753 |
public boolean isBorderOpaque() { return true; } |
|
754 |
} |
|
755 |
||
756 |
} |