org.salespointframework.desktop
Class JOptionPanel

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 org.salespointframework.desktop.JOptionPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class JOptionPanel
extends javax.swing.JPanel

A Swing Panel realising a standard option panel layout. That means, option titles are displayed right in front of their corresponding components. All alignment is done automatically.

Since:
v3.3
Author:
Thomas Ryssel
See Also:
Serialized Form

Nested Class Summary
private  class JOptionPanel.OptionLayout
          A LayoutManager for positioning components in the way wished for.
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int BOTTOM
          Constant representing bottom alignment.
static int CENTER
          Constant representing center alignment.
static int LEFT
          Constant representing left alignment.
private  boolean m_fInitDone
          Whether or not initialization is finished.
private  java.lang.String m_sText
          The title text (will be shown using TitledBorder).
static int RIGHT
          Constant representing right alignment.
static int TOP
          Constant representing top alignment.
 
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
JOptionPanel()
          Create a new JOptionPanel without title and horizontal and vertical alignment set to LEFT and TOP, respectively.
JOptionPanel(java.lang.String text)
          Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively.
JOptionPanel(java.lang.String text, int hgap, int vgap)
          Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively.
JOptionPanel(java.lang.String text, int hgap, int vgap, int horizAlign, int vertAlign)
          Create a new JOptionPanel.
 
Method Summary
 void addOption(java.lang.String title, javax.swing.JComponent component)
          Add the given component under the given title.
 void addOption(java.lang.String title, java.lang.Object text)
          Add a "display only" option. the text's toString() method will be used to construct a JLabel that will be displayed.
 java.awt.Component getOptionComponent(int n)
          Get the n-th option component (in the order they were added).
 java.lang.String getText()
          Get the option panel's title text.
 void setLayout(java.awt.LayoutManager mgr)
          Set layout manager.
 void setText(java.lang.String text)
          Set the option panel's title text.
 
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, getBaseline, getBaselineResizeBehavior, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, 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, 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, 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, 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
 

Field Detail

m_sText

private java.lang.String m_sText
The title text (will be shown using TitledBorder).


m_fInitDone

private boolean m_fInitDone
Whether or not initialization is finished. This is mainly used to guard the LayoutManager once it is set.


CENTER

public static final int CENTER
Constant representing center alignment.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Constant representing left alignment.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Constant representing right alignment.

See Also:
Constant Field Values

TOP

public static final int TOP
Constant representing top alignment.

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Constant representing bottom alignment.

See Also:
Constant Field Values
Constructor Detail

JOptionPanel

public JOptionPanel()
Create a new JOptionPanel without title and horizontal and vertical alignment set to LEFT and TOP, respectively. Horizontal gap will be 16 (pixels) and vertical gap will be set to 4 (pixels).


JOptionPanel

public JOptionPanel(java.lang.String text)
Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively. Horizontal gap will be 16 (pixels) and vertical gap will be set to 4 (pixels).

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.

JOptionPanel

public JOptionPanel(java.lang.String text,
                    int hgap,
                    int vgap)
Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively.

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.
hgap - Horizontal gap (between titles and components).
vgap - Vertical gap.

JOptionPanel

public JOptionPanel(java.lang.String text,
                    int hgap,
                    int vgap,
                    int horizAlign,
                    int vertAlign)
Create a new JOptionPanel.

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.
hgap - Horizontal gap (between titles and components).
vgap - Vertical gap.
horizAlign - Horizontal aligment. Can be either LEFT, RIGHT or CENTER.
vertAlign - Vertical alignment. Can be either TOP, BOTTOM or CENTER.
Method Detail

setText

public void setText(java.lang.String text)
Set the option panel's title text.

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.

getText

public java.lang.String getText()
Get the option panel's title text.

Returns:
The title text of the panel.

addOption

public void addOption(java.lang.String title,
                      javax.swing.JComponent component)
Add the given component under the given title. The layout will be done according to the preferred dimensions of the components.

If the component's preferred width is set to Integer.MAX_VALUE, it will take up all possibly available horizontal space. If the component's preferred height is set to Integer.MAX_VALUE, it will take up all vertical space that is left. Note that there cannot be any other components underneath such a component.

Components are always shown in the order they have been added (from top to bottom).

Parameters:
title - The option's title. If it is no empty string, a colon (":") will be added automatically.
component - The component representing the option in however way.

addOption

public void addOption(java.lang.String title,
                      java.lang.Object text)
Add a "display only" option. the text's toString() method will be used to construct a JLabel that will be displayed. That is merely a convenience method that allows you to simply display information.

For example, you could do something like: addOption("File", "test.txt");.

Parameters:
title - The option's title. If it is no empty string, a colon (":") will be added automatically.
text - The object representing the text to show.

getOptionComponent

public java.awt.Component getOptionComponent(int n)
Get the n-th option component (in the order they were added).

Parameters:
n - Number of the component to retrieve.
Returns:
The component requested.

setLayout

public void setLayout(java.awt.LayoutManager mgr)
Set layout manager. Overridden so that it cannot be used anymore after initialization.

Overrides:
setLayout in class java.awt.Container