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