001: /*
002: * Copyright (c) 2001-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.looks.demo;
032:
033: import java.awt.BorderLayout;
034: import java.awt.Component;
035: import java.awt.GridLayout;
036:
037: import javax.swing.Box;
038: import javax.swing.JButton;
039: import javax.swing.JComponent;
040: import javax.swing.JPanel;
041: import javax.swing.border.CompoundBorder;
042: import javax.swing.border.EmptyBorder;
043: import javax.swing.border.TitledBorder;
044:
045: import com.jgoodies.forms.builder.ButtonBarBuilder;
046: import com.jgoodies.forms.builder.PanelBuilder;
047: import com.jgoodies.forms.layout.CellConstraints;
048: import com.jgoodies.forms.layout.FormLayout;
049:
050: /**
051: * Demonstrates the JGoodies Looks <i>narrowMargin</i> option.
052: * Therefore it contains button rows that use different combinations
053: * of layout managers and narrow hints.
054: *
055: * @author Karsten Lentzsch
056: * @version $Revision: 1.6 $
057: */
058: final class NarrowTab {
059:
060: /**
061: * Builds the panel.
062: */
063: JComponent build() {
064: FormLayout layout = new FormLayout("left:pref, 0:grow",
065: "pref, 14dlu, pref, 14dlu, pref, 0:grow");
066: PanelBuilder builder = new PanelBuilder(layout);
067: builder.setDefaultDialogBorder();
068: builder.getPanel().setOpaque(false);
069:
070: CellConstraints cc = new CellConstraints();
071: builder.add(buildButtonBoxNoNarrow(), cc.xy(1, 1));
072: builder.add(buildButtonFormNoNarrow(), cc.xy(1, 3));
073: builder.add(buildButtonGridNoNarrow(), cc.xy(1, 5));
074:
075: return builder.getPanel();
076: }
077:
078: // Button FlowLayout Panels *********************************************
079:
080: private Component buildButtonBoxNoNarrow() {
081: return buildButtonBox(createButtons());
082: }
083:
084: private Component buildButtonBox(JButton[] buttons) {
085: Box box = Box.createHorizontalBox();
086: for (int i = 0; i < buttons.length; i++) {
087: box.add(buttons[i]);
088: box.add(Box.createHorizontalStrut(6));
089: }
090: JPanel panel = new JPanel(new BorderLayout());
091: panel.add(box, BorderLayout.CENTER);
092: panel.setOpaque(false);
093: panel.setBorder(new CompoundBorder(new TitledBorder(
094: "Raw Button Widths (BoxLayout)"), new EmptyBorder(14,
095: 14, 14, 14)));
096: return panel;
097: }
098:
099: // Button DesignGrids ***************************************************
100:
101: private Component buildButtonFormNoNarrow() {
102: JButton[] buttons = createButtons();
103: ButtonBarBuilder builder = new ButtonBarBuilder();
104: builder.getPanel().setOpaque(false);
105: for (int i = 0; i < buttons.length - 1; i++) {
106: builder.addGridded(buttons[i]);
107: builder.addRelatedGap();
108: }
109: builder.addFixed(buttons[buttons.length - 1]);
110:
111: JPanel panel = new JPanel(new BorderLayout());
112: panel.add(builder.getPanel(), BorderLayout.CENTER);
113: panel.setOpaque(false);
114: panel.setBorder(new CompoundBorder(new TitledBorder(
115: "Adjusted Button Widths (FormLayout)"),
116: new EmptyBorder(14, 14, 14, 14)));
117: return panel;
118: }
119:
120: // Button Grids *********************************************************
121:
122: private Component buildButtonGridNoNarrow() {
123: return buildButtonGrid(createButtons());
124: }
125:
126: private Component buildButtonGrid(JButton[] buttons) {
127: JPanel grid = new JPanel(new GridLayout(1, 4, 6, 0));
128: grid.setOpaque(false);
129: for (int i = 0; i < buttons.length; i++) {
130: grid.add(buttons[i]);
131: }
132: JPanel panel = new JPanel(new BorderLayout());
133: panel.add(grid, BorderLayout.CENTER);
134: panel.setOpaque(false);
135: panel.setBorder(new CompoundBorder(new TitledBorder(
136: "Equalized Button Widths (GridLayout)"),
137: new EmptyBorder(14, 14, 14, 14)));
138: return panel;
139: }
140:
141: // Helper Code **********************************************************
142:
143: /**
144: * Creates and returns an array of buttons that have no narrow hints set.
145: */
146: private JButton[] createButtons() {
147: return new JButton[] { new JButton("Add\u2026"),
148: new JButton("Remove"), new JButton("Up"),
149: new JButton("Down"), new JButton("Copy to Clipboard") };
150: }
151:
152: }
|