001: package net.sourceforge.squirrel_sql.fw.gui;
002:
003: /*
004: * Copyright (C) 2001-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.Component;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.Insets;
025:
026: import javax.swing.Box;
027: import javax.swing.JLabel;
028: import javax.swing.JPanel;
029:
030: public class PropertyPanel extends JPanel {
031: private final GridBagLayout _layout = new GridBagLayout();
032: private boolean _singleColumn = true;
033: private int _nbrComponents;
034: // private int _lastX;
035: private int _lastY;
036:
037: public PropertyPanel() {
038: super ();
039: setLayout(_layout);
040: }
041:
042: public void setSingleColumn(boolean value) {
043: _singleColumn = value;
044: }
045:
046: public void add(JLabel label, Component data) {
047: add(label, data, null);
048: }
049:
050: public void add(JLabel label, Component data, Component extra) {
051: label.setLabelFor(data);
052: pvtAdd(label, data, extra);
053: }
054:
055: public void add(JLabel leftLabel, JLabel rightlabel) {
056: pvtAdd(leftLabel, rightlabel, null);
057: }
058:
059: public void add(Component left, Component right) {
060: pvtAdd(left, right, null);
061: }
062:
063: public void add(Component left, Component right, Component extra) {
064: pvtAdd(left, right, extra);
065: }
066:
067: private void pvtAdd(Component leftComp, Component rightComp,
068: Component extra) {
069: final boolean isOdd = ++_nbrComponents % 2 != 0;
070: final GridBagConstraints cons = new GridBagConstraints();
071: if (_singleColumn || isOdd) {
072: cons.gridy = ++_lastY;
073: } else {
074: cons.gridy = _lastY;
075: }
076: cons.gridheight = 1;
077: cons.gridwidth = 1;
078: cons.insets = new Insets(4, 4, 4, 4);
079: cons.fill = GridBagConstraints.BOTH;
080:
081: if (_singleColumn || isOdd) {
082: cons.gridx = 0;
083: } else {
084: cons.gridx = 3;
085: }
086: cons.weightx = 0.0f;
087: _layout.setConstraints(leftComp, cons);
088: add(leftComp);
089:
090: ++cons.gridx;
091: cons.weightx = 1.0f;
092: if (extra != null) {
093: Box box = Box.createHorizontalBox();
094: box.add(rightComp);
095: box.add(extra);
096: _layout.setConstraints(box, cons);
097: add(box);
098: } else {
099: _layout.setConstraints(rightComp, cons);
100: add(rightComp);
101: }
102: }
103: }
|