Package com.kheops.ui.component
Class Button
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
com.kheops.ui.component.Button
- All Implemented Interfaces:
ActionListener
,ImageObserver
,ItemSelectable
,MenuContainer
,PropertyChangeListener
,Serializable
,Cloneable
,EventListener
,SwingConstants
public class Button
extends AbstractButton
implements ActionListener, Cloneable, PropertyChangeListener
A Button object is a button that can take different configuration. It can be sticky or not, it can popup a menu defined by an array of ButtonDef, etc.
If a group is specified :
Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in
the group. There is no way to turn a button programmatically to "off", in order to clear the button group.
Examples of configurations
- Normal button (w/o text) :
Button(new ButtonDef("theAction", anIcon, null, true), false, new Dimension(32, 32));
- Normal sticky button (with text) :
Button(new ButtonDef("theAction", anIcon, "Example", true), true, new Dimension(32, 32));
- Normal sticky button with a group :
Button(new ButtonDef("theAction", anIcon, "Example", true), aButtonGroup, new Dimension(32, 32));
- A button (w/o little pop bar) that will popup a menu. The user can select an item in the menu. The button will not
be updated with the selection made in the menu. The dimension will be calculated.
Define some ButtonDef :
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Create the button :
Button(anIcon, "List of actions", false, new ButtonDef[]{bDefA, bDefB, bDefC}, null);
- A button that will popup a menu when the user clicks on the little pop bar. If the user clicks directly on the
button, the "Action B" (idx 1) will be fired. The default icon / text displayed is "Action A" (idx 0).
Define some ButtonDef :
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Create the button :
Button(new ButtonDef[]{bDefA, bDefB, bDefC}, 0, 1, new Dimension(44, 32));
- A button that will popup a menu when the user clicks on the little pop bar. The button will be updated with
the choice made by the user. If the user clicks directly on the button, the current action will be fired. The button
is not sticky in this example. The default definition displayed is "Action A" (idx 0).
Define some ButtonDef :
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Create the button :
Button(new ButtonDef[]{bDefA, bDefB, bDefC}, 0, false, new Dimension(44, 32));
- A button that will popup a menu when the user clicks on the little pop bar. The button will be updated with
the choice made by the user. If the user clicks directly on the button, the current action will be fired. The button
is sticky in this example and is appart of a button group. The default definition displayed is "Action C" (idx 2).
Define some ButtonDef :
ButtonDef bDefA = new ButtonDef("actionA", anIcon, "Choice A", false);
ButtonDef bDefB = new ButtonDef("actionB", anIcon, "Choice B", false);
ButtonDef bDefC = new ButtonDef("actionC", anIcon, "Choice C", false);
Create the button :
Button(new ButtonDef[]{bDefA, bDefB, bDefC}, 2, true, aButtonGroup, new Dimension(44, 32));
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
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
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
Constructor Summary
ConstructorDescriptionButton()
Default constructor.Button
(ButtonDef[] buttonDefs, int defaultActionIdx, boolean sticky, ButtonGroup buttonGroup, Dimension dimension) Constructs a button that will be updated with the choice made in the popup menu.Constructs a button that will be updated with the choice made in the popup menu.Button
(ButtonDef[] buttonDefs, int defaultActionIdx, int popupDefaultActionIdx, Dimension dimension) Constructs a button that displays a popup menu when the user clicks on the little pop bar.Construct a normal button.Button
(ButtonDef buttonDef, ButtonGroup buttonGroup, Dimension dimension) Constructs a normal sticky button with a button group.Button
(Action action, ButtonGroup buttonGroup, Dimension dimension) Button
(ImageIcon icon, String text, boolean centerIconText, ButtonDef[] buttonDefs, boolean updateButtonWithUserChoice, Dimension dimension) Constructs a button that will pop a popup menu when the user click on it.Button
(ImageIcon icon, String text, boolean centerIconText, ButtonDef[] buttonDefs, Dimension dimension) Deprecated.use Button(ImageIcon, String, boolean, ButtonDef[], false, Dimension) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clone()
Clones the ButtonReturns the current action name of the buttongetText()
Returns the current visible text.boolean
Returs the selected state of this button.void
protected void
processMouseEvent
(MouseEvent mouseevent) void
void
setCurrentAction
(String actionName) void
setFixedHeight
(int height) Sets the height of the button.void
setFixedSize
(Dimension dimension) Sets the size of the button.void
setFixedWidth
(int width) Sets the width of the button.void
setIcon
(int colorRGB, int w, int h) Creates and sets an icon of a specific RGB color.void
Sets the icon of the current button definition.void
Sets the icon of the current button definition.void
setSelected
(boolean isSelected) Sets the selected state of the button.void
setSize
(int width, int height) void
void
setSticky
(boolean sticky) void
Change the text for a button definition.void
Change the current visible text of the button.Methods inherited from class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, paramString, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setUI, setVerticalAlignment, setVerticalTextPosition, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, 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, 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, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
Button
public Button()Default constructor. For java bean compatibility. -
Button
Construct a normal button. Sticky option can be specified.- Parameters:
buttonDef
- the definition of this buttonsticky
- the sticky statedimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/or the text
-
Button
-
Button
Constructs a normal sticky button with a button group.- Parameters:
buttonDef
- the definition of this buttonbuttonGroup
- a button group. The button group can't benull
.dimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/ord the text
-
Button
-
Button
@Deprecated public Button(ImageIcon icon, String text, boolean centerIconText, ButtonDef[] buttonDefs, Dimension dimension) Deprecated.use Button(ImageIcon, String, boolean, ButtonDef[], false, Dimension)Constructs a button that will pop a popup menu when the user click on it. There is no little pop bar with this constructor and no default action. The button will not be updated with the choice made by the user.- Parameters:
icon
- the icon to be displayed. Can benull
text
- the text to be displayed. Can benull
centerIconText
- center state of the icon/textbuttonDefs
- an array of button definitionsdimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/ord the text
-
Button
public Button(ImageIcon icon, String text, boolean centerIconText, ButtonDef[] buttonDefs, boolean updateButtonWithUserChoice, Dimension dimension) Constructs a button that will pop a popup menu when the user click on it. There is no little pop bar with this constructor and no default action.- Parameters:
icon
- the icon to be displayed. Can benull
text
- the text to be displayed. Can benull
centerIconText
- center state of the icon/textbuttonDefs
- an array of button definitionsupdateButtonWithUserChoice
- if true, the button will be updated with the user's choicedimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/ord the text
-
Button
public Button(ButtonDef[] buttonDefs, int defaultActionIdx, int popupDefaultActionIdx, Dimension dimension) Constructs a button that displays a popup menu when the user clicks on the little pop bar. The button will not be updated with the choice made by the user. If the user clicks directly on the button, thepopupDefaultActionIdx
will be fired. This button will not be sticky.- Parameters:
buttonDefs
- an array of button definitionsdefaultActionIdx
- the default button definition displayedpopupDefaultActionIdx
- the action name to be fired when the user clicks directly on the buttondimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/or the text
-
Button
Constructs a button that will be updated with the choice made in the popup menu. The popup menu will be displayed if the user click on the little pop bar. The current action will be fired if the user clicks on the button. The initial button definition displayed is specified by the defaultActionIdx. Sticky option can be specified.- Parameters:
buttonDefs
- an array of button definitionsdefaultActionIdx
- the default button definition displayedsticky
- sticky optiondimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/or the text
-
Button
public Button(ButtonDef[] buttonDefs, int defaultActionIdx, boolean sticky, ButtonGroup buttonGroup, Dimension dimension) Constructs a button that will be updated with the choice made in the popup menu. The popup menu will be displayed if the user clicks on the little pop bar. The initial button definition displayed is specified by the defaultActionIdx. Sticky option can be specified but if the button group specified is notnull
, sticky option will be set totrue
.- Parameters:
buttonDefs
- an array of button definitionsdefaultActionIdx
- the default button definition displayedsticky
- sticky option. (Overriden if the buttonGroup is notnull
)buttonGroup
- a button group. If notnull
, the sticky option is sets totrue
dimension
- the dimension of the button. Ifnull
, the dimension will be calculated depending on the icon and/or the text
-
-
Method Details
-
setFixedHeight
public void setFixedHeight(int height) Sets the height of the button. -
setFixedWidth
public void setFixedWidth(int width) Sets the width of the button. -
setFixedSize
Sets the size of the button. Note: anull
size has no effects- Parameters:
dimension
- new size
-
setIcon
public void setIcon(int colorRGB, int w, int h) Creates and sets an icon of a specific RGB color. Note: A black border will be added -
setIcon
Sets the icon of the current button definition. Note: A black border will be added- Parameters:
imgTexture
- the iconw
- the widthh
- the height
-
setIcon
Sets the icon of the current button definition.- Overrides:
setIcon
in classAbstractButton
- Parameters:
icon
- the new icon
-
setText
Change the text for a button definition.- Parameters:
buttonDefIdx
- the idx to changenewText
- the new text
-
setText
Change the current visible text of the button. Anull
value remove the current text.- Overrides:
setText
in classAbstractButton
- Parameters:
newText
- the text to display.
-
getText
Returns the current visible text.- Overrides:
getText
in classAbstractButton
- Returns:
- text of the button;
null
if there is no text
-
isSelected
public boolean isSelected()Returs the selected state of this button. Note: Only sticky buttons with a button group are affected by this method.- Overrides:
isSelected
in classAbstractButton
- Returns:
- selected state
-
setSelected
public void setSelected(boolean isSelected) Sets the selected state of the button. Note: Only sticky buttons with a button group are affected by this method.- Overrides:
setSelected
in classAbstractButton
- Parameters:
isSelected
- selected state
-
getCurrentActionName
Returns the current action name of the button- Returns:
- the action name
-
paintComponent
- Overrides:
paintComponent
in classJComponent
-
processMouseEvent
- Overrides:
processMouseEvent
in classJComponent
-
actionPerformed
- Specified by:
actionPerformed
in interfaceActionListener
-
setCurrentAction
-
clone
Clones the Button -
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
-
setSize
-
setSize
public void setSize(int width, int height) -
setSticky
public void setSticky(boolean sticky)
-