DESY ACOP Beans Home

com.cosylab.gui.components
Class SimpleButton

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by com.cosylab.gui.components.ResizableTextLabel
                      extended by com.cosylab.gui.components.GradientLabel
                          extended by com.cosylab.gui.components.SimpleButton
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants
Direct Known Subclasses:
ArrowButton, Digit

public class SimpleButton
extends GradientLabel

A very simple implementation of a button. It supports three action modes identified by:

Version:
$id$
Author:
Jernej Kamenik
See Also:
GradientLabel, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.cosylab.gui.components.ResizableTextLabel
ResizableTextLabel.ResizableAdapter
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int CHAIN_ACTION_MODE
          Events are fired continuously until mouse button is released.
static int DEFAULT_ACTION_MODE
          One event is fired for one click.
static int FAST_ACTION_MODE
          One event is fired for one click.
protected static java.lang.String MOUSE_CHAIN
           
protected static java.lang.String MOUSE_CLICKED
           
protected static java.lang.String MOUSE_PRESSED
           
protected static java.lang.String MOUSE_RELEASED
           
static int NULL_ACTION_MODE
          No events are fired.
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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 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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SimpleButton()
          Creates a simple button without text .
SimpleButton(javax.swing.Icon icon)
          Creates a simple button with Icon.
SimpleButton(java.lang.String text)
          Creates a simple button with text.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
          Adds an action listener to the list of registered listeners for this button.
 void addNotify()
          This method was overriden to implement font resizing.
protected  void fireActionPerformed(java.awt.event.ActionEvent e)
          Fires an action event to all its listeners
 int getActionMode()
          Returns the currently set action mode.
 java.awt.Color getBackground()
           
 java.awt.Color getBackgroundStart()
          Returns the backgroundStart, this is the color that is used for the start of label's gradient.
 javax.swing.border.Border getBorder()
           
 int getFireRate()
          Gets the rate of event firing in the CHAIN_MODE
 java.awt.Color getForeground()
           
 java.awt.Color getPressedBackground()
          Returns the background color displayed when the button is pressed.
 java.awt.Color getPressedBackgroundStart()
          Returns the starting background gradient color displayed when the button is pressed.
 javax.swing.border.Border getPressedBorder()
          Returns the border displayed when the button is pressed.
 java.awt.Color getPressedForeground()
          Returns the foreground color displayed when the button is pressed.
 java.awt.Color getRolloverBackground()
          Returns the background color displayed when the mouse cursor is over the button and rollover is enabled.
 java.awt.Color getRolloverBackgroundStart()
          Returns the start of background gradient color displayed when the mouse cursor is over the button and rollover is enabled.
 javax.swing.border.Border getRolloverBorder()
          Returns the border displayed when the mouse cursor is over the button and rollover is enabled.
 java.awt.Color getRolloverForeground()
          Returns the foreground color displayed when the mouse cursor is over the button and rollover is enabled.
 boolean isPressed()
          Gets the property specifiing whether the button is being pressed.
 boolean isRollover()
          Gets the property specifiing whether the mouse is being moved over the button.
 boolean isRolloverEnabled()
          Returns wether this SimpleButton visually indicates when mouse is over it.
static void main(java.lang.String[] args)
          Run test applet.
protected  void paintBorder(java.awt.Graphics g)
          This method was overloaded to enable advanced graphical features of the SimpleButton
 void paintComponent(java.awt.Graphics g)
          This method was overloaded to enable advanced graphical features of the SimpleButton
 void removeActionListener(java.awt.event.ActionListener l)
          Removes an action listener from the list of registered listeners for this button.
 void removeNotify()
           
 void setActionMode(int newMode)
          Sets the action mode of the SimpleButton.
 void setBackground(java.awt.Color newColor)
          Sets the background color.
 void setBackgroundStart(java.awt.Color newColor)
          Sets the backgroundStart color.
 void setBorder(javax.swing.border.Border newBorder)
           
 void setFireRate(int newRate)
          Sets the rate of event firing in the CHAIN_MODE
 void setForeground(java.awt.Color newColor)
           
protected  void setPressed(boolean newPressed)
          Returns the property specifiing whether the button is being pressed.
 void setPressedBackground(java.awt.Color newColor)
          Sets the background color displayed when the button is pressed.
 void setPressedBackgroundStart(java.awt.Color newColor)
          Sets the starting background gradient color displayed when the button is pressed.
 void setPressedBorder(javax.swing.border.Border newBorder)
          Sets the border displayed when the button is pressed.
 void setPressedForeground(java.awt.Color newColor)
          Sets the foreground color displayed when the button is pressed.
protected  void setRollover(boolean newRollover)
          Sets the property specifiing whether the mouse is being moved over the button.
 void setRolloverBackground(java.awt.Color newColor)
          Sets the background color displayed when the mouse cursor is over the button and rollover is enabled.
 void setRolloverBackgroundStart(java.awt.Color newColor)
          Sets the start of background gradient color displayed when the mouse cursor is over the button and rollover is enabled.
 void setRolloverBorder(javax.swing.border.Border newBorder)
          Sets the border displayed when the mouse cursor is over the button and rollover is enabled.
 void setRolloverEnabled(boolean enabled)
          Enables or disables visual indication when mouse is over this SimpleButton.
 void setRolloverForeground(java.awt.Color newColor)
          Sets the foreground color displayed when the mouse cursor is over the button and rollover is enabled.
 void setVisible(boolean visible)
           
 
Methods inherited from class com.cosylab.gui.components.GradientLabel
isGradientEnabled, setGradientEnabled, setGradientPoints
 
Methods inherited from class com.cosylab.gui.components.ResizableTextLabel
adjustSizeToFont, getColumns, getMaximumFontSize, getMinimumFontSize, getMinimumSize, getPreferredSize, isEnhanced, isResizable, resize, setColumns, setEnhanced, setMaximumFontSize, setMinimumFontSize, setMinimumSize, setPreferredSize, setResizable, setText
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, 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, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, 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, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, 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, 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

MOUSE_PRESSED

protected static final java.lang.String MOUSE_PRESSED

MOUSE_CLICKED

protected static final java.lang.String MOUSE_CLICKED

MOUSE_RELEASED

protected static final java.lang.String MOUSE_RELEASED

MOUSE_CHAIN

protected static final java.lang.String MOUSE_CHAIN

NULL_ACTION_MODE

public static final int NULL_ACTION_MODE
No events are fired.

See Also:
Constant Field Values

DEFAULT_ACTION_MODE

public static final int DEFAULT_ACTION_MODE
One event is fired for one click.

See Also:
Constant Field Values

CHAIN_ACTION_MODE

public static final int CHAIN_ACTION_MODE
Events are fired continuously until mouse button is released.

See Also:
Constant Field Values

FAST_ACTION_MODE

public static final int FAST_ACTION_MODE
One event is fired for one click.

See Also:
Constant Field Values
Constructor Detail

SimpleButton

public SimpleButton(java.lang.String text)
Creates a simple button with text.

Parameters:
text - java.lang.String to be displayed on the button.

SimpleButton

public SimpleButton(javax.swing.Icon icon)
Creates a simple button with Icon.

Parameters:
icon - javax.swing.Icon to be displayed on the button.

SimpleButton

public SimpleButton()
Creates a simple button without text .

Method Detail

setActionMode

public void setActionMode(int newMode)
Sets the action mode of the SimpleButton. DEFAULT_ACTION_MODE fires ActionEvent when left mouse button is clicked. CHAIN_ACTION_MODE fires a series of ActionEvent while left mouse button is being pressed at the fireRate. FAST_ACTION_MODE fires ActionEvent when left mouse button is pressed. NULL_ACTION_MODE fires no ActionEvents on mouse actions but pressing the ENTER key still triggers ActionEvents.

Parameters:
newMode - to be set.
Throws:
java.lang.IllegalArgumentException - if the value entered is not one of DEFAULT_ACTION_MODE, CHAIN_ACTION_MODE, FAST_ACTION_MODE or NULL_ACTION_MODE.

getActionMode

public int getActionMode()
Returns the currently set action mode.

Returns:
int used action mode.

setBackground

public void setBackground(java.awt.Color newColor)
Description copied from class: GradientLabel
Sets the background color. This color is used for the gradient's end point.

Overrides:
setBackground in class GradientLabel
Parameters:
newColor - The color to be set
See Also:
Component.setBackground(Color), GradientLabel.setBackgroundStart(Color)

getBackground

public java.awt.Color getBackground()
Overrides:
getBackground in class java.awt.Component

setForeground

public void setForeground(java.awt.Color newColor)
Overrides:
setForeground in class javax.swing.JComponent

getForeground

public java.awt.Color getForeground()
Overrides:
getForeground in class java.awt.Component

getBackgroundStart

public java.awt.Color getBackgroundStart()
Description copied from class: GradientLabel
Returns the backgroundStart, this is the color that is used for the start of label's gradient. The end color is that of the label's background.

Overrides:
getBackgroundStart in class GradientLabel
Returns:
Color

setBackgroundStart

public void setBackgroundStart(java.awt.Color newColor)
Description copied from class: GradientLabel
Sets the backgroundStart color.

Overrides:
setBackgroundStart in class GradientLabel
Parameters:
newColor - The backgroundStart to set
See Also:
GradientLabel.getBackgroundStart()

setBorder

public void setBorder(javax.swing.border.Border newBorder)
Overrides:
setBorder in class javax.swing.JComponent

getBorder

public javax.swing.border.Border getBorder()
Overrides:
getBorder in class javax.swing.JComponent

getPressedBackground

public java.awt.Color getPressedBackground()
Returns the background color displayed when the button is pressed.

Returns:
Color

setPressedBackground

public void setPressedBackground(java.awt.Color newColor)
Sets the background color displayed when the button is pressed.

Parameters:
newColor - Color

getPressedForeground

public java.awt.Color getPressedForeground()
Returns the foreground color displayed when the button is pressed.

Returns:
Color

setPressedForeground

public void setPressedForeground(java.awt.Color newColor)
Sets the foreground color displayed when the button is pressed.

Parameters:
newColor - Color

getPressedBackgroundStart

public java.awt.Color getPressedBackgroundStart()
Returns the starting background gradient color displayed when the button is pressed.

Returns:
Color

setPressedBackgroundStart

public void setPressedBackgroundStart(java.awt.Color newColor)
Sets the starting background gradient color displayed when the button is pressed.

Parameters:
newColor - Color

getPressedBorder

public javax.swing.border.Border getPressedBorder()
Returns the border displayed when the button is pressed.

Returns:
Border

setPressedBorder

public void setPressedBorder(javax.swing.border.Border newBorder)
Sets the border displayed when the button is pressed.

Parameters:
newBorder - Border

getRolloverBackground

public java.awt.Color getRolloverBackground()
Returns the background color displayed when the mouse cursor is over the button and rollover is enabled.

Returns:
Color

setRolloverBackground

public void setRolloverBackground(java.awt.Color newColor)
Sets the background color displayed when the mouse cursor is over the button and rollover is enabled.

Parameters:
newColor - Color

getRolloverForeground

public java.awt.Color getRolloverForeground()
Returns the foreground color displayed when the mouse cursor is over the button and rollover is enabled.

Returns:
Color

setRolloverForeground

public void setRolloverForeground(java.awt.Color newColor)
Sets the foreground color displayed when the mouse cursor is over the button and rollover is enabled.

Parameters:
newColor - Color

getRolloverBackgroundStart

public java.awt.Color getRolloverBackgroundStart()
Returns the start of background gradient color displayed when the mouse cursor is over the button and rollover is enabled.

Returns:
Color

setRolloverBackgroundStart

public void setRolloverBackgroundStart(java.awt.Color newColor)
Sets the start of background gradient color displayed when the mouse cursor is over the button and rollover is enabled.

Parameters:
newColor - Color

getRolloverBorder

public javax.swing.border.Border getRolloverBorder()
Returns the border displayed when the mouse cursor is over the button and rollover is enabled.

Returns:
Border

setRolloverBorder

public void setRolloverBorder(javax.swing.border.Border newBorder)
Sets the border displayed when the mouse cursor is over the button and rollover is enabled.

Parameters:
newBorder - Border

setRolloverEnabled

public void setRolloverEnabled(boolean enabled)
Enables or disables visual indication when mouse is over this SimpleButton.

Parameters:
enabled - boolean whether this SimpleButton should indicate when mouse is over it.

isRolloverEnabled

public boolean isRolloverEnabled()
Returns wether this SimpleButton visually indicates when mouse is over it.

Returns:
boolean true if rollover indication is enabled, false otherwise.

setFireRate

public void setFireRate(int newRate)
Sets the rate of event firing in the CHAIN_MODE

Parameters:
newRate - int time in miliseconds between successive events are fired.

getFireRate

public int getFireRate()
Gets the rate of event firing in the CHAIN_MODE

Returns:
int

isPressed

public boolean isPressed()
Gets the property specifiing whether the button is being pressed.

Returns:
boolean

setPressed

protected void setPressed(boolean newPressed)
Returns the property specifiing whether the button is being pressed.

Parameters:
newPressed - boolean

isRollover

public boolean isRollover()
Gets the property specifiing whether the mouse is being moved over the button.

Returns:
boolean

setRollover

protected void setRollover(boolean newRollover)
Sets the property specifiing whether the mouse is being moved over the button.

Parameters:
newRollover - boolean

fireActionPerformed

protected void fireActionPerformed(java.awt.event.ActionEvent e)
Fires an action event to all its listeners

Parameters:
e - ActionEvent

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Adds an action listener to the list of registered listeners for this button.

Parameters:
l - ActionListener

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes an action listener from the list of registered listeners for this button.

Parameters:
l - ActionListener

paintComponent

public void paintComponent(java.awt.Graphics g)
This method was overloaded to enable advanced graphical features of the SimpleButton

Overrides:
paintComponent in class GradientLabel
Parameters:
g - Graphics
See Also:
GradientLabel.paintComponent(Graphics)

paintBorder

protected void paintBorder(java.awt.Graphics g)
This method was overloaded to enable advanced graphical features of the SimpleButton

Overrides:
paintBorder in class javax.swing.JComponent
Parameters:
g - Graphics
See Also:
JComponent.paintBorder(Graphics)

addNotify

public void addNotify()
Description copied from class: ResizableTextLabel
This method was overriden to implement font resizing.

Overrides:
addNotify in class ResizableTextLabel
See Also:
JComponent.addNotify()

removeNotify

public void removeNotify()
Overrides:
removeNotify in class javax.swing.JComponent

setVisible

public void setVisible(boolean visible)
Overrides:
setVisible in class javax.swing.JComponent

main

public static void main(java.lang.String[] args)
Run test applet.

Parameters:
args - command line parameters


Copyright © 2010. All Rights Reserved.