jdk/src/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8148 ff3d90bb0503
child 20169 d7fa6d7586c9
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8148
diff changeset
     2
 * Copyright (c) 1997, 2011, 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: 4394
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: 4394
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: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
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
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.swing.UIAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.peer.LightweightPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.SplitPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * A Basic L&F implementation of the SplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Ralph Kar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class BasicSplitPaneUI extends SplitPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The divider used for non-continuous layout is added to the split pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected static final String NON_CONTINUOUS_DIVIDER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "nonContinuousDivider";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * How far (relative) the divider does move when it is moved around by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * the cursor keys on the keyboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected static int KEYBOARD_DIVIDER_MOVE_OFFSET = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * JSplitPane instance this instance is providing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * the look and feel for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected JSplitPane splitPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * LayoutManager that is created and placed into the split pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected BasicHorizontalLayoutManager layoutManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Instance of the divider for this JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected BasicSplitPaneDivider divider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Instance of the PropertyChangeListener for this JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected PropertyChangeListener propertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Instance of the FocusListener for this JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected FocusListener focusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Handler handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Keys to use for forward focus traversal when the JComponent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * managing focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 2658
diff changeset
   107
    private Set<KeyStroke> managingFocusForwardTraversalKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Keys to use for backward focus traversal when the JComponent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * managing focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 2658
diff changeset
   113
    private Set<KeyStroke> managingFocusBackwardTraversalKeys;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * The size of the divider while the dragging session is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected int dividerSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Instance for the shadow of the divider when non continuous layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * is being used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected Component nonContinuousLayoutDivider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Set to true in startDragging if any of the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * (not including the nonContinuousLayoutDivider) are heavy weights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    protected boolean draggingHW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Location of the divider when the dragging session began.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected int beginDragDividerLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected KeyStroke upKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected KeyStroke downKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected KeyStroke leftKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    protected KeyStroke rightKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    protected KeyStroke homeKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    protected KeyStroke endKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    protected KeyStroke dividerResizeToggleKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected ActionListener keyboardUpLeftListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    protected ActionListener keyboardDownRightListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected ActionListener keyboardHomeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected ActionListener keyboardEndListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * As of Java 2 platform v1.3 this previously undocumented field is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Key bindings are now defined by the LookAndFeel, please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    protected ActionListener keyboardResizeToggleListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    // Private data of the instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private int         orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private int         lastDragLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private boolean     continuousLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    private boolean     dividerKeyboardResize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private boolean     dividerLocationIsSet;  // needed for tracking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                               // the first occurrence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                               // setDividerLocation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private Color dividerDraggingColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private boolean rememberPaneSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    // Indicates wether the one of splitpane sides is expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private boolean keepHidden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /** Indicates that we have painted once. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    // This is used by the LayoutManager to determine when it should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    // the divider location provided by the JSplitPane. This is used as there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    // is no way to determine when the layout process has completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    boolean             painted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /** If true, setDividerLocation does nothing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    boolean             ignoreDividerLocationChange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Creates a new BasicSplitPaneUI instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public static ComponentUI createUI(JComponent x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return new BasicSplitPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    static void loadActionMap(LazyActionMap map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        map.put(new Actions(Actions.NEGATIVE_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        map.put(new Actions(Actions.POSITIVE_INCREMENT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        map.put(new Actions(Actions.SELECT_MIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        map.put(new Actions(Actions.SELECT_MAX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        map.put(new Actions(Actions.START_RESIZE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        map.put(new Actions(Actions.TOGGLE_FOCUS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        map.put(new Actions(Actions.FOCUS_OUT_FORWARD));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        map.put(new Actions(Actions.FOCUS_OUT_BACKWARD));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Installs the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        splitPane = (JSplitPane) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        dividerLocationIsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        dividerKeyboardResize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        keepHidden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        setLastDragLocation(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Installs the UI defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    protected void installDefaults(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        LookAndFeel.installBorder(splitPane, "SplitPane.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        LookAndFeel.installColors(splitPane, "SplitPane.background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                  "SplitPane.foreground");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        LookAndFeel.installProperty(splitPane, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (divider == null) divider = createDefaultDivider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        divider.setBasicSplitPaneUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        Border    b = divider.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (b == null || !(b instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            divider.setBorder(UIManager.getBorder("SplitPaneDivider.border"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        dividerDraggingColor = UIManager.getColor("SplitPaneDivider.draggingColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        setOrientation(splitPane.getOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
8148
ff3d90bb0503 6979537: closed/javax/swing/JSplitPane/UnitTest/UnitTest.java fails
alexp
parents: 5506
diff changeset
   345
        // note: don't rename this temp variable to dividerSize
ff3d90bb0503 6979537: closed/javax/swing/JSplitPane/UnitTest/UnitTest.java fails
alexp
parents: 5506
diff changeset
   346
        // since it will conflict with "this.dividerSize" field
ff3d90bb0503 6979537: closed/javax/swing/JSplitPane/UnitTest/UnitTest.java fails
alexp
parents: 5506
diff changeset
   347
        Integer temp = (Integer)UIManager.get("SplitPane.dividerSize");
ff3d90bb0503 6979537: closed/javax/swing/JSplitPane/UnitTest/UnitTest.java fails
alexp
parents: 5506
diff changeset
   348
        LookAndFeel.installProperty(splitPane, "dividerSize", temp == null? 10: temp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        divider.setDividerSize(splitPane.getDividerSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        dividerSize = divider.getDividerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        splitPane.add(divider, JSplitPane.DIVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        setContinuousLayout(splitPane.isContinuousLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        resetLayoutManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        /* Install the nonContinuousLayoutDivider here to avoid having to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        add/remove everything later. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if(nonContinuousLayoutDivider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            setNonContinuousLayoutDivider(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                createDefaultNonContinuousLayoutDivider(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        // focus forward traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (managingFocusForwardTraversalKeys==null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   370
            managingFocusForwardTraversalKeys = new HashSet<KeyStroke>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            managingFocusForwardTraversalKeys.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                        managingFocusForwardTraversalKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // focus backward traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (managingFocusBackwardTraversalKeys==null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   378
            managingFocusBackwardTraversalKeys = new HashSet<KeyStroke>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            managingFocusBackwardTraversalKeys.add(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                        managingFocusBackwardTraversalKeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Installs the event listeners for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if ((propertyChangeListener = createPropertyChangeListener()) !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            splitPane.addPropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if ((focusListener = createFocusListener()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            splitPane.addFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Installs the keyboard actions for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        InputMap km = getInputMap(JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                                  WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        SwingUtilities.replaceUIInputMap(splitPane, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                                       WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                       km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        LazyActionMap.installLazyActionMap(splitPane, BasicSplitPaneUI.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                           "SplitPane.actionMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    InputMap getInputMap(int condition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            return (InputMap)DefaultLookup.get(splitPane, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                               "SplitPane.ancestorInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Uninstalls the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        dividerLocationIsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        dividerKeyboardResize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        splitPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Uninstalls the UI defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if(splitPane.getLayout() == layoutManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            splitPane.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if(nonContinuousLayoutDivider != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            splitPane.remove(nonContinuousLayoutDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        LookAndFeel.uninstallBorder(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        Border    b = divider.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (b instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            divider.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        splitPane.remove(divider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        divider.setBasicSplitPaneUI(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        layoutManager = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        divider = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        nonContinuousLayoutDivider = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        setNonContinuousLayoutDivider(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        // sets the focus forward and backward traversal keys to null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        // to restore the defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Uninstalls the event listeners for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (propertyChangeListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            splitPane.removePropertyChangeListener(propertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            propertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (focusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            splitPane.removeFocusListener(focusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            focusListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        keyboardUpLeftListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        keyboardDownRightListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        keyboardHomeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        keyboardEndListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        keyboardResizeToggleListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        handler = null;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Uninstalls the keyboard actions for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    protected void uninstallKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        SwingUtilities.replaceUIActionMap(splitPane, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        SwingUtilities.replaceUIInputMap(splitPane, JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                      WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                      null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Creates a PropertyChangeListener for the JSplitPane UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    protected PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    private Handler getHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (handler == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return handler;
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
     * Creates a FocusListener for the JSplitPane UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    protected FocusListener createFocusListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return getHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * As of Java 2 platform v1.3 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * longer used. Subclassers previously using this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * instead create an Action wrapping the ActionListener, and register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * that Action by overriding <code>installKeyboardActions</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * placing the Action in the SplitPane's ActionMap. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Creates a ActionListener for the JSplitPane UI that listens for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    protected ActionListener createKeyboardUpLeftListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return new KeyboardUpLeftHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * As of Java 2 platform v1.3 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * longer used. Subclassers previously using this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * instead create an Action wrapping the ActionListener, and register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * that Action by overriding <code>installKeyboardActions</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * placing the Action in the SplitPane's ActionMap. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Creates a ActionListener for the JSplitPane UI that listens for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    protected ActionListener createKeyboardDownRightListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return new KeyboardDownRightHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * As of Java 2 platform v1.3 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * longer used. Subclassers previously using this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * instead create an Action wrapping the ActionListener, and register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * that Action by overriding <code>installKeyboardActions</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * placing the Action in the SplitPane's ActionMap. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * Creates a ActionListener for the JSplitPane UI that listens for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    protected ActionListener createKeyboardHomeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return new KeyboardHomeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * As of Java 2 platform v1.3 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * longer used. Subclassers previously using this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * instead create an Action wrapping the ActionListener, and register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * that Action by overriding <code>installKeyboardActions</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * placing the Action in the SplitPane's ActionMap. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Creates a ActionListener for the JSplitPane UI that listens for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    protected ActionListener createKeyboardEndListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        return new KeyboardEndHandler();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * As of Java 2 platform v1.3 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * longer used. Subclassers previously using this method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * instead create an Action wrapping the ActionListener, and register
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * that Action by overriding <code>installKeyboardActions</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * placing the Action in the SplitPane's ActionMap. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * Creates a ActionListener for the JSplitPane UI that listens for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    protected ActionListener createKeyboardResizeToggleListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        return new KeyboardResizeToggleHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Returns the orientation for the JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public int getOrientation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        return orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Set the orientation for the JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    public void setOrientation(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        this.orientation = orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Determines wether the JSplitPane is set to use a continuous layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public boolean isContinuousLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return continuousLayout;
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
     * Turn continuous layout on/off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public void setContinuousLayout(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        continuousLayout = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Returns the last drag location of the JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    public int getLastDragLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        return lastDragLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * Set the last drag location of the JSplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public void setLastDragLocation(int l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        lastDragLocation = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @return increment via keyboard methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    int getKeyboardMoveIncrement() {
4199
151e13fd2df1 6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents: 2658
diff changeset
   674
        return 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Implementation of the PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * that the JSplitPane UI uses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public class PropertyHandler implements PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         * Messaged from the <code>JSplitPane</code> the receiver is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
         * contained in.  May potentially reset the layout manager and cause a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * <code>validate</code> to be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            getHandler().propertyChange(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Implementation of the FocusListener that the JSplitPane UI uses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public class FocusHandler extends FocusAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        // NOTE: This class exists only for backward compatability. All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        // its functionality has been moved into Handler. If you need to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // new functionality add it to the Handler, but make sure this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        // class calls into the Handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        public void focusGained(FocusEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            getHandler().focusGained(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        public void focusLost(FocusEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            getHandler().focusLost(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * Implementation of an ActionListener that the JSplitPane UI uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * handling specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    public class KeyboardUpLeftHandler implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if (dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                splitPane.setDividerLocation(Math.max(0,getDividerLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                  (splitPane) - getKeyboardMoveIncrement()));
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
     * Implementation of an ActionListener that the JSplitPane UI uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * handling specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public class KeyboardDownRightHandler implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            if (dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                splitPane.setDividerLocation(getDividerLocation(splitPane) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                             getKeyboardMoveIncrement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * Implementation of an ActionListener that the JSplitPane UI uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * handling specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public class KeyboardHomeHandler implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            if (dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                splitPane.setDividerLocation(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * Implementation of an ActionListener that the JSplitPane UI uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * handling specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public class KeyboardEndHandler implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            if (dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                Insets   insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                int      bottomI = (insets != null) ? insets.bottom : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                int      rightI = (insets != null) ? insets.right : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                if (orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    splitPane.setDividerLocation(splitPane.getHeight() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                                       bottomI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                    splitPane.setDividerLocation(splitPane.getWidth() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                                                 rightI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * Implementation of an ActionListener that the JSplitPane UI uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * handling specific key presses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * Instantiate it only within subclasses of BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    public class KeyboardResizeToggleHandler implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            if (!dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                splitPane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * Returns the divider between the top Components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    public BasicSplitPaneDivider getDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return divider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Returns the default non continuous layout divider, which is an
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4199
diff changeset
   830
     * instance of {@code Canvas} that fills in the background with dark gray.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    protected Component createDefaultNonContinuousLayoutDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return new Canvas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                if(!isContinuousLayout() && getLastDragLocation() != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    Dimension      size = splitPane.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    g.setColor(dividerDraggingColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                        g.fillRect(0, 0, dividerSize - 1, size.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                        g.fillRect(0, 0, size.width - 1, dividerSize - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Sets the divider to use when the splitPane is configured to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * not continuously layout. This divider will only be used during a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * dragging session. It is recommended that the passed in component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * be a heavy weight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    protected void setNonContinuousLayoutDivider(Component newDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        setNonContinuousLayoutDivider(newDivider, true);
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
     * Sets the divider to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    protected void setNonContinuousLayoutDivider(Component newDivider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        boolean rememberSizes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        rememberPaneSizes = rememberSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if(nonContinuousLayoutDivider != null && splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            splitPane.remove(nonContinuousLayoutDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        nonContinuousLayoutDivider = newDivider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    private void addHeavyweightDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if(nonContinuousLayoutDivider != null && splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            /* Needs to remove all the components and re-add them! YECK! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            // This is all done so that the nonContinuousLayoutDivider will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            // be drawn on top of the other components, without this, one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            // of the heavyweights will draw over the divider!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            Component             leftC = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            Component             rightC = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            int                   lastLocation = splitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                              getDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            if(leftC != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                splitPane.setLeftComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            if(rightC != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                splitPane.setRightComponent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            splitPane.remove(divider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            splitPane.add(nonContinuousLayoutDivider, BasicSplitPaneUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                          NON_CONTINUOUS_DIVIDER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                          splitPane.getComponentCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            splitPane.setLeftComponent(leftC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            splitPane.setRightComponent(rightC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            splitPane.add(divider, JSplitPane.DIVIDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            if(rememberPaneSizes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                splitPane.setDividerLocation(lastLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * Returns the divider to use when the splitPane is configured to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * not continuously layout. This divider will only be used during a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * dragging session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    public Component getNonContinuousLayoutDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        return nonContinuousLayoutDivider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Returns the splitpane this instance is currently contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    public JSplitPane getSplitPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        return splitPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * Creates the default divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    public BasicSplitPaneDivider createDefaultDivider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        return new BasicSplitPaneDivider(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Messaged to reset the preferred sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    public void resetToPreferredSizes(JSplitPane jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if(splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            layoutManager.resetToPreferredSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            splitPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            splitPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * Sets the location of the divider to location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    public void setDividerLocation(JSplitPane jc, int location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if (!ignoreDividerLocationChange) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            dividerLocationIsSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            splitPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            splitPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            if (keepHidden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                Insets insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                int orientation = splitPane.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                if ((orientation == JSplitPane.VERTICAL_SPLIT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                     location != insets.top &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                     location != splitPane.getHeight()-divider.getHeight()-insets.top) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                    (orientation == JSplitPane.HORIZONTAL_SPLIT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                     location != insets.left &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                     location != splitPane.getWidth()-divider.getWidth()-insets.left)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                    setKeepHidden(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            ignoreDividerLocationChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Returns the location of the divider, which may differ from what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * the splitpane thinks the location of the divider is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    public int getDividerLocation(JSplitPane jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        if(orientation == JSplitPane.HORIZONTAL_SPLIT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            return divider.getLocation().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        return divider.getLocation().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * Gets the minimum location of the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public int getMinimumDividerLocation(JSplitPane jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        int       minLoc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        Component leftC = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        if ((leftC != null) && (leftC.isVisible())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            Insets    insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            Dimension minSize = leftC.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                minLoc = minSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                minLoc = minSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                    minLoc += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    minLoc += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        return minLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
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
     * Gets the maximum location of the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    public int getMaximumDividerLocation(JSplitPane jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        Dimension splitPaneSize = splitPane.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        int       maxLoc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        Component rightC = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (rightC != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            Insets    insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            Dimension minSize = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            if (rightC.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                minSize = rightC.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                maxLoc = splitPaneSize.width - minSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                maxLoc = splitPaneSize.height - minSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            maxLoc -= dividerSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                    maxLoc -= insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    maxLoc -= insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        return Math.max(getMinimumDividerLocation(splitPane), maxLoc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4199
diff changeset
  1042
     * Called when the specified split pane has finished painting
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4199
diff changeset
  1043
     * its children.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4199
diff changeset
  1045
    public void finishedPaintingChildren(JSplitPane sp, Graphics g) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4199
diff changeset
  1046
        if(sp == splitPane && getLastDragLocation() != -1 &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
           !isContinuousLayout() && !draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            Dimension      size = splitPane.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            g.setColor(dividerDraggingColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                g.fillRect(getLastDragLocation(), 0, dividerSize - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                           size.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                g.fillRect(0, lastDragLocation, size.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                           dividerSize - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 4199
diff changeset
  1063
     * @inheritDoc
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public void paint(Graphics g, JComponent jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        if (!painted && splitPane.getDividerLocation()<0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            ignoreDividerLocationChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            splitPane.setDividerLocation(getDividerLocation(splitPane));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        painted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * Returns the preferred size for the passed in component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * This is passed off to the current layoutmanager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    public Dimension getPreferredSize(JComponent jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        if(splitPane != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            return layoutManager.preferredLayoutSize(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * Returns the minimum size for the passed in component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * This is passed off to the current layoutmanager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    public Dimension getMinimumSize(JComponent jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if(splitPane != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            return layoutManager.minimumLayoutSize(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * Returns the maximum size for the passed in component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * This is passed off to the current layoutmanager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    public Dimension getMaximumSize(JComponent jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        if(splitPane != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            return layoutManager.maximumLayoutSize(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        return new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * Returns the insets. The insets are returned from the border insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * of the current border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    public Insets getInsets(JComponent jc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * Resets the layout manager based on orientation and messages it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * with invalidateLayout to pull in appropriate Components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    protected void resetLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            layoutManager = new BasicHorizontalLayoutManager(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            layoutManager = new BasicHorizontalLayoutManager(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        splitPane.setLayout(layoutManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        layoutManager.updateComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        splitPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        splitPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * Set the value to indicate if one of the splitpane sides is expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    void setKeepHidden(boolean keepHidden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        this.keepHidden = keepHidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * The value returned indicates if one of the splitpane sides is expanded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @return true if one of the splitpane sides is expanded, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    private boolean getKeepHidden() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        return keepHidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * Should be messaged before the dragging session starts, resets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * lastDragLocation and dividerSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    protected void startDragging() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        Component       leftC = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        Component       rightC = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        ComponentPeer   cPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        beginDragDividerLocation = getDividerLocation(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        draggingHW = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        if(leftC != null && (cPeer = leftC.getPeer()) != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
           !(cPeer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            draggingHW = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        } else if(rightC != null && (cPeer = rightC.getPeer()) != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                  && !(cPeer instanceof LightweightPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            draggingHW = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            setLastDragLocation(divider.getBounds().x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            dividerSize = divider.getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            if(!isContinuousLayout() && draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                nonContinuousLayoutDivider.setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                        (getLastDragLocation(), 0, dividerSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                         splitPane.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                      addHeavyweightDivider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            setLastDragLocation(divider.getBounds().y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            dividerSize = divider.getSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            if(!isContinuousLayout() && draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                nonContinuousLayoutDivider.setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                        (0, getLastDragLocation(), splitPane.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                         dividerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                      addHeavyweightDivider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * Messaged during a dragging session to move the divider to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * passed in location. If continuousLayout is true the location is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * reset and the splitPane validated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    protected void dragDividerTo(int location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        if(getLastDragLocation() != location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            if(isContinuousLayout()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                splitPane.setDividerLocation(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                setLastDragLocation(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                int lastLoc = getLastDragLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                setLastDragLocation(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    if(draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                        nonContinuousLayoutDivider.setLocation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                            getLastDragLocation(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                        int   splitHeight = splitPane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                        splitPane.repaint(lastLoc, 0, dividerSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                                          splitHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                        splitPane.repaint(location, 0, dividerSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                                          splitHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                    if(draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                        nonContinuousLayoutDivider.setLocation(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                            getLastDragLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                        int    splitWidth = splitPane.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                        splitPane.repaint(0, lastLoc, splitWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                                          dividerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                        splitPane.repaint(0, location, splitWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                                          dividerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Messaged to finish the dragging session. If not continuous display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * the dividers location will be reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    protected void finishDraggingTo(int location) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        dragDividerTo(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        setLastDragLocation(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        if(!isContinuousLayout()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            Component   leftC = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            Rectangle   leftBounds = leftC.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            if (draggingHW) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                if(orientation == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                    nonContinuousLayoutDivider.setLocation(-dividerSize, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                    nonContinuousLayoutDivider.setLocation(0, -dividerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                splitPane.remove(nonContinuousLayoutDivider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            splitPane.setDividerLocation(location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * As of Java 2 platform v1.3 this method is no longer used. Instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * you should set the border on the divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * Returns the width of one side of the divider border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * @deprecated As of Java 2 platform v1.3, instead set the border on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * divider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    protected int getDividerBorderSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * LayoutManager for JSplitPanes that have an orientation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * HORIZONTAL_SPLIT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public class BasicHorizontalLayoutManager implements LayoutManager2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        /* left, right, divider. (in this exact order) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        protected int[]         sizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        protected Component[]   components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        /** Size of the splitpane the last time laid out. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        private int             lastSplitPaneSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        /** True if resetToPreferredSizes has been invoked. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        private boolean         doReset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        /** Axis, 0 for horizontal, or 1 for veritcal. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        private int             axis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        BasicHorizontalLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            this(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        BasicHorizontalLayoutManager(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            this.axis = axis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            components = new Component[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            components[0] = components[1] = components[2] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            sizes = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        // LayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         * Does the actual layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        public void layoutContainer(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            Dimension   containerSize = container.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            // If the splitpane has a zero size then no op out of here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            // If we execute this function now, we're going to cause ourselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            // much grief.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            if (containerSize.height <= 0 || containerSize.width <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                lastSplitPaneSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            int         spDividerLocation = splitPane.getDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            Insets      insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            int         availableSize = getAvailableSize(containerSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                                                         insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            int         newSize = getSizeForPrimaryAxis(containerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            int         beginLocation = getDividerLocation(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            int         dOffset = getSizeForPrimaryAxis(insets, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            Dimension   dSize = (components[2] == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                                 components[2].getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            if ((doReset && !dividerLocationIsSet) || spDividerLocation < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                resetToPreferredSizes(availableSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            else if (lastSplitPaneSize <= 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                     availableSize == lastSplitPaneSize || !painted ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                     (dSize != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                      getSizeForPrimaryAxis(dSize) != sizes[2])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                if (dSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                    sizes[2] = getSizeForPrimaryAxis(dSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                    sizes[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                setDividerLocation(spDividerLocation - dOffset, availableSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                dividerLocationIsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            else if (availableSize != lastSplitPaneSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                distributeSpace(availableSize - lastSplitPaneSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                                getKeepHidden());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            doReset = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            dividerLocationIsSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            lastSplitPaneSize = availableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            // Reset the bounds of each component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            int nextLocation = getInitialLocation(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            int counter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            while (counter < 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                if (components[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                    components[counter].isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                    setComponentToSize(components[counter], sizes[counter],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                                       nextLocation, insets, containerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                    nextLocation += sizes[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                switch (counter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                    counter = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                    counter = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    counter = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            if (painted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                // This is tricky, there is never a good time for us
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                // to push the value to the splitpane, painted appears to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                // the best time to do it. What is really needed is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                // notification that layout has completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                int      newLocation = getDividerLocation(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                if (newLocation != (spDividerLocation - dOffset)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    int  lastLocation = splitPane.getLastDividerLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    ignoreDividerLocationChange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        splitPane.setDividerLocation(newLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        // This is not always needed, but is rather tricky
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                        // to determine when... The case this is needed for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                        // is if the user sets the divider location to some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                        // bogus value, say 0, and the actual value is 1, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                        // call to setDividerLocation(1) will preserve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                        // old value of 0, when we really want the divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                        // location value  before the call. This is needed for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                        // the one touch buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                        splitPane.setLastDividerLocation(lastLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                        ignoreDividerLocationChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
         * Adds the component at place.  Place must be one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
         * JSplitPane.LEFT, RIGHT, TOP, BOTTOM, or null (for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
         * divider).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        public void addLayoutComponent(String place, Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            boolean isValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            if(place != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                if(place.equals(JSplitPane.DIVIDER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                    /* Divider. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                    components[2] = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                    sizes[2] = getSizeForPrimaryAxis(component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                                                     getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                } else if(place.equals(JSplitPane.LEFT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                          place.equals(JSplitPane.TOP)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                    components[0] = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                    sizes[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                } else if(place.equals(JSplitPane.RIGHT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                          place.equals(JSplitPane.BOTTOM)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                    components[1] = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                    sizes[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                } else if(!place.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                                    BasicSplitPaneUI.NON_CONTINUOUS_DIVIDER))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                    isValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                isValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            if(!isValid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                throw new IllegalArgumentException("cannot add to layout: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                    "unknown constraint: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                    place);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            doReset = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
         * Returns the minimum size needed to contain the children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
         * The width is the sum of all the childrens min widths and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
         * the height is the largest of the childrens minimum heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        public Dimension minimumLayoutSize(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            int         minPrimary = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            int         minSecondary = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            Insets      insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            for (int counter=0; counter<3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                if(components[counter] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                    Dimension   minSize = components[counter].getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                    int         secSize = getSizeForSecondaryAxis(minSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                    minPrimary += getSizeForPrimaryAxis(minSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                    if(secSize > minSecondary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                        minSecondary = secSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                minPrimary += getSizeForPrimaryAxis(insets, true) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                              getSizeForPrimaryAxis(insets, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                minSecondary += getSizeForSecondaryAxis(insets, true) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                              getSizeForSecondaryAxis(insets, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                return new Dimension(minPrimary, minSecondary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            return new Dimension(minSecondary, minPrimary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
         * Returns the preferred size needed to contain the children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
         * The width is the sum of all the childrens preferred widths and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
         * the height is the largest of the childrens preferred heights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        public Dimension preferredLayoutSize(Container container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            int         prePrimary = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            int         preSecondary = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            Insets      insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            for(int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                if(components[counter] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                    Dimension   preSize = components[counter].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                                          getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                    int         secSize = getSizeForSecondaryAxis(preSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                    prePrimary += getSizeForPrimaryAxis(preSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                    if(secSize > preSecondary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                        preSecondary = secSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                prePrimary += getSizeForPrimaryAxis(insets, true) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                              getSizeForPrimaryAxis(insets, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                preSecondary += getSizeForSecondaryAxis(insets, true) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                              getSizeForSecondaryAxis(insets, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                return new Dimension(prePrimary, preSecondary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            return new Dimension(preSecondary, prePrimary);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         * Removes the specified component from our knowledge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        public void removeLayoutComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            for(int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                if(components[counter] == component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                    components[counter] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                    sizes[counter] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                    doReset = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        // LayoutManager2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         * Adds the specified component to the layout, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * constraint object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * @param comp the component to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         * @param constraints  where/how the component is added to the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            if ((constraints == null) || (constraints instanceof String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                addLayoutComponent((String)constraints, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                throw new IllegalArgumentException("cannot add to layout: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                                                   "constraint must be a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                                                   "string (or null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
         * Returns the alignment along the x axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
         * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
         * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        public float getLayoutAlignmentX(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            return 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
         * Returns the alignment along the y axis.  This specifies how
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
         * the component would like to be aligned relative to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
         * components.  The value should be a number between 0 and 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
         * where 0 represents alignment along the origin, 1 is aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
         * the furthest away from the origin, 0.5 is centered, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        public float getLayoutAlignmentY(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            return 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
         * Does nothing. If the developer really wants to change the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
         * size of one of the views JSplitPane.resetToPreferredSizes should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
         * be messaged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        public void invalidateLayout(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
         * Returns the maximum layout size, which is Integer.MAX_VALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
         * in both directions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        // New methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
         * Marks the receiver so that the next time this instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
         * laid out it'll ask for the preferred sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        public void resetToPreferredSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            doReset = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
         * Resets the size of the Component at the passed in location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        protected void resetSizeAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            sizes[index] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
            doReset = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
         * Sets the sizes to <code>newSizes</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        protected void setSizes(int[] newSizes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            System.arraycopy(newSizes, 0, sizes, 0, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
         * Returns the sizes of the components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        protected int[] getSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            int[]         retSizes = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            System.arraycopy(sizes, 0, retSizes, 0, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            return retSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
         * Returns the width of the passed in Components preferred size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        protected int getPreferredSizeOfComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            return getSizeForPrimaryAxis(c.getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
         * Returns the width of the passed in Components minimum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        int getMinimumSizeOfComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            return getSizeForPrimaryAxis(c.getMinimumSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
         * Returns the width of the passed in component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        protected int getSizeOfComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            return getSizeForPrimaryAxis(c.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
         * Returns the available width based on the container size and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
         * Insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        protected int getAvailableSize(Dimension containerSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                                       Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            if(insets == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                return getSizeForPrimaryAxis(containerSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            return (getSizeForPrimaryAxis(containerSize) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                    (getSizeForPrimaryAxis(insets, true) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                     getSizeForPrimaryAxis(insets, false)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
         * Returns the left inset, unless the Insets are null in which case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
         * 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        protected int getInitialLocation(Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            if(insets != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                return getSizeForPrimaryAxis(insets, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
         * Sets the width of the component c to be size, placing its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
         * x location at location, y to the insets.top and height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
         * to the containersize.height less the top and bottom insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        protected void setComponentToSize(Component c, int size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                                          int location, Insets insets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                                          Dimension containerSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            if(insets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                    c.setBounds(location, insets.top, size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                                containerSize.height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                                (insets.top + insets.bottom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                    c.setBounds(insets.left, location, containerSize.width -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                                (insets.left + insets.right), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    c.setBounds(location, 0, size, containerSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                    c.setBounds(0, location, containerSize.width, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
         * If the axis == 0, the width is returned, otherwise the height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        int getSizeForPrimaryAxis(Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
         * If the axis == 0, the width is returned, otherwise the height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        int getSizeForSecondaryAxis(Dimension size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
            return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
         * Returns a particular value of the inset identified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
         * axis and <code>isTop</code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
         *   axis isTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
         *    0    true    - left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
         *    0    false   - right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
         *    1    true    - top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
         *    1    false   - bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        int getSizeForPrimaryAxis(Insets insets, boolean isTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                if (isTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                    return insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                return insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            if (isTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                return insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            return insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
         * Returns a particular value of the inset identified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
         * axis and <code>isTop</code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
         *   axis isTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
         *    0    true    - left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
         *    0    false   - right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
         *    1    true    - top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
         *    1    false   - bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        int getSizeForSecondaryAxis(Insets insets, boolean isTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            if (axis == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                if (isTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                    return insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                return insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            if (isTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                return insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            return insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         * Determines the components. This should be called whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
         * a new instance of this is installed into an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
         * SplitPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        protected void updateComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
            comp = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
            if(components[0] != comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                components[0] = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                if(comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                    sizes[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                    sizes[0] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            comp = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            if(components[1] != comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                components[1] = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                if(comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                    sizes[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                    sizes[1] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            /* Find the divider. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            Component[] children = splitPane.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            Component   oldDivider = components[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            components[2] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            for(int counter = children.length - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                if(children[counter] != components[0] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                   children[counter] != components[1] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                   children[counter] != nonContinuousLayoutDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                    if(oldDivider != children[counter]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                        components[2] = children[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                        components[2] = oldDivider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            if(components[2] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                sizes[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                sizes[2] = getSizeForPrimaryAxis(components[2].getPreferredSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
         * Resets the size of the first component to <code>leftSize</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
         * and the right component to the remainder of the space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        void setDividerLocation(int leftSize, int availableSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
            boolean          lValid = (components[0] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                                       components[0].isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            boolean          rValid = (components[1] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                                       components[1].isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
            boolean          dValid = (components[2] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                                       components[2].isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            int              max = availableSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            if (dValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                max -= sizes[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            leftSize = Math.max(0, Math.min(leftSize, max));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            if (lValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                if (rValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                    sizes[0] = leftSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                    sizes[1] = max - leftSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    sizes[0] = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                    sizes[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            else if (rValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                sizes[1] = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                sizes[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
         * Returns an array of the minimum sizes of the components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        int[] getPreferredSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            int[]         retValue = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                if (components[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                    components[counter].isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                    retValue[counter] = getPreferredSizeOfComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                                        (components[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                    retValue[counter] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
         * Returns an array of the minimum sizes of the components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        int[] getMinimumSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            int[]         retValue = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            for (int counter = 0; counter < 2; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                if (components[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    components[counter].isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    retValue[counter] = getMinimumSizeOfComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                                        (components[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    retValue[counter] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            retValue[2] = (components[2] != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                getMinimumSizeOfComponent(components[2]) : -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
         * Resets the components to their preferred sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        void resetToPreferredSizes(int availableSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            // Set the sizes to the preferred sizes (if fits), otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            // set to min sizes and distribute any extra space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            int[]       testSizes = getPreferredSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            int         totalSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                if (testSizes[counter] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                    totalSize += testSizes[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            if (totalSize > availableSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                testSizes = getMinimumSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                totalSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                for (int counter = 0; counter < 3; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                    if (testSizes[counter] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                        totalSize += testSizes[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            setSizes(testSizes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            distributeSpace(availableSize - totalSize, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
         * Distributes <code>space</code> between the two components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
         * (divider won't get any extra space) based on the weighting. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
         * attempts to honor the min size of the components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
         * @param keepHidden if true and one of the components is 0x0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
         *                   it gets none of the extra space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        void distributeSpace(int space, boolean keepHidden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            boolean          lValid = (components[0] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                                       components[0].isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            boolean          rValid = (components[1] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                                       components[1].isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            if (keepHidden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                if (lValid && getSizeForPrimaryAxis(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                                 components[0].getSize()) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                    lValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                    if (rValid && getSizeForPrimaryAxis(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                                     components[1].getSize()) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                        // Both aren't valid, force them both to be valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                        lValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                else if (rValid && getSizeForPrimaryAxis(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                                   components[1].getSize()) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                    rValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            if (lValid && rValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                double        weight = splitPane.getResizeWeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                int           lExtra = (int)(weight * (double)space);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                int           rExtra = (space - lExtra);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                sizes[0] += lExtra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                sizes[1] += rExtra;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                int           lMin = getMinimumSizeOfComponent(components[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                int           rMin = getMinimumSizeOfComponent(components[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                boolean       lMinValid = (sizes[0] >= lMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
                boolean       rMinValid = (sizes[1] >= rMin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                if (!lMinValid && !rMinValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                    if (sizes[0] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                        sizes[1] += sizes[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                        sizes[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                    else if (sizes[1] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                        sizes[0] += sizes[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                        sizes[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                else if (!lMinValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                    if (sizes[1] - (lMin - sizes[0]) < rMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                        // both below min, just make sure > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                        if (sizes[0] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                            sizes[1] += sizes[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                            sizes[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                        sizes[1] -= (lMin - sizes[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                        sizes[0] = lMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                else if (!rMinValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                    if (sizes[0] - (rMin - sizes[1]) < lMin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                        // both below min, just make sure > 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                        if (sizes[1] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                            sizes[0] += sizes[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                            sizes[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                        sizes[0] -= (rMin - sizes[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                        sizes[1] = rMin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                if (sizes[0] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                    sizes[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                if (sizes[1] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    sizes[1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            else if (lValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                sizes[0] = Math.max(0, sizes[0] + space);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            else if (rValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                sizes[1] = Math.max(0, sizes[1] + space);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     * LayoutManager used for JSplitPanes with an orientation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     * VERTICAL_SPLIT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    public class BasicVerticalLayoutManager extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            BasicHorizontalLayoutManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        public BasicVerticalLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            super(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    private class Handler implements FocusListener, PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        // PropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
         * Messaged from the <code>JSplitPane</code> the receiver is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
         * contained in.  May potentially reset the layout manager and cause a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
         * <code>validate</code> to be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            if(e.getSource() == splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                String changeName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                if(changeName == JSplitPane.ORIENTATION_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                    orientation = splitPane.getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                    resetLayoutManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                } else if(changeName == JSplitPane.CONTINUOUS_LAYOUT_PROPERTY){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                    setContinuousLayout(splitPane.isContinuousLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                    if(!isContinuousLayout()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                        if(nonContinuousLayoutDivider == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                            setNonContinuousLayoutDivider(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                                createDefaultNonContinuousLayoutDivider(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                        } else if(nonContinuousLayoutDivider.getParent() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                                  null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                            setNonContinuousLayoutDivider(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                                nonContinuousLayoutDivider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                } else if(changeName == JSplitPane.DIVIDER_SIZE_PROPERTY){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                    divider.setDividerSize(splitPane.getDividerSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                    dividerSize = divider.getDividerSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                    splitPane.revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                    splitPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
        // FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
        public void focusGained(FocusEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            dividerKeyboardResize = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            splitPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
        public void focusLost(FocusEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
            dividerKeyboardResize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            splitPane.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
    private static class Actions extends UIAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        private static final String NEGATIVE_INCREMENT = "negativeIncrement";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        private static final String POSITIVE_INCREMENT = "positiveIncrement";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        private static final String SELECT_MIN = "selectMin";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        private static final String SELECT_MAX = "selectMax";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        private static final String START_RESIZE = "startResize";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        private static final String TOGGLE_FOCUS = "toggleFocus";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
        private static final String FOCUS_OUT_FORWARD = "focusOutForward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        private static final String FOCUS_OUT_BACKWARD = "focusOutBackward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
        Actions(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
            super(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
        public void actionPerformed(ActionEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            JSplitPane splitPane = (JSplitPane)ev.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            BasicSplitPaneUI ui = (BasicSplitPaneUI)BasicLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                      getUIOfType(splitPane.getUI(), BasicSplitPaneUI.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
            if (ui == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            String key = getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
            if (key == NEGATIVE_INCREMENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                if (ui.dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                    splitPane.setDividerLocation(Math.max(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                              0, ui.getDividerLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                              (splitPane) - ui.getKeyboardMoveIncrement()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            else if (key == POSITIVE_INCREMENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                if (ui.dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                    splitPane.setDividerLocation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                        ui.getDividerLocation(splitPane) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                        ui.getKeyboardMoveIncrement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
            else if (key == SELECT_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                if (ui.dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                    splitPane.setDividerLocation(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            else if (key == SELECT_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                if (ui.dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                    Insets   insets = splitPane.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                    int      bottomI = (insets != null) ? insets.bottom : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                    int      rightI = (insets != null) ? insets.right : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                    if (ui.orientation == JSplitPane.VERTICAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                        splitPane.setDividerLocation(splitPane.getHeight() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                                                     bottomI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                        splitPane.setDividerLocation(splitPane.getWidth() -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                                                     rightI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            else if (key == START_RESIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
                if (!ui.dividerKeyboardResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                    splitPane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                    JSplitPane parentSplitPane =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
                        (JSplitPane)SwingUtilities.getAncestorOfClass(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                                         JSplitPane.class, splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                    if (parentSplitPane!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                        parentSplitPane.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            else if (key == TOGGLE_FOCUS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                toggleFocus(splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            else if (key == FOCUS_OUT_FORWARD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                moveFocus(splitPane, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            else if (key == FOCUS_OUT_BACKWARD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                moveFocus(splitPane, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
        private void moveFocus(JSplitPane splitPane, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            Container rootAncestor = splitPane.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            Component focusOn = (direction > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                policy.getComponentAfter(rootAncestor, splitPane) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                policy.getComponentBefore(rootAncestor, splitPane);
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  2170
            HashSet<Component> focusFrom = new HashSet<Component>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            if (splitPane.isAncestorOf(focusOn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                    focusFrom.add(focusOn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                    rootAncestor = focusOn.getFocusCycleRootAncestor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                    policy = rootAncestor.getFocusTraversalPolicy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                    focusOn = (direction > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                        policy.getComponentAfter(rootAncestor, focusOn) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                        policy.getComponentBefore(rootAncestor, focusOn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                } while (splitPane.isAncestorOf(focusOn) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                         !focusFrom.contains(focusOn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            if ( focusOn!=null && !splitPane.isAncestorOf(focusOn) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                focusOn.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        private void toggleFocus(JSplitPane splitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            Component left = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
            Component right = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
            KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            Component focus = manager.getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
            Component focusOn = getNextSide(splitPane, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
            if (focusOn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
                // don't change the focus if the new focused component belongs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                // to the same splitpane and the same side
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
                if ( focus!=null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                     ( (SwingUtilities.isDescendingFrom(focus, left) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                        SwingUtilities.isDescendingFrom(focusOn, left)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
                       (SwingUtilities.isDescendingFrom(focus, right) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                        SwingUtilities.isDescendingFrom(focusOn, right)) ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                SwingUtilities2.compositeRequestFocus(focusOn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
        private Component getNextSide(JSplitPane splitPane, Component focus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
            Component left = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            Component right = splitPane.getRightComponent();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
  2212
            Component next;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
            if (focus!=null && SwingUtilities.isDescendingFrom(focus, left) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                right!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                next = getFirstAvailableComponent(right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                if (next != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                    return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
            JSplitPane parentSplitPane = (JSplitPane)SwingUtilities.getAncestorOfClass(JSplitPane.class, splitPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            if (parentSplitPane!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                // focus next side of the parent split pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
                next = getNextSide(parentSplitPane, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                next = getFirstAvailableComponent(left);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                if (next == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                    next = getFirstAvailableComponent(right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
            return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        private Component getFirstAvailableComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            if (c!=null && c instanceof JSplitPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                JSplitPane sp = (JSplitPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                Component left = getFirstAvailableComponent(sp.getLeftComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                if (left != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                    c = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                    c = getFirstAvailableComponent(sp.getRightComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
            return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
}