103 |
/** The name for the 'free standing' property. */ |
/** The name for the 'free standing' property. */ |
104 |
public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding"; |
public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding"; |
105 |
|
|
106 |
/** The minimum thumb size */ |
/** The minimum thumb size for a scroll bar that is not free standing. */ |
107 |
private static final Dimension MIN_THUMB_SIZE = new Dimension(17, 17); |
private static final Dimension MIN_THUMB_SIZE = new Dimension(15, 15); |
108 |
|
|
109 |
|
/** The minimum thumb size for a scroll bar that is free standing. */ |
110 |
|
private static final Dimension MIN_THUMB_SIZE_FREE_STANDING |
111 |
|
= new Dimension(17, 17); |
112 |
|
|
113 |
/** The button that increases the value in the scroll bar. */ |
/** The button that increases the value in the scroll bar. */ |
114 |
protected MetalScrollButton increaseButton; |
protected MetalScrollButton increaseButton; |
115 |
|
|
125 |
* scroll bar which is not free standing has borders missing from one |
* scroll bar which is not free standing has borders missing from one |
126 |
* side, and relies on being part of another container with its own borders |
* side, and relies on being part of another container with its own borders |
127 |
* to look right visually. */ |
* to look right visually. */ |
128 |
protected boolean isFreeStanding; |
protected boolean isFreeStanding = true; |
129 |
|
|
130 |
|
/** The color for the scroll bar shadow. */ |
131 |
|
Color scrollBarShadowColor; |
132 |
|
|
133 |
/** |
/** |
134 |
* Constructs a new instance of MetalScrollBarUI. |
* Constructs a new instance of MetalScrollBarUI. |
161 |
// that we can do this). |
// that we can do this). |
162 |
Boolean prop = (Boolean) scrollbar.getClientProperty(FREE_STANDING_PROP); |
Boolean prop = (Boolean) scrollbar.getClientProperty(FREE_STANDING_PROP); |
163 |
isFreeStanding = (prop == null ? true : prop.booleanValue()); |
isFreeStanding = (prop == null ? true : prop.booleanValue()); |
164 |
|
scrollBarShadowColor = UIManager.getColor("ScrollBar.shadow"); |
165 |
super.installDefaults(); |
super.installDefaults(); |
166 |
} |
} |
167 |
|
|
191 |
{ |
{ |
192 |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
193 |
scrollBarWidth = defaults.getInt("ScrollBar.width"); |
scrollBarWidth = defaults.getInt("ScrollBar.width"); |
194 |
return new MetalScrollButton(orientation, scrollBarWidth, isFreeStanding); |
decreaseButton = new MetalScrollButton(orientation, scrollBarWidth, |
195 |
|
isFreeStanding); |
196 |
|
return decreaseButton; |
197 |
} |
} |
198 |
|
|
199 |
/** |
/** |
209 |
{ |
{ |
210 |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
211 |
scrollBarWidth = defaults.getInt("ScrollBar.width"); |
scrollBarWidth = defaults.getInt("ScrollBar.width"); |
212 |
return new MetalScrollButton(orientation, scrollBarWidth, isFreeStanding); |
increaseButton = new MetalScrollButton(orientation, scrollBarWidth, |
213 |
|
isFreeStanding); |
214 |
|
return increaseButton; |
215 |
} |
} |
216 |
|
|
217 |
/** |
/** |
255 |
g.drawLine(x, y, x + w - 1, y); |
g.drawLine(x, y, x + w - 1, y); |
256 |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); |
g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); |
257 |
|
|
258 |
g.setColor(MetalLookAndFeel.getControlShadow()); |
g.setColor(scrollBarShadowColor); |
259 |
g.drawLine(x + 1, y + 1, x + 1, y + h - 1); |
g.drawLine(x + 1, y + 1, x + 1, y + h - 1); |
260 |
g.drawLine(x + 1, y + 1, x + w - 2, y + 1); |
g.drawLine(x + 1, y + 1, x + w - 2, y + 1); |
261 |
|
|
263 |
{ |
{ |
264 |
g.setColor(MetalLookAndFeel.getControlDarkShadow()); |
g.setColor(MetalLookAndFeel.getControlDarkShadow()); |
265 |
g.drawLine(x, y + h - 2, x + w - 1, y + h - 2); |
g.drawLine(x, y + h - 2, x + w - 1, y + h - 2); |
266 |
g.setColor(MetalLookAndFeel.getControlShadow()); |
g.setColor(scrollBarShadowColor); |
267 |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); |
268 |
} |
} |
269 |
} |
} |
270 |
else |
else |
271 |
{ |
{ |
272 |
g.setColor(MetalLookAndFeel.getControlDisabled()); |
g.setColor(MetalLookAndFeel.getControlDisabled()); |
273 |
g.drawRect(x, y, w - 1, h - 1); |
if (isFreeStanding) |
274 |
|
g.drawRect(x, y, w - 1, h - 1); |
275 |
|
else |
276 |
|
{ |
277 |
|
g.drawLine(x, y, x + w - 1, y); |
278 |
|
g.drawLine(x, y, x, y + h - 1); |
279 |
|
g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); |
280 |
|
} |
281 |
} |
} |
282 |
} |
} |
283 |
|
|
291 |
* @param w the width for the track bounds. |
* @param w the width for the track bounds. |
292 |
* @param h the height for the track bounds. |
* @param h the height for the track bounds. |
293 |
*/ |
*/ |
294 |
protected void paintTrackVertical(Graphics g, JComponent c, |
private void paintTrackVertical(Graphics g, JComponent c, |
295 |
int x, int y, int w, int h) |
int x, int y, int w, int h) |
296 |
{ |
{ |
297 |
if (c.isEnabled()) |
if (c.isEnabled()) |
301 |
g.drawLine(x, y, x + w - 1, y); |
g.drawLine(x, y, x + w - 1, y); |
302 |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); |
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); |
303 |
|
|
304 |
g.setColor(MetalLookAndFeel.getControlShadow()); |
g.setColor(scrollBarShadowColor); |
305 |
g.drawLine(x + 1, y + 1, x + w - 1, y + 1); |
g.drawLine(x + 1, y + 1, x + w - 1, y + 1); |
306 |
g.drawLine(x + 1, y + 1, x + 1, y + h - 2); |
g.drawLine(x + 1, y + 1, x + 1, y + h - 2); |
|
g.drawLine(x + 1, y + h - 2, x + w - 1, y + h - 2); |
|
307 |
|
|
308 |
if (isFreeStanding) |
if (isFreeStanding) |
309 |
{ |
{ |
316 |
else |
else |
317 |
{ |
{ |
318 |
g.setColor(MetalLookAndFeel.getControlDisabled()); |
g.setColor(MetalLookAndFeel.getControlDisabled()); |
319 |
g.drawRect(x, y, w - 1, h - 1); |
if (isFreeStanding) |
320 |
|
g.drawRect(x, y, w - 1, h - 1); |
321 |
|
else |
322 |
|
{ |
323 |
|
g.drawLine(x, y, x + w - 1, y); |
324 |
|
g.drawLine(x, y, x, y + h - 1); |
325 |
|
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); |
326 |
|
} |
327 |
} |
} |
328 |
} |
} |
329 |
|
|
339 |
// a disabled scrollbar has no thumb in the metal look and feel |
// a disabled scrollbar has no thumb in the metal look and feel |
340 |
if (!c.isEnabled()) |
if (!c.isEnabled()) |
341 |
return; |
return; |
342 |
|
if (scrollbar.getOrientation() == HORIZONTAL) |
343 |
|
paintThumbHorizontal(g, c, thumbBounds); |
344 |
|
else |
345 |
|
paintThumbVertical(g, c, thumbBounds); |
346 |
|
|
347 |
|
// draw the pattern |
348 |
|
MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3, |
349 |
|
thumbBounds.width - 6, thumbBounds.height - 6, |
350 |
|
thumbHighlightColor, thumbLightShadowColor); |
351 |
|
} |
352 |
|
|
353 |
|
private void paintThumbHorizontal(Graphics g, JComponent c, |
354 |
|
Rectangle thumbBounds) |
355 |
|
{ |
356 |
|
int x = thumbBounds.x; |
357 |
|
int y = thumbBounds.y; |
358 |
|
int w = thumbBounds.width; |
359 |
|
int h = thumbBounds.height; |
360 |
|
|
361 |
// first we fill the background |
// first we fill the background |
362 |
g.setColor(thumbColor); |
g.setColor(thumbColor); |
363 |
g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width, |
if (isFreeStanding) |
364 |
thumbBounds.height); |
g.fillRect(x, y, w, h - 1); |
|
|
|
|
// draw the outer dark line |
|
|
int hAdj = 1; |
|
|
int wAdj = 1; |
|
|
if (scrollbar.getOrientation() == HORIZONTAL) |
|
|
hAdj++; |
|
365 |
else |
else |
366 |
wAdj++; |
g.fillRect(x, y, w, h); |
367 |
|
|
368 |
g.setColor(new Color(102, 102, 153)); |
// then draw the dark box |
369 |
g.drawRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - wAdj, |
g.setColor(thumbLightShadowColor); |
370 |
thumbBounds.height - hAdj); |
if (isFreeStanding) |
371 |
|
g.drawRect(x, y, w - 1, h - 2); |
372 |
// draw the inner light line |
else |
373 |
|
{ |
374 |
|
g.drawLine(x, y, x + w - 1, y); |
375 |
|
g.drawLine(x, y, x, y + h - 1); |
376 |
|
g.drawLine(x + w - 1, y, x + w - 1, y + h -1); |
377 |
|
} |
378 |
|
|
379 |
|
// then the highlight |
380 |
g.setColor(thumbHighlightColor); |
g.setColor(thumbHighlightColor); |
381 |
g.drawLine(thumbBounds.x + 1, thumbBounds.y + 1, |
if (isFreeStanding) |
382 |
thumbBounds.x + thumbBounds.width - 2, |
{ |
383 |
thumbBounds.y + 1); |
g.drawLine(x + 1, y + 1, x + w - 3, y + 1); |
384 |
g.drawLine(thumbBounds.x + 1, thumbBounds.y + 1, |
g.drawLine(x + 1, y + 1, x + 1, y + h - 3); |
385 |
thumbBounds.x + 1, |
} |
386 |
thumbBounds.y + thumbBounds.height - 2); |
else |
387 |
|
{ |
388 |
|
g.drawLine(x + 1, y + 1, x + w - 3, y + 1); |
389 |
|
g.drawLine(x + 1, y + 1, x + 1, y + h - 1); |
390 |
|
} |
391 |
|
|
392 |
// draw the shadow line |
// draw the shadow line |
393 |
UIDefaults def = UIManager.getLookAndFeelDefaults(); |
UIDefaults def = UIManager.getLookAndFeelDefaults(); |
394 |
g.setColor(def.getColor("ScrollBar.shadow")); |
g.setColor(def.getColor("ScrollBar.shadow")); |
395 |
g.drawLine(thumbBounds.x + 1, thumbBounds.y + thumbBounds.height, |
g.drawLine(x + w, y + 1, x + w, y + h - 1); |
|
thumbBounds.x + thumbBounds.width, |
|
|
thumbBounds.y + thumbBounds.height); |
|
396 |
|
|
|
// draw the pattern |
|
|
MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3, |
|
|
thumbBounds.width - 6, thumbBounds.height - 6, |
|
|
thumbHighlightColor, new Color(102, 102, 153)); |
|
397 |
} |
} |
398 |
|
|
399 |
|
private void paintThumbVertical(Graphics g, JComponent c, |
400 |
|
Rectangle thumbBounds) |
401 |
|
{ |
402 |
|
int x = thumbBounds.x; |
403 |
|
int y = thumbBounds.y; |
404 |
|
int w = thumbBounds.width; |
405 |
|
int h = thumbBounds.height; |
406 |
|
|
407 |
|
// first we fill the background |
408 |
|
g.setColor(thumbColor); |
409 |
|
if (isFreeStanding) |
410 |
|
g.fillRect(x, y, w - 1, h); |
411 |
|
else |
412 |
|
g.fillRect(x, y, w, h); |
413 |
|
|
414 |
|
// then draw the dark box |
415 |
|
g.setColor(thumbLightShadowColor); |
416 |
|
if (isFreeStanding) |
417 |
|
g.drawRect(x, y, w - 2, h - 1); |
418 |
|
else |
419 |
|
{ |
420 |
|
g.drawLine(x, y, x + w - 1, y); |
421 |
|
g.drawLine(x, y, x, y + h - 1); |
422 |
|
g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); |
423 |
|
} |
424 |
|
|
425 |
|
// then the highlight |
426 |
|
g.setColor(thumbHighlightColor); |
427 |
|
if (isFreeStanding) |
428 |
|
{ |
429 |
|
g.drawLine(x + 1, y + 1, x + w - 3, y + 1); |
430 |
|
g.drawLine(x + 1, y + 1, x + 1, y + h - 3); |
431 |
|
} |
432 |
|
else |
433 |
|
{ |
434 |
|
g.drawLine(x + 1, y + 1, x + w - 1, y + 1); |
435 |
|
g.drawLine(x + 1, y + 1, x + 1, y + h - 3); |
436 |
|
} |
437 |
|
|
438 |
|
// draw the shadow line |
439 |
|
UIDefaults def = UIManager.getLookAndFeelDefaults(); |
440 |
|
g.setColor(def.getColor("ScrollBar.shadow")); |
441 |
|
g.drawLine(x + 1, y + h, x + w - 2, y + h); |
442 |
|
} |
443 |
|
|
444 |
/** |
/** |
445 |
* This method returns the minimum thumb size. |
* This method returns the minimum thumb size. |
446 |
* |
* |
448 |
*/ |
*/ |
449 |
protected Dimension getMinimumThumbSize() |
protected Dimension getMinimumThumbSize() |
450 |
{ |
{ |
451 |
return MIN_THUMB_SIZE; |
if (isFreeStanding) |
452 |
|
return MIN_THUMB_SIZE_FREE_STANDING; |
453 |
|
else |
454 |
|
return MIN_THUMB_SIZE; |
455 |
} |
} |
456 |
|
|
457 |
} |
} |