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.factories.Borders;
036: import com.jgoodies.forms.layout.CellConstraints;
037: import com.jgoodies.forms.layout.FormLayout;
038:
039: /**
040: * Demonstrates how columns and rows can be grouped in FormLayout.
041: *
042: * @author Karsten Lentzsch
043: * @version $Revision: 1.14 $
044: */
045: public final class GroupingExample {
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 :: Grouping");
056: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
057: JComponent panel = new GroupingExample().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("Ungrouped Bar", buildWizardBar(false));
069: tabbedPane.add("Grouped Bar", buildWizardBar(true));
070: tabbedPane.add("Ungrouped Rows", buildEditorPanel(false));
071: tabbedPane.add("Grouped Rows", buildEditorPanel(true));
072: return tabbedPane;
073: }
074:
075: private JComponent buildWizardBar(boolean grouped) {
076: FormLayout layout = new FormLayout(
077: "pref, 6px:grow, pref, pref, 12px, pref, 6px, pref",
078: "pref");
079: if (grouped) {
080: layout.setColumnGroups(new int[][] { { 1, 3, 4, 6, 8 } });
081: }
082: JPanel panel = new JPanel(layout);
083: panel.setBorder(Borders.DIALOG_BORDER);
084: CellConstraints cc = new CellConstraints();
085:
086: panel.add(createNarrowButton("Hilfe"), cc.xy(1, 1));
087: panel.add(createNarrowButton("< Zur\u00FCck"), cc.xy(3, 1));
088: panel.add(createNarrowButton("Vor >"), cc.xy(4, 1));
089: panel.add(createNarrowButton("Beenden"), cc.xy(6, 1));
090: panel.add(createNarrowButton("Abbrechen"), cc.xy(8, 1));
091:
092: return panel;
093: }
094:
095: private JComponent buildEditorPanel(boolean grouped) {
096: FormLayout layout = new FormLayout(
097: "pref, 4dlu, 35dlu, 2dlu, 35dlu, 2dlu, 35dlu, 2dlu, 35dlu",
098: "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p");
099: if (grouped) {
100: layout.setRowGroups(new int[][] { { 1, 3, 5, 7, 9, 11, 13,
101: 15, 17 } });
102: }
103:
104: JPanel panel = new JPanel(layout);
105: panel.setBorder(Borders.DIALOG_BORDER);
106: CellConstraints cc = new CellConstraints();
107:
108: panel.add(new JLabel("File number:"), cc.xy(1, 1));
109: panel.add(new JTextField(), cc.xyw(3, 1, 7));
110: panel.add(new JLabel("BL/MBL number:"), cc.xy(1, 3));
111: panel.add(new JTextField(), cc.xy(3, 3));
112: panel.add(new JTextField(), cc.xy(5, 3));
113: panel.add(new JLabel("Entry date:"), cc.xy(1, 5));
114: panel.add(new JTextField(), cc.xy(3, 5));
115: panel.add(new JLabel("RFQ number:"), cc.xy(1, 7));
116: panel.add(new JTextField(), cc.xyw(3, 7, 7));
117: panel.add(new JLabel("Goods:"), cc.xy(1, 9));
118: panel.add(new JCheckBox("Dangerous"), cc.xyw(3, 9, 7));
119: panel.add(new JLabel("Shipper:"), cc.xy(1, 11));
120: panel.add(new JTextField(), cc.xyw(3, 11, 7));
121: panel.add(new JLabel("Customer:"), cc.xy(1, 13));
122: panel.add(new JTextField(), cc.xyw(3, 13, 5));
123: panel.add(new JButton("..."), cc.xy(9, 13));
124: panel.add(new JLabel("Port of loading:"), cc.xy(1, 15));
125: panel.add(new JTextField(), cc.xyw(3, 15, 7));
126: panel.add(new JLabel("Destination:"), cc.xy(1, 17));
127: panel.add(new JTextField(), cc.xyw(3, 17, 7));
128:
129: return panel;
130: }
131:
132: // Component Creation *****************************************************
133:
134: private JButton createNarrowButton(String text) {
135: JButton button = new JButton(text);
136: button.putClientProperty("jgoodies.isNarrow", Boolean.TRUE);
137: return button;
138: }
139:
140: }
|