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