jdk/src/share/classes/javax/swing/plaf/synth/SynthScrollBarUI.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 16463 9f9632c2aede
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2010, 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: 4966
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: 4966
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: 4966
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4966
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4966
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.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    36
 * Provides the Synth L&F UI delegate for
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    37
 * {@link javax.swing.JScrollBar}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Scott Violet
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    40
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    42
public class SynthScrollBarUI extends BasicScrollBarUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    43
                              implements PropertyChangeListener, SynthUI {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private SynthStyle thumbStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private SynthStyle trackStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private boolean validMinimumThumbSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static ComponentUI createUI(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        return new SynthScrollBarUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    55
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    56
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    57
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    58
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        trackHighlight = NO_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (scrollbar.getLayout() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                     (scrollbar.getLayout() instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            scrollbar.setLayout(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
4966
ff6769741ba1 6924059: SynthScrollBarUI.configureScrollBarColors() should have spec different from the overridden method
rupashka
parents: 4848
diff changeset
    65
        configureScrollBarColors();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        updateStyle(scrollbar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    69
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    70
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    71
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    72
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected void configureScrollBarColors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private void updateStyle(JScrollBar c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            scrollBarWidth = style.getInt(context,"ScrollBar.thumbHeight", 14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            minimumThumbSize = (Dimension)style.get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                                "ScrollBar.minimumThumbSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (minimumThumbSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                minimumThumbSize = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                validMinimumThumbSize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                validMinimumThumbSize = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            maximumThumbSize = (Dimension)style.get(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        "ScrollBar.maximumThumbSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (maximumThumbSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                maximumThumbSize = new Dimension(4096, 4097);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    96
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    97
            incrGap = style.getInt(context, "ScrollBar.incrementButtonGap", 0);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    98
            decrGap = style.getInt(context, "ScrollBar.decrementButtonGap", 0);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    99
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   100
            // handle scaling for sizeVarients for special case components. The
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   101
            // key "JComponent.sizeVariant" scales for large/small/mini
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   102
            // components are based on Apples LAF
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   103
            String scaleKey = (String)scrollbar.getClientProperty(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   104
                    "JComponent.sizeVariant");
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   105
            if (scaleKey != null){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   106
                if ("large".equals(scaleKey)){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   107
                    scrollBarWidth *= 1.15;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   108
                    incrGap *= 1.15;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   109
                    decrGap *= 1.15;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   110
                } else if ("small".equals(scaleKey)){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   111
                    scrollBarWidth *= 0.857;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   112
                    incrGap *= 0.857;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   113
                    decrGap *= 0.857;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   114
                } else if ("mini".equals(scaleKey)){
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   115
                    scrollBarWidth *= 0.714;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   116
                    incrGap *= 0.714;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   117
                    decrGap *= 0.714;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   118
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   119
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        context = getContext(c, Region.SCROLL_BAR_TRACK, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        trackStyle = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        context = getContext(c, Region.SCROLL_BAR_THUMB, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        thumbStyle = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   137
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   138
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   139
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   140
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        scrollbar.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   146
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   147
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   148
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   149
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        scrollbar.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   155
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   156
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   157
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   158
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected void uninstallDefaults(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        SynthContext context = getContext(scrollbar, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        context = getContext(scrollbar, Region.SCROLL_BAR_TRACK, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        trackStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        trackStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        context = getContext(scrollbar, Region.SCROLL_BAR_THUMB, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        thumbStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        thumbStyle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   178
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   179
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   180
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   181
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   183
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private SynthContext getContext(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return getContext(c, region, getComponentState(c, region));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private SynthContext getContext(JComponent c, Region region, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        SynthStyle style = trackStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (region == Region.SCROLL_BAR_THUMB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            style = thumbStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return SynthContext.getContext(SynthContext.class, c, region, style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                       state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private int getComponentState(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (region == Region.SCROLL_BAR_THUMB && isThumbRollover() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                                 c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return SynthLookAndFeel.getComponentState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   213
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   214
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   215
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   216
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public boolean getSupportsAbsolutePositioning() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        SynthContext context = getContext(scrollbar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        boolean value = style.getBoolean(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                      "ScrollBar.allowsAbsolutePositioning", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   225
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   226
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   227
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   228
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   229
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   230
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   231
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   232
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   233
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   234
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   235
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   236
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   237
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        context.getPainter().paintScrollBarBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                          g, 0, 0, c.getWidth(), c.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                          scrollbar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   249
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   250
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   251
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   252
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   253
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   254
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   255
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   256
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   257
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   258
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   266
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   267
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   268
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   269
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   270
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   271
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   272
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        SynthContext subcontext = getContext(scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                             Region.SCROLL_BAR_TRACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        paintTrack(subcontext, g, getTrackBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        subcontext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        subcontext = getContext(scrollbar, Region.SCROLL_BAR_THUMB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        paintThumb(subcontext, g, getThumbBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        subcontext.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   284
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   285
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   286
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   287
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        context.getPainter().paintScrollBarBorder(context, g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                  scrollbar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   294
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   295
     * Paints the scrollbar track.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   296
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   297
     * @param context context for the component being painted
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   298
     * @param g {@code Graphics} object used for painting
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   299
     * @param trackBounds bounding box for the track
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   300
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   301
    protected void paintTrack(SynthContext context, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                              Rectangle trackBounds) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   303
        SynthLookAndFeel.updateSubregion(context, g, trackBounds);
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   304
        context.getPainter().paintScrollBarTrackBackground(context, g, trackBounds.x,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        trackBounds.y, trackBounds.width, trackBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        scrollbar.getOrientation());
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   307
        context.getPainter().paintScrollBarTrackBorder(context, g, trackBounds.x,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        trackBounds.y, trackBounds.width, trackBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        scrollbar.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   312
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   313
     * Paints the scrollbar thumb.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   314
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   315
     * @param context context for the component being painted
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   316
     * @param g {@code Graphics} object used for painting
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   317
     * @param thumbBounds bounding box for the thumb
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   318
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   319
    protected void paintThumb(SynthContext context, Graphics g,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                              Rectangle thumbBounds) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   321
        SynthLookAndFeel.updateSubregion(context, g, thumbBounds);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int orientation = scrollbar.getOrientation();
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   323
        context.getPainter().paintScrollBarThumbBackground(context, g, thumbBounds.x,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        thumbBounds.y, thumbBounds.width, thumbBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        orientation);
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   326
        context.getPainter().paintScrollBarThumbBorder(context, g, thumbBounds.x,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        thumbBounds.y, thumbBounds.width, thumbBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                        orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * A vertical scrollbar's preferred width is the maximum of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * preferred widths of the (non <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * increment/decrement buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * and the minimum width of the thumb. The preferred height is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * sum of the preferred heights of the same parts.  The basis for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * the preferred size of a horizontal scrollbar is similar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * The <code>preferredSize</code> is only computed once, subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * calls to this method just return a cached size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param c the <code>JScrollBar</code> that's delegating this method to us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @return the preferred size of a Basic JScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see #getMaximumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   347
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            ? new Dimension(scrollBarWidth + insets.left + insets.right, 48)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            : new Dimension(48, scrollBarWidth + insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   355
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   356
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   357
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   358
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    protected Dimension getMinimumThumbSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (!validMinimumThumbSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                minimumThumbSize.width = scrollBarWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                minimumThumbSize.height = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                minimumThumbSize.width = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                minimumThumbSize.height = scrollBarWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return minimumThumbSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   372
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   373
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   374
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   375
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    protected JButton createDecreaseButton(int orientation)  {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   377
        SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   378
            @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   379
            public boolean contains(int x, int y) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   380
                if (decrGap < 0) { //there is an overlap between the track and button
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   381
                    int width = getWidth();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   382
                    int height = getHeight();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   383
                    if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   384
                        //adjust the height by decrGap
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   385
                        //Note: decrGap is negative!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   386
                        height += decrGap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   387
                    } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   388
                        //adjust the width by decrGap
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   389
                        //Note: decrGap is negative!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   390
                        width += decrGap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   391
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   392
                    return (x >= 0) && (x < width) && (y >= 0) && (y < height);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   393
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   394
                return super.contains(x, y);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   395
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   396
        };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        synthArrowButton.setName("ScrollBar.button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return synthArrowButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   401
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   402
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   403
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   404
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    protected JButton createIncreaseButton(int orientation)  {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   406
        SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   407
            @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   408
            public boolean contains(int x, int y) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   409
                if (incrGap < 0) { //there is an overlap between the track and button
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   410
                    int width = getWidth();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   411
                    int height = getHeight();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   412
                    if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   413
                        //adjust the height and y by incrGap
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   414
                        //Note: incrGap is negative!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   415
                        height += incrGap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   416
                        y += incrGap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   417
                    } else {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   418
                        //adjust the width and x by incrGap
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   419
                        //Note: incrGap is negative!
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   420
                        width += incrGap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   421
                        x += incrGap;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   422
                    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   423
                    return (x >= 0) && (x < width) && (y >= 0) && (y < height);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   424
                }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   425
                return super.contains(x, y);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   426
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   427
        };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        synthArrowButton.setName("ScrollBar.button");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return synthArrowButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   432
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   433
     * @inheritDoc
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   434
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   435
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    protected void setThumbRollover(boolean active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (isThumbRollover() != active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            scrollbar.repaint(getThumbBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            super.setThumbRollover(active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    private void updateButtonDirections() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        int orient = scrollbar.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (scrollbar.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            ((SynthArrowButton)incrButton).setDirection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        orient == HORIZONTAL? EAST : SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            ((SynthArrowButton)decrButton).setDirection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        orient == HORIZONTAL? WEST : NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            ((SynthArrowButton)incrButton).setDirection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        orient == HORIZONTAL? WEST : SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            ((SynthArrowButton)decrButton).setDirection(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        orient == HORIZONTAL ? EAST : NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            updateStyle((JScrollBar)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if ("orientation" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            updateButtonDirections();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        else if ("componentOrientation" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            updateButtonDirections();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
}