jdk/src/share/classes/javax/swing/plaf/metal/MetalScrollBarUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 24163 d56df89854c4
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.metal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Implementation of ScrollBarUI for the Metal Look and Feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class MetalScrollBarUI extends BasicScrollBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static Color shadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static Color highlightColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static Color darkShadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static Color thumbColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static Color thumbShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static Color thumbHighlightColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    62
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    63
     * The metal bumps.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    64
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected MetalBumps bumps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    67
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    68
     * The increase button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    69
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected MetalScrollButton increaseButton;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    71
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    72
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    73
     * The decrease button.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    74
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected MetalScrollButton decreaseButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    77
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    78
     * The width of the scroll bar.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    79
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected  int scrollBarWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    82
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    83
     * The property {@code JScrollBar.isFreeStanding}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    84
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding";
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    86
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    87
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    88
     * The value of the property {@code JScrollBar.isFreeStanding}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    89
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected boolean isFreeStanding = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    92
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    93
     * Constructs a new {@code MetalScrollBarUI} instance.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    94
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    95
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    96
     * @return a new {@code MetalScrollBarUI} instance
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 24163
diff changeset
    97
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static ComponentUI createUI( JComponent c )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return new MetalScrollBarUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        scrollBarWidth = ((Integer)(UIManager.get( "ScrollBar.width" ))).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        bumps = new MetalBumps( 10, 10, thumbHighlightColor, thumbShadow, thumbColor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected void installListeners(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ((ScrollBarListener)propertyChangeListener).handlePropertyChange( scrollbar.getClientProperty( FREE_STANDING_PROP ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected PropertyChangeListener createPropertyChangeListener(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return new ScrollBarListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    protected void configureScrollBarColors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        super.configureScrollBarColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        shadowColor         = UIManager.getColor("ScrollBar.shadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        highlightColor      = UIManager.getColor("ScrollBar.highlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        darkShadowColor     = UIManager.getColor("ScrollBar.darkShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        thumbColor          = UIManager.getColor("ScrollBar.thumb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        thumbShadow         = UIManager.getColor("ScrollBar.thumbShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public Dimension getPreferredSize( JComponent c )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return new Dimension( scrollBarWidth, scrollBarWidth * 3 + 10 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        else  // Horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return new Dimension( scrollBarWidth * 3 + 10, scrollBarWidth );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /** Returns the view that represents the decrease view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected JButton createDecreaseButton( int orientation )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        decreaseButton = new MetalScrollButton( orientation, scrollBarWidth, isFreeStanding );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return decreaseButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /** Returns the view that represents the increase view. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    protected JButton createIncreaseButton( int orientation )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        increaseButton =  new MetalScrollButton( orientation, scrollBarWidth, isFreeStanding );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return increaseButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        g.translate( trackBounds.x, trackBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        boolean leftToRight = MetalUtils.isLeftToRight(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                trackBounds.width += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                if ( !leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    g.translate( -1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if ( c.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                g.setColor( darkShadowColor );
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   176
                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
   177
                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
   178
                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
   179
                drawHLine(g, 2, trackBounds.width - 2, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                g.setColor( shadowColor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                //      g.setColor( Color.red);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   183
                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
   184
                drawHLine(g, 1, trackBounds.width - 3, 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                if (scrollbar.getValue() != scrollbar.getMaximum()) {  // thumb shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    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
   187
                    drawHLine(g, 1, trackBounds.width - 1, y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                g.setColor(highlightColor);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   190
                drawVLine(g, trackBounds.width - 1, 0, trackBounds.height - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                trackBounds.width -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if ( !leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    g.translate( 1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        else  // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                trackBounds.height += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if ( c.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                g.setColor( darkShadowColor );
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   210
                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
   211
                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
   212
                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
   213
                drawVLine(g, trackBounds.width - 1, 2,  trackBounds.height - 1 ); // right
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                g.setColor( shadowColor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                //      g.setColor( Color.red);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   217
                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
   218
                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
   219
                drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 1 ); // bottom
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                if (scrollbar.getValue() != scrollbar.getMaximum()) {  // thumb shadow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    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
   222
                    drawVLine(g, x, 1, trackBounds.height-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                trackBounds.height -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        g.translate( -trackBounds.x, -trackBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (!c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            oceanPaintThumb(g, c, thumbBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        boolean leftToRight = MetalUtils.isLeftToRight(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        g.translate( thumbBounds.x, thumbBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                thumbBounds.width += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                if ( !leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    g.translate( -1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            g.setColor( thumbColor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            g.setColor( thumbShadow );
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   264
            drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            g.setColor( thumbHighlightColor );
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   267
            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
   268
            drawVLine(g, 1, 1, thumbBounds.height - 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            bumps.paintIcon( c, g, 3, 4 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                thumbBounds.width -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if ( !leftToRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    g.translate( 1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        else  // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                thumbBounds.height += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            g.setColor( thumbColor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            g.setColor( thumbShadow );
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   290
            drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            g.setColor( thumbHighlightColor );
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   293
            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
   294
            drawVLine(g, 1, 1, thumbBounds.height - 3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            bumps.paintIcon( c, g, 4, 3 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                thumbBounds.height -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        g.translate( -thumbBounds.x, -thumbBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private void oceanPaintThumb(Graphics g, JComponent c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                   Rectangle thumbBounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        boolean leftToRight = MetalUtils.isLeftToRight(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        g.translate(thumbBounds.x, thumbBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (!isFreeStanding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                thumbBounds.width += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                if (!leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    g.translate(-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if (thumbColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                g.setColor(thumbColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            g.setColor(thumbShadow);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   327
            drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            g.setColor(thumbHighlightColor);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   330
            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
   331
            drawVLine(g, 1, 1, thumbBounds.height - 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                    thumbBounds.width - 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                    thumbBounds.height - 3, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            int gripSize = thumbBounds.width - 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (gripSize > 2 && thumbBounds.height >= 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                int gripY = thumbBounds.height / 2 - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                for (int counter = 0; counter < 6; counter += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    g.fillRect(4, counter + gripY, gripSize, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                g.setColor(MetalLookAndFeel.getWhite());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                gripY++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                for (int counter = 0; counter < 6; counter += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    g.fillRect(5, counter + gripY, gripSize, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            if (!isFreeStanding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                thumbBounds.width -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                if (!leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    g.translate(1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        else { // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (!isFreeStanding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                thumbBounds.height += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (thumbColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                g.setColor(thumbColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            g.setColor(thumbShadow);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   369
            drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            g.setColor(thumbHighlightColor);
24163
d56df89854c4 8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents: 23715
diff changeset
   372
            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
   373
            drawVLine(g, 1, 1, thumbBounds.height - 3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                    thumbBounds.width - 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                    thumbBounds.height - 4, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            int gripSize = thumbBounds.height - 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (gripSize > 2 && thumbBounds.width >= 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                int gripX = thumbBounds.width / 2 - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                for (int counter = 0; counter < 6; counter += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    g.fillRect(gripX + counter, 4, 1, gripSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                g.setColor(MetalLookAndFeel.getWhite());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                gripX++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                for (int counter = 0; counter < 6; counter += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    g.fillRect(gripX + counter, 5, 1, gripSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (!isFreeStanding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                thumbBounds.height -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        g.translate( -thumbBounds.x, -thumbBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    protected Dimension getMinimumThumbSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return new Dimension( scrollBarWidth, scrollBarWidth );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      * This is overridden only to increase the invalid area.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      * ensures that the "Shadow" below the thumb is invalidated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    protected void setThumbBounds(int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        /* If the thumbs bounds haven't changed, we're done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if ((thumbRect.x == x) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            (thumbRect.y == y) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            (thumbRect.width == width) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            (thumbRect.height == height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        /* Update thumbRect, and repaint the union of x,y,w,h and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * the old thumbRect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int minX = Math.min(x, thumbRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int minY = Math.min(y, thumbRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        int maxX = Math.max(x + width, thumbRect.x + thumbRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        int maxY = Math.max(y + height, thumbRect.y + thumbRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        thumbRect.setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        scrollbar.repaint(minX, minY, (maxX - minX)+1, (maxY - minY)+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    class ScrollBarListener extends BasicScrollBarUI.PropertyChangeHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        public void propertyChange(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            String name = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if ( name.equals( FREE_STANDING_PROP ) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                handlePropertyChange( e.getNewValue() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                super.propertyChange( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        public void handlePropertyChange( Object newValue )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            if ( newValue != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                boolean temp = ((Boolean)newValue).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                boolean becameFlush = temp == false && isFreeStanding == true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                boolean becameNormal = temp == true && isFreeStanding == false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                isFreeStanding = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                if ( becameFlush ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    toFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                else if ( becameNormal ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    toFreeStanding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if ( !isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    isFreeStanding = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    toFreeStanding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                // This commented-out block is used for testing flush scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                if ( isFreeStanding ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    isFreeStanding = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    toFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if ( increaseButton != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                increaseButton.setFreeStanding( isFreeStanding );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            if ( decreaseButton != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                decreaseButton.setFreeStanding( isFreeStanding );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        protected void toFlush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            scrollBarWidth -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        protected void toFreeStanding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            scrollBarWidth += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    } // end class ScrollBarListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
}