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.ButtonChangeListenerNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested 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_PROPERTYFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields 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
ConstructorsConstructorDescriptionButton()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 TypeMethodDescriptionvoidclone()Clones the ButtonReturns the current action name of the buttongetText()Returns the current visible text.booleanReturs the selected state of this button.voidprotected voidprocessMouseEvent(MouseEvent mouseevent) voidvoidsetCurrentAction(String actionName) voidsetFixedHeight(int height) Sets the height of the button.voidsetFixedSize(Dimension dimension) Sets the size of the button.voidsetFixedWidth(int width) Sets the width of the button.voidsetIcon(int colorRGB, int w, int h) Creates and sets an icon of a specific RGB color.voidSets the icon of the current button definition.voidSets the icon of the current button definition.voidsetSelected(boolean isSelected) Sets the selected state of the button.voidsetSize(int width, int height) voidvoidsetSticky(boolean sticky) voidChange the text for a button definition.voidChange 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, updateUIMethods 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, updateMethods 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, validateTreeMethods 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 benulltext- the text to be displayed. Can benullcenterIconText- 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 benulltext- the text to be displayed. Can benullcenterIconText- 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, thepopupDefaultActionIdxwill 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 totruedimension- 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: anullsize 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:
setIconin 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. Anullvalue remove the current text.- Overrides:
setTextin classAbstractButton- Parameters:
newText- the text to display.
-
getText
Returns the current visible text.- Overrides:
getTextin classAbstractButton- Returns:
- text of the button;
nullif 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:
isSelectedin 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:
setSelectedin classAbstractButton- Parameters:
isSelected- selected state
-
getCurrentActionName
Returns the current action name of the button- Returns:
- the action name
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
processMouseEvent
- Overrides:
processMouseEventin classJComponent
-
actionPerformed
- Specified by:
actionPerformedin interfaceActionListener
-
setCurrentAction
-
clone
Clones the Button -
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
setSize
-
setSize
public void setSize(int width, int height) -
setSticky
public void setSticky(boolean sticky)
-