src/demo/share/jfc/SwingSet2/SplitPaneDemo.java
author weijun
Tue, 29 Oct 2019 09:34:21 +0800
changeset 58830 fa0b9f9c597a
parent 49495 f46bfa7a2956
permissions -rw-r--r--
8228969: 2019-09-28 public suffix list update Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49495
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     1
/*
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     2
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     3
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     4
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     7
 * are met:
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     8
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
     9
 *   - Redistributions of source code must retain the above copyright
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    10
 *     notice, this list of conditions and the following disclaimer.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    11
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    12
 *   - Redistributions in binary form must reproduce the above copyright
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    13
 *     notice, this list of conditions and the following disclaimer in the
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    14
 *     documentation and/or other materials provided with the distribution.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    15
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    16
 *   - Neither the name of Oracle nor the names of its
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    17
 *     contributors may be used to endorse or promote products derived
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    18
 *     from this software without specific prior written permission.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    19
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    21
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    22
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    23
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    31
 */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    32
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    33
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    34
import javax.swing.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    35
import javax.swing.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    36
import javax.swing.text.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    37
import javax.swing.table.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    38
import javax.swing.border.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    39
import javax.swing.colorchooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    40
import javax.swing.filechooser.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    41
import javax.accessibility.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    42
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    43
import java.awt.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    44
import java.awt.event.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    45
import java.beans.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    46
import java.util.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    47
import java.io.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    48
import java.applet.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    49
import java.net.*;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    50
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    51
/**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    52
 * Split Pane demo
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    53
 *
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    54
 * @author Scott Violet
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    55
 * @author Jeff Dinkins
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    56
 */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    57
public class SplitPaneDemo extends DemoModule {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    58
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    59
    JSplitPane splitPane = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    60
    JLabel earth = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    61
    JLabel moon = null;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    62
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    63
    JTextField divSize;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    64
    JTextField earthSize;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    65
    JTextField moonSize;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    66
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    67
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    68
     * main method allows us to run as a standalone demo.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    69
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    70
    public static void main(String[] args) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    71
        SplitPaneDemo demo = new SplitPaneDemo(null);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    72
        demo.mainImpl();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    73
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    74
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    75
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    76
     * SplitPaneDemo Constructor
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    77
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    78
    public SplitPaneDemo(SwingSet2 swingset) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    79
        super(swingset, "SplitPaneDemo", "toolbar/JSplitPane.gif");
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    80
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    81
        earth = new JLabel(createImageIcon("splitpane/earth.jpg", getString("SplitPaneDemo.earth")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    82
        earth.setMinimumSize(new Dimension(20, 20));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    83
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    84
        moon = new JLabel(createImageIcon("splitpane/moon.jpg", getString("SplitPaneDemo.moon")));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    85
        moon.setMinimumSize(new Dimension(20, 20));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    86
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    87
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, earth, moon);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    88
        splitPane.setContinuousLayout(true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    89
        splitPane.setOneTouchExpandable(true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    90
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    91
        splitPane.setDividerLocation(200);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    92
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    93
        getDemoPanel().add(splitPane, BorderLayout.CENTER);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    94
        getDemoPanel().setBackground(Color.black);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    95
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    96
        getDemoPanel().add(createSplitPaneControls(), BorderLayout.SOUTH);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    97
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    98
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
    99
    /**
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   100
     * Creates controls to alter the JSplitPane.
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   101
     */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   102
    protected JPanel createSplitPaneControls() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   103
        JPanel wrapper = new JPanel();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   104
        ButtonGroup group = new ButtonGroup();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   105
        JRadioButton button;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   106
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   107
        Box buttonWrapper = new Box(BoxLayout.X_AXIS);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   108
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   109
        wrapper.setLayout(new GridLayout(0, 1));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   110
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   111
        /* Create a radio button to vertically split the split pane. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   112
        button = new JRadioButton(getString("SplitPaneDemo.vert_split"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   113
        button.setMnemonic(getMnemonic("SplitPaneDemo.vert_split_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   114
        button.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   115
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   116
                splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   117
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   118
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   119
        group.add(button);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   120
        buttonWrapper.add(button);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   121
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   122
        /* Create a radio button the horizontally split the split pane. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   123
        button = new JRadioButton(getString("SplitPaneDemo.horz_split"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   124
        button.setMnemonic(getMnemonic("SplitPaneDemo.horz_split_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   125
        button.setSelected(true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   126
        button.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   127
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   128
                splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   129
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   130
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   131
        group.add(button);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   132
        buttonWrapper.add(button);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   133
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   134
        /* Create a check box as to whether or not the split pane continually
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   135
           lays out the component when dragging. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   136
        JCheckBox checkBox = new JCheckBox(getString("SplitPaneDemo.cont_layout"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   137
        checkBox.setMnemonic(getMnemonic("SplitPaneDemo.cont_layout_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   138
        checkBox.setSelected(true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   139
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   140
        checkBox.addChangeListener(new ChangeListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   141
            public void stateChanged(ChangeEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   142
                splitPane.setContinuousLayout(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   143
                    ((JCheckBox)e.getSource()).isSelected());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   144
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   145
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   146
        buttonWrapper.add(checkBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   147
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   148
        /* Create a check box as to whether or not the split pane divider
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   149
           contains the oneTouchExpandable buttons. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   150
        checkBox = new JCheckBox(getString("SplitPaneDemo.one_touch_expandable"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   151
        checkBox.setMnemonic(getMnemonic("SplitPaneDemo.one_touch_expandable_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   152
        checkBox.setSelected(true);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   153
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   154
        checkBox.addChangeListener(new ChangeListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   155
            public void stateChanged(ChangeEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   156
                splitPane.setOneTouchExpandable(
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   157
                    ((JCheckBox) e.getSource()).isSelected());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   158
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   159
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   160
        buttonWrapper.add(checkBox);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   161
        wrapper.add(buttonWrapper);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   162
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   163
        /* Create a text field to change the divider size. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   164
        JPanel                   tfWrapper;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   165
        JLabel                   label;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   166
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   167
        divSize = new JTextField();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   168
        divSize.setText(new Integer(splitPane.getDividerSize()).toString());
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   169
        divSize.setColumns(5);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   170
        divSize.getAccessibleContext().setAccessibleName(getString("SplitPaneDemo.divider_size"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   171
        divSize.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   172
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   173
                String  value = ((JTextField)e.getSource()).getText();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   174
                int newSize;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   175
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   176
                try {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   177
                    newSize = Integer.parseInt(value);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   178
                } catch (Exception ex) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   179
                    newSize = -1;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   180
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   181
                if(newSize > 0) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   182
                    splitPane.setDividerSize(newSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   183
                } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   184
                    JOptionPane.showMessageDialog(splitPane,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   185
                                                  getString("SplitPaneDemo.invalid_divider_size"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   186
                                                  getString("SplitPaneDemo.error"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   187
                                                  JOptionPane.ERROR_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   188
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   189
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   190
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   191
        label = new JLabel(getString("SplitPaneDemo.divider_size"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   192
        tfWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   193
        tfWrapper.add(label);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   194
        tfWrapper.add(divSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   195
        label.setLabelFor(divSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   196
        label.setDisplayedMnemonic(getMnemonic("SplitPaneDemo.divider_size_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   197
        wrapper.add(tfWrapper);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   198
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   199
        /* Create a text field that will change the preferred/minimum size
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   200
           of the earth component. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   201
        earthSize = new JTextField(String.valueOf(earth.getMinimumSize().width));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   202
        earthSize.setColumns(5);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   203
        earthSize.getAccessibleContext().setAccessibleName(getString("SplitPaneDemo.first_component_min_size"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   204
        earthSize.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   205
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   206
                String           value = ((JTextField)e.getSource()).getText();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   207
                int              newSize;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   208
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   209
                try {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   210
                    newSize = Integer.parseInt(value);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   211
                } catch (Exception ex) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   212
                    newSize = -1;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   213
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   214
                if(newSize > 10) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   215
                    earth.setMinimumSize(new Dimension(newSize, newSize));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   216
                } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   217
                    JOptionPane.showMessageDialog(splitPane,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   218
                                                  getString("SplitPaneDemo.invalid_min_size") +
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   219
                                                  getString("SplitPaneDemo.must_be_greater_than") + 10,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   220
                                                  getString("SplitPaneDemo.error"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   221
                                                  JOptionPane.ERROR_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   222
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   223
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   224
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   225
        label = new JLabel(getString("SplitPaneDemo.first_component_min_size"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   226
        tfWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   227
        tfWrapper.add(label);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   228
        tfWrapper.add(earthSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   229
        label.setLabelFor(earthSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   230
        label.setDisplayedMnemonic(getMnemonic("SplitPaneDemo.first_component_min_size_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   231
        wrapper.add(tfWrapper);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   232
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   233
        /* Create a text field that will change the preferred/minimum size
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   234
           of the moon component. */
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   235
        moonSize = new JTextField(String.valueOf(moon.getMinimumSize().width));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   236
        moonSize.setColumns(5);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   237
        moonSize.getAccessibleContext().setAccessibleName(getString("SplitPaneDemo.second_component_min_size"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   238
        moonSize.addActionListener(new ActionListener() {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   239
            public void actionPerformed(ActionEvent e) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   240
                String           value = ((JTextField)e.getSource()).getText();
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   241
                int              newSize;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   242
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   243
                try {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   244
                    newSize = Integer.parseInt(value);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   245
                } catch (Exception ex) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   246
                    newSize = -1;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   247
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   248
                if(newSize > 10) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   249
                    moon.setMinimumSize(new Dimension(newSize, newSize));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   250
                } else {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   251
                    JOptionPane.showMessageDialog(splitPane,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   252
                                                  getString("SplitPaneDemo.invalid_min_size") +
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   253
                                                  getString("SplitPaneDemo.must_be_greater_than") + 10,
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   254
                                                  getString("SplitPaneDemo.error"),
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   255
                                                  JOptionPane.ERROR_MESSAGE);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   256
                }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   257
            }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   258
        });
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   259
        label = new JLabel(getString("SplitPaneDemo.second_component_min_size"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   260
        tfWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   261
        tfWrapper.add(label);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   262
        tfWrapper.add(moonSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   263
        label.setLabelFor(moonSize);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   264
        label.setDisplayedMnemonic(getMnemonic("SplitPaneDemo.second_component_min_size_mnemonic"));
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   265
        wrapper.add(tfWrapper);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   266
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   267
        return wrapper;
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   268
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   269
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   270
    void updateDragEnabled(boolean dragEnabled) {
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   271
        divSize.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   272
        earthSize.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   273
        moonSize.setDragEnabled(dragEnabled);
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   274
    }
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   275
f46bfa7a2956 8198990: Move SwingSet2 from closed to OpenJDK
prr
parents:
diff changeset
   276
}