eu.beesoft.gaia.swing
Class SimpleSwingForm

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by eu.beesoft.gaia.swing.SimpleSwingForm
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class SimpleSwingForm
extends javax.swing.JPanel

SimpleSwingForm is a component designed to the simplification of building the Swing forms.

Here is a simple example of SimpleSwingForm usage:

 SimpleSwingForm form = new SimpleSwingForm ();
 form.addLabeledComponent ("Label 1", form.createTextField ());
 form.addLabeledComponent ("Label 2", new JTextArea ());
 Action okAction = new MyOkAction (); // you must do something on OK
 form.showDialog ("My form", okAction, form.createStandardCancelAction ());
 

This builds on the 5 lines of code a two-rows form with labels "Label 1" and "Label 2" in the first column and components text field and text area in the second. Then is the form displayed in a dialog.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SimpleSwingForm()
          Create a new instance of the SimpleSwingForm.
 
Method Summary
 void addComponent(javax.swing.JComponent component)
          Adds component to this form.
 void addComponent(javax.swing.JComponent component, int width, int height)
          Adds component to this form.
 void addFiller()
          Adds filler as last component in the form.
 javax.swing.JLabel addLabel(java.lang.String label)
          Creates a new JLabel component for given label text and adds it to this form.
 javax.swing.JLabel addLabeledComponent(java.lang.String label, javax.swing.JComponent component)
          Adds component and its label to this form.
 javax.swing.JLabel addLabeledComponent(java.lang.String label, javax.swing.JComponent component, int width, int height)
          Adds component and its label to this form.
protected  void cancelActionPerformed()
          Invoked when user press standard Cancel action.
 javax.swing.Action createStandardCancelAction()
          Creates Action for Cancel button.
 javax.swing.Action createStandardOkAction()
          Creates Action for OK button.
 javax.swing.JTextArea createTextArea()
          Creates a new text area with processed minimum size and sets the font from JLabel as its font.
 javax.swing.JTextArea createTextArea(int rows)
          Creates a new text area with processed minimum size and sets the font from JLabel as its font.
 javax.swing.JTextField createTextField()
          Creates a new text field with processed minimum size.
 javax.swing.JTextField createTextField(int columns)
          Creates a new text field with processed minimum size.
protected  void customizeComponentConstraints(java.awt.GridBagConstraints gbc, javax.swing.JComponent component)
          Customizes GridBagConstraints object for the component.
protected  void customizeLabelConstraints(java.awt.GridBagConstraints gbc, javax.swing.JLabel label)
          Customizes GridBagConstraints object for label.
 void destroyDialog()
          Removes dialog in which is displayed this form and disposes it.
 java.awt.GridBagConstraints getConstraints()
          Returns the constraints object used by this SimpleSwingForm.
static javax.swing.Icon getIcon(java.lang.String name)
          Builds and returns an ImageIcon for given name.
protected  void okActionPerformed()
          Invoked when user press standard OK action.
 void showDialog(javax.swing.JDialog owner, java.lang.String title, javax.swing.Action... actions)
          Displays this form in the dialog.
 void showDialog(javax.swing.JDialog owner, java.lang.String title, javax.swing.JButton... buttons)
          Displays this form in the dialog.
 void showDialog(javax.swing.JFrame owner, java.lang.String title, javax.swing.Action... actions)
          Displays this form in the dialog.
 void showDialog(javax.swing.JFrame owner, java.lang.String title, javax.swing.JButton... buttons)
          Displays this form in the dialog.
 void showDialog(java.lang.String title, javax.swing.Action... actions)
          Displays this form in the dialog.
 void showDialog(java.lang.String title, javax.swing.JButton... buttons)
          Displays this form in the dialog.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintComponent, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printComponent, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, checkImage, checkImage, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleSwingForm

public SimpleSwingForm()
Create a new instance of the SimpleSwingForm.

Method Detail

getConstraints

public java.awt.GridBagConstraints getConstraints()
Returns the constraints object used by this SimpleSwingForm.

Returns:
the constraints object

addLabeledComponent

public javax.swing.JLabel addLabeledComponent(java.lang.String label,
                                              javax.swing.JComponent component)
Adds component and its label to this form.

Parameters:
label - - a label text usually displayed in front of component, can be null
component - - component to add
Returns:
created JLabel component

addLabeledComponent

public javax.swing.JLabel addLabeledComponent(java.lang.String label,
                                              javax.swing.JComponent component,
                                              int width,
                                              int height)
Adds component and its label to this form.

Parameters:
label - - a label text usually displayed in front of component, can be null
component - - component to add
width - - specifies the number of cells in a row for the component's display area.
height - - specifies the number of cells in a column for the component's display area.
Returns:
created JLabel component

addLabel

public javax.swing.JLabel addLabel(java.lang.String label)
Creates a new JLabel component for given label text and adds it to this form.

Parameters:
label - - a label text
Returns:
created JLabel component

customizeLabelConstraints

protected void customizeLabelConstraints(java.awt.GridBagConstraints gbc,
                                         javax.swing.JLabel label)
Customizes GridBagConstraints object for label. It sets these values to the constraints:

Parameters:
gbc - - a constraints
label - - a JLabel component

addComponent

public void addComponent(javax.swing.JComponent component)
Adds component to this form.

Parameters:
component - - a component to add

addComponent

public void addComponent(javax.swing.JComponent component,
                         int width,
                         int height)
Adds component to this form.

Parameters:
component - - a component to add
width - - specifies the number of cells in a row for the component's display area.
height - - specifies the number of cells in a column for the component's display area.

customizeComponentConstraints

protected void customizeComponentConstraints(java.awt.GridBagConstraints gbc,
                                             javax.swing.JComponent component)
Customizes GridBagConstraints object for the component. It sets these values to the constraints:

Parameters:
gbc - - a constraints
component - - a component

addFiller

public void addFiller()
Adds filler as last component in the form. It fills the remaining vertical space.


showDialog

public void showDialog(java.lang.String title,
                       javax.swing.Action... actions)
Displays this form in the dialog.

Parameters:
title - - the dialog title
actions - - the actions to control dialog

showDialog

public void showDialog(javax.swing.JFrame owner,
                       java.lang.String title,
                       javax.swing.Action... actions)
Displays this form in the dialog.

Parameters:
owner - - the Frame from which the dialog is displayed
title - - the dialog title
actions - - the actions to control dialog

showDialog

public void showDialog(javax.swing.JDialog owner,
                       java.lang.String title,
                       javax.swing.Action... actions)
Displays this form in the dialog.

Parameters:
owner - - the Dialog from which the new dialog is displayed
title - - the dialog title
actions - - the actions to control dialog

showDialog

public void showDialog(java.lang.String title,
                       javax.swing.JButton... buttons)
Displays this form in the dialog.

Parameters:
title - - the dialog title
buttons - - the buttons to control dialog

showDialog

public void showDialog(javax.swing.JDialog owner,
                       java.lang.String title,
                       javax.swing.JButton... buttons)
Displays this form in the dialog.

Parameters:
owner - - the Dialog from which the new dialog is displayed
title - - the dialog title
buttons - - the buttons to control dialog

showDialog

public void showDialog(javax.swing.JFrame owner,
                       java.lang.String title,
                       javax.swing.JButton... buttons)
Displays this form in the dialog.

Parameters:
owner - - the Frame from which the dialog is displayed
title - - the dialog title
buttons - - the buttons to control dialog

destroyDialog

public void destroyDialog()
Removes dialog in which is displayed this form and disposes it.


okActionPerformed

protected void okActionPerformed()
Invoked when user press standard OK action. Simply calls destroyDialog() in this implementation.


cancelActionPerformed

protected void cancelActionPerformed()
Invoked when user press standard Cancel action. Simply calls destroyDialog() in this implementation.


createStandardOkAction

public javax.swing.Action createStandardOkAction()
Creates Action for OK button. When this action is invoked, it calls okActionPerformed() method to process the event.

Returns:
newly created OK action

createStandardCancelAction

public javax.swing.Action createStandardCancelAction()
Creates Action for Cancel button. When this action is invoked, it calls cancelActionPerformed() method to process the event.

Returns:
newly created OK action

createTextField

public javax.swing.JTextField createTextField()
Creates a new text field with processed minimum size.

Returns:
newly created text field

createTextField

public javax.swing.JTextField createTextField(int columns)
Creates a new text field with processed minimum size.

Parameters:
columns - - the number of columns to use to calculate the preferred width; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
Returns:
newly created text field

createTextArea

public javax.swing.JTextArea createTextArea()
Creates a new text area with processed minimum size and sets the font from JLabel as its font.

Returns:
newly created text area

createTextArea

public javax.swing.JTextArea createTextArea(int rows)
Creates a new text area with processed minimum size and sets the font from JLabel as its font.

Parameters:
rows - - the number of rows >= 0
Returns:
newly created text area

getIcon

public static javax.swing.Icon getIcon(java.lang.String name)
Builds and returns an ImageIcon for given name. The name is a resource name on the classpath.

Parameters:
name - - icon name (or file name) on classpath
Returns:
newly created icon or null if not found