Class SimpleButton

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, 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: DEFAULT_ACTION_MODE - the button fires one event when the user clicks (presses and releases) the left mouse button inside the area of the button. CHAIN_ACTION_MODE - the button fires one event when the user presses the left mouse button inside the area of the button and continues firing events at a constant rate until the user releases the button or moves outside the button area. NULL_ACTION_MODE - the button fires no events at all.
Version:
$id$
Author:
Jernej Kamenik
See Also:
  • Field Details

  • Constructor Details

    • SimpleButton

      public SimpleButton(String text)
      Creates a simple button with text.
      Parameters:
      text - java.lang.String to be displayed on the button.
    • SimpleButton

      public SimpleButton(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 Details

    • 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:
      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(Color newColor)
      Overriden for rendering purposes.
      Overrides:
      setBackground in class GradientLabel
      Parameters:
      newColor - Color
      See Also:
    • getBackground

      public Color getBackground()
      Overriden for rendering purposes.
      Overrides:
      getBackground in class Component
      Returns:
      Color
      See Also:
    • setForeground

      public void setForeground(Color newColor)
      Overriden for rendering purposes.
      Overrides:
      setForeground in class JComponent
      Parameters:
      newColor - Color
      See Also:
    • getForeground

      public Color getForeground()
      Overriden for rendering purposes.
      Overrides:
      getForeground in class Component
      Returns:
      Color
      See Also:
    • getBackgroundStart

      public Color getBackgroundStart()
      Overriden for rendering purposes.
      Overrides:
      getBackgroundStart in class GradientLabel
      Returns:
      Color
      See Also:
    • setBackgroundStart

      public void setBackgroundStart(Color newColor)
      Overriden for rendering purposes.
      Overrides:
      setBackgroundStart in class GradientLabel
      Parameters:
      newColor - Color
      See Also:
    • setBorder

      public void setBorder(Border newBorder)
      Overriden for rendering purposes.
      Overrides:
      setBorder in class JComponent
      Parameters:
      newBorder - Border
      See Also:
    • getBorder

      public Border getBorder()
      Overriden for rendering purposes.
      Overrides:
      getBorder in class JComponent
      Returns:
      Border
      See Also:
    • getPressedBackground

      public Color getPressedBackground()
      Gets the background color displayed when the button is pressed.
      Returns:
      Color
    • setPressedBackground

      public void setPressedBackground(Color newColor)
      Sets the background color displayed when the button is pressed.
      Parameters:
      newColor - Color
    • getPressedForeground

      public Color getPressedForeground()
      Gets the foreground color displayed when the button is pressed.
      Returns:
      Color
    • setPressedForeground

      public void setPressedForeground(Color newColor)
      Sets the foreground color displayed when the button is pressed.
      Parameters:
      newColor - Color
    • getPressedBackgroundStart

      public Color getPressedBackgroundStart()
      Gets the starting background gradient color displayed when the button is pressed.
      Returns:
      Color
    • setPressedBackgroundStart

      public void setPressedBackgroundStart(Color newColor)
      Sets the starting background gradient color displayed when the button is pressed.
      Parameters:
      newColor - Color
    • getPressedBorder

      public Border getPressedBorder()
      Gets the border displayed when the button is pressed.
      Returns:
      Border
    • setPressedBorder

      public void setPressedBorder(Border newBorder)
      Sets the border displayed when the button is pressed.
      Parameters:
      newBorder - Border
    • getRolloverBackground

      public Color getRolloverBackground()
      Gets the background color displayed when the mouse cursor is over the button and rollover is enabled.
      Returns:
      Color
    • setRolloverBackground

      public void setRolloverBackground(Color newColor)
      Sets the background color displayed when the mouse cursor is over the button and rollover is enabled.
      Parameters:
      newColor - Color
    • getRolloverForeground

      public Color getRolloverForeground()
      Gets the foreground color displayed when the mouse cursor is over the button and rollover is enabled.
      Returns:
      Color
    • setRolloverForeground

      public void setRolloverForeground(Color newColor)
      Sets the foreground color displayed when the mouse cursor is over the button and rollover is enabled.
      Parameters:
      newColor - Color
    • getRolloverBackgroundStart

      public Color getRolloverBackgroundStart()
      Gets 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(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 Border getRolloverBorder()
      Gets the border displayed when the mouse cursor is over the button and rollover is enabled.
      Returns:
      Border
    • setRolloverBorder

      public void setRolloverBorder(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(ActionEvent e)
      Fires an action event to all its listeners
      Parameters:
      e - ActionEvent
    • addActionListener

      public void addActionListener(ActionListener l)
      Adds an action listener to the list of registered listeners for this button.
      Parameters:
      l - ActionListener
    • removeActionListener

      public void removeActionListener(ActionListener l)
      Removes an action listener from the list of registered listeners for this button.
      Parameters:
      l - ActionListener
    • paintComponent

      public void paintComponent(Graphics g)
      This method was overloaded to enable advanced graphical features of the SimpleButton
      Overrides:
      paintComponent in class GradientLabel
      Parameters:
      g - Graphics
      See Also:
    • paintBorder

      protected void paintBorder(Graphics g)
      This method was overloaded to enable advanced graphical features of the SimpleButton
      Overrides:
      paintBorder in class JComponent
      Parameters:
      g - Graphics
      See Also:
    • addNotify

      public void addNotify()
      DOCUMENT ME!
      Overrides:
      addNotify in class ResizableTextLabel
      See Also:
    • removeNotify

      public void removeNotify()
      DOCUMENT ME!
      Overrides:
      removeNotify in class JComponent
    • setVisible

      public void setVisible(boolean visible)
      DOCUMENT ME!
      Overrides:
      setVisible in class JComponent
      Parameters:
      visible - DOCUMENT ME!