maspack.widgets
Class LabeledComponent

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 maspack.widgets.LabeledComponentBase
                      extended by maspack.widgets.LabeledComponent
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, HasProperties, Disposable, HasAlignableLabels, LabeledWidget
Direct Known Subclasses:
CompositePropertyWidget, LabeledControl

public class LabeledComponent
extends LabeledComponentBase

A container class which arranges its components horizontally using a box layout, and has an optional label component at the left edge.

Other components can be added to this container as usual. However, components which are added using addMajorComponent will be accompanied by extra horizontal spacing (equal to the amount specified by setSpacing.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static PropertyList myProps
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
LabeledComponent(java.lang.String labelText)
          Creates a new LabledContainer, with a label containing the specified text.
LabeledComponent(java.lang.String labelText, java.awt.Component comp)
          Creates a new LabledContainer, with a label containing the specified text and an additional major component.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void addMajorComponent(java.awt.Component comp)
          Adds a major component to this labeled component.
 void addMajorComponent(java.awt.Component comp, int idx)
          Adds a major component to this labeled component at a specified location.
 void dispose()
           
 java.util.ArrayList<java.lang.String> getActions()
           
 PropertyList getAllPropertyInfo()
          Returns a list giving static information about all properties exported by this object.
 javax.swing.JLabel getLabel()
          Returns the JLabel associated with this control.
 void getLabelSpacing(LabelSpacing spacing)
           
 java.awt.Component getMainComponent()
           
 java.awt.Component getMajorComponent(int idx)
          Gets the major component located at a specific index.
 java.awt.Dimension getMaximumSize()
          
 java.awt.Dimension getMinimumSize()
           
 void getPreferredLabelSpacing(LabelSpacing spacing)
           
 int getSpacing()
          Gets the spacing associated with this component.
 int indexOfMajor(java.awt.Component comp)
          Gets the index of a specified major component, or -1 if the component is not present.
 boolean isLabelStretchable()
           
 boolean isStretchable()
          Returns true if this component is horizontally stretchable.
 int numMajorComponents()
           
 int removeMajorComponent(java.awt.Component comp)
          Removes the specified major component from this labeled component.
 void setLabelSpacing(LabelSpacing spacing)
           
 void setLabelStretchable(boolean flexible)
           
 void setLabelText(java.lang.String text)
          Sets the label text associated with this component.
 void setSpacing(int m)
          Sets the spacing associated with this component.
 void setStretchable(boolean enable)
          Specifies whether or not this component is horizontally stretchable.
 
Methods inherited from class maspack.widgets.LabeledComponentBase
getBackgroundColor, getLabelFontColor, getLabelText, getLeftInset, getProperty, isSelected, setBackgroundColor, setLabelFontColor, setSelected
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, 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, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface maspack.widgets.LabeledWidget
getToolTipText, setToolTipText
 

Field Detail

myProps

public static PropertyList myProps
Constructor Detail

LabeledComponent

public LabeledComponent(java.lang.String labelText)
Creates a new LabledContainer, with a label containing the specified text. If the label text is null, then no label is created.

Parameters:
labelText - optional text for this component's label

LabeledComponent

public LabeledComponent(java.lang.String labelText,
                        java.awt.Component comp)
Creates a new LabledContainer, with a label containing the specified text and an additional major component. Spacing is inserted between the label and the component. If the label text is null, then no label is created.

Parameters:
labelText - optional text for this component's label
comp - major component to add
Method Detail

getAllPropertyInfo

public PropertyList getAllPropertyInfo()
Description copied from interface: HasProperties
Returns a list giving static information about all properties exported by this object.

Specified by:
getAllPropertyInfo in interface HasProperties
Overrides:
getAllPropertyInfo in class LabeledComponentBase
Returns:
static information for all exported properties

isLabelStretchable

public boolean isLabelStretchable()

setLabelStretchable

public void setLabelStretchable(boolean flexible)

isStretchable

public boolean isStretchable()
Returns true if this component is horizontally stretchable.

Returns:
true if this component is stretchable
See Also:
setStretchable(boolean)

setStretchable

public void setStretchable(boolean enable)
Specifies whether or not this component is horizontally stretchable. By default, labeled components are not stretchable, which implies that their sizes are fixed at their preferred size.

Parameters:
enable - if true, makes this component horizontally stretchable
See Also:
isStretchable()

setSpacing

public void setSpacing(int m)
Sets the spacing associated with this component. Spacing is inserted between the label and all components added using addMajorComponent.

Parameters:
m - new spacing value, in pixels
See Also:
getSpacing()

getSpacing

public int getSpacing()
Gets the spacing associated with this component.

Returns:
spacing (in pixels) for this component
See Also:
setSpacing(int)

getMajorComponent

public java.awt.Component getMajorComponent(int idx)
Gets the major component located at a specific index.

Parameters:
idx - index of the major component
Returns:
major component at idx
See Also:
addMajorComponent(java.awt.Component)

addMajorComponent

public void addMajorComponent(java.awt.Component comp)
Adds a major component to this labeled component. A major component differs from other components in that it is separated from other components by some horizontal spacing (see getSpacing).

Parameters:
comp - component to add

addMajorComponent

public void addMajorComponent(java.awt.Component comp,
                              int idx)
Adds a major component to this labeled component at a specified location. A major component differs from other components in that it is separated from other components by some horizontal spacing (see getSpacing).

Parameters:
comp - component to add
idx - location within the major component list

numMajorComponents

public int numMajorComponents()

removeMajorComponent

public int removeMajorComponent(java.awt.Component comp)
Removes the specified major component from this labeled component.

Parameters:
comp - component to remove
See Also:
addMajorComponent(java.awt.Component)

indexOfMajor

public int indexOfMajor(java.awt.Component comp)
Gets the index of a specified major component, or -1 if the component is not present.


getLabel

public javax.swing.JLabel getLabel()
Returns the JLabel associated with this control.

Returns:
label component for this control

getMainComponent

public java.awt.Component getMainComponent()

setLabelText

public void setLabelText(java.lang.String text)
Sets the label text associated with this component.

Specified by:
setLabelText in interface LabeledWidget
Overrides:
setLabelText in class LabeledComponentBase
Parameters:
text - new label text
See Also:
LabeledComponentBase.getLabelText()

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

getMaximumSize

public java.awt.Dimension getMaximumSize()

Overrides:
getMaximumSize in class javax.swing.JComponent

getLabelSpacing

public void getLabelSpacing(LabelSpacing spacing)

setLabelSpacing

public void setLabelSpacing(LabelSpacing spacing)

getPreferredLabelSpacing

public void getPreferredLabelSpacing(LabelSpacing spacing)

dispose

public void dispose()
Specified by:
dispose in interface Disposable
Overrides:
dispose in class LabeledComponentBase

getActions

public java.util.ArrayList<java.lang.String> getActions()
Overrides:
getActions in class LabeledComponentBase

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class LabeledComponentBase