jdk/src/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7010 324a3db27d8f
child 20169 d7fa6d7586c9
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7010
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5277
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
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) {
7010
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   365
        if (c == null) {
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   366
            throw new NullPointerException("Component must be non-null");
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   367
        }
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   368
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   369
        if (width < 0 || height < 0) {
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   370
            throw new IllegalArgumentException("Width and height must be >= 0");
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   371
        }
324a3db27d8f 6632810: javax.swing.plaf.basic.BasicScrollPaneUI.getBaseline(JComponent, int, int) doesn't throw NPE and IAE
rupashka
parents: 5506
diff changeset
   372
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Insets spInsets = scrollpane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        int y = spInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        height = height - spInsets.top - spInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        width = width - spInsets.left - spInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        JViewport columnHeader = scrollpane.getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (columnHeader != null && columnHeader.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            Component header = columnHeader.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (header != null && header.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                // Header is always given it's preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                Dimension headerPref = header.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                int baseline = header.getBaseline(headerPref.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                                                  headerPref.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    return y + baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            Dimension columnPref = columnHeader.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            height -= columnPref.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            y += columnPref.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        Component view = (viewport == null) ? null : viewport.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (view != null && view.isVisible() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                view.getBaselineResizeBehavior() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                Component.BaselineResizeBehavior.CONSTANT_ASCENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            Border viewportBorder = scrollpane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (viewportBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                Insets vpbInsets = viewportBorder.getBorderInsets(scrollpane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                y += vpbInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                height = height - vpbInsets.top - vpbInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                width = width - vpbInsets.left - vpbInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if (view.getWidth() > 0 && view.getHeight() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                Dimension min = view.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                width = Math.max(min.width, view.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                height = Math.max(min.height, view.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (width > 0 && height > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                int baseline = view.getBaseline(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                if (baseline > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    return y + baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Returns an enum indicating how the baseline of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        super.getBaselineResizeBehavior(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        // Baseline is either from the header, in which case it's always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        // the same size and therefor can be created as CONSTANT_ASCENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // If the header doesn't have a baseline than the baseline will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // be valid if it's BaselineResizeBehavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // CONSTANT_ASCENT, so, return CONSTANT_ASCENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Listener for viewport events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public class ViewportChangeHandler implements ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    protected ChangeListener createViewportChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Horizontal scrollbar listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public class HSBChangeListener implements ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        public void stateChanged(ChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Returns a <code>PropertyChangeListener</code> that will be installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * on the horizontal <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    private PropertyChangeListener createHSBPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    protected ChangeListener createHSBChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Vertical scrollbar listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public class VSBChangeListener implements ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        public void stateChanged(ChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            getHandler().stateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Returns a <code>PropertyChangeListener</code> that will be installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * on the vertical <code>JScrollBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    private PropertyChangeListener createVSBPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    protected ChangeListener createVSBChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * MouseWheelHandler is an inner class which implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * MouseWheelListener interface.  MouseWheelHandler responds to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * MouseWheelEvents by scrolling the JScrollPane appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * If the scroll pane's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * <code>isWheelScrollingEnabled</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * method returns false, no scrolling occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see javax.swing.JScrollPane#isWheelScrollingEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @see #createMouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see java.awt.event.MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @see java.awt.event.MouseWheelEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    protected class MouseWheelHandler implements MouseWheelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         * Called when the mouse wheel is rotated while over a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         * JScrollPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         * @param e     MouseWheelEvent to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        public void mouseWheelMoved(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            getHandler().mouseWheelMoved(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Creates an instance of MouseWheelListener, which is added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * JScrollPane by installUI().  The returned MouseWheelListener is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * to handle mouse wheel-driven scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @return      MouseWheelListener which implements wheel-driven scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @see MouseWheelHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    protected MouseWheelListener createMouseWheelListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    protected void updateScrollBarDisplayPolicy(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        scrollpane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        scrollpane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    protected void updateViewport(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        JViewport oldViewport = (JViewport)(e.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        JViewport newViewport = (JViewport)(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (oldViewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            oldViewport.removeChangeListener(viewportChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (newViewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            Point p = newViewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                p.x = Math.max(p.x, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                int max = newViewport.getViewSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                int extent = newViewport.getExtentSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                if (extent > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    p.x = max - extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    p.x = Math.max(0, Math.min(max - extent, p.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            p.y = Math.max(p.y, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            newViewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            newViewport.addChangeListener(viewportChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    protected void updateRowHeader(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        JViewport newRowHead = (JViewport)(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (newRowHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            Point p = newRowHead.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            p.y = (viewport != null) ? viewport.getViewPosition().y : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            newRowHead.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    protected void updateColumnHeader(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        JViewport newColHead = (JViewport)(e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (newColHead != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            Point p = newColHead.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            if (viewport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                p.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    p.x = viewport.getViewPosition().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    p.x = Math.max(0, viewport.getViewPosition().x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            newColHead.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            scrollpane.add(newColHead, COLUMN_HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
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 updateHorizontalScrollBar(PropertyChangeEvent pce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        updateScrollBar(pce, hsbChangeListener, hsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    private void updateVerticalScrollBar(PropertyChangeEvent pce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        updateScrollBar(pce, vsbChangeListener, vsbPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    private void updateScrollBar(PropertyChangeEvent pce, ChangeListener cl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                 PropertyChangeListener pcl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        JScrollBar sb = (JScrollBar)pce.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (sb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                sb.getModel().removeChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if (pcl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                sb.removePropertyChangeListener(pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        sb = (JScrollBar)pce.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (sb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                sb.getModel().addChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            if (pcl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                sb.addPropertyChangeListener(pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    public class PropertyChangeHandler implements PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        public void propertyChange(PropertyChangeEvent e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Creates an instance of PropertyChangeListener that's added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * the JScrollPane by installUI().  Subclasses can override this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * to return a custom PropertyChangeListener, e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * class MyScrollPaneUI extends BasicScrollPaneUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *    protected PropertyChangeListener <b>createPropertyChangeListener</b>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *        return new MyPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *    public class MyPropertyChangeListener extends PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *            if (e.getPropertyName().equals("viewport")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *                // do some extra work when the viewport changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *            super.propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @see java.beans.PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        private static final String SCROLL_UP = "scrollUp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        private static final String SCROLL_DOWN = "scrollDown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        private static final String SCROLL_HOME = "scrollHome";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        private static final String SCROLL_END = "scrollEnd";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        private static final String UNIT_SCROLL_UP = "unitScrollUp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        private static final String UNIT_SCROLL_DOWN = "unitScrollDown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        private static final String SCROLL_LEFT = "scrollLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        private static final String SCROLL_RIGHT = "scrollRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        private static final String UNIT_SCROLL_LEFT = "unitScrollLeft";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        private static final String UNIT_SCROLL_RIGHT = "unitScrollRight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            JScrollPane scrollPane = (JScrollPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            boolean ltr = scrollPane.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if (key == SCROLL_UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                scroll(scrollPane, SwingConstants.VERTICAL, -1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            else if (key == SCROLL_DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                scroll(scrollPane, SwingConstants.VERTICAL, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            else if (key == SCROLL_HOME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                scrollHome(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            else if (key == SCROLL_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                scrollEnd(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            else if (key == UNIT_SCROLL_UP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                scroll(scrollPane, SwingConstants.VERTICAL, -1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            else if (key == UNIT_SCROLL_DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                scroll(scrollPane, SwingConstants.VERTICAL, 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            else if (key == 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
                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            else if (key == 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
                       true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            else if (key == UNIT_SCROLL_LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? -1 : 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            else if (key == UNIT_SCROLL_RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                scroll(scrollPane, SwingConstants.HORIZONTAL, ltr ? 1 : -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                       false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        private void scrollEnd(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            Component view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if (vp != null && (view = vp.getView()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                Rectangle visRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                Rectangle bounds = view.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    vp.setViewPosition(new Point(bounds.width - visRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                                             bounds.height - visRect.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    vp.setViewPosition(new Point(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                             bounds.height - visRect.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        private void scrollHome(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            Component view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            if (vp != null && (view = vp.getView()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    vp.setViewPosition(new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    Rectangle visRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    Rectangle bounds = view.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    vp.setViewPosition(new Point(bounds.width - visRect.width, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        private void scroll(JScrollPane scrollpane, int orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                            int direction, boolean block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            Component view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            if (vp != null && (view = vp.getView()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                Rectangle visRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                Dimension vSize = view.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                int amount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                if (view instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    if (block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                        amount = ((Scrollable)view).getScrollableBlockIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                 (visRect, orientation, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                        amount = ((Scrollable)view).getScrollableUnitIncrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                                 (visRect, orientation, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    if (block) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                            amount = visRect.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                            amount = visRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                        amount = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    visRect.y += (amount * direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                    if ((visRect.y + visRect.height) > vSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                        visRect.y = Math.max(0, vSize.height - visRect.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    else if (visRect.y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                        visRect.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    }
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
                    if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                        visRect.x += (amount * direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                        if ((visRect.x + visRect.width) > vSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                            visRect.x = Math.max(0, vSize.width - visRect.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                        } else if (visRect.x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                            visRect.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                        visRect.x -= (amount * direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                        if (visRect.width > vSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                            visRect.x = vSize.width - visRect.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                            visRect.x = Math.max(0, Math.min(vSize.width - visRect.width, visRect.x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                vp.setViewPosition(visRect.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    class Handler implements ChangeListener, PropertyChangeListener, MouseWheelListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        // MouseWheelListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        public void mouseWheelMoved(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if (scrollpane.isWheelScrollingEnabled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                e.getWheelRotation() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                JScrollBar toScroll = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                int direction = e.getWheelRotation() < 0 ? -1 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                int orientation = SwingConstants.VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                // find which scrollbar to scroll, or return if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                if (toScroll == null || !toScroll.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    toScroll = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    if (toScroll == null || !toScroll.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                    orientation = SwingConstants.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
5277
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 3350
diff changeset
   881
                e.consume();
03170721df2e 6920842: Wheel events do not bubbling to the browser if they was not treated in applet.
uta
parents: 3350
diff changeset
   882
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    JViewport vp = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    if (vp == null) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                    Component comp = vp.getView();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    int units = Math.abs(e.getUnitsToScroll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                    // When the scrolling speed is set to maximum, it's possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                    // for a single wheel click to scroll by more units than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    // will fit in the visible area.  This makes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                    // hard/impossible to get to certain parts of the scrolling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                    // Component with the wheel.  To make for more accurate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                    // low-speed scrolling, we limit scrolling to the block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                    // increment if the wheel was only rotated one click.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                    boolean limitScroll = Math.abs(e.getWheelRotation()) == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                    // Check if we should use the visibleRect trick
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                    Object fastWheelScroll = toScroll.getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                                               "JScrollBar.fastWheelScrolling");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    if (Boolean.TRUE == fastWheelScroll &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                        comp instanceof Scrollable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                        // 5078454: Under maximum acceleration, we may scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                        // by many 100s of units in ~1 second.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                        // BasicScrollBarUI.scrollByUnits() can bog down the EDT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                        // with repaints in this situation.  However, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                        // Scrollable interface allows us to pass in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                        // arbitrary visibleRect.  This allows us to accurately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                        // calculate the total scroll amount, and then update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                        // the GUI once.  This technique provides much faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                        // accelerated wheel scrolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        Scrollable scrollComp = (Scrollable) comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                        Rectangle viewRect = vp.getViewRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        int startingX = viewRect.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                        boolean leftToRight =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                                 comp.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                        int scrollMin = toScroll.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                        int scrollMax = toScroll.getMaximum() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                        toScroll.getModel().getExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                        if (limitScroll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                            int blockIncr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                                scrollComp.getScrollableBlockIncrement(viewRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                                                    orientation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                                                    direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                            if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                scrollMin = Math.max(scrollMin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                               toScroll.getValue() - blockIncr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                                scrollMax = Math.min(scrollMax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                                               toScroll.getValue() + blockIncr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                        for (int i = 0; i < units; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                            int unitIncr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                                scrollComp.getScrollableUnitIncrement(viewRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                                        orientation, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                            // Modify the visible rect for the next unit, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                            // check to see if we're at the end already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                            if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                                if (direction < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                                    viewRect.y -= unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                                    if (viewRect.y <= scrollMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                                        viewRect.y = scrollMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                                        break;
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 { // (direction > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                                    viewRect.y += unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                                    if (viewRect.y >= scrollMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                                        viewRect.y = scrollMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                // Scroll left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                                if ((leftToRight && direction < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                                    (!leftToRight && direction > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                                    viewRect.x -= unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                                    if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                        if (viewRect.x < scrollMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                            viewRect.x = scrollMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                // Scroll right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                else if ((leftToRight && direction > 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                                    (!leftToRight && direction < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                    viewRect.x += unitIncr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                                    if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                        if (viewRect.x > scrollMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                                            viewRect.x = scrollMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                    assert false : "Non-sensical ComponentOrientation / scroll direction";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                        // Set the final view position on the ScrollBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                        if (orientation == SwingConstants.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                            toScroll.setValue(viewRect.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                                toScroll.setValue(viewRect.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                                // rightToLeft scrollbars are oriented with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                                // minValue on the right and maxValue on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                                // left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                                int newPos = toScroll.getValue() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                                                       (viewRect.x - startingX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                                if (newPos < scrollMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                                    newPos = scrollMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                                else if (newPos > scrollMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                                    newPos = scrollMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                toScroll.setValue(newPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                        // Viewport's view is not a Scrollable, or fast wheel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                        // scrolling is not enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                        BasicScrollBarUI.scrollByUnits(toScroll, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                                                       units, limitScroll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                else if (e.getScrollType() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                         MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                    BasicScrollBarUI.scrollByBlock(toScroll, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        // ChangeListener: This is added to the vieport, and hsb/vsb models.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            if (viewport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                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
  1033
                    syncScrollPaneWithViewport();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    if (hsb != null && e.getSource() == hsb.getModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                        hsbStateChanged(viewport, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                        JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                        if (vsb != null && e.getSource() == vsb.getModel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                            vsbStateChanged(viewport, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        private void vsbStateChanged(JViewport viewport, ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            BoundedRangeModel model = (BoundedRangeModel)(e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            Point p = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            p.y = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            viewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        private void hsbStateChanged(JViewport viewport, ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            BoundedRangeModel model = (BoundedRangeModel)(e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            Point p = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            int value = model.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                p.x = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                int max = viewport.getViewSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                int extent = viewport.getExtentSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                int oldX = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                /* Set new X coordinate based on "value".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                p.x = max - extent - value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                /* If setValue() was called before "extent" was fixed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                 * turn setValueCalled flag on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                if ((extent == 0) && (value != 0) && (oldX == max)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    setValueCalled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    /* When a pane without a horizontal scroll bar was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                     * reduced and the bar appeared, the viewport should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                     * show the right side of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                    if ((extent != 0) && (oldX < 0) && (p.x == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                        p.x += value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            viewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        // PropertyChangeListener: This is installed on both the JScrollPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        // and the horizontal/vertical scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        // Listens for changes in the model property and reinstalls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        // horizontal/vertical PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            if (e.getSource() == scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                scrollPanePropertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                sbPropertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        private void scrollPanePropertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            if (propertyName == "verticalScrollBarDisplayPolicy") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                updateScrollBarDisplayPolicy(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            else if (propertyName == "horizontalScrollBarDisplayPolicy") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                updateScrollBarDisplayPolicy(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            else if (propertyName == "viewport") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                updateViewport(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            else if (propertyName == "rowHeader") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                updateRowHeader(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            else if (propertyName == "columnHeader") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                updateColumnHeader(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            else if (propertyName == "verticalScrollBar") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                updateVerticalScrollBar(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            else if (propertyName == "horizontalScrollBar") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                updateHorizontalScrollBar(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            else if (propertyName == "componentOrientation") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                scrollpane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                scrollpane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        // PropertyChangeListener for the horizontal and vertical scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        private void sbPropertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            if ("model" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                JScrollBar sb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                BoundedRangeModel oldModel = (BoundedRangeModel)e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                                     getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                ChangeListener cl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                if (source == sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                    cl = vsbChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                else if (source == scrollpane.getHorizontalScrollBar()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                    sb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                    cl = hsbChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                    if (oldModel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                        oldModel.removeChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                    if (sb.getModel() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                        sb.getModel().addChangeListener(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            else if ("componentOrientation" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                if (source == scrollpane.getHorizontalScrollBar()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                    JViewport viewport = scrollpane.getViewport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                    Point p = viewport.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                    if (scrollpane.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                        p.x = hsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                        p.x = viewport.getViewSize().width - viewport.getExtentSize().width - hsb.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                    viewport.setViewPosition(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
}