41
41
import java.awt.Color;
42
42
import java.awt.Dimension;
43
43
import java.awt.Graphics;
44
import java.awt.Insets;
44
45
import java.awt.Rectangle;
45
46
import java.beans.PropertyChangeEvent;
46
47
import java.beans.PropertyChangeListener;
48
49
import javax.swing.JButton;
49
50
import javax.swing.JComponent;
50
51
import javax.swing.JScrollBar;
51
import javax.swing.UIDefaults;
52
import javax.swing.SwingConstants;
52
53
import javax.swing.UIManager;
53
54
import javax.swing.plaf.ComponentUI;
54
55
import javax.swing.plaf.basic.BasicScrollBarUI;
196
197
protected JButton createDecreaseButton(int orientation)
198
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
199
scrollBarWidth = defaults.getInt("ScrollBar.width");
199
scrollBarWidth = UIManager.getInt("ScrollBar.width");
200
200
decreaseButton = new MetalScrollButton(orientation, scrollBarWidth,
202
202
return decreaseButton;
214
214
protected JButton createIncreaseButton(int orientation)
216
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
217
scrollBarWidth = defaults.getInt("ScrollBar.width");
216
scrollBarWidth = UIManager.getInt("ScrollBar.width");
218
217
increaseButton = new MetalScrollButton(orientation, scrollBarWidth,
220
219
return increaseButton;
351
350
paintThumbVertical(g, c, thumbBounds);
354
MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3,
355
thumbBounds.width - 6, thumbBounds.height - 6,
356
thumbHighlightColor, thumbLightShadowColor);
352
// Draw the pattern when the theme is not Ocean.
353
if (! (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme))
355
MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3,
356
thumbBounds.width - 6,
357
thumbBounds.height - 6,
359
thumbLightShadowColor);
371
375
int w = thumbBounds.width;
372
376
int h = thumbBounds.height;
374
// first we fill the background
375
g.setColor(thumbColor);
377
g.fillRect(x, y, w, h - 1);
378
// First we fill the background.
379
MetalTheme theme = MetalLookAndFeel.getCurrentTheme();
380
if (theme instanceof OceanTheme
381
&& UIManager.get("ScrollBar.gradient") != null)
383
MetalUtils.paintGradient(g, x + 2, y + 2, w - 4, h - 2,
384
SwingConstants.VERTICAL,
385
"ScrollBar.gradient");
379
g.fillRect(x, y, w, h);
389
g.setColor(thumbColor);
391
g.fillRect(x, y, w, h - 1);
393
g.fillRect(x, y, w, h);
381
396
// then draw the dark box
382
397
g.setColor(thumbLightShadowColor);
383
398
if (isFreeStanding)
405
420
// draw the shadow line
406
UIDefaults def = UIManager.getLookAndFeelDefaults();
407
g.setColor(def.getColor("ScrollBar.shadow"));
421
g.setColor(UIManager.getColor("ScrollBar.shadow"));
408
422
g.drawLine(x + w, y + 1, x + w, y + h - 1);
424
// For the OceanTheme, draw the 3 lines in the middle.
425
if (theme instanceof OceanTheme)
427
g.setColor(thumbLightShadowColor);
428
int middle = x + w / 2;
429
g.drawLine(middle - 2, y + 4, middle - 2, y + h - 5);
430
g.drawLine(middle, y + 4, middle, y + h - 5);
431
g.drawLine(middle + 2, y + 4, middle + 2, y + h - 5);
432
g.setColor(UIManager.getColor("ScrollBar.highlight"));
433
g.drawLine(middle - 1, y + 5, middle - 1, y + h - 4);
434
g.drawLine(middle + 1, y + 5, middle + 1, y + h - 4);
435
g.drawLine(middle + 3, y + 5, middle + 3, y + h - 4);
424
451
int w = thumbBounds.width;
425
452
int h = thumbBounds.height;
427
// first we fill the background
428
g.setColor(thumbColor);
430
g.fillRect(x, y, w - 1, h);
454
// First we fill the background.
455
MetalTheme theme = MetalLookAndFeel.getCurrentTheme();
456
if (theme instanceof OceanTheme
457
&& UIManager.get("ScrollBar.gradient") != null)
459
MetalUtils.paintGradient(g, x + 2, y + 2, w - 2, h - 4,
460
SwingConstants.HORIZONTAL,
461
"ScrollBar.gradient");
432
g.fillRect(x, y, w, h);
465
g.setColor(thumbColor);
467
g.fillRect(x, y, w - 1, h);
469
g.fillRect(x, y, w, h);
434
472
// then draw the dark box
435
473
g.setColor(thumbLightShadowColor);
436
474
if (isFreeStanding)
458
496
// draw the shadow line
459
UIDefaults def = UIManager.getLookAndFeelDefaults();
460
g.setColor(def.getColor("ScrollBar.shadow"));
497
g.setColor(UIManager.getColor("ScrollBar.shadow"));
461
498
g.drawLine(x + 1, y + h, x + w - 2, y + h);
500
// For the OceanTheme, draw the 3 lines in the middle.
501
if (theme instanceof OceanTheme)
503
g.setColor(thumbLightShadowColor);
504
int middle = y + h / 2;
505
g.drawLine(x + 4, middle - 2, x + w - 5, middle - 2);
506
g.drawLine(x + 4, middle, x + w - 5, middle);
507
g.drawLine(x + 4, middle + 2, x + w - 5, middle + 2);
508
g.setColor(UIManager.getColor("ScrollBar.highlight"));
509
g.drawLine(x + 5, middle - 1, x + w - 4, middle - 1);
510
g.drawLine(x + 5, middle + 1, x + w - 4, middle + 1);
511
g.drawLine(x + 5, middle + 3, x + w - 4, middle + 3);
471
522
protected Dimension getMinimumThumbSize()
474
return MIN_THUMB_SIZE_FREE_STANDING;
525
if (scrollbar != null)
528
retVal = MIN_THUMB_SIZE_FREE_STANDING;
530
retVal = MIN_THUMB_SIZE;
476
return MIN_THUMB_SIZE;
533
retVal = new Dimension(0, 0);
538
* Returns the <code>preferredSize</code> for the specified scroll bar.
539
* For a vertical scrollbar the height is the sum of the preferred heights
540
* of the buttons plus <code>30</code>. The width is fetched from the
541
* <code>UIManager</code> property <code>ScrollBar.width</code>.
543
* For horizontal scrollbars the width is the sum of the preferred widths
544
* of the buttons plus <code>30</code>. The height is fetched from the
545
* <code>UIManager</code> property <code>ScrollBar.height</code>.
547
* @param c the scrollbar for which to calculate the preferred size
549
* @return the <code>preferredSize</code> for the specified scroll bar
551
public Dimension getPreferredSize(JComponent c)
557
if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
559
width += incrButton.getPreferredSize().getWidth();
560
width += decrButton.getPreferredSize().getWidth();
562
height = UIManager.getInt("ScrollBar.width");
566
height += incrButton.getPreferredSize().getHeight();
567
height += decrButton.getPreferredSize().getHeight();
569
width = UIManager.getInt("ScrollBar.width");
572
Insets insets = scrollbar.getInsets();
574
height += insets.top + insets.bottom;
575
width += insets.left + insets.right;
577
return new Dimension(width, height);