author | serb |
Mon, 07 Apr 2014 15:34:27 +0400 | |
changeset 24163 | d56df89854c4 |
parent 23715 | 54ae9dd9df73 |
child 25178 | dbab904451e9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
2 |
* Copyright (c) 1998, 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.metal; |
|
27 |
||
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
28 |
import java.awt.Color; |
2 | 29 |
import java.awt.Dimension; |
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
30 |
import java.awt.Graphics; |
2 | 31 |
import java.awt.Rectangle; |
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
32 |
import java.beans.PropertyChangeEvent; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
33 |
import java.beans.PropertyChangeListener; |
2 | 34 |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
35 |
import javax.swing.JButton; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
36 |
import javax.swing.JComponent; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
37 |
import javax.swing.JScrollBar; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
38 |
import javax.swing.UIManager; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
39 |
import javax.swing.plaf.ComponentUI; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
40 |
import javax.swing.plaf.basic.BasicScrollBarUI; |
2 | 41 |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
42 |
import static sun.swing.SwingUtilities2.drawHLine; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
43 |
import static sun.swing.SwingUtilities2.drawRect; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
44 |
import static sun.swing.SwingUtilities2.drawVLine; |
2 | 45 |
|
46 |
||
47 |
/** |
|
48 |
* Implementation of ScrollBarUI for the Metal Look and Feel |
|
49 |
* |
|
50 |
* @author Tom Santos |
|
51 |
* @author Steve Wilson |
|
52 |
*/ |
|
53 |
public class MetalScrollBarUI extends BasicScrollBarUI |
|
54 |
{ |
|
55 |
private static Color shadowColor; |
|
56 |
private static Color highlightColor; |
|
57 |
private static Color darkShadowColor; |
|
58 |
private static Color thumbColor; |
|
59 |
private static Color thumbShadow; |
|
60 |
private static Color thumbHighlightColor; |
|
61 |
||
62 |
||
63 |
protected MetalBumps bumps; |
|
64 |
||
65 |
protected MetalScrollButton increaseButton; |
|
66 |
protected MetalScrollButton decreaseButton; |
|
67 |
||
68 |
protected int scrollBarWidth; |
|
69 |
||
70 |
public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding"; |
|
71 |
protected boolean isFreeStanding = true; |
|
72 |
||
73 |
public static ComponentUI createUI( JComponent c ) |
|
74 |
{ |
|
75 |
return new MetalScrollBarUI(); |
|
76 |
} |
|
77 |
||
78 |
protected void installDefaults() { |
|
79 |
scrollBarWidth = ((Integer)(UIManager.get( "ScrollBar.width" ))).intValue(); |
|
80 |
super.installDefaults(); |
|
81 |
bumps = new MetalBumps( 10, 10, thumbHighlightColor, thumbShadow, thumbColor ); |
|
82 |
} |
|
83 |
||
84 |
protected void installListeners(){ |
|
85 |
super.installListeners(); |
|
86 |
((ScrollBarListener)propertyChangeListener).handlePropertyChange( scrollbar.getClientProperty( FREE_STANDING_PROP ) ); |
|
87 |
} |
|
88 |
||
89 |
protected PropertyChangeListener createPropertyChangeListener(){ |
|
90 |
return new ScrollBarListener(); |
|
91 |
} |
|
92 |
||
93 |
protected void configureScrollBarColors() |
|
94 |
{ |
|
95 |
super.configureScrollBarColors(); |
|
96 |
shadowColor = UIManager.getColor("ScrollBar.shadow"); |
|
97 |
highlightColor = UIManager.getColor("ScrollBar.highlight"); |
|
98 |
darkShadowColor = UIManager.getColor("ScrollBar.darkShadow"); |
|
99 |
thumbColor = UIManager.getColor("ScrollBar.thumb"); |
|
100 |
thumbShadow = UIManager.getColor("ScrollBar.thumbShadow"); |
|
101 |
thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight"); |
|
102 |
||
103 |
||
104 |
} |
|
105 |
||
106 |
public Dimension getPreferredSize( JComponent c ) |
|
107 |
{ |
|
108 |
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) |
|
109 |
{ |
|
110 |
return new Dimension( scrollBarWidth, scrollBarWidth * 3 + 10 ); |
|
111 |
} |
|
112 |
else // Horizontal |
|
113 |
{ |
|
114 |
return new Dimension( scrollBarWidth * 3 + 10, scrollBarWidth ); |
|
115 |
} |
|
116 |
||
117 |
} |
|
118 |
||
119 |
/** Returns the view that represents the decrease view. |
|
120 |
*/ |
|
121 |
protected JButton createDecreaseButton( int orientation ) |
|
122 |
{ |
|
123 |
decreaseButton = new MetalScrollButton( orientation, scrollBarWidth, isFreeStanding ); |
|
124 |
return decreaseButton; |
|
125 |
} |
|
126 |
||
127 |
/** Returns the view that represents the increase view. */ |
|
128 |
protected JButton createIncreaseButton( int orientation ) |
|
129 |
{ |
|
130 |
increaseButton = new MetalScrollButton( orientation, scrollBarWidth, isFreeStanding ); |
|
131 |
return increaseButton; |
|
132 |
} |
|
133 |
||
134 |
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) |
|
135 |
{ |
|
136 |
g.translate( trackBounds.x, trackBounds.y ); |
|
137 |
||
138 |
boolean leftToRight = MetalUtils.isLeftToRight(c); |
|
139 |
||
140 |
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) |
|
141 |
{ |
|
142 |
if ( !isFreeStanding ) { |
|
143 |
trackBounds.width += 2; |
|
144 |
if ( !leftToRight ) { |
|
145 |
g.translate( -1, 0 ); |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
if ( c.isEnabled() ) { |
|
150 |
g.setColor( darkShadowColor ); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
151 |
drawVLine(g, 0, 0, trackBounds.height - 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
152 |
drawVLine(g, trackBounds.width - 2, 0, trackBounds.height - 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
153 |
drawHLine(g, 2, trackBounds.width - 1, trackBounds.height - 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
154 |
drawHLine(g, 2, trackBounds.width - 2, 0); |
2 | 155 |
|
156 |
g.setColor( shadowColor ); |
|
157 |
// g.setColor( Color.red); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
158 |
drawVLine(g, 1, 1, trackBounds.height - 2); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
159 |
drawHLine(g, 1, trackBounds.width - 3, 1); |
2 | 160 |
if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow |
161 |
int y = thumbRect.y + thumbRect.height - trackBounds.y; |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
162 |
drawHLine(g, 1, trackBounds.width - 1, y); |
2 | 163 |
} |
164 |
g.setColor(highlightColor); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
165 |
drawVLine(g, trackBounds.width - 1, 0, trackBounds.height - 1); |
2 | 166 |
} else { |
167 |
MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height ); |
|
168 |
} |
|
169 |
||
170 |
if ( !isFreeStanding ) { |
|
171 |
trackBounds.width -= 2; |
|
172 |
if ( !leftToRight ) { |
|
173 |
g.translate( 1, 0 ); |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
else // HORIZONTAL |
|
178 |
{ |
|
179 |
if ( !isFreeStanding ) { |
|
180 |
trackBounds.height += 2; |
|
181 |
} |
|
182 |
||
183 |
if ( c.isEnabled() ) { |
|
184 |
g.setColor( darkShadowColor ); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
185 |
drawHLine(g, 0, trackBounds.width - 1, 0); // top |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
186 |
drawVLine(g, 0, 2, trackBounds.height - 2); // left |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
187 |
drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 2 ); // bottom |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
188 |
drawVLine(g, trackBounds.width - 1, 2, trackBounds.height - 1 ); // right |
2 | 189 |
|
190 |
g.setColor( shadowColor ); |
|
191 |
// g.setColor( Color.red); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
192 |
drawHLine(g, 1, trackBounds.width - 2, 1 ); // top |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
193 |
drawVLine(g, 1, 1, trackBounds.height - 3 ); // left |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
194 |
drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 1 ); // bottom |
2 | 195 |
if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow |
196 |
int x = thumbRect.x + thumbRect.width - trackBounds.x; |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
197 |
drawVLine(g, x, 1, trackBounds.height-1); |
2 | 198 |
} |
199 |
} else { |
|
200 |
MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height ); |
|
201 |
} |
|
202 |
||
203 |
if ( !isFreeStanding ) { |
|
204 |
trackBounds.height -= 2; |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
g.translate( -trackBounds.x, -trackBounds.y ); |
|
209 |
} |
|
210 |
||
211 |
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) |
|
212 |
{ |
|
213 |
if (!c.isEnabled()) { |
|
214 |
return; |
|
215 |
} |
|
216 |
||
217 |
if (MetalLookAndFeel.usingOcean()) { |
|
218 |
oceanPaintThumb(g, c, thumbBounds); |
|
219 |
return; |
|
220 |
} |
|
221 |
||
222 |
boolean leftToRight = MetalUtils.isLeftToRight(c); |
|
223 |
||
224 |
g.translate( thumbBounds.x, thumbBounds.y ); |
|
225 |
||
226 |
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) |
|
227 |
{ |
|
228 |
if ( !isFreeStanding ) { |
|
229 |
thumbBounds.width += 2; |
|
230 |
if ( !leftToRight ) { |
|
231 |
g.translate( -1, 0 ); |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
g.setColor( thumbColor ); |
|
236 |
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 ); |
|
237 |
||
238 |
g.setColor( thumbShadow ); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
239 |
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1); |
2 | 240 |
|
241 |
g.setColor( thumbHighlightColor ); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
242 |
drawHLine(g, 1, thumbBounds.width - 3, 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
243 |
drawVLine(g, 1, 1, thumbBounds.height - 2); |
2 | 244 |
|
245 |
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 ); |
|
246 |
bumps.paintIcon( c, g, 3, 4 ); |
|
247 |
||
248 |
if ( !isFreeStanding ) { |
|
249 |
thumbBounds.width -= 2; |
|
250 |
if ( !leftToRight ) { |
|
251 |
g.translate( 1, 0 ); |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
else // HORIZONTAL |
|
256 |
{ |
|
257 |
if ( !isFreeStanding ) { |
|
258 |
thumbBounds.height += 2; |
|
259 |
} |
|
260 |
||
261 |
g.setColor( thumbColor ); |
|
262 |
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 ); |
|
263 |
||
264 |
g.setColor( thumbShadow ); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
265 |
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2); |
2 | 266 |
|
267 |
g.setColor( thumbHighlightColor ); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
268 |
drawHLine(g, 1, thumbBounds.width - 3, 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
269 |
drawVLine(g, 1, 1, thumbBounds.height - 3); |
2 | 270 |
|
271 |
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 ); |
|
272 |
bumps.paintIcon( c, g, 4, 3 ); |
|
273 |
||
274 |
if ( !isFreeStanding ) { |
|
275 |
thumbBounds.height -= 2; |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
g.translate( -thumbBounds.x, -thumbBounds.y ); |
|
280 |
} |
|
281 |
||
282 |
private void oceanPaintThumb(Graphics g, JComponent c, |
|
283 |
Rectangle thumbBounds) { |
|
284 |
boolean leftToRight = MetalUtils.isLeftToRight(c); |
|
285 |
||
286 |
g.translate(thumbBounds.x, thumbBounds.y); |
|
287 |
||
288 |
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { |
|
289 |
if (!isFreeStanding) { |
|
290 |
thumbBounds.width += 2; |
|
291 |
if (!leftToRight) { |
|
292 |
g.translate(-1, 0); |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
if (thumbColor != null) { |
|
297 |
g.setColor(thumbColor); |
|
298 |
g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1); |
|
299 |
} |
|
300 |
||
301 |
g.setColor(thumbShadow); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
302 |
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1); |
2 | 303 |
|
304 |
g.setColor(thumbHighlightColor); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
305 |
drawHLine(g, 1, thumbBounds.width - 3, 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
306 |
drawVLine(g, 1, 1, thumbBounds.height - 2); |
2 | 307 |
|
308 |
MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2, |
|
309 |
thumbBounds.width - 4, |
|
310 |
thumbBounds.height - 3, false); |
|
311 |
||
312 |
int gripSize = thumbBounds.width - 8; |
|
313 |
if (gripSize > 2 && thumbBounds.height >= 10) { |
|
314 |
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); |
|
315 |
int gripY = thumbBounds.height / 2 - 2; |
|
316 |
for (int counter = 0; counter < 6; counter += 2) { |
|
317 |
g.fillRect(4, counter + gripY, gripSize, 1); |
|
318 |
} |
|
319 |
||
320 |
g.setColor(MetalLookAndFeel.getWhite()); |
|
321 |
gripY++; |
|
322 |
for (int counter = 0; counter < 6; counter += 2) { |
|
323 |
g.fillRect(5, counter + gripY, gripSize, 1); |
|
324 |
} |
|
325 |
} |
|
326 |
if (!isFreeStanding) { |
|
327 |
thumbBounds.width -= 2; |
|
328 |
if (!leftToRight) { |
|
329 |
g.translate(1, 0); |
|
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 |
else { // HORIZONTAL |
|
334 |
if (!isFreeStanding) { |
|
335 |
thumbBounds.height += 2; |
|
336 |
} |
|
337 |
||
338 |
if (thumbColor != null) { |
|
339 |
g.setColor(thumbColor); |
|
340 |
g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2); |
|
341 |
} |
|
342 |
||
343 |
g.setColor(thumbShadow); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
344 |
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2); |
2 | 345 |
|
346 |
g.setColor(thumbHighlightColor); |
|
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
347 |
drawHLine(g, 1, thumbBounds.width - 2, 1); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
23715
diff
changeset
|
348 |
drawVLine(g, 1, 1, thumbBounds.height - 3); |
2 | 349 |
|
350 |
MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2, |
|
351 |
thumbBounds.width - 3, |
|
352 |
thumbBounds.height - 4, true); |
|
353 |
||
354 |
int gripSize = thumbBounds.height - 8; |
|
355 |
if (gripSize > 2 && thumbBounds.width >= 10) { |
|
356 |
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); |
|
357 |
int gripX = thumbBounds.width / 2 - 2; |
|
358 |
for (int counter = 0; counter < 6; counter += 2) { |
|
359 |
g.fillRect(gripX + counter, 4, 1, gripSize); |
|
360 |
} |
|
361 |
||
362 |
g.setColor(MetalLookAndFeel.getWhite()); |
|
363 |
gripX++; |
|
364 |
for (int counter = 0; counter < 6; counter += 2) { |
|
365 |
g.fillRect(gripX + counter, 5, 1, gripSize); |
|
366 |
} |
|
367 |
} |
|
368 |
||
369 |
if (!isFreeStanding) { |
|
370 |
thumbBounds.height -= 2; |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
g.translate( -thumbBounds.x, -thumbBounds.y ); |
|
375 |
} |
|
376 |
||
377 |
protected Dimension getMinimumThumbSize() |
|
378 |
{ |
|
379 |
return new Dimension( scrollBarWidth, scrollBarWidth ); |
|
380 |
} |
|
381 |
||
382 |
/** |
|
383 |
* This is overridden only to increase the invalid area. This |
|
384 |
* ensures that the "Shadow" below the thumb is invalidated |
|
385 |
*/ |
|
386 |
protected void setThumbBounds(int x, int y, int width, int height) |
|
387 |
{ |
|
388 |
/* If the thumbs bounds haven't changed, we're done. |
|
389 |
*/ |
|
390 |
if ((thumbRect.x == x) && |
|
391 |
(thumbRect.y == y) && |
|
392 |
(thumbRect.width == width) && |
|
393 |
(thumbRect.height == height)) { |
|
394 |
return; |
|
395 |
} |
|
396 |
||
397 |
/* Update thumbRect, and repaint the union of x,y,w,h and |
|
398 |
* the old thumbRect. |
|
399 |
*/ |
|
400 |
int minX = Math.min(x, thumbRect.x); |
|
401 |
int minY = Math.min(y, thumbRect.y); |
|
402 |
int maxX = Math.max(x + width, thumbRect.x + thumbRect.width); |
|
403 |
int maxY = Math.max(y + height, thumbRect.y + thumbRect.height); |
|
404 |
||
405 |
thumbRect.setBounds(x, y, width, height); |
|
406 |
scrollbar.repaint(minX, minY, (maxX - minX)+1, (maxY - minY)+1); |
|
407 |
} |
|
408 |
||
409 |
||
410 |
||
411 |
class ScrollBarListener extends BasicScrollBarUI.PropertyChangeHandler |
|
412 |
{ |
|
413 |
public void propertyChange(PropertyChangeEvent e) |
|
414 |
{ |
|
415 |
String name = e.getPropertyName(); |
|
416 |
if ( name.equals( FREE_STANDING_PROP ) ) |
|
417 |
{ |
|
418 |
handlePropertyChange( e.getNewValue() ); |
|
419 |
} |
|
420 |
else { |
|
421 |
super.propertyChange( e ); |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
public void handlePropertyChange( Object newValue ) |
|
426 |
{ |
|
427 |
if ( newValue != null ) |
|
428 |
{ |
|
429 |
boolean temp = ((Boolean)newValue).booleanValue(); |
|
430 |
boolean becameFlush = temp == false && isFreeStanding == true; |
|
431 |
boolean becameNormal = temp == true && isFreeStanding == false; |
|
432 |
||
433 |
isFreeStanding = temp; |
|
434 |
||
435 |
if ( becameFlush ) { |
|
436 |
toFlush(); |
|
437 |
} |
|
438 |
else if ( becameNormal ) { |
|
439 |
toFreeStanding(); |
|
440 |
} |
|
441 |
} |
|
442 |
else |
|
443 |
{ |
|
444 |
||
445 |
if ( !isFreeStanding ) { |
|
446 |
isFreeStanding = true; |
|
447 |
toFreeStanding(); |
|
448 |
} |
|
449 |
||
450 |
// This commented-out block is used for testing flush scrollbars. |
|
451 |
/* |
|
452 |
if ( isFreeStanding ) { |
|
453 |
isFreeStanding = false; |
|
454 |
toFlush(); |
|
455 |
} |
|
456 |
*/ |
|
457 |
} |
|
458 |
||
459 |
if ( increaseButton != null ) |
|
460 |
{ |
|
461 |
increaseButton.setFreeStanding( isFreeStanding ); |
|
462 |
} |
|
463 |
if ( decreaseButton != null ) |
|
464 |
{ |
|
465 |
decreaseButton.setFreeStanding( isFreeStanding ); |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
protected void toFlush() { |
|
470 |
scrollBarWidth -= 2; |
|
471 |
} |
|
472 |
||
473 |
protected void toFreeStanding() { |
|
474 |
scrollBarWidth += 2; |
|
475 |
} |
|
476 |
} // end class ScrollBarListener |
|
477 |
} |