jdk/src/share/classes/javax/swing/plaf/metal/MetalSliderUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 22574 7f8ce0c8c20a
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
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
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: 4199
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: 4199
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: 4199
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4199
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.plaf.basic.BasicSliderUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    40
 * A Java L&amp;F implementation of SliderUI.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20169
diff changeset
    47
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
    53
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class MetalSliderUI extends BasicSliderUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    56
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    57
     * The buffer of a tick.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    58
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected final int TICK_BUFFER = 4;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    60
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    61
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    62
     * The value of the property {@code JSlider.isFilled}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    63
     * By default, {@code false} if the property is not set,
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    64
     * {@code true} for Ocean theme.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    65
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected boolean filledSlider = false;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    67
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
    68
    // NOTE: these next five variables are currently unused.
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    69
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    70
     * The color of a thumb
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    71
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected static Color thumbColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    73
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    74
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    75
     * The color of highlighting.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    76
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected static Color highlightColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    78
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    79
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    80
     * The color of dark shadow.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    81
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected static Color darkShadowColor;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    83
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    84
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    85
     * The width of a track.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    86
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected static int trackWidth;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    88
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    89
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    90
     * The length of a tick.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    91
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected static int tickLength;
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
    93
    private int safeLength;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    * A default horizontal thumb <code>Icon</code>. This field might not be
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
    97
    * used. To change the <code>Icon</code> used by this delegate directly set it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    * using the <code>Slider.horizontalThumbIcon</code> UIManager property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected static Icon horizThumbIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    * A default vertical thumb <code>Icon</code>. This field might not be
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
   104
    * used. To change the <code>Icon</code> used by this delegate directly set it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    * using the <code>Slider.verticalThumbIcon</code> UIManager property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected static Icon vertThumbIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private static Icon SAFE_HORIZ_THUMB_ICON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static Icon SAFE_VERT_THUMB_ICON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   112
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   113
     * Property for {@code JSlider.isFilled}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   114
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected final String SLIDER_FILL = "JSlider.isFilled";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   117
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   118
     * Constructs a {@code MetalSliderUI} instance.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   119
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   120
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   121
     * @return a {@code MetalSliderUI} instance
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   122
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static ComponentUI createUI(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return new MetalSliderUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   127
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   128
     * Constructs a {@code MetalSliderUI} instance.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   129
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public MetalSliderUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        super( null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static Icon getHorizThumbIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (System.getSecurityManager() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            return SAFE_HORIZ_THUMB_ICON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return horizThumbIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private static Icon getVertThumbIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (System.getSecurityManager() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return SAFE_VERT_THUMB_ICON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return vertThumbIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void installUI( JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        trackWidth = ((Integer)UIManager.get( "Slider.trackWidth" )).intValue();
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   152
        tickLength = safeLength = ((Integer)UIManager.get( "Slider.majorTickLength" )).intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        horizThumbIcon = SAFE_HORIZ_THUMB_ICON =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                UIManager.getIcon( "Slider.horizontalThumbIcon" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        vertThumbIcon = SAFE_VERT_THUMB_ICON =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                UIManager.getIcon( "Slider.verticalThumbIcon" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        super.installUI( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        thumbColor = UIManager.getColor("Slider.thumb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        highlightColor = UIManager.getColor("Slider.highlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        darkShadowColor = UIManager.getColor("Slider.darkShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        scrollListener.setScrollByBlock( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   166
        prepareFilledSliderField();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   169
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   170
     * Constructs {@code MetalPropertyListener}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   171
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   172
     * @param slider a {@code JSlider}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   173
     * @return the {@code MetalPropertyListener}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   174
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return new MetalPropertyListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   179
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   180
     * {@code PropertyListener} for {@code JSlider.isFilled}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   181
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public void propertyChange( PropertyChangeEvent e ) {  // listen for slider fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            super.propertyChange( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   186
            if (e.getPropertyName().equals(SLIDER_FILL)) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   187
                prepareFilledSliderField();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   192
    private void prepareFilledSliderField() {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   193
        // Use true for Ocean theme
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   194
        filledSlider = MetalLookAndFeel.usingOcean();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   195
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   196
        Object sliderFillProp = slider.getClientProperty(SLIDER_FILL);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   197
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   198
        if (sliderFillProp != null) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   199
            filledSlider = ((Boolean) sliderFillProp).booleanValue();
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   200
        }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   201
    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   202
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public void paintThumb(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Rectangle knobBounds = thumbRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        g.translate( knobBounds.x, knobBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            getHorizThumbIcon().paintIcon( slider, g, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            getVertThumbIcon().paintIcon( slider, g, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        g.translate( -knobBounds.x, -knobBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns a rectangle enclosing the track that will be painted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    private Rectangle getPaintTrackRect() {
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   222
        int trackLeft = 0, trackRight, trackTop = 0, trackBottom;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (slider.getOrientation() == JSlider.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            trackBottom = (trackRect.height - 1) - getThumbOverhang();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            trackTop = trackBottom - (getTrackWidth() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            trackRight = trackRect.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (MetalUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                trackLeft = (trackRect.width - getThumbOverhang()) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                                         getTrackWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                trackRight = (trackRect.width - getThumbOverhang()) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                trackLeft = getThumbOverhang();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                trackRight = getThumbOverhang() + getTrackWidth() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            trackBottom = trackRect.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return new Rectangle(trackRect.x + trackLeft, trackRect.y + trackTop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                             trackRight - trackLeft, trackBottom - trackTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public void paintTrack(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            oceanPaintTrack(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        Color trackColor = !slider.isEnabled() ? MetalLookAndFeel.getControlShadow() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                           slider.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        boolean leftToRight = MetalUtils.isLeftToRight(slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        g.translate( trackRect.x, trackRect.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int trackLeft = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        int trackTop = 0;
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   258
        int trackRight;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   259
        int trackBottom;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // Draw the track
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            trackBottom = (trackRect.height - 1) - getThumbOverhang();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            trackTop = trackBottom - (getTrackWidth() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            trackRight = trackRect.width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                trackLeft = (trackRect.width - getThumbOverhang()) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                                         getTrackWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                trackRight = (trackRect.width - getThumbOverhang()) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                trackLeft = getThumbOverhang();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                trackRight = getThumbOverhang() + getTrackWidth() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            trackBottom = trackRect.height - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if ( slider.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            g.setColor( MetalLookAndFeel.getControlDarkShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            g.drawRect( trackLeft, trackTop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                        (trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            g.setColor( MetalLookAndFeel.getControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            g.drawLine( trackLeft + 1, trackBottom, trackRight, trackBottom );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            g.drawLine( trackRight, trackTop + 1, trackRight, trackBottom );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            g.setColor( MetalLookAndFeel.getControlShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            g.drawLine( trackLeft + 1, trackTop + 1, trackRight - 2, trackTop + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            g.drawLine( trackLeft + 1, trackTop + 1, trackLeft + 1, trackBottom - 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            g.setColor( MetalLookAndFeel.getControlShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            g.drawRect( trackLeft, trackTop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                        (trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // Draw the fill
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if ( filledSlider ) {
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   301
            int middleOfThumb;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   302
            int fillTop;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   303
            int fillLeft;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   304
            int fillBottom;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   305
            int fillRight;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                middleOfThumb = thumbRect.x + (thumbRect.width / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                middleOfThumb -= trackRect.x; // To compensate for the g.translate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                fillTop = !slider.isEnabled() ? trackTop : trackTop + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    fillRight = middleOfThumb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    fillLeft = middleOfThumb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                middleOfThumb = thumbRect.y + (thumbRect.height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                middleOfThumb -= trackRect.y; // To compensate for the g.translate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    fillTop = middleOfThumb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    fillTop = !slider.isEnabled() ? trackTop : trackTop + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    fillBottom = middleOfThumb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if ( slider.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                g.setColor( slider.getBackground() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                g.drawLine( fillLeft, fillTop, fillRight, fillTop );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                g.drawLine( fillLeft, fillTop, fillLeft, fillBottom );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                g.setColor( MetalLookAndFeel.getControlShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                g.fillRect( fillLeft + 1, fillTop + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                            fillRight - fillLeft, fillBottom - fillTop );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                g.setColor( MetalLookAndFeel.getControlShadow() );
1304
f0e7af74a2bc 6742358: MetalSliderUI paint wrong vertical disabled filled JSlider for DefaultMetalTheme
rupashka
parents: 2
diff changeset
   349
                g.fillRect(fillLeft, fillTop, fillRight - fillLeft, fillBottom - fillTop);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        g.translate( -trackRect.x, -trackRect.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private void oceanPaintTrack(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        boolean leftToRight = MetalUtils.isLeftToRight(slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        boolean drawInverted = drawInverted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        Color sliderAltTrackColor = (Color)UIManager.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                    "Slider.altTrackColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        // Translate to the origin of the painting rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        Rectangle paintRect = getPaintTrackRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        g.translate(paintRect.x, paintRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // Width and height of the painting rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int w = paintRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        int h = paintRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   370
        if (slider.getOrientation() == JSlider.HORIZONTAL) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   371
            int middleOfThumb = thumbRect.x + thumbRect.width / 2 - paintRect.x;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   372
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   373
            if (slider.isEnabled()) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   374
                int fillMinX;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   375
                int fillMaxX;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   376
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   377
                if (middleOfThumb > 0) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   378
                    g.setColor(drawInverted ? MetalLookAndFeel.getControlDarkShadow() :
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   379
                            MetalLookAndFeel.getPrimaryControlDarkShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   380
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   381
                    g.drawRect(0, 0, middleOfThumb - 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   382
                }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   383
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   384
                if (middleOfThumb < w) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   385
                    g.setColor(drawInverted ? MetalLookAndFeel.getPrimaryControlDarkShadow() :
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   386
                            MetalLookAndFeel.getControlDarkShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   387
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   388
                    g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   389
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   391
                if (filledSlider) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   392
                    g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   393
                    if (drawInverted) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   394
                        fillMinX = middleOfThumb;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   395
                        fillMaxX = w - 2;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   396
                        g.drawLine(1, 1, middleOfThumb, 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   397
                    } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   398
                        fillMinX = 1;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   399
                        fillMaxX = middleOfThumb;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   400
                        g.drawLine(middleOfThumb, 1, w - 1, 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   401
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   402
                    if (h == 6) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   403
                        g.setColor(MetalLookAndFeel.getWhite());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   404
                        g.drawLine(fillMinX, 1, fillMaxX, 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   405
                        g.setColor(sliderAltTrackColor);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   406
                        g.drawLine(fillMinX, 2, fillMaxX, 2);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   407
                        g.setColor(MetalLookAndFeel.getControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   408
                        g.drawLine(fillMinX, 3, fillMaxX, 3);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   409
                        g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   410
                        g.drawLine(fillMinX, 4, fillMaxX, 4);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   411
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   412
                }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   413
            } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                g.setColor(MetalLookAndFeel.getControlShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   416
                if (middleOfThumb > 0) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   417
                    if (!drawInverted && filledSlider) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   418
                        g.fillRect(0, 0, middleOfThumb - 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   419
                    } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   420
                        g.drawRect(0, 0, middleOfThumb - 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   421
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   423
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   424
                if (middleOfThumb < w) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   425
                    if (drawInverted && filledSlider) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   426
                        g.fillRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   427
                    } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   428
                        g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   429
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   432
        } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   433
            int middleOfThumb = thumbRect.y + (thumbRect.height / 2) - paintRect.y;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   434
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   435
            if (slider.isEnabled()) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   436
                int fillMinY;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   437
                int fillMaxY;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   438
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   439
                if (middleOfThumb > 0) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   440
                    g.setColor(drawInverted ? MetalLookAndFeel.getPrimaryControlDarkShadow() :
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   441
                            MetalLookAndFeel.getControlDarkShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   442
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   443
                    g.drawRect(0, 0, w - 1, middleOfThumb - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   445
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   446
                if (middleOfThumb < h) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   447
                    g.setColor(drawInverted ? MetalLookAndFeel.getControlDarkShadow() :
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   448
                            MetalLookAndFeel.getPrimaryControlDarkShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   449
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   450
                    g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
1317
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   452
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   453
                if (filledSlider) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   454
                    g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   455
                    if (drawInverted()) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   456
                        fillMinY = 1;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   457
                        fillMaxY = middleOfThumb;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   458
                        if (leftToRight) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   459
                            g.drawLine(1, middleOfThumb, 1, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   460
                        } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   461
                            g.drawLine(w - 2, middleOfThumb, w - 2, h - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   462
                        }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   463
                    } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   464
                        fillMinY = middleOfThumb;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   465
                        fillMaxY = h - 2;
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   466
                        if (leftToRight) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   467
                            g.drawLine(1, 1, 1, middleOfThumb);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   468
                        } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   469
                            g.drawLine(w - 2, 1, w - 2, middleOfThumb);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   470
                        }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   471
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   472
                    if (w == 6) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   473
                        g.setColor(leftToRight ? MetalLookAndFeel.getWhite() : MetalLookAndFeel.getPrimaryControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   474
                        g.drawLine(1, fillMinY, 1, fillMaxY);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   475
                        g.setColor(leftToRight ? sliderAltTrackColor : MetalLookAndFeel.getControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   476
                        g.drawLine(2, fillMinY, 2, fillMaxY);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   477
                        g.setColor(leftToRight ? MetalLookAndFeel.getControlShadow() : sliderAltTrackColor);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   478
                        g.drawLine(3, fillMinY, 3, fillMaxY);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   479
                        g.setColor(leftToRight ? MetalLookAndFeel.getPrimaryControlShadow() : MetalLookAndFeel.getWhite());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   480
                        g.drawLine(4, fillMinY, 4, fillMaxY);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   481
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   482
                }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   483
            } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   484
                g.setColor(MetalLookAndFeel.getControlShadow());
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   485
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   486
                if (middleOfThumb > 0) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   487
                    if (drawInverted && filledSlider) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   488
                        g.fillRect(0, 0, w - 1, middleOfThumb - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   489
                    } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   490
                        g.drawRect(0, 0, w - 1, middleOfThumb - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   491
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   492
                }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   493
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   494
                if (middleOfThumb < h) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   495
                    if (!drawInverted && filledSlider) {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   496
                        g.fillRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   497
                    } else {
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   498
                        g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1);
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   499
                    }
0ba1e3d36c19 6587742: filling half of a JSlider's track is no longer optional
rupashka
parents: 1304
diff changeset
   500
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        g.translate(-paintRect.x, -paintRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public void paintFocus(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    protected Dimension getThumbSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        Dimension size = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if ( slider.getOrientation() == JSlider.VERTICAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            size.width = getVertThumbIcon().getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            size.height = getVertThumbIcon().getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            size.width = getHorizThumbIcon().getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            size.height = getHorizThumbIcon().getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Gets the height of the tick area for horizontal sliders and the width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * tick area for vertical sliders.  BasicSliderUI uses the returned value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * determine the tick area rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public int getTickLength() {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   531
        return slider.getOrientation() == JSlider.HORIZONTAL ? safeLength + TICK_BUFFER + 1 :
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   532
        safeLength + TICK_BUFFER + 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Returns the shorter dimension of the track.
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   537
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   538
     * @return the shorter dimension of the track
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    protected int getTrackWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        // This strange calculation is here to keep the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        // track in proportion to the thumb.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        final double kIdealTrackWidth = 7.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        final double kIdealThumbHeight = 16.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        final double kWidthScalar = kIdealTrackWidth / kIdealThumbHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            return (int)(kWidthScalar * thumbRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return (int)(kWidthScalar * thumbRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Returns the longer dimension of the slide bar.  (The slide bar is only the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * part that runs directly under the thumb)
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   558
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   559
     * @return the longer dimension of the slide bar
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    protected int getTrackLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return trackRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return trackRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Returns the amount that the thumb goes past the slide bar.
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   570
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   571
     * @return the amount that the thumb goes past the slide bar
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    protected int getThumbOverhang() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return (int)(getThumbSize().getHeight()-getTrackWidth())/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    protected void scrollDueToClickInTrack( int dir ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        scrollByUnit( dir );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   583
        g.drawLine( x, TICK_BUFFER, x, TICK_BUFFER + (safeLength / 2) );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   588
        g.drawLine( x, TICK_BUFFER , x, TICK_BUFFER + (safeLength - 1) );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (MetalUtils.isLeftToRight(slider)) {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   595
            g.drawLine( TICK_BUFFER, y, TICK_BUFFER + (safeLength / 2), y );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        else {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   598
            g.drawLine( 0, y, safeLength/2, y );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (MetalUtils.isLeftToRight(slider)) {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   606
            g.drawLine( TICK_BUFFER, y, TICK_BUFFER + safeLength, y );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        else {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 1639
diff changeset
   609
            g.drawLine( 0, y, safeLength, y );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
}