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.Component;
034:
035: import javax.swing.*;
036:
037: import org.jvnet.lafwidget.LafWidget;
038: import org.jvnet.substance.SubstanceLookAndFeel;
039:
040: import test.check.command.*;
041:
042: import com.jgoodies.forms.builder.DefaultFormBuilder;
043: import com.jgoodies.forms.layout.FormLayout;
044:
045: /**
046: * Test application panel for testing {@link JSpinner} component.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SpinnerPanel extends JPanel {
051: /**
052: * Creates a test panel with spinners.
053: */
054: public SpinnerPanel() {
055: this .setLayout(new BorderLayout());
056:
057: FormLayout lm = new FormLayout(
058: "right:pref, 4dlu, left:pref:grow", "");
059: DefaultFormBuilder builder = new DefaultFormBuilder(lm,
060: new ScrollablePanel());
061: builder.setDefaultDialogBorder();
062:
063: CreationCommand<Component> basicCr = new CreationCommand<Component>() {
064: public Component create() {
065: JSpinner basicSpinner = new JSpinner();
066: return basicSpinner;
067: }
068: };
069: CreationCommand<Component> dateCr = new CreationCommand<Component>() {
070: public Component create() {
071: JSpinner dateEnSpinner = new JSpinner(
072: new SpinnerDateModel());
073: return dateEnSpinner;
074: }
075: };
076: CreationCommand<Component> weekdaysCr = new CreationCommand<Component>() {
077: public Component create() {
078: String weekdaysEn[] = new String[] { "Sunday",
079: "Monday", "Tuesday", "Wednesday", "Thursday",
080: "Friday", "Saturday" };
081: JSpinner listEnSpinner = new JSpinner(
082: new SpinnerListModel(weekdaysEn));
083: return listEnSpinner;
084: }
085: };
086: CreationCommand<Component> numberCr = new CreationCommand<Component>() {
087: public Component create() {
088: JSpinner numberEnSpinner = new JSpinner(
089: new SpinnerNumberModel(0, 0, 100, 5));
090: return numberEnSpinner;
091: }
092: };
093:
094: builder.appendSeparator("Enabled");
095: addSpinner(builder, "Basic", basicCr, null);
096: addSpinner(builder, "Date", dateCr, null);
097: addSpinner(builder, "Weekdays", weekdaysCr, null);
098: addSpinner(builder, "Weekdays select on focus", weekdaysCr,
099: new ClientPropertyCommand(
100: LafWidget.TEXT_SELECT_ON_FOCUS, Boolean.TRUE));
101: addSpinner(builder, "Number", numberCr, null);
102: addSpinner(builder, "Number flat", numberCr,
103: new ClientPropertyCommand(
104: SubstanceLookAndFeel.FLAT_PROPERTY,
105: Boolean.TRUE));
106:
107: builder.appendSeparator("Disabled");
108: addSpinner(builder, "Basic", basicCr, new DisableCommand());
109: addSpinner(builder, "Date", dateCr, new DisableCommand());
110: addSpinner(builder, "Weekdays", weekdaysCr,
111: new DisableCommand());
112: addSpinner(builder, "Weekdays select on focus", weekdaysCr,
113: new ChainCommand<Component>(new ClientPropertyCommand(
114: LafWidget.TEXT_SELECT_ON_FOCUS, Boolean.TRUE),
115: new DisableCommand()));
116: addSpinner(builder, "Number", numberCr, new DisableCommand());
117: addSpinner(builder, "Number flat", numberCr,
118: new ChainCommand<Component>(new ClientPropertyCommand(
119: SubstanceLookAndFeel.FLAT_PROPERTY,
120: Boolean.TRUE), new DisableCommand()));
121:
122: this .add(new JScrollPane(builder.getPanel()),
123: BorderLayout.CENTER);
124: }
125:
126: private void addSpinner(DefaultFormBuilder builder, String label,
127: CreationCommand<Component> creationCmd,
128: ConfigurationCommand<Component> configurationCmd) {
129:
130: Component comp = creationCmd.create();
131:
132: if (configurationCmd != null) {
133: configurationCmd.configure(comp);
134: }
135:
136: JLabel jl = new JLabel(label);
137: builder.append(jl);
138: builder.append(comp);
139: }
140:
141: }
|