001: /*
002: * Copyright (c) 2002-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.forms.tutorial.basics;
032:
033: import javax.swing.*;
034:
035: import com.jgoodies.forms.builder.PanelBuilder;
036: import com.jgoodies.forms.layout.CellConstraints;
037: import com.jgoodies.forms.layout.FormLayout;
038:
039: /**
040: * Demonstrates the basic FormLayout sizes: constant, minimum, preferred.
041: *
042: * @author Karsten Lentzsch
043: * @version $Revision: 1.14 $
044: */
045: public final class BoundedSizesExample {
046:
047: public static void main(String[] args) {
048: try {
049: UIManager
050: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
051: } catch (Exception e) {
052: // Likely PlasticXP is not in the class path; ignore.
053: }
054: JFrame frame = new JFrame();
055: frame.setTitle("Forms Tutorial :: Bounded Sizes");
056: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
057: JComponent panel = new BoundedSizesExample().buildPanel();
058: frame.getContentPane().add(panel);
059: frame.pack();
060: frame.setVisible(true);
061: }
062:
063: public JComponent buildPanel() {
064: JTabbedPane tabbedPane = new JTabbedPane();
065: tabbedPane.putClientProperty("jgoodies.noContentBorder",
066: Boolean.TRUE);
067:
068: tabbedPane.add("Jumping 1", buildJumping1Panel());
069: tabbedPane.add("Jumping 2", buildJumping2Panel());
070: tabbedPane.add("Stable 1", buildStable1Panel());
071: tabbedPane.add("Stable 2", buildStable2Panel());
072: return tabbedPane;
073: }
074:
075: private JComponent buildJumping1Panel() {
076: FormLayout layout = new FormLayout(
077: "right:pref, 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
078: EDITOR_ROW_SPEC);
079: return buildEditorGeneralPanel(layout);
080: }
081:
082: private JComponent buildJumping2Panel() {
083: FormLayout layout = new FormLayout(
084: "right:pref, 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
085: EDITOR_ROW_SPEC);
086: return buildEditorTransportPanel(layout);
087: }
088:
089: private JComponent buildStable1Panel() {
090: FormLayout layout = new FormLayout(
091: "right:max(50dlu;pref), 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
092: EDITOR_ROW_SPEC);
093: return buildEditorGeneralPanel(layout);
094: }
095:
096: private JComponent buildStable2Panel() {
097: FormLayout layout = new FormLayout(
098: "right:max(50dlu;pref), 4dlu, max(35dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
099: EDITOR_ROW_SPEC);
100: return buildEditorTransportPanel(layout);
101: }
102:
103: private static final String EDITOR_ROW_SPEC = "p, 3dlu, p, 3dlu, p, 3dlu, p";
104:
105: /**
106: * Builds and answer the editor's general tab for the given layout.
107: *
108: * @param layout the layout to be used
109: * @return the editor's general panel
110: */
111: private JComponent buildEditorGeneralPanel(FormLayout layout) {
112: layout.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
113: PanelBuilder builder = new PanelBuilder(layout);
114:
115: builder.setDefaultDialogBorder();
116: CellConstraints cc = new CellConstraints();
117:
118: builder.addLabel("File number:", cc.xy(1, 1));
119: builder.add(new JTextField(), cc.xyw(3, 1, 7));
120: builder.addLabel("RFQ number:", cc.xy(1, 3));
121: builder.add(new JTextField(), cc.xyw(3, 3, 7));
122: builder.addLabel("Entry date:", cc.xy(1, 5));
123: builder.add(new JTextField(), cc.xy(3, 5));
124: builder.addLabel("Sales Person:", cc.xy(1, 7));
125: builder.add(new JTextField(), cc.xyw(3, 7, 7));
126:
127: return builder.getPanel();
128: }
129:
130: /**
131: * Builds and answer the editor's transport tab for the given layout.
132: *
133: * @param layout the layout to be used
134: * @return the editor's transport panel
135: */
136: private JComponent buildEditorTransportPanel(FormLayout layout) {
137: layout.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
138: PanelBuilder builder = new PanelBuilder(layout);
139:
140: builder.setDefaultDialogBorder();
141: CellConstraints cc = new CellConstraints();
142:
143: builder.addLabel("Shipper:", cc.xy(1, 1));
144: builder.add(new JTextField(), cc.xy(3, 1));
145: builder.add(new JTextField(), cc.xyw(5, 1, 5));
146: builder.addLabel("Consignee:", cc.xy(1, 3));
147: builder.add(new JTextField(), cc.xy(3, 3));
148: builder.add(new JTextField(), cc.xyw(5, 3, 5));
149: builder.addLabel("Departure:", cc.xy(1, 5));
150: builder.add(new JTextField(), cc.xy(3, 5));
151: builder.add(new JTextField(), cc.xyw(5, 5, 5));
152: builder.addLabel("Destination:", cc.xy(1, 7));
153: builder.add(new JTextField(), cc.xy(3, 7));
154: builder.add(new JTextField(), cc.xyw(5, 7, 5));
155:
156: return builder.getPanel();
157: }
158:
159: }
|