|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
net.wotonomy.ui.swing.components.ButtonPanel
public class ButtonPanel
ButtonPanel handles display and event broadcasting of standard buttons like
OK/Cancel/Save/etc. The constructor takes a list or array of strings, each
representing a button to appear on the panel from left to right.
Any button click will send an action event to all listeners with the action
command containing the corresponding string. Note action events are simply
forwarded from the buttons themselves, so the source of the event will be
the button, not the button panel. The button panel is the source of the
STATE_CHANGED events that notify about changes to the panel itself.
Nested Class Summary | |
---|---|
class |
ButtonPanel.ActionChangeListener
A property change listener that listens specifically for property changes from action objects. |
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
|
static java.lang.String |
ADD
Specifies an "Add" button. |
protected java.awt.Container |
buttonContainer
This is the container to which buttons are added. |
protected java.util.Vector |
buttonList
This is the list of all buttons on the panel. |
protected java.awt.FlowLayout |
buttonPanelLayout
This is the layout manager - which must be a FlowLayout or subclass. |
static java.lang.String |
CANCEL
Specifies a "Refresh" button. |
static java.lang.String |
CLEAR_ALL
Specifies a "Clear All" button. |
protected java.awt.Insets |
insets
The insets for this panel, so they can be modified. |
static java.lang.String |
NO
Specifies a "No" button. |
static java.lang.String |
OK
Specifies a "OK" button. |
static java.lang.String |
REFRESH
Specifies a "Refresh" button. |
static java.lang.String |
REMOVE
Specifies a "Remove" button. |
static java.lang.String |
SAVE
Specifies a "Save" button. |
static java.lang.String |
STATE_CHANGED
This is the action command to all listeners when the button state is changed. |
static java.lang.String |
YES
Specifies a "Yes" button. |
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 | |
---|---|
ButtonPanel()
Constructs a ButtonPanel. |
|
ButtonPanel(javax.swing.Action[] actionList)
Constructs a ButtonPane using specified actions. |
|
ButtonPanel(java.lang.String[] buttonList)
Constructs a ButtonPanel using specified buttons. |
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 button events and changes in button state. |
protected void |
addComponentToPanel(java.awt.Component aComponent)
Adds a component to the right-most side of the layout. |
protected void |
broadcastEvent(java.awt.event.ActionEvent e)
Notifies all registered action listeners of a pending Action Event. |
protected java.awt.Component |
createComponentWithLabel(java.lang.String aLabel)
Creates a new component with the specified label. |
int |
getAlignment()
Gets the alignment of the buttons in the panel. |
java.awt.Component |
getButton(java.lang.String aLabel)
Gets the first component having the specified name. |
int |
getHgap()
Gets the current horizontal spacing between components. |
java.awt.Insets |
getInsets()
Overridden to return the user-specified insets for this panel. |
java.lang.String[] |
getLabels()
Gets the labels of the buttons that appear on the panel, ordered from left to right. |
int |
getVgap()
Gets the current vertical spacing between components. |
protected void |
initLayout()
This method is responsible for the initial layout of the panel. |
static void |
main(java.lang.String[] argv)
|
void |
mouseDragged(java.awt.event.MouseEvent e)
|
void |
mouseMoved(java.awt.event.MouseEvent e)
|
void |
removeActionListener(java.awt.event.ActionListener l)
Removes an action listener from the list that will be notified by button events and changes in button state. |
void |
setAlignment(int alignment)
Changes the alignment of the buttons in the panel. |
void |
setEnabled(boolean isEnabled)
Overridden to call setEnabled on all components on panel. |
void |
setHgap(int newHgap)
Changes the horizontal spacing between components in the panel. |
void |
setInsets(java.awt.Insets newInsets)
Changes the insets for this panel. |
void |
setLabels(javax.swing.Action[] actions)
|
void |
setLabels(java.lang.String[] labels)
Creates the buttons to appear on the panel. |
void |
setVgap(int newVgap)
Changes the vertical spacing between components in the panel. |
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, 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, 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, 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 |
---|
public static final java.lang.String OK
public static final java.lang.String SAVE
public static final java.lang.String REFRESH
public static final java.lang.String CLEAR_ALL
public static final java.lang.String CANCEL
public static final java.lang.String YES
public static final java.lang.String NO
public static final java.lang.String ADD
public static final java.lang.String REMOVE
public static final java.lang.String STATE_CHANGED
protected java.awt.Container buttonContainer
protected java.util.Vector buttonList
protected java.awt.Insets insets
protected java.awt.FlowLayout buttonPanelLayout
protected java.awt.event.ActionListener actionListener
Constructor Detail |
---|
public ButtonPanel()
public ButtonPanel(java.lang.String[] buttonList)
buttonList
- An array containing the strings to be used in labeling the buttons.public ButtonPanel(javax.swing.Action[] actionList)
actionList
- An array of actions to be used to create buttons with.Method Detail |
---|
protected void initLayout()
public void setLabels(java.lang.String[] labels)
labels
- An array of strings to be used in labeling the buttons.
If null, all buttons will be removed.public void setLabels(javax.swing.Action[] actions)
public java.lang.String[] getLabels()
public java.awt.Component getButton(java.lang.String aLabel)
protected java.awt.Component createComponentWithLabel(java.lang.String aLabel)
aLabel
- The label for the component that will be created.
protected void addComponentToPanel(java.awt.Component aComponent)
aComponent
- The component to be added to the layout.public void setAlignment(int alignment)
alignment
- A valid alignment code, per BetterFlowLayout implementation.BetterFlowLayout
public int getAlignment()
FlowLayout
public void setHgap(int newHgap)
newHgap
- the new spacing, in pixels. May not be negative.public int getHgap()
public void setVgap(int newVgap)
newVgap
- the new spacing, in pixels. May not be negative.public int getVgap()
public void setInsets(java.awt.Insets newInsets)
newInsets
- the new insets.public java.awt.Insets getInsets()
getInsets
in class javax.swing.JComponent
public void setEnabled(boolean isEnabled)
setEnabled
in class javax.swing.JComponent
isEnabled
- whether to enable the panel and all components on it.public void addActionListener(java.awt.event.ActionListener l)
l
- An action listener to be notified.public void removeActionListener(java.awt.event.ActionListener l)
l
- An action listener to be removed.protected void broadcastEvent(java.awt.event.ActionEvent e)
e
- An action event to be broadcast.public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
e
- An action event to be received.public static void main(java.lang.String[] argv)
public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |