Holger's
Java API

com.antelmann.util.gui
Class FormFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by com.antelmann.util.gui.JMainFrame
                          extended by com.antelmann.util.gui.FormFrame
All Implemented Interfaces:
Form, ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class FormFrame
extends JMainFrame
implements Form

a Frame that takes some form along with a FormValidator to edit some data. The Frame contains the form and a toolbar with a save and a close button. Upon saving, disposing or in the event of exceptions, events are generated that can be monitored via the Listener interface. Since all components sit on the embedded mainPanel using a BorderLayout, it is relatively easy to add additional components to the sides of the frame.

Since:
24. November 2007, 19:48
Author:
Holger Antelmann
See Also:
FormDialog, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JButton closeButton
           
protected  JPanel mainPanel
           
protected  JButton saveButton
           
 
Fields inherited from class com.antelmann.util.gui.JMainFrame
hasStatusBar, logger, statusBar, statusLabel, verbose
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.antelmann.util.gui.Form
EDIT_PROPERTY_KEY
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FormFrame(String title, JComponent form, FormValidator<?> validator)
          calls the next constructor with saveAlwaysEnabled=true
FormFrame(String title, JComponent form, FormValidator<?> validator, boolean saveAlwaysEnabled)
           
 
Method Summary
 void addListener(FormListener l)
           
 boolean closeAction()
           
 boolean disposeForm(boolean forceWithoutConfirm)
          allows to programmatically close the form.
 JToolBar getButtonContainer()
          returns the toolbar that already contains save and close buttons
 JComponent getFormComponent()
           
 Container getFormContainer()
          provides access to the overall window, dialog, frame, internal frame or other that holds the form with the formComponent and all the functional buttons that belong to the form
 FormListener[] getFormListeners()
           
 FormValidator<?> getFormValidator()
           
 JPanel getMainPanel()
          returns the panel in the center that has the toolbar and the form on it
 boolean getWarnOnClose()
          determines whether a warning is displayed upon cancel if the form is marked as changed (false by default)
 boolean isDirty()
          determines whether the form is currently considered to be in a 'changed'-mode.
 Object performSaveAction()
          programmatically performs the action that would commonly be performed upon pressing 'save' on the form.
 void propertyChange(PropertyChangeEvent evt)
          marks the form dirty and enables the save button (in case it's not already generally enabled)
 boolean removeListener(FormListener l)
           
 void setWarnOnClose(boolean flag)
          if set to true, a warning is displayed when the form is closed w/o saving if it is marked changed
 
Methods inherited from class com.antelmann.util.gui.JMainFrame
complain, dispose, getStatusText, hasStatusBar, initStatusBar, say, setCentralContent, setStatusText, updateStatusText
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

mainPanel

protected final JPanel mainPanel

saveButton

protected JButton saveButton

closeButton

protected JButton closeButton
Constructor Detail

FormFrame

public FormFrame(String title,
                 JComponent form,
                 FormValidator<?> validator)
calls the next constructor with saveAlwaysEnabled=true


FormFrame

public FormFrame(String title,
                 JComponent form,
                 FormValidator<?> validator,
                 boolean saveAlwaysEnabled)
Method Detail

getMainPanel

public JPanel getMainPanel()
returns the panel in the center that has the toolbar and the form on it


getButtonContainer

public JToolBar getButtonContainer()
returns the toolbar that already contains save and close buttons

Specified by:
getButtonContainer in interface Form

getFormComponent

public JComponent getFormComponent()
Specified by:
getFormComponent in interface Form

getFormValidator

public FormValidator<?> getFormValidator()
Specified by:
getFormValidator in interface Form

addListener

public void addListener(FormListener l)
Specified by:
addListener in interface Form

removeListener

public boolean removeListener(FormListener l)
Specified by:
removeListener in interface Form

getFormListeners

public FormListener[] getFormListeners()
Specified by:
getFormListeners in interface Form

isDirty

public boolean isDirty()
Description copied from interface: Form
determines whether the form is currently considered to be in a 'changed'-mode. The form is in a changed mode after it received a PropertyChangeEvent until it is saved again.

Specified by:
isDirty in interface Form

performSaveAction

public Object performSaveAction()
Description copied from interface: Form
programmatically performs the action that would commonly be performed upon pressing 'save' on the form. Commonly, this method would first call FormValidator.validateForm(Component) and then call FormValidator.commitFormAction(Component); also this method resets the Form.isDirty() status if the commit was successful.

Specified by:
performSaveAction in interface Form
Returns:
the object saved or null if that didn't happen

getWarnOnClose

public boolean getWarnOnClose()
Description copied from interface: Form
determines whether a warning is displayed upon cancel if the form is marked as changed (false by default)

Specified by:
getWarnOnClose in interface Form

setWarnOnClose

public void setWarnOnClose(boolean flag)
Description copied from interface: Form
if set to true, a warning is displayed when the form is closed w/o saving if it is marked changed

Specified by:
setWarnOnClose in interface Form

closeAction

public boolean closeAction()

disposeForm

public boolean disposeForm(boolean forceWithoutConfirm)
Description copied from interface: Form
allows to programmatically close the form.

Specified by:
disposeForm in interface Form
Parameters:
forceWithoutConfirm - if true, the form will be disposed no matter what; if false, a confirmation dialog may appear if the form is dirty and warnOnClose is true
Returns:
true only if the form has been closed (and the listeners were informed accordingly)

propertyChange

public void propertyChange(PropertyChangeEvent evt)
marks the form dirty and enables the save button (in case it's not already generally enabled)

Specified by:
propertyChange in interface PropertyChangeListener

getFormContainer

public Container getFormContainer()
Description copied from interface: Form
provides access to the overall window, dialog, frame, internal frame or other that holds the form with the formComponent and all the functional buttons that belong to the form

Specified by:
getFormContainer in interface Form


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads