net.wotonomy.ui.swing.components
Class InfoPanel

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 net.wotonomy.ui.swing.components.InfoPanel
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class InfoPanel
extends javax.swing.JPanel
implements java.awt.event.ActionListener

InfoPanel uses labels and textfields (or any other component - see below) to display a list of keys and values in a well-aligned and consistent manner, conforming to alignment and pixel spacing in the java look and feel design guidelines.

Each key is displayed in a label to the left of the component that contains the corresponding value. Each row is displayed starting at the top of the component's available area. Each row's height is the maximum preferred height of its components and the field itself gets as much of the width as it can, dependent on the length of the longest label.

The values in the fields can be editable, and the current value can be retrieved using the key - for this reason, unique keys are recommended.

As a convenience, push buttons may be placed across the bottom of the panel in a manner similar to ButtonPanel.

The panel forwards any ActionEvents generated by the components and buttons on it to all registered listeners.

Optionally, any component can be used instead of a textfield. However, get/setValueForKey() and get/setEditable() may not work for those components. Use getComponentForKey() to access them instead.

Version:
$Revision: 904 $ $Date: 2006-02-18 23:19:05 +0000 (Sat, 18 Feb 2006) $
Author:
michael@mpowers.net, $Author: cgruber $
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
protected  java.awt.event.ActionListener actionListener
           
protected  ButtonPanel buttonPanel
           
protected  int columns
           
protected  java.util.List fields
           
protected  java.util.List fieldSpacers
           
protected  int hgap
           
static java.lang.String HIDDEN
          Special label for an empty pair - a label and component that take up space but are hidden from view.
protected  boolean isEditable
           
protected  int labelAlign
           
protected  int labelAnchor
           
protected  java.util.List labels
           
protected  java.awt.Container listContainer
           
protected  java.util.Collection listenedToComponents
           
protected  int margin
           
protected  java.lang.String postfix
           
protected  java.lang.String prefix
           
protected  int vgap
           
 
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
InfoPanel()
          Constructs an empty InfoPanel.
InfoPanel(java.lang.String[] labelArray)
          Constructs an InfoPanel with the specified labels each paired with a blank textfield.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called by buttons on panel and by other components that might be set to broadcast events to this listener.
 void addActionListener(java.awt.event.ActionListener l)
          Adds an action listener to the list that will be notified by events occurring in the panel.
protected  void addCompositeComponent(java.lang.String key, java.awt.Component component)
          Appends a label containing a key and the specified component to the bottom of the panel.
 void addPair(java.lang.String key, java.awt.Component component)
          Appends a label containing a key and the specified component to the bottom of the panel.
 void addPair(java.lang.String key, java.lang.String value)
          Convenience method that uses a stock JTextField.
 void addPair(java.lang.String key, java.lang.String value, javax.swing.JTextField textField)
          Convenience method that uses the specified JTextField or subclass and sets it to the specified value.
 void addRow(java.lang.String key, java.awt.Component component)
          Appends a label containing a key and the specified component to the bottom of the panel.
 void addRow(java.lang.String key, java.awt.Component[] components)
          Appends a label containing a key and the specified components to the bottom of the panel.
 void addRow(java.lang.String key, java.awt.Component west, java.awt.Component center, java.awt.Component east)
          Appends a label containing a key and the specified components to the bottom of the panel.
 void addRow(java.lang.String key, java.awt.Component west, java.awt.Component north, java.awt.Component center, java.awt.Component south, java.awt.Component east)
          Appends a label containing a key and the specified components to the bottom of the panel.
protected  void broadcastEvent(java.awt.event.ActionEvent e)
          Notifies all registered action listeners of a pending Action Event.
protected  javax.swing.JLabel createLabel()
          Provided for backwards compatibility, and called by the default implementation of createLabelForKey.
protected  java.awt.Component createLabelForKey(java.lang.String aKey)
          Override to return a specific component to be used as a label.
 javax.swing.JPanel createPanel()
          Factory method for creating panel spacers.
protected  void doInitialLayout()
          This method is responsible for the initial layout of the panel.
 ButtonPanel getButtonPanel()
          Retrieves the actual button panel, if any.
 java.lang.String[] getButtons()
          Retrieves the names of the buttons that are displayed, if any.
 int getColumns()
          Gets the current number of columns.
 java.lang.Object getComponentForIndex(int row)
          Gets the component at the specified row.
 java.lang.Object getComponentForIndex(int row, int col)
          Gets the component at the specified row and column.
 java.awt.Component getComponentForKey(java.lang.String key)
          Gets the component associated with the key.
 java.awt.Component getComponentForKey(java.lang.String key, int index)
          Gets the component associated with the key and index.
protected  java.awt.Container getCompositeComponentForKey(java.lang.String key)
          Gets the container associated with the key.
 javax.swing.JTextField getFieldForKey(java.lang.String key)
          Gets the component associated with the key as a JTextField, for backwards compatibility.
 int getHgap()
          Gets the current horizontal spacing between components.
 int getLabelAlignment()
          Retrieves the constant used to align the labels in place.
 int getLabelAnchor()
          Retrieves the constant used to anchor the labels in place.
 java.awt.Component getLabelComponentForKey(java.lang.String key)
          Get the label component associated with the key.
 javax.swing.JLabel getLabelForKey(java.lang.String key)
          Provided for backwards compatibility: calls getLabelComponentForKey.
 java.lang.String getLabelPostfix()
          Gets the string that appears after each label's text on the panel.
 java.lang.String getLabelPrefix()
          Gets the string that appears before each label's text on the panel.
 java.lang.String[] getLabels()
          Retrieves the labls for the components on the panel in the order in which they are displayed from top WIDTH bottom.
 int getMargin()
          Gets the current minimum margin for the labels column.
protected  java.lang.Object getValueForComponent(java.awt.Component aComponent)
          Gets the value in the specified component.
 java.lang.Object getValueForIndex(int anIndex)
          Gets the value in the field at the specified index.
 java.lang.Object getValueForIndex(int row, int col)
          Gets the value in the field at the specified row and column.
 java.lang.Object getValueForKey(java.lang.String key)
          Gets the value in the field associated with the key.
 java.lang.Object getValueForKey(java.lang.String key, int index)
          Gets the value in the field associated with the key.
 double getVerticalWeightForKey(java.lang.String key)
          Sets the vertical weight used for determining how to distribute additional vertical space in the component.
 int getVgap()
          Gets the current vertical spacing between components.
protected  void introspectComponent(java.awt.Component aComponent, java.lang.String aKey)
          Introspects a component to set the action command and to add the InfoPanel to its list of ActionListeners.
 boolean isEditable()
          Gets whether the values displayed in the panel are editable.
protected  java.awt.Container makeCompositeComponent(java.lang.String key, java.awt.Component[] components)
          Produces a container that contains the specified components, using GridLayout.
protected  java.awt.Container makeCompositeComponent(java.lang.String key, java.awt.Component west, java.awt.Component center, java.awt.Component east)
          Produces a container that contains the specified components, using BorderLayout.
protected  java.awt.Container makeCompositeComponent(java.lang.String key, java.awt.Component west, java.awt.Component north, java.awt.Component center, java.awt.Component south, java.awt.Component east)
          Produces a container that contains the specified components, using BorderLayout.
 void removeActionListener(java.awt.event.ActionListener l)
          Removes an action listener from the list that will be notified by events occurring in the panel.
 void removeAll()
          Removes all components from the list.
 void setButtons(java.lang.String[] buttons)
          Adds one or buttons to the bottom of the panel with the specified labels from left to right.
 void setColumns(int newColumns)
          Sets the number of columns for the panel.
 void setComponentForIndex(int row, java.awt.Component c)
          Replaces the first component in the specified row.
 void setComponentForIndex(int row, int col, java.awt.Component c)
          Replaces the component associated with the key.
 void setComponentForKey(java.lang.String key, java.awt.Component c)
          Replaces the first component associated with the key.
 void setComponentForKey(java.lang.String key, java.awt.Component c, int index)
          Replaces the component associated with the key.
 void setEditable(boolean isEditable)
          Sets whether the values displayed in the panel should be editable.
 void setHgap(int newHgap)
          Changes the horizontal spacing between the label and the components in the panel.
 void setLabelAlignment(int anAlignmentConstant)
          Sets the constant used to align the labels in place and reflows the layout.
 void setLabelAnchor(int anAnchorConstant)
          Sets the constant used to anchor the labels in place and reflows the layout.
 void setLabelPostfix(java.lang.String aString)
          Sets the string that appears after each label's text on the panel.
 void setLabelPrefix(java.lang.String aString)
          Sets the string that appears before each label's text on the panel.
 void setLabels(java.lang.String[] labelArray)
          Creates a set of labels and empty textfields after first clearing all existing components on the panel.
 void setMargin(int newMargin)
          Sets the minimum width for the labels column.
protected  void setText(java.awt.Component c, java.lang.String text)
          Called to populate a label component with the specified text.
protected  void setValueForComponent(java.awt.Component aComponent, java.lang.Object value)
          Sets the value in the field at the specified index.
 void setValueForIndex(int row, int col, java.lang.Object value)
          Sets the field at the specified row index and column index to the specified value.
 void setValueForIndex(int row, java.lang.Object value)
          Sets the first field at the specified row index to the specified value.
 void setValueForKey(java.lang.String key, java.lang.Object value)
          Sets the field associated with the key to the specified value.
 void setValueForKey(java.lang.String key, java.lang.Object value, int index)
          Sets the field associated with the key to the specified value.
 void setVerticalWeightForKey(java.lang.String key, double weighty)
          Sets the vertical weight used for determining how to distribute additional vertical space in the component.
 void setVgap(int newVgap)
          Changes the vertical spacing between components in the panel.
protected  void updateGaps()
          Updates the insets for all components.
protected  void updateLabels()
          Updates the label alignment.
 
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, 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, 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, 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

HIDDEN

public static final java.lang.String HIDDEN
Special label for an empty pair - a label and component that take up space but are hidden from view. This might be useful for achieving certain layouts.

See Also:
Constant Field Values

listContainer

protected java.awt.Container listContainer

hgap

protected int hgap

vgap

protected int vgap

margin

protected int margin

columns

protected int columns

fields

protected java.util.List fields

labels

protected java.util.List labels

fieldSpacers

protected java.util.List fieldSpacers

buttonPanel

protected ButtonPanel buttonPanel

isEditable

protected boolean isEditable

prefix

protected java.lang.String prefix

postfix

protected java.lang.String postfix

labelAnchor

protected int labelAnchor

labelAlign

protected int labelAlign

actionListener

protected java.awt.event.ActionListener actionListener

listenedToComponents

protected java.util.Collection listenedToComponents
Constructor Detail

InfoPanel

public InfoPanel()
Constructs an empty InfoPanel.


InfoPanel

public InfoPanel(java.lang.String[] labelArray)
Constructs an InfoPanel with the specified labels each paired with a blank textfield.

Parameters:
labelArray - An Array containing the labels in the order in which they should appear from top to bottom. A null value produces an empty panel.
Method Detail

setLabels

public void setLabels(java.lang.String[] labelArray)
Creates a set of labels and empty textfields after first clearing all existing components on the panel.

Parameters:
labelArray - An Array containing the labels in the order in which they should appear from top to bottom. A null value will clear the panel.

getLabels

public java.lang.String[] getLabels()
Retrieves the labls for the components on the panel in the order in which they are displayed from top WIDTH bottom. These are the keys used to reference values or to reference the components directly.

Returns:
An Array of Strings containing the labels.

getLabelAnchor

public int getLabelAnchor()
Retrieves the constant used to anchor the labels in place. The default value is GridBagConstraints.NORTHWEST.


setLabelAnchor

public void setLabelAnchor(int anAnchorConstant)
Sets the constant used to anchor the labels in place and reflows the layout.

Parameters:
anAnchorConstant - An anchor constant from GridBagConstraints.

getLabelAlignment

public int getLabelAlignment()
Retrieves the constant used to align the labels in place. The default value is GridBagConstraints.CENTER.


setLabelAlignment

public void setLabelAlignment(int anAlignmentConstant)
Sets the constant used to align the labels in place and reflows the layout.

Parameters:
anAlignmentConstant - LEFT, CENTER, or RIGHT constants from SwingUtilities.

createPanel

public javax.swing.JPanel createPanel()
Factory method for creating panel spacers. This implementation returns a JPanel with opaque set to false. Override to customize.


doInitialLayout

protected void doInitialLayout()
This method is responsible for the initial layout of the panel. All labels and textfields will later added to listContainer. This method is responsible for initializing listContainer.


setHgap

public void setHgap(int newHgap)
Changes the horizontal spacing between the label and the components in the panel. Note: Assumes listContainer uses a GridBagLayout.

Parameters:
newHgap - the new spacing, in pixels. May not be negative.

getHgap

public int getHgap()
Gets the current horizontal spacing between components.

Returns:
the current horizontal spacing, in pixels.

setVgap

public void setVgap(int newVgap)
Changes the vertical spacing between components in the panel. Note: Assumes listContainer uses a GridBagLayout.

Parameters:
newVgap - the new spacing, in pixels. May not be negative.

getVgap

public int getVgap()
Gets the current vertical spacing between components.

Returns:
the current vertical spacing, in pixels.

setMargin

public void setMargin(int newMargin)
Sets the minimum width for the labels column. This left margin will grow if one of the labels is wider than this value. Note: assumes GridBagLayout.

Parameters:
newMargin - the new minimum margin in pixels. May not be negative.

getMargin

public int getMargin()
Gets the current minimum margin for the labels column.

Returns:
the current minimum margin in pixels.

setColumns

public void setColumns(int newColumns)
Sets the number of columns for the panel. Label/Component pairs will start from the top left and fill in to the right before wrapping to the next row. The default number of columns is one. Note: assumes GridBagLayout.

Parameters:
newColumns - the new number of columns. May not be less than one.

getVerticalWeightForKey

public double getVerticalWeightForKey(java.lang.String key)
Sets the vertical weight used for determining how to distribute additional vertical space in the component.

Parameters:
aComponent - Key that exists in the layout.
Returns:
weighty The weight of the component, or -1.0 if not found.

setVerticalWeightForKey

public void setVerticalWeightForKey(java.lang.String key,
                                    double weighty)
Sets the vertical weight used for determining how to distribute additional vertical space in the component. By default, all weights are zero, so each component gets its preferred height. If any weights are specified, then additional space is allocated to those components proportionately.

Parameters:
aComponent - Key that exists in the layout.
weighty - The new weight.

getColumns

public int getColumns()
Gets the current number of columns.

Returns:
the current number of columns.

addPair

public void addPair(java.lang.String key,
                    java.awt.Component component)
Appends a label containing a key and the specified component to the bottom of the panel. Any registered action listeners will receive action events from the component - the key corresponding to the component will be used as the action command.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
component - A component that will be placed next to the label. If null, a blank JPanel will be used.

addRow

public void addRow(java.lang.String key,
                   java.awt.Component component)
Appends a label containing a key and the specified component to the bottom of the panel. Any registered action listeners will receive action events from the component - the key corresponding to the component will be used as the action command.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
component - A component that will be placed next to the label. If null, a blank JPanel will appear.

addRow

public void addRow(java.lang.String key,
                   java.awt.Component[] components)
Appends a label containing a key and the specified components to the bottom of the panel. Any registered action listeners will receive action events from the component - the key corresponding to the component will be used as the action command.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
components - An array of components that will be placed next to the label. Any nulls in the list will be replaced with blank JPanels.

addRow

public void addRow(java.lang.String key,
                   java.awt.Component west,
                   java.awt.Component center,
                   java.awt.Component east)
Appends a label containing a key and the specified components to the bottom of the panel. Any registered action listeners will receive action events from the components - the key corresponding to the component will be used as the action command.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
west - A component that will appear to the left of the other components, as wide as its preferred width and as tall as the tallest of the other components. A null will be replaced with a blank JPanel.
center - A component that will appear between the other components, taking up available space. A null will be replaced with a blank JPanel.
east - A component that will appear to the right of the other components, as wide as its preferred width and as tall as the tallest of the other components. A null will be replaced with a blank JPanel.

addRow

public void addRow(java.lang.String key,
                   java.awt.Component west,
                   java.awt.Component north,
                   java.awt.Component center,
                   java.awt.Component south,
                   java.awt.Component east)
Appends a label containing a key and the specified components to the bottom of the panel. Any registered action listeners will receive action events from the components - the key corresponding to the component will be used as the action command.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
west - A component that will appear to the left of the other components, as wide as its preferred width and as tall as the tallest of the other components. A null will be replaced with a blank JPanel.
north - A component that will appear above all the other components, as tall as its preferred height and as wide as the info panel itself.
center - A component that will appear between the other components, taking up available space. A null will be replaced with a blank JPanel.
south - A component that will appear below all the other components, as tall as its preferred height and as wide as the info panel itself.
east - A component that will appear to the right of the other components, as wide as its preferred width and as tall as the tallest of the other components. A null will be replaced with a blank JPanel.

makeCompositeComponent

protected java.awt.Container makeCompositeComponent(java.lang.String key,
                                                    java.awt.Component[] components)
Produces a container that contains the specified components, using GridLayout. Nulls are ignored. This implementation returns a JPanel.


makeCompositeComponent

protected java.awt.Container makeCompositeComponent(java.lang.String key,
                                                    java.awt.Component west,
                                                    java.awt.Component center,
                                                    java.awt.Component east)
Produces a container that contains the specified components, using BorderLayout. Nulls are ignored. This implementation returns a JPanel.


makeCompositeComponent

protected java.awt.Container makeCompositeComponent(java.lang.String key,
                                                    java.awt.Component west,
                                                    java.awt.Component north,
                                                    java.awt.Component center,
                                                    java.awt.Component south,
                                                    java.awt.Component east)
Produces a container that contains the specified components, using BorderLayout. Nulls are ignored. This implementation returns a JPanel.


createLabelForKey

protected java.awt.Component createLabelForKey(java.lang.String aKey)
Override to return a specific component to be used as a label. This implementation calls createLabel().


createLabel

protected javax.swing.JLabel createLabel()
Provided for backwards compatibility, and called by the default implementation of createLabelForKey. This implementation returns a JLabel.


addCompositeComponent

protected void addCompositeComponent(java.lang.String key,
                                     java.awt.Component component)
Appends a label containing a key and the specified component to the bottom of the panel. Any registered action listeners will receive action events from the component - the key corresponding to the component will be used as the action command.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
component - A component that will be placed next to the label. If null, a stock JTextField will be used.

introspectComponent

protected void introspectComponent(java.awt.Component aComponent,
                                   java.lang.String aKey)
Introspects a component to set the action command and to add the InfoPanel to its list of ActionListeners.

Parameters:
aComponent - The Component to be introspected.
aKey - The action command to be set.

setText

protected void setText(java.awt.Component c,
                       java.lang.String text)
Called to populate a label component with the specified text. This implementation attempts to call setText(String) on the component. Override to customize.


updateGaps

protected void updateGaps()
Updates the insets for all components.


updateLabels

protected void updateLabels()
Updates the label alignment.


addPair

public void addPair(java.lang.String key,
                    java.lang.String value)
Convenience method that uses a stock JTextField.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
value - A string that will be displayed in a textfield.

addPair

public void addPair(java.lang.String key,
                    java.lang.String value,
                    javax.swing.JTextField textField)
Convenience method that uses the specified JTextField or subclass and sets it to the specified value.

Parameters:
key - A string that will be displayed in a label, preferrably unique.
value - A string that will be displayed in a textfield.
textField - A JTextField or subclass that will be used to display the value. If null, a stock JTextField will be used.

removeAll

public void removeAll()
Removes all components from the list. Buttons, if any, will remain unchanged - use setButtons( null ) to remove them. NOTE: does not call super.removeAll().

Overrides:
removeAll in class java.awt.Container

setButtons

public void setButtons(java.lang.String[] buttons)
Adds one or buttons to the bottom of the panel with the specified labels from left to right. Any action listeners will receive action events from clicks on these buttons - the supplied label will be used as the action command.

Parameters:
buttons - A string array containing the strings to be used for the button labels and action commands. A null value will remove the button panel.
See Also:
ButtonPanel

getButtons

public java.lang.String[] getButtons()
Retrieves the names of the buttons that are displayed, if any.

Returns:
A string array containing the strings used for the button labels and action commands, or null if no buttons have been created.
See Also:
ButtonPanel

getButtonPanel

public ButtonPanel getButtonPanel()
Retrieves the actual button panel, if any.

Returns:
A button panel, or null if none has been created.
See Also:
ButtonPanel

setEditable

public void setEditable(boolean isEditable)
Sets whether the values displayed in the panel should be editable. Defaults to true.

Parameters:
isEditable - Whether the values should be editable.

isEditable

public boolean isEditable()
Gets whether the values displayed in the panel are editable.

Returns:
Whether the values should be editable.

setValueForKey

public void setValueForKey(java.lang.String key,
                           java.lang.Object value)
Sets the field associated with the key to the specified value. Note: If the component does not respond to setText() or setString() or setValue() the value will not be set. JTextFields and the like will work.

Parameters:
key - A string representing the key associated with the field. Nulls are converted to an empty string.
value - A object to be displayed in the specified field. Nulls are converted to an empty string.

setValueForKey

public void setValueForKey(java.lang.String key,
                           java.lang.Object value,
                           int index)
Sets the field associated with the key to the specified value. Note: If the component does not respond to setText() or setString() or setValue() the value will not be set. JTextFields and the like will work.

Parameters:
key - A string representing the key associated with the field. Nulls are converted to an empty string.
value - A object to be displayed in the specified field. Nulls are converted to an empty string.

setValueForIndex

public void setValueForIndex(int row,
                             java.lang.Object value)
Sets the first field at the specified row index to the specified value. Note: If the component does not respond to setText() or setString() or setValue() the value will not be set. JTextFields and the like will work.

Parameters:
row - The row index of the component.
value - A object to be displayed in the specified field. Nulls are converted to an empty string.

setValueForIndex

public void setValueForIndex(int row,
                             int col,
                             java.lang.Object value)
Sets the field at the specified row index and column index to the specified value. Note: If the component does not respond to setText() or setString() or setValue() the value will not be set. JTextFields and the like will work.

Parameters:
row - The row index of the component.
index - The column index of the component.
value - A object to be displayed in the specified field. Nulls are converted to an empty string.

setValueForComponent

protected void setValueForComponent(java.awt.Component aComponent,
                                    java.lang.Object value)
Sets the value in the field at the specified index. Note: If the component does not respond to setText() or setString() or setValue() this method will return null. JTextFields and the like will work.

Parameters:
A - valid index.
value - A object to be displayed in the specified field.

getValueForIndex

public java.lang.Object getValueForIndex(int anIndex)
Gets the value in the field at the specified index. Note: If the component does not respond to getText() or getString() or getSelectedItem() this method will return null. JTextFields and the like will work.

Parameters:
A - valid index.
Returns:
An object representing the value in the field at the specified index, or null if the component does not have a text property or if the index is out of bounds.

getValueForIndex

public java.lang.Object getValueForIndex(int row,
                                         int col)
Gets the value in the field at the specified row and column. Note: If the component does not respond to getText() or getString() or getSelectedItem() this method will return null. JTextFields and the like will work.

Parameters:
A - valid index.
Returns:
An object representing the value in the field at the specified index, or null if the component does not have a text property or if the index is out of bounds.

getValueForKey

public java.lang.Object getValueForKey(java.lang.String key)
Gets the value in the field associated with the key. Note: If the component does not respond to getText() or getString() or getSelectedItem() this method will return null. JTextFields and the like will work.

Parameters:
key - An string representing the key associated with the field. Nulls are converted to an empty string.
Returns:
An object representing the value in the field associated with the key, or null if the key does not exist or if the component does not have a text property.

getValueForKey

public java.lang.Object getValueForKey(java.lang.String key,
                                       int index)
Gets the value in the field associated with the key. Note: If the component does not respond to getText() or getString() or getSelectedItem() this method will return null. JTextFields and the like will work.

Parameters:
key - An string representing the key associated with the field. Nulls are converted to an empty string.
Returns:
An object representing the value in the field associated with the key, or null if the key does not exist or if the component does not have a text property.

getValueForComponent

protected java.lang.Object getValueForComponent(java.awt.Component aComponent)
Gets the value in the specified component. Note: If the component does not respond to getText() or getString() or getSelectedItem() this method will return null. JTextFields and the like will work.

Parameters:
aComponent - The specified component.
Returns:
An object representing the value in the component. or null if the component does not have a text property.

getFieldForKey

public javax.swing.JTextField getFieldForKey(java.lang.String key)
Gets the component associated with the key as a JTextField, for backwards compatibility.

Parameters:
key - A string representing the key associated with the component. Nulls are converted to an empty string.
Returns:
A JTextField that contains the value associated with the key, or null if the key does not exist or if the component is not a JTextField.

getComponentForKey

public java.awt.Component getComponentForKey(java.lang.String key)
Gets the component associated with the key. If more than one component is associated with the key, returns the first such component.

Parameters:
key - A string representing the key associated with the component. Nulls are converted to an empty string.
Returns:
A component that contains the value associated with the key, or null if the key does not exist.

getComponentForKey

public java.awt.Component getComponentForKey(java.lang.String key,
                                             int index)
Gets the component associated with the key and index.

Parameters:
key - A string representing the key associated with the component. Nulls are converted to an empty string.
Returns:
A component that contains the value associated with the key, or null if the key does not exist.

getComponentForIndex

public java.lang.Object getComponentForIndex(int row)
Gets the component at the specified row. If more than one component exists on that row, returns the first such component.

Returns:
A component or null if the row does not exist.

getComponentForIndex

public java.lang.Object getComponentForIndex(int row,
                                             int col)
Gets the component at the specified row and column.

Returns:
A component or null if the index is out of bounds.

getCompositeComponentForKey

protected java.awt.Container getCompositeComponentForKey(java.lang.String key)
Gets the container associated with the key.

Parameters:
key - A string representing the key associated with the component. Nulls are converted to an empty string.
Returns:
A component that contains the value associated with the key, or null if the key does not exist.

getLabelForKey

public javax.swing.JLabel getLabelForKey(java.lang.String key)
Provided for backwards compatibility: calls getLabelComponentForKey.

Parameters:
key - A string representing the key associated with the compoent. Nulls are converted to an empty string.
Returns:
Component label object associated with the key, or null if the key does not exist or if the label component is not an instance of JLabel.

getLabelComponentForKey

public java.awt.Component getLabelComponentForKey(java.lang.String key)
Get the label component associated with the key.

Parameters:
key - A string representing the key associated with the compoent. Nulls are converted to an empty string.
Returns:
Component label object associated with the key, or null if the key does not exist.

setComponentForKey

public void setComponentForKey(java.lang.String key,
                               java.awt.Component c)
Replaces the first component associated with the key. Any value in the existing component will be copied to the new component.

Parameters:
key - A string representing the key to be associated with the component. Nulls are converted to an empty string.
c - A component to be placed next to the label corresponding to the key. Nulls are converted to a JTextField.

setComponentForKey

public void setComponentForKey(java.lang.String key,
                               java.awt.Component c,
                               int index)
Replaces the component associated with the key. Any value in the existing component will be copied to the new component.

Parameters:
key - A string representing the key to be associated with the component. Nulls are converted to an empty string.
c - A component to be placed next to the label corresponding to the key. Nulls are converted to a JTextField.

setComponentForIndex

public void setComponentForIndex(int row,
                                 java.awt.Component c)
Replaces the first component in the specified row. Any value in the existing component will be copied to the new component.

Parameters:
row - A valid index.
c - A component to be placed next to the label corresponding to the key.

setComponentForIndex

public void setComponentForIndex(int row,
                                 int col,
                                 java.awt.Component c)
Replaces the component associated with the key. Any value in the existing component will be copied to the new component.

Parameters:
row - A valid index.
c - A component to be placed next to the label corresponding to the key.

setLabelPrefix

public void setLabelPrefix(java.lang.String aString)
Sets the string that appears before each label's text on the panel.

Parameters:
aString - A String to be used as the label prefix.

getLabelPrefix

public java.lang.String getLabelPrefix()
Gets the string that appears before each label's text on the panel. Defaults to "", an empty string.

Returns:
A String that is currently used as the label prefix.

setLabelPostfix

public void setLabelPostfix(java.lang.String aString)
Sets the string that appears after each label's text on the panel. Defaults to ": ", a colon followed by a space.

Parameters:
aString - A String to be used as the label postfix.

getLabelPostfix

public java.lang.String getLabelPostfix()
Gets the string that appears after each label's text on the panel.

Returns:
A String that is currently used as the label postfix.

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Adds an action listener to the list that will be notified by events occurring in the panel.

Parameters:
l - An action listener to be notified.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes an action listener from the list that will be notified by events occurring in the panel.

Parameters:
l - An action listener to be removed.

broadcastEvent

protected void broadcastEvent(java.awt.event.ActionEvent e)
Notifies all registered action listeners of a pending Action Event.

Parameters:
e - An action event to be broadcast.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called by buttons on panel and by other components that might be set to broadcast events to this listener. Simply forwards the action event unchanged.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - An action event to be received.


Copyright © 2006 null. All Rights Reserved.