jdk/src/solaris/classes/sun/awt/X11/XScrollPanePeer.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 10096 f9ac9a52952d
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
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, 2007, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
class XScrollPanePeer extends XComponentPeer implements ScrollPanePeer, XScrollbarClient {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public final static int     MARGIN = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public final static int     SCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public final static int     SPACE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    public final static int     SCROLLBAR_INSET = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public final static int     VERTICAL = 1 << 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public final static int     HORIZONTAL = 1 << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static Method m_setValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        m_setValue = SunToolkit.getMethod(ScrollPaneAdjustable.class, "setTypedValue", new Class[] {Integer.TYPE, Integer.TYPE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        SCROLLBAR = XToolkit.getUIDefaults().getInt("ScrollBar.defaultWidth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    XVerticalScrollbar       vsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    XHorizontalScrollbar     hsb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    XWindow                  clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int                         active=VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    int                         hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    int                         vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static class XScrollPaneContentWindow extends XWindow {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        XScrollPaneContentWindow(ScrollPane target, long parentWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            super(target, parentWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        public String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            return "ScrollPane content";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    XScrollPanePeer(ScrollPane target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        // Create the clip window. The field "clip" must be null when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        // we call winCreate, or the parent of clip will be set to itself!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        clip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        XWindow c = new XScrollPaneContentWindow(target,window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        clip = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        vsb = new XVerticalScrollbar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        hsb = new XHorizontalScrollbar(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (target.getScrollbarDisplayPolicy() == ScrollPane.SCROLLBARS_ALWAYS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            vsbSpace = hsbSpace = SCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            vsbSpace = hsbSpace = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        int unitIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Adjustable vAdjustable = target.getVAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (vAdjustable != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            unitIncrement = vAdjustable.getUnitIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int h = height-hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        vsb.setValues(0, h, 0, h, unitIncrement, Math.max(1, (int)(h * 0.90)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        vsb.setSize(vsbSpace-SCROLLBAR_INSET, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        unitIncrement = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Adjustable hAdjustable = target.getHAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (hAdjustable != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            unitIncrement = hAdjustable.getUnitIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        int w = width - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        hsb.setValues(0, w, 0, w, unitIncrement, Math.max(1, (int)(w * 0.90)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        hsb.setSize(w, hsbSpace-SCROLLBAR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        setViewportSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        clip.xSetVisible(true);
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
    public long getContentWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return (clip == null) ? window : clip.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void setBounds(int x, int y, int w, int h, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super.setBounds(x, y, w, h, op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (clip == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        setScrollbarSpace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        setViewportSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return new Insets(MARGIN, MARGIN, MARGIN+hsbSpace, MARGIN+vsbSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public int getHScrollbarHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return SCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public int getVScrollbarWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return SCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void childResized(int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (setScrollbarSpace()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            setViewportSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    Dimension getChildSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        ScrollPane sp = (ScrollPane)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (sp.countComponents() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            Component c = sp.getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return c.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    boolean setScrollbarSpace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        ScrollPane sp = (ScrollPane)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        boolean changed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int sbDisplayPolicy = sp.getScrollbarDisplayPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (sbDisplayPolicy == ScrollPane.SCROLLBARS_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return changed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Dimension cSize = getChildSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (sbDisplayPolicy == ScrollPane.SCROLLBARS_AS_NEEDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            int oldHsbSpace = hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            int oldVsbSpace = vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            hsbSpace = (cSize.width <= (width - 2*MARGIN) ? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            vsbSpace = (cSize.height <= (height - 2*MARGIN) ? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (hsbSpace == 0 && vsbSpace != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                hsbSpace = (cSize.width <= (width - SCROLLBAR - 2*MARGIN) ? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (vsbSpace == 0 && hsbSpace != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                vsbSpace = (cSize.height <= (height - SCROLLBAR - 2*MARGIN) ? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (oldHsbSpace != hsbSpace || oldVsbSpace != vsbSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                changed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (vsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            int vis = height - (2*MARGIN) - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            int max = Math.max(cSize.height, vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            vsb.setValues(vsb.getValue(), vis, 0, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            vsb.setBlockIncrement((int)(vsb.getVisibleAmount() * .90));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            vsb.setSize(vsbSpace-SCROLLBAR_INSET, height-hsbSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            // Adjustable vadj = sp.getVAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            // vadj.setVisibleAmount(vsb.vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            // vadj.setMaximum(vsb.max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            // vadj.setBlockIncrement(vsb.page);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (hsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            int vis = width - (2*MARGIN) - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            int max = Math.max(cSize.width, vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            hsb.setValues(hsb.getValue(), vis, 0, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            hsb.setBlockIncrement((int)(hsb.getVisibleAmount() * .90));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            hsb.setSize(width-vsbSpace, hsbSpace-SCROLLBAR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            // Adjustable hadj = sp.getHAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // hadj.setVisibleAmount(hsb.vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // hadj.setMaximum(hsb.max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // hadj.setBlockIncrement(hsb.page);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Check to see if we hid either of the scrollbars but left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // ourselves scrolled off of the top and/or right of the pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // If we did, we need to scroll to the top and/or right of of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // the pane to make it visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // Reminder: see if there is a better place to put this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        boolean must_scroll = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // Get the point at which the ScrollPane is currently located
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // if number of components > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        Point p = new Point(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (((ScrollPane)target).getComponentCount() > 0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            p = ((ScrollPane)target).getComponent(0).location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if ((vsbSpace == 0) && (p.y < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                p.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                must_scroll = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if ((hsbSpace == 0) && (p.x < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                p.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                must_scroll = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (must_scroll)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            scroll(x, y, VERTICAL | HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return changed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    void setViewportSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        clip.xSetBounds(MARGIN, MARGIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                width - (2*MARGIN)  - vsbSpace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                height - (2*MARGIN) - hsbSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public void setUnitIncrement(Adjustable adj, int u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (adj.getOrientation() == Adjustable.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            vsb.setUnitIncrement(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            hsb.setUnitIncrement(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void setValue(Adjustable adj, int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (adj.getOrientation() == Adjustable.VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            scroll(-1, v, VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            // HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            scroll(v, -1, HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public void setScrollPosition(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        scroll(x, y, VERTICAL | HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    void scroll(int x, int y, int flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        scroll(x, y, flag, AdjustmentEvent.TRACK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Scroll the contents to position x, y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    void scroll(int x, int y, int flag, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        checkSecurity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        ScrollPane sp = (ScrollPane)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        Component c = getScrollChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        int sx, sy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        Color colors[] = getGUIcolors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (sp.getScrollbarDisplayPolicy() == ScrollPane.SCROLLBARS_NEVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            sx = -x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            sy = -y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Point p = c.location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            sx = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            sy = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            if ((flag & HORIZONTAL) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                hsb.setValue(Math.min(x, hsb.getMaximum()-hsb.getVisibleAmount()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                ScrollPaneAdjustable hadj = (ScrollPaneAdjustable)sp.getHAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                setAdjustableValue(hadj, hsb.getValue(), type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                sx = -(hsb.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    paintHorScrollbar(g, colors, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if ((flag & VERTICAL) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                vsb.setValue(Math.min(y, vsb.getMaximum() - vsb.getVisibleAmount()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                ScrollPaneAdjustable vadj = (ScrollPaneAdjustable)sp.getVAdjustable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                setAdjustableValue(vadj, vsb.getValue(), type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                sy = -(vsb.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    paintVerScrollbar(g, colors, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        c.move(sx, sy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    void setAdjustableValue(ScrollPaneAdjustable adj, int value, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            m_setValue.invoke(adj, new Object[] {Integer.valueOf(value), Integer.valueOf(type)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            adj.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        } catch (IllegalArgumentException iae2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            adj.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            adj.setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            ite.getCause().printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    void paintScrollBars(Graphics g, Color[] colors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (vsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            paintVerScrollbar(g, colors, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            // paint the whole scrollbar
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 (hsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            paintHorScrollbar(g, colors, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            // paint the whole scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
   void repaintScrollBars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
       Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
       Color colors[] = getGUIcolors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
       if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
           paintScrollBars(g,colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
       g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public void repaintScrollbarRequest(XScrollbar sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
       Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
       Color colors[] = getGUIcolors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
       if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
           if (sb ==  vsb)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
               paintVerScrollbar(g,colors,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
           else if (sb ==  hsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
               paintHorScrollbar(g,colors,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Paint the scrollpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void paintComponent(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        Color colors[] = getGUIcolors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        g.setColor(colors[BACKGROUND_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int h = height - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int w = width - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        g.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // paint rectangular region between scrollbars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        g.fillRect(w, h, vsbSpace, hsbSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (MARGIN > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            draw3DRect(g, colors, 0, 0, w - 1, h - 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        paintScrollBars(g,colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public void handleEvent(java.awt.AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        super.handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            case PaintEvent.PAINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            case PaintEvent.UPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                repaintScrollBars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Paint the horizontal scrollbar to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param g the graphics context to draw into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @param colors the colors used to draw the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @param paintAll paint the whole scrollbar if true, just the thumb if false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    void paintHorScrollbar(Graphics g, Color colors[], boolean paintAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (hsbSpace <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        g.setColor(colors[BACKGROUND_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        // SCROLLBAR is the height of scrollbar area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // but the actual scrollbar is SCROLLBAR-SPACE high;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // the rest must be filled with background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        int w = width - vsbSpace - (2*MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        g.fillRect(MARGIN, height-SCROLLBAR, w, SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        g.fillRect(0, height-SCROLLBAR, MARGIN, SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        g.fillRect(MARGIN + w, height-SCROLLBAR, MARGIN, SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            ng.translate(MARGIN, height - (SCROLLBAR - SPACE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            hsb.paint(ng, colors, paintAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Paint the vertical scrollbar to the screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param g the graphics context to draw into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param colors the colors used to draw the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param paintAll paint the whole scrollbar if true, just the thumb if false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    void paintVerScrollbar(Graphics g, Color colors[], boolean paintAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (vsbSpace <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        g.setColor(colors[BACKGROUND_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        // SCROLLBAR is the width of scrollbar area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // but the actual scrollbar is SCROLLBAR-SPACE wide;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // the rest must be filled with background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        int h = height - hsbSpace - (2*MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        g.fillRect(width-SCROLLBAR, MARGIN, SPACE, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        g.fillRect(width-SCROLLBAR, 0, SCROLLBAR, MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        g.fillRect(width-SCROLLBAR, MARGIN+h, SCROLLBAR, MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            ng.translate(width - (SCROLLBAR - SPACE), MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            vsb.paint(ng, colors, paintAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @see java.awt.event.MouseEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * MouseEvent.MOUSE_CLICKED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * MouseEvent.MOUSE_PRESSED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * MouseEvent.MOUSE_RELEASED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * MouseEvent.MOUSE_MOVED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * MouseEvent.MOUSE_ENTERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * MouseEvent.MOUSE_EXITED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * MouseEvent.MOUSE_DRAGGED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        super.handleJavaMouseEvent(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        int modifiers = mouseEvent.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        int id = mouseEvent.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        int x = mouseEvent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        int y = mouseEvent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        //        super.handleMouseEvent(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if ((modifiers & InputEvent.BUTTON1_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                if (inVerticalScrollbar(x,y )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    active = VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    int h = height - hsbSpace - (2*MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    vsb.handleMouseEvent(id,modifiers,x - (width - SCROLLBAR + SPACE),y-MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                } else if (inHorizontalScrollbar(x, y) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    active = HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    int w = width - 2*MARGIN - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    hsb.handleMouseEvent(id,modifiers,x-MARGIN,y-(height - SCROLLBAR + SPACE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                // On mouse up, pass the event through to the scrollbar to stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                // scrolling. The x & y passed do not matter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                //     winReleaseCursorFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                if (active == VERTICAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    vsb.handleMouseEvent(id,modifiers,x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                } else if (active == HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    hsb.handleMouseEvent(id,modifiers,x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                if ((active == VERTICAL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    int h = height - 2*MARGIN - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    vsb.handleMouseEvent(id,modifiers,x-(width - SCROLLBAR + SPACE),y-MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                } else if ((active == HORIZONTAL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    int w = width - 2*MARGIN - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    hsb.handleMouseEvent(id,modifiers,x-MARGIN,y-(height - SCROLLBAR + SPACE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * return value from the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (obj == vsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            scroll(-1, v, VERTICAL, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        } else if ((XHorizontalScrollbar)obj == hsb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            scroll(v, -1, HORIZONTAL, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * return true if the x and y position is in the verticalscrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    boolean inVerticalScrollbar(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (vsbSpace <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        int h = height - MARGIN - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return (x >= width - (SCROLLBAR - SPACE)) && (x < width) && (y >= MARGIN) && (y < h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * return true if the x and y position is in the horizontal scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    boolean inHorizontalScrollbar(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (hsbSpace <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        int w = width - MARGIN - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return (x >= MARGIN) && (x < w) && (y >= height - (SCROLLBAR - SPACE)) && (y < height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    private Component getScrollChild() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        ScrollPane sp = (ScrollPane)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        Component child = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            child = sp.getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        } catch (ArrayIndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            // do nothing.  in this case we return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        return child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    int vval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    int hval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    int vmax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    int hmax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Print the native component by rendering the Motif look ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * ToDo(aim): needs to query native motif for more accurate size and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * color information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        ScrollPane sp = (ScrollPane)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        Dimension d = sp.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        Color bg = sp.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        Color fg = sp.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        Point p = sp.getScrollPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        Component c = getScrollChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        Dimension cd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            cd = c.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            cd = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        int sbDisplay = sp.getScrollbarDisplayPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        int vvis, hvis, vmin, hmin, vmax, hmax, vval, hval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        switch (sbDisplay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            case ScrollPane.SCROLLBARS_NEVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                hsbSpace = vsbSpace = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            case ScrollPane.SCROLLBARS_ALWAYS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                hsbSpace = vsbSpace = SCROLLBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            case ScrollPane.SCROLLBARS_AS_NEEDED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                hsbSpace = (cd.width <= (d.width - 2*MARGIN)? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                vsbSpace = (cd.height <= (d.height - 2*MARGIN)? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                if (hsbSpace == 0 && vsbSpace != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    hsbSpace = (cd.width <= (d.width - SCROLLBAR - 2*MARGIN)? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                if (vsbSpace == 0 && hsbSpace != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    vsbSpace = (cd.height <= (d.height - SCROLLBAR - 2*MARGIN)? 0 : SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        vvis = hvis = vmin = hmin = vmax = hmax = vval = hval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (vsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            vmin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            vvis = d.height - (2*MARGIN) - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            vmax = Math.max(cd.height - vvis, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            vval = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (hsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            hmin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            hvis = d.width - (2*MARGIN) - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            hmax = Math.max(cd.width - hvis, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            hval = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        // need to be careful to add the margins back in here because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // we're drawing the margin border, after all!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        int w = d.width - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        int h = d.height - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        g.fillRect(0, 0, d.width, d.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (hsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            int sbw = d.width - vsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            g.fillRect(1, d.height - SCROLLBAR - 3, sbw - 1, SCROLLBAR - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                ng.translate(0, d.height - (SCROLLBAR - 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                drawScrollbar(ng, bg, SCROLLBAR - 2, sbw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        hmin, hmax, hval, hvis, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if (vsbSpace > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            int sbh = d.height - hsbSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            g.fillRect(d.width - SCROLLBAR - 3, 1, SCROLLBAR - 3, sbh - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                ng.translate(d.width - (SCROLLBAR - 2), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                drawScrollbar(ng, bg, SCROLLBAR - 2, sbh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                        vmin, vmax, vval, vvis, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        draw3DRect(g, bg, 0, 0, w - 1, h - 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        target.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        sp.printComponents(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
}