jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java
author darcy
Tue, 14 Apr 2015 14:47:12 -0700
changeset 30461 57e36ed1a9ab
parent 29880 665cb957c3d0
child 36466 64a41d6ef451
permissions -rw-r--r--
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 5277
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: 5277
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: 5277
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
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 sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 7668
diff changeset
    48
 * A default L&F implementation of ScrollPaneUI.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class BasicScrollPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    extends ScrollPaneUI implements ScrollPaneConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    55
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    56
     * The instance of {@code JScrollPane}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    57
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected JScrollPane scrollpane;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    59
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    60
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    61
     * {@code ChangeListener} installed on the vertical scrollbar.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    62
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected ChangeListener vsbChangeListener;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    64
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    65
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    66
     * {@code ChangeListener} installed on the horizontal scrollbar.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    67
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected ChangeListener hsbChangeListener;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    69
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    70
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    71
     * {@code ChangeListener} installed on the viewport.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    72
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected ChangeListener viewportChangeListener;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    74
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    75
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    76
     * {@code PropertyChangeListener} installed on the scroll pane.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    77
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected PropertyChangeListener spPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private MouseWheelListener mouseScrollListener;
3350
100ac73bfe6e 6864297: Right-to-left oriented JScrollPane is aligned to the wrong direction while resizing the container
malenkov
parents: 2
diff changeset
    80
    private int oldExtent = Integer.MIN_VALUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    83
     * {@code PropertyChangeListener} installed on the vertical scrollbar.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private PropertyChangeListener vsbPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    88
     * {@code PropertyChangeListener} installed on the horizontal scrollbar.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private PropertyChangeListener hsbPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * State flag that shows whether setValue() was called from a user program
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * before the value of "extent" was set in right-to-left component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private boolean setValueCalled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   101
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   102
     * Returns a new instance of {@code BasicScrollPaneUI}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   103
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   104
     * @param x a component.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   105
     * @return a new instance of {@code BasicScrollPaneUI}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   106
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return new BasicScrollPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        map.put(new Actions(Actions.SCROLL_UP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        map.put(new Actions(Actions.SCROLL_DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        map.put(new Actions(Actions.SCROLL_HOME));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        map.put(new Actions(Actions.SCROLL_END));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        map.put(new Actions(Actions.UNIT_SCROLL_UP));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        map.put(new Actions(Actions.UNIT_SCROLL_DOWN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        map.put(new Actions(Actions.SCROLL_LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        map.put(new Actions(Actions.SCROLL_RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        map.put(new Actions(Actions.UNIT_SCROLL_RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        map.put(new Actions(Actions.UNIT_SCROLL_LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Border vpBorder = scrollpane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (vpBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            Rectangle r = scrollpane.getViewportBorderBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   142
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   143
     * Installs default properties.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   144
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   145
     * @param scrollpane an instance of {@code JScrollPane}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   146
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    protected void installDefaults(JScrollPane scrollpane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        LookAndFeel.installBorder(scrollpane, "ScrollPane.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        LookAndFeel.installColorsAndFont(scrollpane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            "ScrollPane.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            "ScrollPane.foreground",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            "ScrollPane.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Border vpBorder = scrollpane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if ((vpBorder == null) ||( vpBorder instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            vpBorder = UIManager.getBorder("ScrollPane.viewportBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            scrollpane.setViewportBorder(vpBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        LookAndFeel.installProperty(scrollpane, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   163
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   164
     * Registers listeners.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   165
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   166
     * @param c an instance of {@code JScrollPane}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   167
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected void installListeners(JScrollPane c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        vsbChangeListener = createVSBChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        vsbPropertyChangeListener = createVSBPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        hsbChangeListener = createHSBChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        hsbPropertyChangeListener = createHSBPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        viewportChangeListener = createViewportChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        spPropertyChangeListener = createPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            viewport.addChangeListener(viewportChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            vsb.getModel().addChangeListener(vsbChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            vsb.addPropertyChangeListener(vsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            hsb.getModel().addChangeListener(hsbChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            hsb.addPropertyChangeListener(hsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        scrollpane.addPropertyChangeListener(spPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    mouseScrollListener = createMouseWheelListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    scrollpane.addMouseWheelListener(mouseScrollListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   200
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   201
     * Registers keyboard actions.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   202
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   203
     * @param c an instance of {@code JScrollPane}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   204
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    protected void installKeyboardActions(JScrollPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        InputMap inputMap = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        SwingUtilities.replaceUIInputMap(c, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                               WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        LazyActionMap.installLazyActionMap(c, BasicScrollPaneUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                           "ScrollPane.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            InputMap keyMap = (InputMap)DefaultLookup.get(scrollpane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                        "ScrollPane.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            InputMap rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (scrollpane.getComponentOrientation().isLeftToRight() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    ((rtlKeyMap = (InputMap)DefaultLookup.get(scrollpane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    "ScrollPane.ancestorInputMap.RightToLeft")) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                return keyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                rtlKeyMap.setParent(keyMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                return rtlKeyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void installUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        scrollpane = (JScrollPane)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        installDefaults(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        installListeners(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        installKeyboardActions(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   241
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   242
     * Uninstalls default properties.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   243
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   244
     * @param c an instance of {@code JScrollPane}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   245
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    protected void uninstallDefaults(JScrollPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        LookAndFeel.uninstallBorder(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (scrollpane.getViewportBorder() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            scrollpane.setViewportBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   254
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   255
     * Unregisters listeners.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   256
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   257
     * @param c a component
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   258
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    protected void uninstallListeners(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            viewport.removeChangeListener(viewportChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            vsb.getModel().removeChangeListener(vsbChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            vsb.removePropertyChangeListener(vsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            hsb.getModel().removeChangeListener(hsbChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            hsb.removePropertyChangeListener(hsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        scrollpane.removePropertyChangeListener(spPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if (mouseScrollListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        scrollpane.removeMouseWheelListener(mouseScrollListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        vsbChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        hsbChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        viewportChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        spPropertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        mouseScrollListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        handler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   290
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   291
     * Unregisters keyboard actions.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   292
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   293
     * @param c an instance of {@code JScrollPane}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   294
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    protected void uninstallKeyboardActions(JScrollPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        SwingUtilities.replaceUIActionMap(c, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        SwingUtilities.replaceUIInputMap(c, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                           WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        uninstallDefaults(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        uninstallListeners(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        uninstallKeyboardActions(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        scrollpane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   316
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   317
     * Synchronizes the {@code JScrollPane} with {@code Viewport}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   318
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    protected void syncScrollPaneWithViewport()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        JViewport rowHead = scrollpane.getRowHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        JViewport colHead = scrollpane.getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        boolean ltr = scrollpane.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            Dimension extentSize = viewport.getExtentSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            Dimension viewSize = viewport.getViewSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            Point viewPosition = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                int extent = extentSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                int max = viewSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                int value = Math.max(0, Math.min(viewPosition.y, max - extent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                vsb.setValues(value, extent, 0, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                int extent = extentSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                int max = viewSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    value = Math.max(0, Math.min(viewPosition.x, max - extent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    int currentValue = hsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    /* Use a particular formula to calculate "value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                     * until effective x coordinate is calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    if (setValueCalled && ((max - currentValue) == viewPosition.x)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        value = Math.max(0, Math.min(max - extent, currentValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        /* After "extent" is set, turn setValueCalled flag off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        if (extent != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                            setValueCalled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        if (extent > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                            viewPosition.x = max - extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                            viewport.setViewPosition(viewPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                            value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                           /* The following line can't handle a small value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                            * viewPosition.x like Integer.MIN_VALUE correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                            * because (max - extent - viewPositoiin.x) causes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                            * an overflow. As a result, value becomes zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                            * (e.g. setViewPosition(Integer.MAX_VALUE, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                            *       in a user program causes a overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                            *       Its expected value is (max - extent).)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                            * However, this seems a trivial bug and adding a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                            * fix makes this often-called method slow, so I'll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                            * leave it until someone claims.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                            value = Math.max(0, Math.min(max - extent, max - extent - viewPosition.x));
3350
100ac73bfe6e 6864297: Right-to-left oriented JScrollPane is aligned to the wrong direction while resizing the container
malenkov
parents: 2
diff changeset
   378
                            if (oldExtent > extent) {
100ac73bfe6e 6864297: Right-to-left oriented JScrollPane is aligned to the wrong direction while resizing the container
malenkov
parents: 2
diff changeset
   379
                                value -= oldExtent - extent;
100ac73bfe6e 6864297: Right-to-left oriented JScrollPane is aligned to the wrong direction while resizing the container
malenkov
parents: 2
diff changeset
   380
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                }
3350
100ac73bfe6e 6864297: Right-to-left oriented JScrollPane is aligned to the wrong direction while resizing the container
malenkov
parents: 2
diff changeset
   384
                oldExtent = extent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                hsb.setValues(value, extent, 0, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (rowHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                Point p = rowHead.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                p.y = viewport.getViewPosition().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                p.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                rowHead.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            if (colHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                Point p = colHead.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                if (ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    p.x = viewport.getViewPosition().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    p.x = Math.max(0, viewport.getViewPosition().x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                p.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                colHead.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public int getBaseline(JComponent c, int width, int height) {
7010
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   417
        if (c == null) {
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   418
            throw new NullPointerException("Component must be non-null");
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   419
        }
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   420
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   421
        if (width < 0 || height < 0) {
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   422
            throw new IllegalArgumentException("Width and height must be >= 0");
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   423
        }
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   424
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Insets spInsets = scrollpane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        int y = spInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        height = height - spInsets.top - spInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        width = width - spInsets.left - spInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        JViewport columnHeader = scrollpane.getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if (columnHeader != null && columnHeader.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            Component header = columnHeader.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (header != null && header.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                // Header is always given it's preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                Dimension headerPref = header.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                int baseline = header.getBaseline(headerPref.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                                  headerPref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    return y + baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            Dimension columnPref = columnHeader.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            height -= columnPref.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            y += columnPref.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        Component view = (viewport == null) ? null : viewport.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (view != null && view.isVisible() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                view.getBaselineResizeBehavior() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                Component.BaselineResizeBehavior.CONSTANT_ASCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            Border viewportBorder = scrollpane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            if (viewportBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                Insets vpbInsets = viewportBorder.getBorderInsets(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                y += vpbInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                height = height - vpbInsets.top - vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                width = width - vpbInsets.left - vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (view.getWidth() > 0 && view.getHeight() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                Dimension min = view.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                width = Math.max(min.width, view.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                height = Math.max(min.height, view.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (width > 0 && height > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                int baseline = view.getBaseline(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                if (baseline > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    return y + baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        // Baseline is either from the header, in which case it's always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // the same size and therefor can be created as CONSTANT_ASCENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        // If the header doesn't have a baseline than the baseline will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // be valid if it's BaselineResizeBehavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        // CONSTANT_ASCENT, so, return CONSTANT_ASCENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Listener for viewport events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public class ViewportChangeHandler implements ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   498
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   508
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   509
     * Returns an instance of viewport {@code ChangeListener}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   510
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   511
     * @return an instance of viewport {@code ChangeListener}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   512
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    protected ChangeListener createViewportChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Horizontal scrollbar listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public class HSBChangeListener implements ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   524
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        public void stateChanged(ChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Returns a <code>PropertyChangeListener</code> that will be installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * on the horizontal <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    private PropertyChangeListener createHSBPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   543
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   544
     * Returns an instance of horizontal scroll bar {@code ChangeListener}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   545
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   546
     * @return an instance of horizontal scroll bar {@code ChangeListener}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   547
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    protected ChangeListener createHSBChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Vertical scrollbar listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public class VSBChangeListener implements ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   559
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        public void stateChanged(ChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns a <code>PropertyChangeListener</code> that will be installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * on the vertical <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private PropertyChangeListener createVSBPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   579
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   580
     * Returns an instance of vertical scroll bar {@code ChangeListener}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   581
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   582
     * @return an instance of vertical scroll bar {@code ChangeListener}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   583
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    protected ChangeListener createVSBChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * MouseWheelHandler is an inner class which implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * MouseWheelListener interface.  MouseWheelHandler responds to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * MouseWheelEvents by scrolling the JScrollPane appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * If the scroll pane's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <code>isWheelScrollingEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * method returns false, no scrolling occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @see javax.swing.JScrollPane#isWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @see #createMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @see java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @see java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    protected class MouseWheelHandler implements MouseWheelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   604
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         * Called when the mouse wheel is rotated while over a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
         * JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
         * @param e     MouseWheelEvent to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        public void mouseWheelMoved(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            getHandler().mouseWheelMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Creates an instance of MouseWheelListener, which is added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * JScrollPane by installUI().  The returned MouseWheelListener is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * to handle mouse wheel-driven scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @return      MouseWheelListener which implements wheel-driven scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see MouseWheelHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    protected MouseWheelListener createMouseWheelListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   635
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   636
     * Updates a scroll bar display policy.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   637
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   638
     * @param e the property change event
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   639
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    protected void updateScrollBarDisplayPolicy(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        scrollpane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        scrollpane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   645
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   646
     * Updates viewport.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   647
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   648
     * @param e the property change event
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   649
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    protected void updateViewport(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        JViewport oldViewport = (JViewport)(e.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        JViewport newViewport = (JViewport)(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (oldViewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            oldViewport.removeChangeListener(viewportChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        if (newViewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            Point p = newViewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                p.x = Math.max(p.x, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                int max = newViewport.getViewSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                int extent = newViewport.getExtentSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                if (extent > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    p.x = max - extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    p.x = Math.max(0, Math.min(max - extent, p.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            p.y = Math.max(p.y, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            newViewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            newViewport.addChangeListener(viewportChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   678
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   679
     * Updates row header.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   680
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   681
     * @param e the property change event
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   682
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    protected void updateRowHeader(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        JViewport newRowHead = (JViewport)(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        if (newRowHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            Point p = newRowHead.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            p.y = (viewport != null) ? viewport.getViewPosition().y : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            newRowHead.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   694
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   695
     * Updates column header.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   696
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   697
     * @param e the property change event
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   698
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    protected void updateColumnHeader(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        JViewport newColHead = (JViewport)(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (newColHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            Point p = newColHead.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            if (viewport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                p.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    p.x = viewport.getViewPosition().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    p.x = Math.max(0, viewport.getViewPosition().x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            newColHead.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            scrollpane.add(newColHead, COLUMN_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    private void updateHorizontalScrollBar(PropertyChangeEvent pce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        updateScrollBar(pce, hsbChangeListener, hsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    private void updateVerticalScrollBar(PropertyChangeEvent pce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        updateScrollBar(pce, vsbChangeListener, vsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    private void updateScrollBar(PropertyChangeEvent pce, ChangeListener cl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                                 PropertyChangeListener pcl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        JScrollBar sb = (JScrollBar)pce.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        if (sb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                sb.getModel().removeChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if (pcl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                sb.removePropertyChangeListener(pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        sb = (JScrollBar)pce.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (sb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                sb.getModel().addChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (pcl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                sb.addPropertyChangeListener(pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
   749
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
   750
     * Property change handler.
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
   751
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    public class PropertyChangeHandler implements PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   755
        // NOTE: This class exists only for backward compatibility. All
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
   760
        /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
   761
         * {@inheritDoc}
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 29880
diff changeset
   762
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        public void propertyChange(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    /**
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   772
     * Creates an instance of {@code PropertyChangeListener} that's added to
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   773
     * the {@code JScrollPane} by {@code installUI()}. Subclasses can override
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   774
     * this method to return a custom {@code PropertyChangeListener}, e.g.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * class MyScrollPaneUI extends BasicScrollPaneUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *    protected PropertyChangeListener <b>createPropertyChangeListener</b>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *        return new MyPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *    public class MyPropertyChangeListener extends PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *            if (e.getPropertyName().equals("viewport")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *                // do some extra work when the viewport changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *            super.propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   791
     * @return an instance of {@code PropertyChangeListener}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   792
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @see java.beans.PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        private static final String SCROLL_UP = "scrollUp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        private static final String SCROLL_DOWN = "scrollDown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        private static final String SCROLL_HOME = "scrollHome";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        private static final String SCROLL_END = "scrollEnd";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        private static final String UNIT_SCROLL_UP = "unitScrollUp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        private static final String UNIT_SCROLL_DOWN = "unitScrollDown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        private static final String SCROLL_LEFT = "scrollLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        private static final String SCROLL_RIGHT = "scrollRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        private static final String UNIT_SCROLL_LEFT = "unitScrollLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        private static final String UNIT_SCROLL_RIGHT = "unitScrollRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            JScrollPane scrollPane = (JScrollPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            boolean ltr = scrollPane.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if (key == SCROLL_UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                scroll(scrollPane, SwingConstants.VERTICAL, -1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            else if (key == SCROLL_DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                scroll(scrollPane, SwingConstants.VERTICAL, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            else if (key == SCROLL_HOME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                scrollHome(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            else if (key == SCROLL_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                scrollEnd(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            else if (key == UNIT_SCROLL_UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                scroll(scrollPane, SwingConstants.VERTICAL, -1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            else if (key == UNIT_SCROLL_DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                scroll(scrollPane, SwingConstants.VERTICAL, 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            else if (key == SCROLL_LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? -1 : 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            else if (key == SCROLL_RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? 1 : -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            else if (key == UNIT_SCROLL_LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? -1 : 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            else if (key == UNIT_SCROLL_RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? 1 : -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        private void scrollEnd(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            Component view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            if (vp != null && (view = vp.getView()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                Rectangle visRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                Rectangle bounds = view.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    vp.setViewPosition(new Point(bounds.width - visRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                             bounds.height - visRect.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                    vp.setViewPosition(new Point(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                             bounds.height - visRect.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        private void scrollHome(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            Component view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            if (vp != null && (view = vp.getView()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    vp.setViewPosition(new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    Rectangle visRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                    Rectangle bounds = view.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        private void scroll(JScrollPane scrollpane, int orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                            int direction, boolean block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            Component view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            if (vp != null && (view = vp.getView()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                Rectangle visRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                Dimension vSize = view.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                int amount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                if (view instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    if (block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                        amount = ((Scrollable)view).getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                                 (visRect, orientation, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                        amount = ((Scrollable)view).getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                                 (visRect, orientation, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                    }
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
                    if (block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                            amount = visRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                            amount = visRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                        amount = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                    visRect.y += (amount * direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    if ((visRect.y + visRect.height) > vSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                        visRect.y = Math.max(0, vSize.height - visRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                    else if (visRect.y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                        visRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                        visRect.x += (amount * direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                        if ((visRect.x + visRect.width) > vSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                            visRect.x = Math.max(0, vSize.width - visRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                        } else if (visRect.x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                            visRect.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                        visRect.x -= (amount * direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                        if (visRect.width > vSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                            visRect.x = vSize.width - visRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                            visRect.x = Math.max(0, Math.min(vSize.width - visRect.width, visRect.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                vp.setViewPosition(visRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    class Handler implements ChangeListener, PropertyChangeListener, MouseWheelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        // MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        public void mouseWheelMoved(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (scrollpane.isWheelScrollingEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                e.getWheelRotation() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                JScrollBar toScroll = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                int direction = e.getWheelRotation() < 0 ? -1 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                int orientation = SwingConstants.VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                // find which scrollbar to scroll, or return if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                if (toScroll == null || !toScroll.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    toScroll = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    if (toScroll == null || !toScroll.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    orientation = SwingConstants.HORIZONTAL;
29880
665cb957c3d0 8033000: No Horizontal Mouse Wheel Support In
alexsch
parents: 25859
diff changeset
   971
                } else if(e.isShiftDown()){
665cb957c3d0 8033000: No Horizontal Mouse Wheel Support In
alexsch
parents: 25859
diff changeset
   972
                    JScrollBar hScroll = scrollpane.getHorizontalScrollBar();
665cb957c3d0 8033000: No Horizontal Mouse Wheel Support In
alexsch
parents: 25859
diff changeset
   973
                    if (hScroll != null && hScroll.isVisible()) {
665cb957c3d0 8033000: No Horizontal Mouse Wheel Support In
alexsch
parents: 25859
diff changeset
   974
                        toScroll = hScroll;
665cb957c3d0 8033000: No Horizontal Mouse Wheel Support In
alexsch
parents: 25859
diff changeset
   975
                        orientation = SwingConstants.HORIZONTAL;
665cb957c3d0 8033000: No Horizontal Mouse Wheel Support In
alexsch
parents: 25859
diff changeset
   976
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
5277
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 3350
diff changeset
   979
                e.consume();
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 3350
diff changeset
   980
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                    JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                    if (vp == null) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    Component comp = vp.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                    int units = Math.abs(e.getUnitsToScroll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    // When the scrolling speed is set to maximum, it's possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    // for a single wheel click to scroll by more units than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    // will fit in the visible area.  This makes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    // hard/impossible to get to certain parts of the scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    // Component with the wheel.  To make for more accurate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    // low-speed scrolling, we limit scrolling to the block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                    // increment if the wheel was only rotated one click.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    boolean limitScroll = Math.abs(e.getWheelRotation()) == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                    // Check if we should use the visibleRect trick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                    Object fastWheelScroll = toScroll.getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                                               "JScrollBar.fastWheelScrolling");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                    if (Boolean.TRUE == fastWheelScroll &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                        comp instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                        // 5078454: Under maximum acceleration, we may scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                        // by many 100s of units in ~1 second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                        // BasicScrollBarUI.scrollByUnits() can bog down the EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                        // with repaints in this situation.  However, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                        // Scrollable interface allows us to pass in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                        // arbitrary visibleRect.  This allows us to accurately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                        // calculate the total scroll amount, and then update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                        // the GUI once.  This technique provides much faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                        // accelerated wheel scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                        Scrollable scrollComp = (Scrollable) comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                        Rectangle viewRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                        int startingX = viewRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                        boolean leftToRight =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                                 comp.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                        int scrollMin = toScroll.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                        int scrollMax = toScroll.getMaximum() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                                        toScroll.getModel().getExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                        if (limitScroll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                            int blockIncr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                scrollComp.getScrollableBlockIncrement(viewRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                                                                    orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                                                                    direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                            if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                                scrollMin = Math.max(scrollMin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                               toScroll.getValue() - blockIncr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                                scrollMax = Math.min(scrollMax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                                               toScroll.getValue() + blockIncr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                        for (int i = 0; i < units; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                            int unitIncr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                                scrollComp.getScrollableUnitIncrement(viewRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                                                        orientation, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                            // Modify the visible rect for the next unit, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                            // check to see if we're at the end already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                            if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                                if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                                    viewRect.y -= unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                                    if (viewRect.y <= scrollMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                        viewRect.y = scrollMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                else { // (direction > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                                    viewRect.y += unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                                    if (viewRect.y >= scrollMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                                        viewRect.y = scrollMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                                // Scroll left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                                if ((leftToRight && direction < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                                    (!leftToRight && direction > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                                    viewRect.x -= unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                                    if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                                        if (viewRect.x < scrollMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                                            viewRect.x = scrollMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                                // Scroll right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                                else if ((leftToRight && direction > 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                                    (!leftToRight && direction < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                                    viewRect.x += unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                    if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                                        if (viewRect.x > scrollMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                                            viewRect.x = scrollMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                                    assert false : "Non-sensical ComponentOrientation / scroll direction";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                        // Set the final view position on the ScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                            toScroll.setValue(viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                                toScroll.setValue(viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                                // rightToLeft scrollbars are oriented with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                                // minValue on the right and maxValue on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                                // left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                                int newPos = toScroll.getValue() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                                                       (viewRect.x - startingX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                                if (newPos < scrollMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                                    newPos = scrollMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                                else if (newPos > scrollMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                                    newPos = scrollMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                                toScroll.setValue(newPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                        // Viewport's view is not a Scrollable, or fast wheel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                        // scrolling is not enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                        BasicScrollBarUI.scrollByUnits(toScroll, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                                                       units, limitScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                else if (e.getScrollType() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                         MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                    BasicScrollBarUI.scrollByBlock(toScroll, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        // ChangeListener: This is added to the vieport, and hsb/vsb models.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                if (e.getSource() == viewport) {
3350
100ac73bfe6e 6864297: Right-to-left oriented JScrollPane is aligned to the wrong direction while resizing the container
malenkov
parents: 2
diff changeset
  1131
                    syncScrollPaneWithViewport();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    if (hsb != null && e.getSource() == hsb.getModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                        hsbStateChanged(viewport, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                        if (vsb != null && e.getSource() == vsb.getModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                            vsbStateChanged(viewport, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        private void vsbStateChanged(JViewport viewport, ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            BoundedRangeModel model = (BoundedRangeModel)(e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            Point p = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            p.y = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            viewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        private void hsbStateChanged(JViewport viewport, ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            BoundedRangeModel model = (BoundedRangeModel)(e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            Point p = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            int value = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                p.x = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                int max = viewport.getViewSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                int extent = viewport.getExtentSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                int oldX = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                /* Set new X coordinate based on "value".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                p.x = max - extent - value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                /* If setValue() was called before "extent" was fixed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                 * turn setValueCalled flag on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                if ((extent == 0) && (value != 0) && (oldX == max)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                    setValueCalled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                    /* When a pane without a horizontal scroll bar was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                     * reduced and the bar appeared, the viewport should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                     * show the right side of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    if ((extent != 0) && (oldX < 0) && (p.x == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                        p.x += value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            viewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        // PropertyChangeListener: This is installed on both the JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        // and the horizontal/vertical scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        // Listens for changes in the model property and reinstalls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        // horizontal/vertical PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            if (e.getSource() == scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                scrollPanePropertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                sbPropertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        private void scrollPanePropertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            if (propertyName == "verticalScrollBarDisplayPolicy") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                updateScrollBarDisplayPolicy(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            else if (propertyName == "horizontalScrollBarDisplayPolicy") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                updateScrollBarDisplayPolicy(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            else if (propertyName == "viewport") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                updateViewport(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            else if (propertyName == "rowHeader") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                updateRowHeader(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            else if (propertyName == "columnHeader") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                updateColumnHeader(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            else if (propertyName == "verticalScrollBar") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                updateVerticalScrollBar(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            else if (propertyName == "horizontalScrollBar") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                updateHorizontalScrollBar(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            else if (propertyName == "componentOrientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                scrollpane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                scrollpane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        // PropertyChangeListener for the horizontal and vertical scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        private void sbPropertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            if ("model" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                JScrollBar sb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                BoundedRangeModel oldModel = (BoundedRangeModel)e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                                     getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                ChangeListener cl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                if (source == sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                    cl = vsbChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                else if (source == scrollpane.getHorizontalScrollBar()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                    sb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    cl = hsbChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                        oldModel.removeChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                    if (sb.getModel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                        sb.getModel().addChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            else if ("componentOrientation" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                if (source == scrollpane.getHorizontalScrollBar()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                    Point p = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                        p.x = hsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                        p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                    viewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
}