jimm.datavision.gui
Class EditFieldLayout

java.lang.Object
  extended by jimm.datavision.gui.EditFieldLayout

public class EditFieldLayout
extends java.lang.Object

Lays out a bunch of label/edit widget pairs. Optionally creates the edit widget for you. This is not a layout manager per se. Calling any of the add* methods creates label/edit widget pairs. Calling getPanel returns a panel containing the labels and edit widgets, arranged for your pleasure.

Author:
Jim Menard, jimm@io.com

Nested Class Summary
(package private) static class EditFieldLayout.Row
          Represents a label/component pair.
 
Field Summary
protected  javax.swing.border.Border border
           
protected  javax.swing.JPanel panel
           
protected  java.util.ArrayList rows
           
 
Constructor Summary
EditFieldLayout()
           
 
Method Summary
 java.awt.Component add(java.lang.String label, java.awt.Component c)
          Adds the label/component pair to the layout and returns the component.
 javax.swing.JButton addButton(java.lang.String label)
          Creates a button and adds it to the right-hand side, under the fields.
 javax.swing.JCheckBox addCheckBox(java.lang.String label)
          Creates a check box and adds it and the label.
 javax.swing.JCheckBox addCheckBox(java.lang.String label, int key)
          Creates a check box and adds it and the label.
 javax.swing.JComboBox addComboBox(java.lang.String label, java.lang.Object[] items)
          Creates a combo box and adds it and the label.
 javax.swing.JComboBox addComboBox(java.lang.String label, java.lang.Object[] items, boolean editable)
          Creates a combo box and adds it and the label.
 javax.swing.JLabel addLabel(java.lang.String label, java.lang.String text)
          Creates two labels and adds them.
 javax.swing.JPasswordField addPasswordField(java.lang.String label)
          Creates a password field and adds it and the label.
 javax.swing.JPasswordField addPasswordField(java.lang.String label, int columns)
          Creates a password field and adds it and the label.
 javax.swing.JPasswordField addPasswordField(java.lang.String label, java.lang.String password)
          Creates a password field and adds it and the label.
 javax.swing.JPasswordField addPasswordField(java.lang.String label, java.lang.String password, int columns)
          Creates a password field and adds it and the label.
 javax.swing.JTextArea addTextArea(java.lang.String label)
          Creates a text area and adds it and the label.
 javax.swing.JTextArea addTextArea(java.lang.String label, int rows, int cols)
          Creates a text area and adds it and the label.
 javax.swing.JTextArea addTextArea(java.lang.String label, java.lang.String text)
          Creates a text area and adds it and the label.
 javax.swing.JTextArea addTextArea(java.lang.String label, java.lang.String text, int rows, int cols)
          Creates a text area and adds it and the label.
 javax.swing.JTextField addTextField(java.lang.String label)
          Creates a text field and adds it and the label.
 javax.swing.JTextField addTextField(java.lang.String label, int columns)
          Creates a text field and adds it and the label.
 javax.swing.JTextField addTextField(java.lang.String label, java.lang.String text)
          Creates a text field and adds it and the label.
 javax.swing.JTextField addTextField(java.lang.String label, java.lang.String text, int columns)
          Creates a text field and adds it and the label.
protected  void buildPanel()
          Builds the panel.
 javax.swing.JPanel getPanel()
          Returns the panel containing all the labels and edit widgets.
 void setBorder(int allSides)
          Creates an empty border the same size on all sides.
 void setBorder(int top, int left, int bottom, int right)
          Creates an empty border on all sides.
 void skipRow()
          Creates an empty row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rows

protected java.util.ArrayList rows

border

protected javax.swing.border.Border border

panel

protected javax.swing.JPanel panel
Constructor Detail

EditFieldLayout

public EditFieldLayout()
Method Detail

add

public java.awt.Component add(java.lang.String label,
                              java.awt.Component c)
Adds the label/component pair to the layout and returns the component. If label does not end with a colon, one will be added. label may be null, in which case no label is displayed.

All the other add* methods call this one.

Parameters:
label - a possibly null label string
c - a GUI component
Returns:
the component

addTextField

public javax.swing.JTextField addTextField(java.lang.String label)
Creates a text field and adds it and the label.

Parameters:
label - a possibly null label string
Returns:
the new text field

addTextField

public javax.swing.JTextField addTextField(java.lang.String label,
                                           int columns)
Creates a text field and adds it and the label.

Parameters:
label - a possibly null label string
columns - the text field's size
Returns:
the new text field

addTextField

public javax.swing.JTextField addTextField(java.lang.String label,
                                           java.lang.String text)
Creates a text field and adds it and the label.

Parameters:
label - a possibly null label string
text - the text field's initial text
Returns:
the new text field

addTextField

public javax.swing.JTextField addTextField(java.lang.String label,
                                           java.lang.String text,
                                           int columns)
Creates a text field and adds it and the label.

Parameters:
label - a possibly null label string
text - the text field's initial text
columns - the text field's size
Returns:
the new text field

addTextArea

public javax.swing.JTextArea addTextArea(java.lang.String label)
Creates a text area and adds it and the label.

Parameters:
label - a possibly null label string
Returns:
the new text area

addTextArea

public javax.swing.JTextArea addTextArea(java.lang.String label,
                                         int rows,
                                         int cols)
Creates a text area and adds it and the label.

Parameters:
label - a possibly null label string
rows - the text field's height
cols - the text field's width
Returns:
the new text area

addTextArea

public javax.swing.JTextArea addTextArea(java.lang.String label,
                                         java.lang.String text)
Creates a text area and adds it and the label.

Parameters:
label - a possibly null label string
text - the text field's initial text
Returns:
the new text area

addTextArea

public javax.swing.JTextArea addTextArea(java.lang.String label,
                                         java.lang.String text,
                                         int rows,
                                         int cols)
Creates a text area and adds it and the label.

Parameters:
label - a possibly null label string
text - the text field's initial text
rows - the text field's height
cols - the text field's width
Returns:
the new text area

addCheckBox

public javax.swing.JCheckBox addCheckBox(java.lang.String label)
Creates a check box and adds it and the label.

Parameters:
label - a possibly null label string
Returns:
the new check box

addCheckBox

public javax.swing.JCheckBox addCheckBox(java.lang.String label,
                                         int key)
Creates a check box and adds it and the label.

Parameters:
label - a possibly null label string
key - the mnemonic key (a KeyEvent constant)
Returns:
the new check box

addComboBox

public javax.swing.JComboBox addComboBox(java.lang.String label,
                                         java.lang.Object[] items)
Creates a combo box and adds it and the label.

Parameters:
label - a possibly null label string
items - an array of objects
Returns:
the new combo box

addComboBox

public javax.swing.JComboBox addComboBox(java.lang.String label,
                                         java.lang.Object[] items,
                                         boolean editable)
Creates a combo box and adds it and the label.

Parameters:
label - a possibly null label string
items - an array of objects
editable - if true, the combo box will allow custom value entry by the user
Returns:
the new combo box

addLabel

public javax.swing.JLabel addLabel(java.lang.String label,
                                   java.lang.String text)
Creates two labels and adds them.

Parameters:
label - a possibly null label string
text - text for the right-hand label
Returns:
the new right-hand label

addPasswordField

public javax.swing.JPasswordField addPasswordField(java.lang.String label)
Creates a password field and adds it and the label.

Parameters:
label - a possibly null label string
Returns:
the new password field

addPasswordField

public javax.swing.JPasswordField addPasswordField(java.lang.String label,
                                                   int columns)
Creates a password field and adds it and the label.

Parameters:
label - a possibly null label string
columns - the password field's size
Returns:
the new password field

addPasswordField

public javax.swing.JPasswordField addPasswordField(java.lang.String label,
                                                   java.lang.String password)
Creates a password field and adds it and the label.

Parameters:
label - a possibly null label string
password - the initial password text
Returns:
the new password field

addPasswordField

public javax.swing.JPasswordField addPasswordField(java.lang.String label,
                                                   java.lang.String password,
                                                   int columns)
Creates a password field and adds it and the label.

Parameters:
label - a possibly null label string
password - the initial password text
columns - the password field's size
Returns:
the new password field

addButton

public javax.swing.JButton addButton(java.lang.String label)
Creates a button and adds it to the right-hand side, under the fields.

Parameters:
label - a button label
Returns:
the new button

skipRow

public void skipRow()
Creates an empty row.


setBorder

public void setBorder(int allSides)
Creates an empty border the same size on all sides.

Parameters:
allSides - the width of the border

setBorder

public void setBorder(int top,
                      int left,
                      int bottom,
                      int right)
Creates an empty border on all sides.

Parameters:
top - top border size
left - left border size
bottom - bottom border size
right - right border size

getPanel

public javax.swing.JPanel getPanel()
Returns the panel containing all the labels and edit widgets. Lazily instantiates the panel.

Returns:
the panel containing all the labels and edit widgets

buildPanel

protected void buildPanel()
Builds the panel.