001: /*
002: * Copyright (c) 2003-2007 JGoodies Karsten Lentzsch. 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 JGoodies Karsten Lentzsch 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:
031: package com.jgoodies.validation.tests;
032:
033: import java.awt.BorderLayout;
034: import java.awt.Dimension;
035:
036: import javax.swing.*;
037:
038: import com.jgoodies.forms.builder.PanelBuilder;
039: import com.jgoodies.forms.factories.Borders;
040: import com.jgoodies.forms.layout.CellConstraints;
041: import com.jgoodies.forms.layout.FormLayout;
042: import com.jgoodies.validation.tutorial.shared.Order;
043: import com.jgoodies.validation.tutorial.shared.OrderModel;
044: import com.jgoodies.validation.tutorial.util.ExampleComponentFactory;
045: import com.jgoodies.validation.tutorial.util.IconFeedbackPanel;
046: import com.jgoodies.validation.tutorial.util.TutorialUtils;
047: import com.jgoodies.validation.view.ValidationComponentUtils;
048:
049: /**
050: * Tests the IconFeedbackPanel with and without a border
051: * and plain and wrapped by a JScrollPane.
052: *
053: * @author Karsten Lentzsch
054: * @version $Revision: 1.6 $
055: */
056:
057: public final class IconFeedbackTestPanel {
058:
059: private final OrderModel orderModel;
060:
061: public static void main(String[] args) {
062: try {
063: UIManager
064: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
065: } catch (Exception e) {
066: // Likely Plastic is not in the classpath; ignore it.
067: }
068: JFrame frame = new JFrame();
069: frame.setTitle("Icon Feedback Test");
070: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
071: JComponent panel = new IconFeedbackTestPanel().buildPanel();
072: frame.getContentPane().add(panel);
073: frame.pack();
074: TutorialUtils.locateOnOpticalScreenCenter(frame);
075: frame.setVisible(true);
076: }
077:
078: // Instance Creation ******************************************************
079:
080: public IconFeedbackTestPanel() {
081: orderModel = new OrderModel(new Order());
082: }
083:
084: // Building ***************************************************************
085:
086: /**
087: * Builds and returns the whole editor with 3 sections
088: * for a plain panel, panel with border and scrollable panel.
089: */
090: public JComponent buildPanel() {
091: JComponent plainPanel = buildTestPanel();
092:
093: JComponent nestedPanel = buildTestPanel();
094: JPanel borderPanel = new JPanel(new BorderLayout());
095: borderPanel.setBorder(Borders.DLU14_BORDER);
096: borderPanel.add(nestedPanel);
097:
098: JComponent scrollablePanel = buildTestPanel();
099: JPanel outerScrollablePanel = new JPanel(new BorderLayout());
100: outerScrollablePanel.add(scrollablePanel);
101: outerScrollablePanel.setBorder(Borders.DLU14_BORDER);
102: JScrollPane scrollPane = new JScrollPane(scrollablePanel);
103: scrollPane.setPreferredSize(new Dimension(200, 100));
104:
105: FormLayout layout = new FormLayout("fill:pref",
106: "p, 3dlu, p, 17dlu, p, 3dlu, p, 17dlu, p, 3dlu, p");
107:
108: PanelBuilder builder = new PanelBuilder(layout);
109: builder.setDefaultDialogBorder();
110: CellConstraints cc = new CellConstraints();
111:
112: builder.addSeparator("Panel with Border", cc.xy(1, 1));
113: builder.add(plainPanel, cc.xy(1, 3));
114: builder.addSeparator("Nested Panel", cc.xy(1, 5));
115: builder.add(borderPanel, cc.xy(1, 7));
116: builder.addSeparator("Wrapped by a JScrollPane", cc.xy(1, 9));
117: builder.add(scrollPane, cc.xy(1, 11, "left, fill"));
118:
119: return IconFeedbackPanel.getWrappedComponentTree(orderModel
120: .getValidationResultModel(), builder.getPanel());
121: }
122:
123: private JComponent buildTestPanel() {
124: JTextField orderNoField;
125: JTextField orderDateField;
126: JTextField deliveryDateField;
127: JTextArea deliveryNotesArea;
128:
129: orderNoField = ExampleComponentFactory
130: .createTextField(orderModel
131: .getModel(Order.PROPERTYNAME_ORDER_NO), false);
132: orderDateField = ExampleComponentFactory
133: .createDateField(orderModel
134: .getModel(Order.PROPERTYNAME_ORDER_DATE));
135: deliveryDateField = ExampleComponentFactory.createDateField(
136: orderModel.getModel(Order.PROPERTYNAME_DELIVERY_DATE),
137: true);
138: deliveryNotesArea = ExampleComponentFactory.createTextArea(
139: orderModel.getModel(Order.PROPERTYNAME_DELIVERY_NOTES),
140: false);
141:
142: ValidationComponentUtils.setMandatory(orderNoField, true);
143: ValidationComponentUtils.setMessageKey(orderNoField,
144: "Order.Order No");
145: ValidationComponentUtils.setMandatory(orderDateField, true);
146: ValidationComponentUtils.setMessageKey(orderDateField,
147: "Order.Order Date");
148: ValidationComponentUtils.setMessageKey(deliveryDateField,
149: "Order.Delivery Date");
150: ValidationComponentUtils.setMessageKey(deliveryNotesArea,
151: "Order.Notes");
152:
153: FormLayout layout = new FormLayout(
154: "right:max(65dlu;pref), 4dlu, 40dlu, 2dlu, 40dlu",
155: "p, 3dlu, p, 3dlu, p, 3dlu, p, 2px"); // extra bottom space for icons
156:
157: layout.setRowGroups(new int[][] { { 1, 3, 5, 7 } });
158: PanelBuilder builder = new PanelBuilder(layout);
159: builder.setDefaultDialogBorder();
160: CellConstraints cc = new CellConstraints();
161:
162: builder.addLabel("Order No", cc.xy(1, 1));
163: builder.add(orderNoField, cc.xyw(3, 1, 3));
164: builder.addLabel("Order-/Delivery Date", cc.xy(1, 3));
165: builder.add(orderDateField, cc.xy(3, 3));
166: builder.add(deliveryDateField, cc.xy(5, 3));
167: builder.addLabel("Notes", cc.xy(1, 5));
168: builder.add(new JScrollPane(deliveryNotesArea), cc.xywh(3, 5,
169: 3, 3));
170:
171: return builder.getPanel();
172: }
173:
174: }
|