jdk/src/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java
author yan
Thu, 05 Dec 2013 18:04:12 +0400
changeset 21982 fd6e5fe509df
parent 20458 f2423fb3fd19
child 22574 7f8ce0c8c20a
permissions -rw-r--r--
8029264: [doclint] more doclint and tidy cleanup Reviewed-by: alexsch, serb, malenkov
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) 1997, 2006, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Divider used by BasicSplitPaneUI. Subclassers may wish to override
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * paint to do something more interesting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The border effect is drawn in BasicSplitPaneUI, so if you don't like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * that border, reset it there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * To conditionally drag from certain areas subclass mousePressed and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * call super when you wish the dragging to begin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 9471
diff changeset
    56
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class BasicSplitPaneDivider extends Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    implements PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Width or height of the divider based on orientation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * BasicSplitPaneUI adds two to this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected static final int ONE_TOUCH_SIZE = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected static final int ONE_TOUCH_OFFSET = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Handles mouse dragging message to do the actual dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected DragController dragger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * UI this instance was created from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected BasicSplitPaneUI splitPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Size of the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected int dividerSize = 0; // default - SET TO 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
     * Divider that is used for noncontinuous layout mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected Component hiddenDivider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * JSplitPane the receiver is contained in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected JSplitPane splitPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Handles mouse events from both this class, and the split pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Mouse events are handled for the splitpane since you want to be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * to drag when clicking on the border of the divider, which is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * drawn by the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected MouseHandler mouseHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Orientation of the JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected int orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Button for quickly toggling the left component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected JButton leftButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Button for quickly toggling the right component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    protected JButton rightButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /** Border. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private Border border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Is the mouse over the divider?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private boolean mouseOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private int oneTouchSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private int oneTouchOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * If true the one touch buttons are centered on the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private boolean centerOneTouchButtons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Creates an instance of BasicSplitPaneDivider. Registers this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * instance for mouse events and mouse dragged events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public BasicSplitPaneDivider(BasicSplitPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                "SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                "SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                 ui, "SplitPane.centerOneTouchButtons", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        setLayout(new DividerLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        setBasicSplitPaneUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        orientation = splitPane.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                  Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                  Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        setBackground(UIManager.getColor("SplitPane.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 5506
diff changeset
   157
    private void revalidateSplitPane() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            splitPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Sets the SplitPaneUI that is using the receiver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            splitPane.removePropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
           if (mouseHandler != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
               splitPane.removeMouseListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
               splitPane.removeMouseMotionListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
               removeMouseListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
               removeMouseMotionListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
               mouseHandler = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        splitPaneUI = newUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (newUI != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            splitPane = newUI.getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                if (mouseHandler == null) mouseHandler = new MouseHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                splitPane.addMouseListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                splitPane.addMouseMotionListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                addMouseListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                addMouseMotionListener(mouseHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                splitPane.addPropertyChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                if (splitPane.isOneTouchExpandable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    oneTouchExpandableChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            splitPane = 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns the <code>SplitPaneUI</code> the receiver is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public BasicSplitPaneUI getBasicSplitPaneUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return splitPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Sets the size of the divider to <code>newSize</code>. That is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * the width if the splitpane is <code>HORIZONTAL_SPLIT</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * the height of <code>VERTICAL_SPLIT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void setDividerSize(int newSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        dividerSize = newSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the size of the divider, that is the width if the splitpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * is HORIZONTAL_SPLIT, or the height of VERTICAL_SPLIT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int getDividerSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return dividerSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Sets the border of this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void setBorder(Border border) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Border         oldBorder = this.border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        this.border = border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Returns the border of this component or null if no border is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * currently set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return the border object for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public Border getBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * If a border has been set on this component, returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * border's insets, else calls super.getInsets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return the value of the insets property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #setBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        Border    border = getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            return border.getBorderInsets(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return super.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Sets whether or not the mouse is currently over the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param mouseOver whether or not the mouse is currently over the divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    protected void setMouseOver(boolean mouseOver) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        this.mouseOver = mouseOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns whether or not the mouse is currently over the divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return whether or not the mouse is currently over the divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public boolean isMouseOver() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return mouseOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Returns dividerSize x dividerSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // Ideally this would return the size from the layout manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // but that could result in the layed out size being different from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // the dividerSize, which may break developers as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return new Dimension(getDividerSize(), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return new Dimension(1, getDividerSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Returns dividerSize x dividerSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Property change event, presumably from the JSplitPane, will message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * updateOrientation if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (e.getSource() == splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                orientation = splitPane.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                          Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                          Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 5506
diff changeset
   318
                revalidateSplitPane();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            else if (e.getPropertyName() == JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                      ONE_TOUCH_EXPANDABLE_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                oneTouchExpandableChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Paints the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      // Paint the border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      Border   border = getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
          Dimension     size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
          border.paintBorder(this, g, 0, 0, size.width, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Messaged when the oneTouchExpandable value of the JSplitPane the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * receiver is contained in changes. Will create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * <code>leftButton</code> and <code>rightButton</code> if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * are null. invalidates the receiver as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    protected void oneTouchExpandableChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (!DefaultLookup.getBoolean(splitPane, splitPaneUI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                           "SplitPane.supportsOneTouchButtons", true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            // Look and feel doesn't want to support one touch buttons, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (splitPane.isOneTouchExpandable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            leftButton == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            rightButton == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            /* Create the left button and add an action listener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
               expand/collapse it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            leftButton = createLeftOneTouchButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (leftButton != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                leftButton.addActionListener(new OneTouchActionHandler(true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            /* Create the right button and add an action listener to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
               expand/collapse it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            rightButton = createRightOneTouchButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (rightButton != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                rightButton.addActionListener(new OneTouchActionHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    (false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (leftButton != null && rightButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                add(leftButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                add(rightButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents: 5506
diff changeset
   379
        revalidateSplitPane();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Creates and return an instance of JButton that can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * collapse the left component in the split pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    protected JButton createLeftOneTouchButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        JButton b = new JButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            public void setBorder(Border b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    int[]   xs = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    int[]   ys = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    int     blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    // Fill the background first ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    g.setColor(this.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    g.fillRect(0, 0, this.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                               this.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    // ... then draw the arrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                        blockSize = Math.min(getHeight(), oneTouchSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        xs[0] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        xs[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                        xs[2] = blockSize << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                        ys[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                        ys[1] = ys[2] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        g.drawPolygon(xs, ys, 3); // Little trick to make the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                                  // arrows of equal size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        blockSize = Math.min(getWidth(), oneTouchSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        xs[0] = xs[2] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        xs[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                        ys[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                        ys[1] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        ys[2] = blockSize << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    g.fillPolygon(xs, ys, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            // Don't want the button to participate in focus traversable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        b.setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        b.setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        b.setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return b;
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
     * Creates and return an instance of JButton that can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * collapse the right component in the split pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    protected JButton createRightOneTouchButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        JButton b = new JButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            public void setBorder(Border border) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    int[]          xs = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    int[]          ys = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    int            blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    // Fill the background first ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    g.setColor(this.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    g.fillRect(0, 0, this.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                               this.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    // ... then draw the arrow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        blockSize = Math.min(getHeight(), oneTouchSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                        xs[0] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        xs[1] = blockSize << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        xs[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        ys[0] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        ys[1] = ys[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        blockSize = Math.min(getWidth(), oneTouchSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        xs[0] = xs[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        xs[1] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        ys[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        ys[1] = blockSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        ys[2] = blockSize << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    g.fillPolygon(xs, ys, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            // Don't want the button to participate in focus traversable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        b.setFocusPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        b.setBorderPainted(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        b.setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Message to prepare for dragging. This messages the BasicSplitPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * with startDragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    protected void prepareForDragging() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        splitPaneUI.startDragging();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Messages the BasicSplitPaneUI with dragDividerTo that this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * is contained in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    protected void dragDividerTo(int location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        splitPaneUI.dragDividerTo(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Messages the BasicSplitPaneUI with finishDraggingTo that this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * is contained in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    protected void finishDraggingTo(int location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        splitPaneUI.finishDraggingTo(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * MouseHandler is responsible for converting mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * (released, dragged...) into the appropriate DragController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * methods.
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   524
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    protected class MouseHandler extends MouseAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            implements MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         * Starts the dragging session by creating the appropriate instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         * of DragController.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            if ((e.getSource() == BasicSplitPaneDivider.this ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                 e.getSource() == splitPane) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                dragger == null &&splitPane.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                Component            newHiddenDivider = splitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                     getNonContinuousLayoutDivider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                if (hiddenDivider != newHiddenDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    if (hiddenDivider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                        hiddenDivider.removeMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                        hiddenDivider.removeMouseMotionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    hiddenDivider = newHiddenDivider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    if (hiddenDivider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        hiddenDivider.addMouseMotionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        hiddenDivider.addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                if (splitPane.getLeftComponent() != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    splitPane.getRightComponent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        dragger = new DragController(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        dragger = new VerticalDragController(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    if (!dragger.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        dragger = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                        prepareForDragging();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        dragger.continueDrag(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         * If dragger is not null it is messaged with completeDrag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            if (dragger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                if (e.getSource() == splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    dragger.completeDrag(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                else if (e.getSource() == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    Point   ourLoc = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    dragger.completeDrag(e.getX() + ourLoc.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                         e.getY() + ourLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                else if (e.getSource() == hiddenDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    Point   hDividerLoc = hiddenDivider.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    int     ourX = e.getX() + hDividerLoc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    int     ourY = e.getY() + hDividerLoc.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    dragger.completeDrag(ourX, ourY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                dragger = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        // MouseMotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         * If dragger is not null it is messaged with continueDrag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (dragger != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                if (e.getSource() == splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    dragger.continueDrag(e.getX(), e.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                else if (e.getSource() == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    Point   ourLoc = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    dragger.continueDrag(e.getX() + ourLoc.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                         e.getY() + ourLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                else if (e.getSource() == hiddenDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    Point   hDividerLoc = hiddenDivider.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    int     ourX = e.getX() + hDividerLoc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    int     ourY = e.getY() + hDividerLoc.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    dragger.continueDrag(ourX, ourY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         *  Resets the cursor based on the orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        public void mouseMoved(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         * Invoked when the mouse enters a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         * @param e MouseEvent describing the details of the enter event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            if (e.getSource() == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                setMouseOver(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * Invoked when the mouse exits a component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * @param e MouseEvent describing the details of the exit event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            if (e.getSource() == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                setMouseOver(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Handles the events during a dragging session for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * HORIZONTAL_SPLIT oriented split pane. This continually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * messages <code>dragDividerTo</code> and then when done messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <code>finishDraggingTo</code>. When an instance is created it should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * messaged with <code>isValid</code> to insure that dragging can happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * (dragging won't be allowed if the two views can not be resized).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 9471
diff changeset
   674
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    protected class DragController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
         * Initial location of the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        int initialX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         * Maximum and minimum positions to drag to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        int maxX, minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
         * Initial location the mouse down happened at.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        protected DragController(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            JSplitPane  splitPane = splitPaneUI.getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            Component   leftC = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            Component   rightC = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            initialX = getLocation().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (e.getSource() == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                offset = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            else { // splitPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                offset = e.getX() - initialX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if (leftC == null || rightC == null || offset < -1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                offset >= getSize().width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                // Don't allow dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                maxX = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                Insets      insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                if (leftC.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    minX = leftC.getMinimumSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                        minX += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    minX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                if (rightC.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    int right = (insets != null) ? insets.right : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                    maxX = Math.max(0, splitPane.getSize().width -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                                    (getSize().width + right) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                                    rightC.getMinimumSize().width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    int right = (insets != null) ? insets.right : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    maxX = Math.max(0, splitPane.getSize().width -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                                    (getSize().width + right));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                if (maxX < minX) minX = maxX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         * Returns true if the dragging session is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        protected boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            return (maxX > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         * Returns the new position to put the divider at based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         * the passed in MouseEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        protected int positionForMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            int newX = (e.getSource() == BasicSplitPaneDivider.this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                        (e.getX() + getLocation().x) : e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            newX = Math.min(maxX, Math.max(minX, newX - offset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            return newX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         * Returns the x argument, since this is used for horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         * splits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        protected int getNeededLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            int newX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            newX = Math.min(maxX, Math.max(minX, x - offset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            return newX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        protected void continueDrag(int newX, int newY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            dragDividerTo(getNeededLocation(newX, newY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * Messages dragDividerTo with the new location for the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        protected void continueDrag(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            dragDividerTo(positionForMouseEvent(e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        protected void completeDrag(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            finishDraggingTo(getNeededLocation(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         * Messages finishDraggingTo with the new location for the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         * event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        protected void completeDrag(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            finishDraggingTo(positionForMouseEvent(e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    } // End of BasicSplitPaneDivider.DragController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * Handles the events during a dragging session for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * VERTICAL_SPLIT oriented split pane. This continually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * messages <code>dragDividerTo</code> and then when done messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * <code>finishDraggingTo</code>. When an instance is created it should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * messaged with <code>isValid</code> to insure that dragging can happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * (dragging won't be allowed if the two views can not be resized).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    protected class VerticalDragController extends DragController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        /* DragControllers ivars are now in terms of y, not x. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        protected VerticalDragController(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            super(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            JSplitPane splitPane = splitPaneUI.getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            Component  leftC = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            Component  rightC = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            initialX = getLocation().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            if (e.getSource() == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                offset = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                offset = e.getY() - initialX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            if (leftC == null || rightC == null || offset < -1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                offset > getSize().height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                // Don't allow dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                maxX = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                Insets     insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                if (leftC.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    minX = leftC.getMinimumSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                        minX += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    minX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                if (rightC.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                    int    bottom = (insets != null) ? insets.bottom : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    maxX = Math.max(0, splitPane.getSize().height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                                    (getSize().height + bottom) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                                    rightC.getMinimumSize().height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                    int    bottom = (insets != null) ? insets.bottom : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    maxX = Math.max(0, splitPane.getSize().height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                                    (getSize().height + bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                if (maxX < minX) minX = maxX = 0;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
         * Returns the y argument, since this is used for vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * splits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        protected int getNeededLocation(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            int newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            newY = Math.min(maxX, Math.max(minX, y - offset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            return newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         * Returns the new position to put the divider at based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         * the passed in MouseEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        protected int positionForMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            int newY = (e.getSource() == BasicSplitPaneDivider.this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                        (e.getY() + getLocation().y) : e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            newY = Math.min(maxX, Math.max(minX, newY - offset));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            return newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    } // End of BasicSplitPaneDividier.VerticalDragController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * Used to layout a <code>BasicSplitPaneDivider</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Layout for the divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * involves appropriately moving the left/right buttons around.
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
   893
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    protected class DividerLayout implements LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            if (leftButton != null && rightButton != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                c == BasicSplitPaneDivider.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                if (splitPane.isOneTouchExpandable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                    Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                    if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                        int extraX = (insets != null) ? insets.left : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                        int blockSize = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                        if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                            blockSize -= (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                            blockSize = Math.max(blockSize, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                        blockSize = Math.min(blockSize, oneTouchSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        int y = (c.getSize().height - blockSize) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                        if (!centerOneTouchButtons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                            y = (insets != null) ? insets.top : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                            extraX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                        leftButton.setBounds(extraX + oneTouchOffset, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                             blockSize * 2, blockSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                        rightButton.setBounds(extraX + oneTouchOffset +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                                              oneTouchSize * 2, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                                              blockSize * 2, blockSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        int extraY = (insets != null) ? insets.top : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                        int blockSize = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                        if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                            blockSize -= (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                            blockSize = Math.max(blockSize, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                        blockSize = Math.min(blockSize, oneTouchSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                        int x = (c.getSize().width - blockSize) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                        if (!centerOneTouchButtons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                            x = (insets != null) ? insets.left : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                            extraY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                        leftButton.setBounds(x, extraY + oneTouchOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                                             blockSize, blockSize * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                        rightButton.setBounds(x, extraY + oneTouchOffset +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                                              oneTouchSize * 2, blockSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                                              blockSize * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                    leftButton.setBounds(-5, -5, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    rightButton.setBounds(-5, -5, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            // NOTE: This isn't really used, refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            // BasicSplitPaneDivider.getPreferredSize for the reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            // I leave it in hopes of having this used at some point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            if (c != BasicSplitPaneDivider.this || splitPane == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                return new Dimension(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            Dimension buttonMinSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            if (splitPane.isOneTouchExpandable() && leftButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                buttonMinSize = leftButton.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            int width = getDividerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            int height = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                if (buttonMinSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    int size = buttonMinSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        size += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                    height = Math.max(height, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                if (buttonMinSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                    int size = buttonMinSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    if (insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                        size += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    width = Math.max(width, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                height = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        public Dimension preferredLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        public void addLayoutComponent(String string, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    } // End of class BasicSplitPaneDivider.DividerLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * Listeners installed on the one touch expandable buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    private class OneTouchActionHandler implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        /** True indicates the resize should go the minimum (top or left)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
         * vs false which indicates the resize should go to the maximum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        private boolean toMinimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        OneTouchActionHandler(boolean toMinimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            this.toMinimum = toMinimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            Insets  insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            int     lastLoc = splitPane.getLastDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            int     currentLoc = splitPaneUI.getDividerLocation(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            int     newLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            // We use the location from the UI directly, as the location the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            // JSplitPane itself maintains is not necessarly correct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            if (toMinimum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                    if (currentLoc >= (splitPane.getHeight() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                       insets.bottom - getHeight())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                        int maxLoc = splitPane.getMaximumDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                        newLoc = Math.min(lastLoc, maxLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                        splitPaneUI.setKeepHidden(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                        newLoc = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                        splitPaneUI.setKeepHidden(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                    if (currentLoc >= (splitPane.getWidth() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                       insets.right - getWidth())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                        int maxLoc = splitPane.getMaximumDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                        newLoc = Math.min(lastLoc, maxLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                        splitPaneUI.setKeepHidden(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                        newLoc = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                        splitPaneUI.setKeepHidden(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    if (currentLoc == insets.top) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                        int maxLoc = splitPane.getMaximumDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                        newLoc = Math.min(lastLoc, maxLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                        splitPaneUI.setKeepHidden(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                        newLoc = splitPane.getHeight() - getHeight() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                                 insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                        splitPaneUI.setKeepHidden(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                    if (currentLoc == insets.left) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                        int maxLoc = splitPane.getMaximumDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                        newLoc = Math.min(lastLoc, maxLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                        splitPaneUI.setKeepHidden(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                        newLoc = splitPane.getWidth() - getWidth() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                                 insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                        splitPaneUI.setKeepHidden(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            if (currentLoc != newLoc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                splitPane.setDividerLocation(newLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                // We do this in case the dividers notion of the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                // differs from the real location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                splitPane.setLastDividerLocation(currentLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    } // End of class BasicSplitPaneDivider.LeftActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
}