jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSliderUI.java
author pkbalakr
Fri, 09 Sep 2016 13:15:10 +0530
changeset 41007 d48361243925
parent 30461 57e36ed1a9ab
permissions -rw-r--r--
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick Reviewed-by: alexsch, aghaisas Contributed-by: prem.balakrishnan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41007
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
     2
 * Copyright (c) 1997, 2016, 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: 4963
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: 4963
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: 4963
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4963
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4963
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.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
677
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
    29
import java.awt.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Dictionary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
    42
 * A Basic L&F implementation of SliderUI.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class BasicSliderUI extends SliderUI{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // Old actions forward to an instance of this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final Actions SHARED_ACTION = new Actions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    50
    /** Positive scroll */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int POSITIVE_SCROLL = +1;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    52
    /** Negative scroll */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int NEGATIVE_SCROLL = -1;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    54
    /** Minimum scroll */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final int MIN_SCROLL = -2;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    56
    /** Maximum scroll */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static final int MAX_SCROLL = +2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    59
    /** Scroll timer */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected Timer scrollTimer;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    61
    /** Slider */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected JSlider slider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    64
    /** Focus insets */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected Insets focusInsets = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    66
    /** Inset cache */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected Insets insetCache = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    68
    /** Left-to-right cache */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected boolean leftToRightCache = true;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    70
    /** Focus rectangle */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected Rectangle focusRect = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    72
    /** Content rectangle */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected Rectangle contentRect = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    74
    /** Label rectangle */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected Rectangle labelRect = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    76
    /** Tick rectangle */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected Rectangle tickRect = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    78
    /** Track rectangle */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected Rectangle trackRect = null;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    80
    /** Thumb rectangle */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected Rectangle thumbRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    83
    /** The distance that the track is from the side of the control */
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    84
    protected int trackBuffer = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private transient boolean isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    88
    /** Track listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected TrackListener trackListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    90
    /** Change listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected ChangeListener changeListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    92
    /** Component listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected ComponentListener componentListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    94
    /** Focus listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected FocusListener focusListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    96
    /** Scroll listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected ScrollListener scrollListener;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
    98
    /** Property chane listener */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private int lastValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // Colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private Color shadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private Color highlightColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private Color focusColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Whther or not sameLabelBaselines is up to date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private boolean checkedLabelBaselines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Whether or not all the entries in the labeltable have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private boolean sameLabelBaselines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   118
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   119
     * Returns the shadow color.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   120
     * @return the shadow color
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   121
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected Color getShadowColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return shadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   126
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   127
     * Returns the highlight color.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   128
     * @return the highlight color
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   129
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected Color getHighlightColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return highlightColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   134
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   135
     * Returns the focus color.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   136
     * @return the focus color
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   137
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected Color getFocusColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return focusColor;
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
     * Returns true if the user is dragging the slider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return true if the user is dragging the slider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    protected boolean isDragging() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return isDragging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // ComponentUI Interface Implementation methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /////////////////////////////////////////////////////////////////////////////
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   155
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   156
     * Creates a UI.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   157
     * @param b a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   158
     * @return a UI
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   159
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static ComponentUI createUI(JComponent b)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return new BasicSliderUI((JSlider)b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   164
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   165
     * Constructs a {@code BasicSliderUI}.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   166
     * @param b a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   167
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public BasicSliderUI(JSlider b)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   171
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   172
     * Installs a UI.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   173
     * @param c a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   174
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void installUI(JComponent c)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        slider = (JSlider) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        checkedLabelBaselines = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        slider.setEnabled(slider.isEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        LookAndFeel.installProperty(slider, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        trackListener = createTrackListener( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        changeListener = createChangeListener( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        componentListener = createComponentListener( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        focusListener = createFocusListener( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        scrollListener = createScrollListener( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        propertyChangeListener = createPropertyChangeListener( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        installDefaults( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        installListeners( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        installKeyboardActions( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        scrollTimer = new Timer( 100, scrollListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        scrollTimer.setInitialDelay( 300 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        insetCache = slider.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        leftToRightCache = BasicGraphicsUtils.isLeftToRight(slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        focusRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        contentRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        labelRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        tickRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        trackRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        thumbRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        lastValue = slider.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        calculateGeometry(); // This figures out where the labels, ticks, track, and thumb are.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   211
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   212
     * Uninstalls a UI.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   213
     * @param c a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   214
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if ( c != slider )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            throw new IllegalComponentStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                                    this + " was asked to deinstall() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                                    + c + " when it only knows about "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                                    + slider + ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        scrollTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        scrollTimer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
4963
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   225
        uninstallDefaults(slider);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        uninstallListeners( slider );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        uninstallKeyboardActions(slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        insetCache = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        leftToRightCache = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        focusRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        contentRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        labelRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        tickRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        trackRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        thumbRect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        trackListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        changeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        componentListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        focusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        scrollListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        slider = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   246
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   247
     * Installs the defaults.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   248
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   249
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    protected void installDefaults( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        LookAndFeel.installBorder(slider, "Slider.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        LookAndFeel.installColorsAndFont(slider, "Slider.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                         "Slider.foreground", "Slider.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        highlightColor = UIManager.getColor("Slider.highlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        shadowColor = UIManager.getColor("Slider.shadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        focusColor = UIManager.getColor("Slider.focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        focusInsets = (Insets)UIManager.get( "Slider.focusInsets" );
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2488
diff changeset
   260
        // use default if missing so that BasicSliderUI can be used in other
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2488
diff changeset
   261
        // LAFs like Nimbus
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2488
diff changeset
   262
        if (focusInsets == null) focusInsets = new InsetsUIResource(2,2,2,2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   265
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   266
     * Uninstalls the defaults.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   267
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   268
     */
4963
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   269
    protected void uninstallDefaults(JSlider slider) {
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   270
        LookAndFeel.uninstallBorder(slider);
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   271
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   272
        focusInsets = null;
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   273
    }
004eaf21ba24 6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents: 4957
diff changeset
   274
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   275
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   276
     * Creates a track listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   277
     * @return a track listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   278
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   279
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    protected TrackListener createTrackListener(JSlider slider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return new TrackListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   284
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   285
     * Creates a change listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   286
     * @return a change listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   287
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   288
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    protected ChangeListener createChangeListener(JSlider slider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   293
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   294
     * Creates a composite listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   295
     * @return a composite listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   296
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   297
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    protected ComponentListener createComponentListener(JSlider slider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   302
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   303
     * Creates a focus listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   304
     * @return a focus listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   305
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   306
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected FocusListener createFocusListener(JSlider slider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   311
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   312
     * Creates a scroll listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   313
     * @return a scroll listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   314
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   315
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    protected ScrollListener createScrollListener( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return new ScrollListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   320
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   321
     * Creates a property change listener.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   322
     * @return a property change listener
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   323
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   324
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    protected PropertyChangeListener createPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            JSlider slider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   337
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   338
     * Installs listeners.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   339
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   340
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    protected void installListeners( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        slider.addMouseListener(trackListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        slider.addMouseMotionListener(trackListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        slider.addFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        slider.addComponentListener(componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        slider.addPropertyChangeListener( propertyChangeListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        slider.getModel().addChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   350
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   351
     * Uninstalls listeners.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   352
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   353
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    protected void uninstallListeners( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        slider.removeMouseListener(trackListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        slider.removeMouseMotionListener(trackListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        slider.removeFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        slider.removeComponentListener(componentListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        slider.removePropertyChangeListener( propertyChangeListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        slider.getModel().removeChangeListener(changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   364
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   365
     * Installs keyboard actions.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   366
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   367
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    protected void installKeyboardActions( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        InputMap km = getInputMap(JComponent.WHEN_FOCUSED, slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        SwingUtilities.replaceUIInputMap(slider, JComponent.WHEN_FOCUSED, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        LazyActionMap.installLazyActionMap(slider, BasicSliderUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                "Slider.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    InputMap getInputMap(int condition, JSlider slider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (condition == JComponent.WHEN_FOCUSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            InputMap keyMap = (InputMap)DefaultLookup.get(slider, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                  "Slider.focusInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            InputMap rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (slider.getComponentOrientation().isLeftToRight() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                ((rtlKeyMap = (InputMap)DefaultLookup.get(slider, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                          "Slider.focusInputMap.RightToLeft")) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                return keyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                rtlKeyMap.setParent(keyMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                return rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return null;
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
     * Populates ComboBox's actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        map.put(new Actions(Actions.POSITIVE_UNIT_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        map.put(new Actions(Actions.POSITIVE_BLOCK_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        map.put(new Actions(Actions.NEGATIVE_UNIT_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        map.put(new Actions(Actions.NEGATIVE_BLOCK_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        map.put(new Actions(Actions.MIN_SCROLL_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        map.put(new Actions(Actions.MAX_SCROLL_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   405
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   406
     * Uninstalls keyboard actions.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   407
     * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   408
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    protected void uninstallKeyboardActions( JSlider slider ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        SwingUtilities.replaceUIActionMap(slider, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        SwingUtilities.replaceUIInputMap(slider, JComponent.WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                         null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (slider.getPaintLabels() && labelsHaveSameBaselines()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            FontMetrics metrics = slider.getFontMetrics(slider.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            Insets insets = slider.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            Dimension thumbSize = getThumbSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            if (slider.getOrientation() == JSlider.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                int tickLength = getTickLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                int contentHeight = height - insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    focusInsets.top - focusInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                int thumbHeight = thumbSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                int centerSpacing = thumbHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                if (slider.getPaintTicks()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    centerSpacing += tickLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                // Assume uniform labels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                centerSpacing += getHeightOfTallestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                int trackY = insets.top + focusInsets.top +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    (contentHeight - centerSpacing - 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                int trackHeight = thumbHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                int tickY = trackY + trackHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                int tickHeight = tickLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if (!slider.getPaintTicks()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    tickHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                int labelY = tickY + tickHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                return labelY + metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            else { // vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                boolean inverted = slider.getInverted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                Integer value = inverted ? getLowestValue() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                                           getHighestValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    int thumbHeight = thumbSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    int trackBuffer = Math.max(metrics.getHeight() / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                               thumbHeight / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    int contentY = focusInsets.top + insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    int trackY = contentY + trackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    int trackHeight = height - focusInsets.top -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        focusInsets.bottom - insets.top - insets.bottom -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        trackBuffer - trackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    int yPosition = yPositionForValue(value, trackY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                                      trackHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    return yPosition - metrics.getHeight() / 2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // NOTE: BasicSpinner really provides for CENTER_OFFSET, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        // the default min/pref size is smaller than it should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        // so that getBaseline() doesn't implement the contract
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        // for CENTER_OFFSET as defined in Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return Component.BaselineResizeBehavior.OTHER;
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
     * Returns true if all the labels from the label table have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @return true if all the labels from the label table have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *         same baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    protected boolean labelsHaveSameBaselines() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (!checkedLabelBaselines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            checkedLabelBaselines = true;
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   504
            @SuppressWarnings("rawtypes")
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   505
            Dictionary dictionary = slider.getLabelTable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (dictionary != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                sameLabelBaselines = true;
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   508
                Enumeration<?> elements = dictionary.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                int baseline = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                while (elements.hasMoreElements()) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   511
                    JComponent label = (JComponent) elements.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    Dimension pref = label.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    int labelBaseline = label.getBaseline(pref.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                                          pref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    if (labelBaseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        if (baseline == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                            baseline = labelBaseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                        else if (baseline != labelBaseline) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                            sameLabelBaselines = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        sameLabelBaselines = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                sameLabelBaselines = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return sameLabelBaselines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   537
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   538
     * Returns the preferred horizontal size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   539
     * @return the preferred horizontal size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   540
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public Dimension getPreferredHorizontalSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        Dimension horizDim = (Dimension)DefaultLookup.get(slider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                this, "Slider.horizontalSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (horizDim == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            horizDim = new Dimension(200, 21);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return horizDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   550
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   551
     * Returns the preferred vertical size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   552
     * @return the preferred vertical size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   553
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public Dimension getPreferredVerticalSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        Dimension vertDim = (Dimension)DefaultLookup.get(slider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                this, "Slider.verticalSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (vertDim == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            vertDim = new Dimension(21, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return vertDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   563
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   564
     * Returns the minimum horizontal size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   565
     * @return the minimum horizontal size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   566
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public Dimension getMinimumHorizontalSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        Dimension minHorizDim = (Dimension)DefaultLookup.get(slider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                this, "Slider.minimumHorizontalSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        if (minHorizDim == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            minHorizDim = new Dimension(36, 21);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return minHorizDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   576
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   577
     * Returns the minimum vertical size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   578
     * @return the minimum vertical size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   579
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public Dimension getMinimumVerticalSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        Dimension minVertDim = (Dimension)DefaultLookup.get(slider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                this, "Slider.minimumVerticalSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (minVertDim == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            minVertDim = new Dimension(21, 36);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return minVertDim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   589
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   590
     * Returns the preferred size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   591
     * @param c a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   592
     * @return the preferred size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   593
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public Dimension getPreferredSize(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        recalculateIfInsetsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        Dimension d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if ( slider.getOrientation() == JSlider.VERTICAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            d = new Dimension(getPreferredVerticalSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            d.width = insetCache.left + insetCache.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            d.width += focusInsets.left + focusInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            d.width += trackRect.width + tickRect.width + labelRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            d = new Dimension(getPreferredHorizontalSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            d.height = insetCache.top + insetCache.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            d.height += focusInsets.top + focusInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            d.height += trackRect.height + tickRect.height + labelRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   613
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   614
     * Returns the minimum size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   615
     * @param c a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   616
     * @return the minimum size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   617
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public Dimension getMinimumSize(JComponent c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        recalculateIfInsetsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        Dimension d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        if ( slider.getOrientation() == JSlider.VERTICAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            d = new Dimension(getMinimumVerticalSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            d.width = insetCache.left + insetCache.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            d.width += focusInsets.left + focusInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            d.width += trackRect.width + tickRect.width + labelRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            d = new Dimension(getMinimumHorizontalSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            d.height = insetCache.top + insetCache.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            d.height += focusInsets.top + focusInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            d.height += trackRect.height + tickRect.height + labelRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   638
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   639
     * Returns the maximum size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   640
     * @param c a component
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   641
     * @return the maximum size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   642
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        Dimension d = getPreferredSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        if ( slider.getOrientation() == JSlider.VERTICAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            d.height = Short.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            d.width = Short.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   655
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   656
     * Calculates the geometry.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   657
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    protected void calculateGeometry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        calculateFocusRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        calculateContentRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        calculateThumbSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        calculateTrackBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        calculateTrackRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        calculateTickRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        calculateLabelRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        calculateThumbLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   669
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   670
     * Calculates the focus rectangle.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   671
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    protected void calculateFocusRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        focusRect.x = insetCache.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        focusRect.y = insetCache.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        focusRect.width = slider.getWidth() - (insetCache.left + insetCache.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        focusRect.height = slider.getHeight() - (insetCache.top + insetCache.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   679
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   680
     * Calculates the thumb size rectangle.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   681
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    protected void calculateThumbSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        Dimension size = getThumbSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        thumbRect.setSize( size.width, size.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   687
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   688
     * Calculates the content rectangle.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   689
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    protected void calculateContentRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        contentRect.x = focusRect.x + focusInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        contentRect.y = focusRect.y + focusInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        contentRect.width = focusRect.width - (focusInsets.left + focusInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        contentRect.height = focusRect.height - (focusInsets.top + focusInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   697
    private int getTickSpacing() {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   698
        int majorTickSpacing = slider.getMajorTickSpacing();
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   699
        int minorTickSpacing = slider.getMinorTickSpacing();
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   700
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   701
        int result;
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   702
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   703
        if (minorTickSpacing > 0) {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   704
            result = minorTickSpacing;
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   705
        } else if (majorTickSpacing > 0) {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   706
            result = majorTickSpacing;
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   707
        } else {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   708
            result = 0;
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   709
        }
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   710
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   711
        return result;
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   712
    }
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   713
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   714
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   715
     * Calculates the thumb location.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   716
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    protected void calculateThumbLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        if ( slider.getSnapToTicks() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            int sliderValue = slider.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            int snappedValue = sliderValue;
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
   721
            int tickSpacing = getTickSpacing();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if ( tickSpacing != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                // If it's not on a tick, change the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                if ( (sliderValue - slider.getMinimum()) % tickSpacing != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    float temp = (float)(sliderValue - slider.getMinimum()) / (float)tickSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                    int whichTick = Math.round( temp );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    // This is the fix for the bug #6401380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                    if (temp - (int)temp == .5 && sliderValue < lastValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                      whichTick --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    snappedValue = slider.getMinimum() + (whichTick * tickSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                if( snappedValue != sliderValue ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    slider.setValue( snappedValue );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            int valuePosition = xPositionForValue(slider.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            thumbRect.x = valuePosition - (thumbRect.width / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            thumbRect.y = trackRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            int valuePosition = yPositionForValue(slider.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            thumbRect.x = trackRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            thumbRect.y = valuePosition - (thumbRect.height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   756
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   757
     * Calculates the track buffer.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   758
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    protected void calculateTrackBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if ( slider.getPaintLabels() && slider.getLabelTable()  != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            Component highLabel = getHighestValueLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            Component lowLabel = getLowestValueLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                trackBuffer = Math.max( highLabel.getBounds().width, lowLabel.getBounds().width ) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                trackBuffer = Math.max( trackBuffer, thumbRect.width / 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                trackBuffer = Math.max( highLabel.getBounds().height, lowLabel.getBounds().height ) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                trackBuffer = Math.max( trackBuffer, thumbRect.height / 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                trackBuffer = thumbRect.width / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                trackBuffer = thumbRect.height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   783
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   784
     * Calculates the track rectangle.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   785
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    protected void calculateTrackRect() {
676
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
   787
        int centerSpacing; // used to center sliders added using BorderLayout.CENTER (bug 4275631)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            centerSpacing = thumbRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            if ( slider.getPaintTicks() ) centerSpacing += getTickLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if ( slider.getPaintLabels() ) centerSpacing += getHeightOfTallestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            trackRect.x = contentRect.x + trackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            trackRect.y = contentRect.y + (contentRect.height - centerSpacing - 1)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            trackRect.width = contentRect.width - (trackBuffer * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            trackRect.height = thumbRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            centerSpacing = thumbRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            if (BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                if ( slider.getPaintTicks() ) centerSpacing += getTickLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                if ( slider.getPaintLabels() ) centerSpacing += getWidthOfWidestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                if ( slider.getPaintTicks() ) centerSpacing -= getTickLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                if ( slider.getPaintLabels() ) centerSpacing -= getWidthOfWidestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            trackRect.x = contentRect.x + (contentRect.width - centerSpacing - 1)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            trackRect.y = contentRect.y + trackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            trackRect.width = thumbRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            trackRect.height = contentRect.height - (trackBuffer * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   815
     * Gets the height of the tick area for horizontal sliders and the width of
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   816
     * the tick area for vertical sliders. BasicSliderUI uses the returned value
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   817
     * to determine the tick area rectangle. If you want to give your ticks some
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   818
     * room, make this larger than you need and paint your ticks away from the
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   819
     * sides in paintTicks().
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   820
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   821
     * @return an integer representing the height of the tick area for
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   822
     * horizontal sliders, and the width of the tick area for the vertical
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
   823
     * sliders
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    protected int getTickLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        return 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   829
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   830
     * Calculates the tick rectangle.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   831
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    protected void calculateTickRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            tickRect.x = trackRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            tickRect.y = trackRect.y + trackRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            tickRect.width = trackRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            tickRect.height = (slider.getPaintTicks()) ? getTickLength() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            tickRect.width = (slider.getPaintTicks()) ? getTickLength() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            if(BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                tickRect.x = trackRect.x + trackRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                tickRect.x = trackRect.x - tickRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            tickRect.y = trackRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            tickRect.height = trackRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   852
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   853
     * Calculates the label rectangle.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   854
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    protected void calculateLabelRect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        if ( slider.getPaintLabels() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                labelRect.x = tickRect.x - trackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                labelRect.y = tickRect.y + tickRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                labelRect.width = tickRect.width + (trackBuffer * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                labelRect.height = getHeightOfTallestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                if(BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    labelRect.x = tickRect.x + tickRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    labelRect.width = getWidthOfWidestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                    labelRect.width = getWidthOfWidestLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    labelRect.x = tickRect.x - labelRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                labelRect.y = tickRect.y - trackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                labelRect.height = tickRect.height + (trackBuffer * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                labelRect.x = tickRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                labelRect.y = tickRect.y + tickRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                labelRect.width = tickRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                labelRect.height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                if(BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    labelRect.x = tickRect.x + tickRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                    labelRect.x = tickRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                labelRect.y = tickRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                labelRect.width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                labelRect.height = tickRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   897
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   898
     * Returns the thumb size.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   899
     * @return the thumb size
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   900
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    protected Dimension getThumbSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        Dimension size = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        if ( slider.getOrientation() == JSlider.VERTICAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            size.width = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            size.height = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            size.width = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            size.height = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   916
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   917
     * A property change handler.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   918
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    public class PropertyChangeHandler implements PropertyChangeListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   920
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        // class calls into the Handler.
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   924
        /** {@inheritDoc} */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        public void propertyChange( PropertyChangeEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   930
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   931
     * Returns the width of the widest label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   932
     * @return the width of the widest label
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   933
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    protected int getWidthOfWidestLabel() {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   935
        @SuppressWarnings("rawtypes")
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   936
        Dictionary dictionary = slider.getLabelTable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        int widest = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        if ( dictionary != null ) {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23697
diff changeset
   939
            Enumeration<?> keys = dictionary.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            while ( keys.hasMoreElements() ) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   941
                JComponent label = (JComponent) dictionary.get(keys.nextElement());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                widest = Math.max( label.getPreferredSize().width, widest );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        return widest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   948
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   949
     * Returns the height of the tallest label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   950
     * @return the height of the tallest label
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   951
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    protected int getHeightOfTallestLabel() {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   953
        @SuppressWarnings("rawtypes")
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   954
        Dictionary dictionary = slider.getLabelTable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        int tallest = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if ( dictionary != null ) {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23697
diff changeset
   957
            Enumeration<?> keys = dictionary.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            while ( keys.hasMoreElements() ) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
   959
                JComponent label = (JComponent) dictionary.get(keys.nextElement());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                tallest = Math.max( label.getPreferredSize().height, tallest );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        return tallest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   966
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   967
     * Returns the width of the highest value label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   968
     * @return the width of the highest value label
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   969
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    protected int getWidthOfHighValueLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        Component label = getHighestValueLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        int width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        if ( label != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            width = label.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   981
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   982
     * Returns the width of the lowest value label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   983
     * @return the width of the lowest value label
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   984
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    protected int getWidthOfLowValueLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        Component label = getLowestValueLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        int width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        if ( label != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            width = label.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   996
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   997
     * Returns the height of the highest value label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   998
     * @return the height of the highest value label
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
   999
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    protected int getHeightOfHighValueLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        Component label = getHighestValueLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        if ( label != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            height = label.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1011
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1012
     * Returns the height of the lowest value label.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1013
     * @return the height of the lowest value label
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1014
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    protected int getHeightOfLowValueLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        Component label = getLowestValueLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        int height = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        if ( label != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            height = label.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1026
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1027
     * Draws inverted.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1028
     * @return the inverted-ness
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1029
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    protected boolean drawInverted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (slider.getOrientation()==JSlider.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            if(BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                return slider.getInverted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                return !slider.getInverted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return slider.getInverted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * Returns the biggest value that has an entry in the label table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @return biggest value that has an entry in the label table, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *         null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    protected Integer getHighestValue() {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1050
        @SuppressWarnings("rawtypes")
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1051
        Dictionary dictionary = slider.getLabelTable();
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1052
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1053
        if (dictionary == null) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1054
            return null;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1055
        }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1056
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1057
        Enumeration<?> keys = dictionary.keys();
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1058
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1059
        Integer max = null;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1060
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1061
        while (keys.hasMoreElements()) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1062
            Integer i = (Integer) keys.nextElement();
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1063
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1064
            if (max == null || i > max) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1065
                max = i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        }
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1068
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1069
        return max;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * Returns the smallest value that has an entry in the label table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @return smallest value that has an entry in the label table, or
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1076
     * null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    protected Integer getLowestValue() {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1080
        @SuppressWarnings("rawtypes")
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1081
        Dictionary dictionary = slider.getLabelTable();
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1082
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1083
        if (dictionary == null) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1084
            return null;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1085
        }
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1086
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1087
        Enumeration<?> keys = dictionary.keys();
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1088
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1089
        Integer min = null;
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1090
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1091
        while (keys.hasMoreElements()) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1092
            Integer i = (Integer) keys.nextElement();
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1093
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1094
            if (min == null || i < min) {
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1095
                min = i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
1852
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1098
958801d67667 6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents: 715
diff changeset
  1099
        return min;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    /**
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1104
     * Returns the label that corresponds to the highest slider value in the
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1105
     * label table.
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1106
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1107
     * @return the label that corresponds to the highest slider value in the
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1108
     * label table
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @see JSlider#setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    protected Component getLowestValueLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        Integer min = getLowestValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        if (min != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            return (Component)slider.getLabelTable().get(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    /**
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1120
     * Returns the label that corresponds to the lowest slider value in the
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1121
     * label table.
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1122
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1123
     * @return the label that corresponds to the lowest slider value in the
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1124
     * label table
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * @see JSlider#setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    protected Component getHighestValueLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        Integer max = getHighestValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        if (max != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            return (Component)slider.getLabelTable().get(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    public void paint( Graphics g, JComponent c )   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        recalculateIfInsetsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        recalculateIfOrientationChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        if ( !clip.intersects(trackRect) && slider.getPaintTrack())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        if ( slider.getPaintTrack() && clip.intersects( trackRect ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            paintTrack( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        if ( slider.getPaintTicks() && clip.intersects( tickRect ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            paintTicks( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        if ( slider.getPaintLabels() && clip.intersects( labelRect ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            paintLabels( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        if ( slider.hasFocus() && clip.intersects( focusRect ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            paintFocus( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        if ( clip.intersects( thumbRect ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            paintThumb( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1160
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1161
     * Recalculates if the insets have changed.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1162
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    protected void recalculateIfInsetsChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        Insets newInsets = slider.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        if ( !newInsets.equals( insetCache ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            insetCache = newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1171
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1172
     * Recalculates if the orientation has changed.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1173
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    protected void recalculateIfOrientationChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        boolean ltr = BasicGraphicsUtils.isLeftToRight(slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        if ( ltr!=leftToRightCache ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            leftToRightCache = ltr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1182
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1183
     * Paints focus.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1184
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1185
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    public void paintFocus(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        g.setColor( getFocusColor() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        BasicGraphicsUtils.drawDashedRect( g, focusRect.x, focusRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                                           focusRect.width, focusRect.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1193
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1194
     * Paints track.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1195
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1196
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public void paintTrack(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        Rectangle trackBounds = trackRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            int cy = (trackBounds.height / 2) - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            int cw = trackBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            g.translate(trackBounds.x, trackBounds.y + cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            g.setColor(getShadowColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            g.drawLine(0, 0, cw - 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            g.drawLine(0, 1, 0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            g.setColor(getHighlightColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            g.drawLine(0, 3, cw, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            g.drawLine(cw, 0, cw, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            g.drawLine(1, 1, cw-2, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            g.translate(-trackBounds.x, -(trackBounds.y + cy));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            int cx = (trackBounds.width / 2) - 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            int ch = trackBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            g.translate(trackBounds.x + cx, trackBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            g.setColor(getShadowColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            g.drawLine(0, 0, 0, ch - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            g.drawLine(1, 0, 2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            g.setColor(getHighlightColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            g.drawLine(3, 0, 3, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            g.drawLine(0, ch, 3, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            g.drawLine(1, 1, 1, ch-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            g.translate(-(trackBounds.x + cx), -trackBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1237
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1238
     * Paints ticks.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1239
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1240
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    public void paintTicks(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        Rectangle tickBounds = tickRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        g.setColor(DefaultLookup.getColor(slider, this, "Slider.tickColor", Color.black));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1247
            g.translate(0, tickBounds.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1249
            if (slider.getMinorTickSpacing() > 0) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1250
                int value = slider.getMinimum();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                while ( value <= slider.getMaximum() ) {
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1253
                    int xPos = xPositionForValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    paintMinorTickForHorizSlider( g, tickBounds, xPos );
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1255
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1256
                    // Overflow checking
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1257
                    if (Integer.MAX_VALUE - slider.getMinorTickSpacing() < value) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1258
                        break;
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1259
                    }
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    value += slider.getMinorTickSpacing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1265
            if (slider.getMajorTickSpacing() > 0) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1266
                int value = slider.getMinimum();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                while ( value <= slider.getMaximum() ) {
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1269
                    int xPos = xPositionForValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                    paintMajorTickForHorizSlider( g, tickBounds, xPos );
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1271
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1272
                    // Overflow checking
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1273
                    if (Integer.MAX_VALUE - slider.getMajorTickSpacing() < value) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1274
                        break;
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1275
                    }
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1276
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                    value += slider.getMajorTickSpacing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            g.translate( 0, -tickBounds.y);
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1282
        } else {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1283
            g.translate(tickBounds.x, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1285
            if (slider.getMinorTickSpacing() > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                int offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                if(!BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                    offset = tickBounds.width - tickBounds.width / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                    g.translate(offset, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1292
                int value = slider.getMinimum();
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1293
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1294
                while (value <= slider.getMaximum()) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1295
                    int yPos = yPositionForValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    paintMinorTickForVertSlider( g, tickBounds, yPos );
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1297
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1298
                    // Overflow checking
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1299
                    if (Integer.MAX_VALUE - slider.getMinorTickSpacing() < value) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1300
                        break;
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1301
                    }
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    value += slider.getMinorTickSpacing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                if(!BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    g.translate(-offset, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1311
            if (slider.getMajorTickSpacing() > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                if(!BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    g.translate(2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1316
                int value = slider.getMinimum();
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1317
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1318
                while (value <= slider.getMaximum()) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1319
                    int yPos = yPositionForValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                    paintMajorTickForVertSlider( g, tickBounds, yPos );
2488
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1321
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1322
                    // Overflow checking
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1323
                    if (Integer.MAX_VALUE - slider.getMajorTickSpacing() < value) {
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1324
                        break;
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1325
                    }
4d54c9133cda 6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents: 1852
diff changeset
  1326
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                    value += slider.getMajorTickSpacing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                if(!BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                    g.translate(-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            g.translate(-tickBounds.x, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1338
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1339
     * Paints minor tick for horizontal slider.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1340
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1341
     * @param tickBounds the tick bounds
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1342
     * @param x the x coordinate
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1343
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        g.drawLine( x, 0, x, tickBounds.height / 2 - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1348
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1349
     * Paints major tick for horizontal slider.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1350
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1351
     * @param tickBounds the tick bounds
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1352
     * @param x the x coordinate
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1353
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        g.drawLine( x, 0, x, tickBounds.height - 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1358
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1359
     * Paints minor tick for vertical slider.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1360
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1361
     * @param tickBounds the tick bounds
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1362
     * @param y the y coordinate
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1363
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        g.drawLine( 0, y, tickBounds.width / 2 - 1, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1368
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1369
     * Paints major tick for vertical slider.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1370
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1371
     * @param tickBounds the tick bounds
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1372
     * @param y the y coordinate
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1373
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        g.drawLine( 0, y,  tickBounds.width - 2, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1378
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1379
     * Paints the labels.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1380
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1381
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    public void paintLabels( Graphics g ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        Rectangle labelBounds = labelRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1385
        @SuppressWarnings("rawtypes")
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1386
        Dictionary dictionary = slider.getLabelTable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        if ( dictionary != null ) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1388
            Enumeration<?> keys = dictionary.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            int minValue = slider.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            int maxValue = slider.getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            boolean enabled = slider.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            while ( keys.hasMoreElements() ) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1393
                Integer key = (Integer)keys.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                int value = key.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                if (value >= minValue && value <= maxValue) {
26352
fa12363e21d6 8055254: Address source incompatability of JSlider generification
darcy
parents: 26351
diff changeset
  1396
                    JComponent label = (JComponent) dictionary.get(key);
676
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
  1397
                    label.setEnabled(enabled);
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
  1398
677
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1399
                    if (label instanceof JLabel) {
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1400
                        Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon();
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1401
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1402
                        if (icon instanceof ImageIcon) {
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1403
                            // Register Slider as an image observer. It allows to catch notifications about
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1404
                            // image changes (e.g. gif animation)
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1405
                            Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider);
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1406
                        }
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1407
                    }
20718977427b 4987336: JSlider doesn't show label's animated icon
rupashka
parents: 676
diff changeset
  1408
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                        g.translate( 0, labelBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                        paintHorizontalLabel( g, value, label );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                        g.translate( 0, -labelBounds.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                        int offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                        if (!BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                            offset = labelBounds.width -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                label.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                        g.translate( labelBounds.x + offset, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                        paintVerticalLabel( g, value, label );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                        g.translate( -labelBounds.x - offset, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    /**
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1431
     * Called for every label in the label table. Used to draw the labels for
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1432
     * horizontal sliders. The graphics have been translated to labelRect.y
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1433
     * already.
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1434
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1435
     * @param g the graphics context in which to paint
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1436
     * @param value the value of the slider
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1437
     * @param label the component label in the label table that needs to be
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1438
     * painted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * @see JSlider#setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
    protected void paintHorizontalLabel( Graphics g, int value, Component label ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        int labelCenter = xPositionForValue( value );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        int labelLeft = labelCenter - (label.getPreferredSize().width / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        g.translate( labelLeft, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        label.paint( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        g.translate( -labelLeft, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    /**
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1450
     * Called for every label in the label table. Used to draw the labels for
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1451
     * vertical sliders. The graphics have been translated to labelRect.x
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1452
     * already.
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1453
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1454
     * @param g the graphics context in which to paint
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1455
     * @param value the value of the slider
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1456
     * @param label the component label in the label table that needs to be
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1457
     * painted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * @see JSlider#setLabelTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    protected void paintVerticalLabel( Graphics g, int value, Component label ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        int labelCenter = yPositionForValue( value );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        int labelTop = labelCenter - (label.getPreferredSize().height / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        g.translate( 0, labelTop );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        label.paint( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        g.translate( 0, -labelTop );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1468
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1469
     * Paints the thumb.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1470
     * @param g the graphics
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1471
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    public void paintThumb(Graphics g)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        Rectangle knobBounds = thumbRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        int w = knobBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        int h = knobBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        g.translate(knobBounds.x, knobBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        if ( slider.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            g.setColor(slider.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            g.setColor(slider.getBackground().darker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        Boolean paintThumbArrowShape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            (Boolean)slider.getClientProperty("Slider.paintThumbArrowShape");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        if ((!slider.getPaintTicks() && paintThumbArrowShape == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            paintThumbArrowShape == Boolean.FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            // "plain" version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            g.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            g.drawLine(w-1, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            g.setColor(highlightColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            g.drawLine(0, 0, 0, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            g.drawLine(1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            g.setColor(shadowColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            g.drawLine(1, h-2, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            g.drawLine(w-2, 1, w-2, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        else if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            int cw = w / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            g.fillRect(1, 1, w-3, h-1-cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            Polygon p = new Polygon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            p.addPoint(1, h-cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            p.addPoint(cw-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            p.addPoint(w-2, h-1-cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            g.fillPolygon(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            g.setColor(highlightColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            g.drawLine(0, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            g.drawLine(0, 1, 0, h-1-cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            g.drawLine(0, h-cw, cw-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            g.drawLine(w-1, 0, w-1, h-2-cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            g.drawLine(w-1, h-1-cw, w-1-cw, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            g.setColor(shadowColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            g.drawLine(w-2, 1, w-2, h-2-cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
            g.drawLine(w-2, h-1-cw, w-1-cw, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        else {  // vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            int cw = h / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            if(BasicGraphicsUtils.isLeftToRight(slider)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                  g.fillRect(1, 1, w-1-cw, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                  Polygon p = new Polygon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                  p.addPoint(w-cw-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                  p.addPoint(w-1, cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                  p.addPoint(w-1-cw, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                  g.fillPolygon(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                  g.setColor(highlightColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                  g.drawLine(0, 0, 0, h - 2);                  // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                  g.drawLine(1, 0, w-1-cw, 0);                 // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                  g.drawLine(w-cw-1, 0, w-1, cw);              // top slant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                  g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                  g.drawLine(0, h-1, w-2-cw, h-1);             // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                  g.drawLine(w-1-cw, h-1, w-1, h-1-cw);        // bottom slant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                  g.setColor(shadowColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                  g.drawLine(1, h-2, w-2-cw,  h-2 );         // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                  g.drawLine(w-1-cw, h-2, w-2, h-cw-1 );     // bottom slant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                  g.fillRect(5, 1, w-1-cw, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                  Polygon p = new Polygon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                  p.addPoint(cw, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                  p.addPoint(0, cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                  p.addPoint(cw, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                  g.fillPolygon(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                  g.setColor(highlightColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                  g.drawLine(cw-1, 0, w-2, 0);             // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                  g.drawLine(0, cw, cw, 0);                // top slant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                  g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                  g.drawLine(0, h-1-cw, cw, h-1 );         // bottom slant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                  g.drawLine(cw, h-1, w-1, h-1);           // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                  g.setColor(shadowColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                  g.drawLine(cw, h-2, w-2,  h-2 );         // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                  g.drawLine(w-1, 1, w-1,  h-2 );          // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        g.translate(-knobBounds.x, -knobBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    // Used exclusively by setThumbLocation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    private static Rectangle unionRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1580
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1581
     * Sets the thumb location.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1582
     * @param x the x coordinate
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1583
     * @param y the y coordinate
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1584
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    public void setThumbLocation(int x, int y)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        unionRect.setBounds( thumbRect );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        thumbRect.setLocation( x, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        SwingUtilities.computeUnion( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height, unionRect );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        slider.repaint( unionRect.x, unionRect.y, unionRect.width, unionRect.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1594
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1595
     * Scrolls by block.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1596
     * @param direction the direction
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1597
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    public void scrollByBlock(int direction)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        synchronized(slider)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            int blockIncrement =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                (slider.getMaximum() - slider.getMinimum()) / 10;
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1602
            if (blockIncrement == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                blockIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
41007
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
  1606
            int tickSpacing = getTickSpacing();
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1607
            if (slider.getSnapToTicks()) {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1608
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1609
                if (blockIncrement < tickSpacing) {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1610
                    blockIncrement = tickSpacing;
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1611
                }
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1612
            }
41007
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
  1613
            else {
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
  1614
                if (tickSpacing > 0) {
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
  1615
                    blockIncrement = tickSpacing;
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
  1616
                }
d48361243925 8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents: 30461
diff changeset
  1617
            }
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1618
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            int delta = blockIncrement * ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL);
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1620
            slider.setValue(slider.getValue() + delta);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1624
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1625
     * Scrolls by unit.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1626
     * @param direction the direction
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1627
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    public void scrollByUnit(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        synchronized(slider)    {
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1630
            int delta = ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1632
            if (slider.getSnapToTicks()) {
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1633
                delta *= getTickSpacing();
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1634
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
457
8682623ee3c3 6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents: 456
diff changeset
  1636
            slider.setValue(slider.getValue() + delta);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    /**
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1641
     * This function is called when a mousePressed was detected in the track,
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1642
     * not in the thumb. The default behavior is to scroll by block. You can
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1643
     * override this method to stop it from scrolling or to add additional
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1644
     * behavior.
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1645
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1646
     * @param dir the direction and number of blocks to scroll
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    protected void scrollDueToClickInTrack( int dir ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        scrollByBlock( dir );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1652
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1653
     * Returns the x position for a value.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1654
     * @param value the value
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1655
     * @return the x position for a value
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1656
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    protected int xPositionForValue( int value )    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        int min = slider.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        int max = slider.getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        int trackLength = trackRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        double valueRange = (double)max - (double)min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        double pixelsPerValue = (double)trackLength / valueRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        int trackLeft = trackRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        int trackRight = trackRect.x + (trackRect.width - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        int xPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
            xPosition = trackLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            xPosition += Math.round( pixelsPerValue * ((double)value - min) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            xPosition = trackRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            xPosition -= Math.round( pixelsPerValue * ((double)value - min) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        xPosition = Math.max( trackLeft, xPosition );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        xPosition = Math.min( trackRight, xPosition );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        return xPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1682
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1683
     * Returns the y position for a value.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1684
     * @param value the value
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1685
     * @return the y position for a value
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1686
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    protected int yPositionForValue( int value )  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        return yPositionForValue(value, trackRect.y, trackRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * Returns the y location for the specified value.  No checking is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * done on the arguments.  In particular if <code>trackHeight</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * negative undefined results may occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * @param value the slider value to get the location for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * @param trackY y-origin of the track
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * @param trackHeight the height of the track
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1699
     * @return the y location for the specified value of the slider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    protected int yPositionForValue(int value, int trackY, int trackHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        int min = slider.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        int max = slider.getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        double valueRange = (double)max - (double)min;
676
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
  1706
        double pixelsPerValue = (double)trackHeight / valueRange;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        int trackBottom = trackY + (trackHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        int yPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            yPosition = trackY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            yPosition += Math.round( pixelsPerValue * ((double)max - value ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            yPosition = trackY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            yPosition += Math.round( pixelsPerValue * ((double)value - min) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        yPosition = Math.max( trackY, yPosition );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        yPosition = Math.min( trackBottom, yPosition );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        return yPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1726
     * Returns the value at the y position. If {@code yPos} is beyond the
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26353
diff changeset
  1727
     * track at the bottom or the top, this method sets the value to either
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1728
     * the minimum or maximum value of the slider, depending on if the slider
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1729
     * is inverted or not.
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1730
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1731
     * @param yPos the location of the slider along the y axis
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1732
     * @return the value at the y position
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    public int valueForYPosition( int yPos ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        final int minValue = slider.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        final int maxValue = slider.getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        final int trackLength = trackRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        final int trackTop = trackRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        final int trackBottom = trackRect.y + (trackRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        if ( yPos <= trackTop ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            value = drawInverted() ? minValue : maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        else if ( yPos >= trackBottom ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            value = drawInverted() ? maxValue : minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            int distanceFromTrackTop = yPos - trackTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            double valueRange = (double)maxValue - (double)minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            double valuePerPixel = valueRange / (double)trackLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            int valueFromTrackTop = (int)Math.round( distanceFromTrackTop * valuePerPixel );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            value = drawInverted() ? minValue + valueFromTrackTop : maxValue - valueFromTrackTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1761
     * Returns the value at the x position.  If {@code xPos} is beyond the
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1762
     * track at the left or the right, this method sets the value to either the
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1763
     * minimum or maximum value of the slider, depending on if the slider is
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 3735
diff changeset
  1764
     * inverted or not.
26012
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1765
     *
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1766
     * @param xPos the location of the slider along the x axis
36ecb579dbc8 8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents: 25565
diff changeset
  1767
     * @return the value of the x position
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
    public int valueForXPosition( int xPos ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        final int minValue = slider.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        final int maxValue = slider.getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        final int trackLength = trackRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        final int trackLeft = trackRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        final int trackRight = trackRect.x + (trackRect.width - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        if ( xPos <= trackLeft ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            value = drawInverted() ? maxValue : minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        else if ( xPos >= trackRight ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            value = drawInverted() ? minValue : maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            int distanceFromTrackLeft = xPos - trackLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            double valueRange = (double)maxValue - (double)minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            double valuePerPixel = valueRange / (double)trackLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            int valueFromTrackLeft = (int)Math.round( distanceFromTrackLeft * valuePerPixel );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            value = drawInverted() ? maxValue - valueFromTrackLeft :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
              minValue + valueFromTrackLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
    private class Handler implements ChangeListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            ComponentListener, FocusListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        // Change Handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
            if (!isDragging) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                calculateThumbLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                slider.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
            lastValue = slider.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        // Component Handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        public void componentHidden(ComponentEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        public void componentMoved(ComponentEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        public void componentResized(ComponentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            slider.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        public void componentShown(ComponentEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        // Focus Handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        public void focusGained(FocusEvent e) { slider.repaint(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        public void focusLost(FocusEvent e) { slider.repaint(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
        // Property Change Handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            if (propertyName == "orientation" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    propertyName == "inverted" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    propertyName == "labelTable" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                    propertyName == "majorTickSpacing" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    propertyName == "minorTickSpacing" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                    propertyName == "paintTicks" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    propertyName == "paintTrack" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                    propertyName == "font" ||
3735
72286b35d392 6579827: vista : JSlider on JColorchooser is not properly render or can't be seen completely.
rupashka
parents: 2658
diff changeset
  1832
                    propertyName == "paintLabels" ||
72286b35d392 6579827: vista : JSlider on JColorchooser is not properly render or can't be seen completely.
rupashka
parents: 2658
diff changeset
  1833
                    propertyName == "Slider.paintThumbArrowShape") {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                checkedLabelBaselines = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                slider.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            } else if (propertyName == "componentOrientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                slider.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                InputMap km = getInputMap(JComponent.WHEN_FOCUSED, slider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                SwingUtilities.replaceUIInputMap(slider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    JComponent.WHEN_FOCUSED, km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            } else if (propertyName == "model") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                ((BoundedRangeModel)e.getOldValue()).removeChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                    changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                ((BoundedRangeModel)e.getNewValue()).addChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                    changeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                calculateThumbLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                slider.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    /////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    /// Model Listener Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    /////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * Data model listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
  1861
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
    public class ChangeHandler implements ChangeListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  1864
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    /////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
    /// Track Listener Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    /////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     * Track mouse movements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
  1880
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    public class TrackListener extends MouseInputAdapter {
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1883
        /** The offset */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        protected transient int offset;
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1885
        /** Current mouse x. */
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1886
        protected transient int currentMouseX;
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1887
        /** Current mouse y. */
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1888
        protected transient int currentMouseY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1890
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1891
         * {@inheritDoc}
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  1892
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            if (!slider.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            scrollTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
4957
e33105a2db5b 6848475: JSlider does not display the correct value of its BoundedRangeModel
rupashka
parents: 4394
diff changeset
  1901
            isDragging = false;
e33105a2db5b 6848475: JSlider does not display the correct value of its BoundedRangeModel
rupashka
parents: 4394
diff changeset
  1902
            slider.setValueIsAdjusting(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            slider.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        * If the mouse is pressed above the "thumb" component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        * then reduce the scrollbars value by one page ("page up"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        * otherwise increase it by one page.  If there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        * thumb then page up if the mouse is in the upper half
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        * of the track.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            if (!slider.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            // We should recalculate geometry just before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            // calculation of the thumb movement direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            // It is important for the case, when JSlider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            // is a cell editor in JTable. See 6348946.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            calculateGeometry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            currentMouseX = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            currentMouseY = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            if (slider.isRequestFocusEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                slider.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            // Clicked in the Thumb area?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            if (thumbRect.contains(currentMouseX, currentMouseY)) {
456
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1933
                if (UIManager.getBoolean("Slider.onlyLeftMouseButtonDrag")
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1934
                        && !SwingUtilities.isLeftMouseButton(e)) {
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1935
                    return;
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1936
                }
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1937
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                switch (slider.getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                case JSlider.VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                    offset = currentMouseY - thumbRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                case JSlider.HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                    offset = currentMouseX - thumbRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            }
456
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1949
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1950
            if (!SwingUtilities.isLeftMouseButton(e)) {
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1951
                return;
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1952
            }
8ded0dbe4aaa 6614972: JSlider value should not change on right-click
rupashka
parents: 2
diff changeset
  1953
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            slider.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            Dimension sbSize = slider.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            int direction = POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            switch (slider.getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
            case JSlider.VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                if ( thumbRect.isEmpty() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                    int scrollbarCenter = sbSize.height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                    if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                        direction = (currentMouseY < scrollbarCenter) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                            POSITIVE_SCROLL : NEGATIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                        direction = (currentMouseY < scrollbarCenter) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                            NEGATIVE_SCROLL : POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                    int thumbY = thumbRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                    if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                        direction = (currentMouseY < thumbY) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                            POSITIVE_SCROLL : NEGATIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                        direction = (currentMouseY < thumbY) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                            NEGATIVE_SCROLL : POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            case JSlider.HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                if ( thumbRect.isEmpty() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                    int scrollbarCenter = sbSize.width / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                    if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                        direction = (currentMouseX < scrollbarCenter) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                            NEGATIVE_SCROLL : POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                        direction = (currentMouseX < scrollbarCenter) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                            POSITIVE_SCROLL : NEGATIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                    int thumbX = thumbRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                    if ( !drawInverted() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                        direction = (currentMouseX < thumbX) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                            NEGATIVE_SCROLL : POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                        direction = (currentMouseX < thumbX) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                            POSITIVE_SCROLL : NEGATIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            if (shouldScroll(direction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                scrollDueToClickInTrack(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            if (shouldScroll(direction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                scrollTimer.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                scrollListener.setDirection(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                scrollTimer.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2021
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2022
         * Returns if scrolling should occur
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2023
         * @param direction the direction.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2024
         * @return if scrolling should occur
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2025
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        public boolean shouldScroll(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            Rectangle r = thumbRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
            if (slider.getOrientation() == JSlider.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                if (drawInverted() ? direction < 0 : direction > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                    if (r.y  <= currentMouseY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                else if (r.y + r.height >= currentMouseY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                if (drawInverted() ? direction < 0 : direction > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                    if (r.x + r.width  >= currentMouseX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                else if (r.x <= currentMouseX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
            if (direction > 0 && slider.getValue() + slider.getExtent() >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                    slider.getMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            else if (direction < 0 && slider.getValue() <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                    slider.getMinimum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
        /**
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2062
         * Set the models value to the position of the top/left
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2063
         * of the thumb relative to the origin of the track.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2064
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        public void mouseDragged(MouseEvent e) {
676
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
  2066
            int thumbMiddle;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
            if (!slider.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            currentMouseX = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            currentMouseY = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            if (!isDragging) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            slider.setValueIsAdjusting(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
            switch (slider.getOrientation()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            case JSlider.VERTICAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                int halfThumbHeight = thumbRect.height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                int thumbTop = e.getY() - offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                int trackTop = trackRect.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                int trackBottom = trackRect.y + (trackRect.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                int vMax = yPositionForValue(slider.getMaximum() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                                            slider.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                if (drawInverted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                    trackBottom = vMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                    trackTop = vMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                setThumbLocation(thumbRect.x, thumbTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                thumbMiddle = thumbTop + halfThumbHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                slider.setValue( valueForYPosition( thumbMiddle ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            case JSlider.HORIZONTAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                int halfThumbWidth = thumbRect.width / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                int thumbLeft = e.getX() - offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                int trackLeft = trackRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                int trackRight = trackRect.x + (trackRect.width - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                int hMax = xPositionForValue(slider.getMaximum() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                                            slider.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                if (drawInverted()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                    trackLeft = hMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                    trackRight = hMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                setThumbLocation(thumbLeft, thumbRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                thumbMiddle = thumbLeft + halfThumbWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                slider.setValue(valueForXPosition(thumbMiddle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2129
        /** {@inheritDoc} */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        public void mouseMoved(MouseEvent e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * Scroll-event listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
  2137
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
    public class ScrollListener implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        // changed this class to public to avoid bogus IllegalAccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        // bug in InternetExplorer browser.  It was protected.  Work around
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        // for 4109432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        int direction = POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        boolean useBlockIncrement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2146
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2147
         * Constructs a {@code ScrollListener}
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2148
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        public ScrollListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            direction = POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            useBlockIncrement = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2154
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2155
         * Constructs a {@code ScrollListener}
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2156
         * @param dir the direction
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2157
         * @param block whether or not to scroll by block
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2158
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        public ScrollListener(int dir, boolean block)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            direction = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            useBlockIncrement = block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2164
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2165
         * Sets the direction.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2166
         * @param direction the new direction
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2167
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        public void setDirection(int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2172
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2173
         * Sets scrolling by block
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2174
         * @param block the new scroll by block value
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2175
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
        public void setScrollByBlock(boolean block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            this.useBlockIncrement = block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2180
        /** {@inheritDoc} */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            if (useBlockIncrement) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                scrollByBlock(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                scrollByUnit(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            if (!trackListener.shouldScroll(direction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                ((Timer)e.getSource()).stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * Listener for resizing events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
  2198
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
    public class ComponentHandler extends ComponentAdapter {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2201
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
        public void componentResized(ComponentEvent e)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            getHandler().componentResized(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        }
676
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
  2208
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * Focus-change listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
  2214
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
    public class FocusHandler implements FocusListener {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2217
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            getHandler().focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
            getHandler().focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     * As of Java 2 platform v1.3 this undocumented class is no longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     * The recommended approach to creating bindings is to use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     * combination of an <code>ActionMap</code>, to contain the action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     * and an <code>InputMap</code> to contain the mapping from KeyStroke
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 26353
diff changeset
  2235
     * to action description. The InputMap is usually described in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * LookAndFeel tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * Please refer to the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * This class should be treated as a &quot;protected&quot; inner class.
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
  2241
     * Instantiate it only within subclasses of <code>Foo</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2243
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
    public class ActionScroller extends AbstractAction {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2245
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
        // its functionality has been moved into Actions. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        // new functionality add it to the Actions, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        // class calls into the Actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        int dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
        boolean block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        JSlider slider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2253
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2254
         * Constructs an {@code ActionScroller}.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2255
         * @param slider a slider
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2256
         * @param dir the direction
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2257
         * @param block block scrolling or not
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2258
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
        public ActionScroller( JSlider slider, int dir, boolean block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            this.dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
            this.block = block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
            this.slider = slider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2265
        /** {@inheritDoc} */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
            SHARED_ACTION.scroll(slider, BasicSliderUI.this, dir, block);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 28059
diff changeset
  2270
        /** {@inheritDoc} */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
            boolean b = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            if (slider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                b = slider.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
676
8cf833d60e87 6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents: 457
diff changeset
  2279
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * A static version of the above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
  2285
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    static class SharedActionScroller extends AbstractAction {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
  2287
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        // its functionality has been moved into Actions. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        // new functionality add it to the Actions, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        // class calls into the Actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        int dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        boolean block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        public SharedActionScroller(int dir, boolean block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            this.dir = dir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
            this.block = block;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
            JSlider slider = (JSlider)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
            BasicSliderUI ui = (BasicSliderUI)BasicLookAndFeel.getUIOfType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
                    slider.getUI(), BasicSliderUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            SHARED_ACTION.scroll(slider, ui, dir, block);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        public static final String POSITIVE_UNIT_INCREMENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            "positiveUnitIncrement";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
        public static final String POSITIVE_BLOCK_INCREMENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
            "positiveBlockIncrement";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        public static final String NEGATIVE_UNIT_INCREMENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            "negativeUnitIncrement";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        public static final String NEGATIVE_BLOCK_INCREMENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
            "negativeBlockIncrement";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        public static final String MIN_SCROLL_INCREMENT = "minScroll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
        public static final String MAX_SCROLL_INCREMENT = "maxScroll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        Actions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            super(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        public Actions(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        public void actionPerformed(ActionEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            JSlider slider = (JSlider)evt.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            BasicSliderUI ui = (BasicSliderUI)BasicLookAndFeel.getUIOfType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
                     slider.getUI(), BasicSliderUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
            String name = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            if (POSITIVE_UNIT_INCREMENT == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
                scroll(slider, ui, POSITIVE_SCROLL, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
            } else if (NEGATIVE_UNIT_INCREMENT == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                scroll(slider, ui, NEGATIVE_SCROLL, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            } else if (POSITIVE_BLOCK_INCREMENT == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
                scroll(slider, ui, POSITIVE_SCROLL, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
            } else if (NEGATIVE_BLOCK_INCREMENT == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                scroll(slider, ui, NEGATIVE_SCROLL, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
            } else if (MIN_SCROLL_INCREMENT == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                scroll(slider, ui, MIN_SCROLL, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            } else if (MAX_SCROLL_INCREMENT == name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                scroll(slider, ui, MAX_SCROLL, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        private void scroll(JSlider slider, BasicSliderUI ui, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                boolean isBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            boolean invert = slider.getInverted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            if (direction == NEGATIVE_SCROLL || direction == POSITIVE_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                if (invert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                    direction = (direction == POSITIVE_SCROLL) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                        NEGATIVE_SCROLL : POSITIVE_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                if (isBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                    ui.scrollByBlock(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                    ui.scrollByUnit(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            } else {  // MIN or MAX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                if (invert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
                    direction = (direction == MIN_SCROLL) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                        MAX_SCROLL : MIN_SCROLL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                slider.setValue((direction == MIN_SCROLL) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                    slider.getMinimum() : slider.getMaximum());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
}