001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package test.check;
031:
032: import java.awt.BorderLayout;
033: import java.awt.Dimension;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: import javax.swing.*;
038:
039: import org.jvnet.substance.SubstanceLookAndFeel;
040: import org.jvnet.substance.grip.*;
041:
042: import com.jgoodies.forms.builder.DefaultFormBuilder;
043: import com.jgoodies.forms.layout.FormLayout;
044:
045: /**
046: * Test application panel for testing {@link JSplitPane} component.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SplitPanel extends ControllablePanel {
051: /**
052: * Split pane.
053: */
054: private JSplitPane splitPane;
055:
056: /**
057: * Creates a test panel with split pane.
058: */
059: public SplitPanel() {
060: this .setLayout(new BorderLayout());
061: splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
062: new NumberedPanel(1), new NumberedPanel(2));
063: splitPane.setDividerLocation(100);
064: this .add(splitPane, BorderLayout.CENTER);
065:
066: FormLayout lm = new FormLayout("fill:pref:grow", "");
067: DefaultFormBuilder builder = new DefaultFormBuilder(lm,
068: new ScrollablePanel());
069:
070: final JCheckBox isOneTouch = new JCheckBox("is one-touch");
071: isOneTouch.setSelected(true);
072: splitPane.setOneTouchExpandable(true);
073: isOneTouch.addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent e) {
075: splitPane
076: .setOneTouchExpandable(isOneTouch.isSelected());
077: }
078: });
079:
080: final JCheckBox isFlat = new JCheckBox("is flat");
081: isFlat.setSelected(true);
082: isFlat.addActionListener(new ActionListener() {
083: public void actionPerformed(ActionEvent e) {
084: splitPane.putClientProperty(
085: SubstanceLookAndFeel.FLAT_PROPERTY, (isFlat
086: .isSelected() ? Boolean.TRUE
087: : Boolean.FALSE));
088: splitPane.repaint();
089: }
090: });
091:
092: final JCheckBox isVertical = new JCheckBox("is vertical");
093: splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
094: isVertical.setSelected(true);
095: isVertical.addActionListener(new ActionListener() {
096: public void actionPerformed(ActionEvent e) {
097: splitPane
098: .setOrientation(isVertical.isSelected() ? JSplitPane.VERTICAL_SPLIT
099: : JSplitPane.HORIZONTAL_SPLIT);
100: }
101: });
102:
103: builder.append(isOneTouch);
104: builder.append(isFlat);
105: builder.append(isVertical);
106:
107: builder.appendSeparator("Grip painters");
108: ButtonGroup gripGroup = new ButtonGroup();
109: JRadioButton defaultGrip = getGripControl(splitPane, null,
110: "Default (drag)", true, gripGroup);
111: JRadioButton bumpsGrip = getGripControl(splitPane,
112: new DragBumpsGripPainter(), "Drag bumps", false,
113: gripGroup);
114: JRadioButton nullGrip = getGripControl(splitPane,
115: new NullGripPainter(), "Null", false, gripGroup);
116: builder.append("Select", defaultGrip);
117: builder.append("", bumpsGrip);
118: builder.append("", nullGrip);
119:
120: this .controlPanel = builder.getPanel();
121:
122: this .setPreferredSize(new Dimension(400, 400));
123: this .setSize(this .getPreferredSize());
124: this .setMinimumSize(this .getPreferredSize());
125: }
126:
127: private JRadioButton getGripControl(final JSplitPane splitPane,
128: final GripPainter gripPainter, String text,
129: boolean isDefault, ButtonGroup buttonGroup) {
130: final JRadioButton result = new JRadioButton(text);
131: result.setSelected(isDefault);
132: buttonGroup.add(result);
133: result.addActionListener(new ActionListener() {
134: public void actionPerformed(ActionEvent e) {
135: if (result.isSelected()) {
136: splitPane.putClientProperty(
137: SubstanceLookAndFeel.GRIP_PAINTER,
138: gripPainter);
139: splitPane.repaint();
140: }
141: }
142: });
143: return result;
144: }
145:
146: }
|