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 SummaryNested classes/interfaces inherited from class javax.swing.AbstractButtonAbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListenerNested classes/interfaces inherited from class javax.swing.JComponentJComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.ContainerContainer.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
- 
Field SummaryFields inherited from class javax.swing.AbstractButtonactionListener, 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.JComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.SwingConstantsBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
- 
Constructor SummaryConstructorsConstructorDescriptionButton()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 SummaryModifier 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.AbstractButtonactionPropertyChanged, 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.JComponentaddAncestorListener, 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.Containeradd, 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.Componentaction, 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- 
Buttonpublic Button()Default constructor. For java bean compatibility.
- 
ButtonConstruct a normal button. Sticky option can be specified.- Parameters:
- buttonDef- the definition of this button
- sticky- the sticky state
- dimension- the dimension of the button. If- null, the dimension will be calculated depending on the icon and/or the text
 
- 
Button
- 
ButtonConstructs a normal sticky button with a button group.- Parameters:
- buttonDef- the definition of this button
- buttonGroup- a button group. The button group can't be- null.
- dimension- the dimension of the button. If- null, 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 be- null
- text- the text to be displayed. Can be- null
- centerIconText- center state of the icon/text
- buttonDefs- an array of button definitions
- dimension- the dimension of the button. If- null, the dimension will be calculated depending on the icon and/ord the text
 
- 
Buttonpublic 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 be- null
- text- the text to be displayed. Can be- null
- centerIconText- center state of the icon/text
- buttonDefs- an array of button definitions
- updateButtonWithUserChoice- if true, the button will be updated with the user's choice
- dimension- the dimension of the button. If- null, the dimension will be calculated depending on the icon and/ord the text
 
- 
Buttonpublic 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 definitions
- defaultActionIdx- the default button definition displayed
- popupDefaultActionIdx- the action name to be fired when the user clicks directly on the button
- dimension- the dimension of the button. If- null, the dimension will be calculated depending on the icon and/or the text
 
- 
ButtonConstructs 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 definitions
- defaultActionIdx- the default button definition displayed
- sticky- sticky option
- dimension- the dimension of the button. If- null, the dimension will be calculated depending on the icon and/or the text
 
- 
Buttonpublic 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 definitions
- defaultActionIdx- the default button definition displayed
- sticky- sticky option. (Overriden if the buttonGroup is not- null)
- buttonGroup- a button group. If not- null, the sticky option is sets to- true
- dimension- the dimension of the button. If- null, the dimension will be calculated depending on the icon and/or the text
 
 
- 
- 
Method Details- 
setFixedHeightpublic void setFixedHeight(int height) Sets the height of the button.
- 
setFixedWidthpublic void setFixedWidth(int width) Sets the width of the button.
- 
setFixedSizeSets the size of the button. Note: anullsize has no effects- Parameters:
- dimension- new size
 
- 
setIconpublic 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
- 
setIconSets the icon of the current button definition. Note: A black border will be added- Parameters:
- imgTexture- the icon
- w- the width
- h- the height
 
- 
setIconSets the icon of the current button definition.- Overrides:
- setIconin class- AbstractButton
- Parameters:
- icon- the new icon
 
- 
setTextChange the text for a button definition.- Parameters:
- buttonDefIdx- the idx to change
- newText- the new text
 
- 
setTextChange the current visible text of the button. Anullvalue remove the current text.- Overrides:
- setTextin class- AbstractButton
- Parameters:
- newText- the text to display.
 
- 
getTextReturns the current visible text.- Overrides:
- getTextin class- AbstractButton
- Returns:
- text of the button; nullif there is no text
 
- 
isSelectedpublic boolean isSelected()Returs the selected state of this button. Note: Only sticky buttons with a button group are affected by this method.- Overrides:
- isSelectedin class- AbstractButton
- Returns:
- selected state
 
- 
setSelectedpublic 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 class- AbstractButton
- Parameters:
- isSelected- selected state
 
- 
getCurrentActionNameReturns the current action name of the button- Returns:
- the action name
 
- 
paintComponent- Overrides:
- paintComponentin class- JComponent
 
- 
processMouseEvent- Overrides:
- processMouseEventin class- JComponent
 
- 
actionPerformed- Specified by:
- actionPerformedin interface- ActionListener
 
- 
setCurrentAction
- 
cloneClones the Button
- 
propertyChange- Specified by:
- propertyChangein interface- PropertyChangeListener
 
- 
setSize
- 
setSizepublic void setSize(int width, int height) 
- 
setStickypublic void setSticky(boolean sticky) 
 
-