org.zaval.lw
Class LwStButton

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwCanvas
              |
              +--org.zaval.lw.LwStButton
All Implemented Interfaces:
Drawable, java.util.EventListener, Layoutable, LwComponent, LwMouseListener, LwMouseMotionListener, java.lang.Runnable, Validationable
Direct Known Subclasses:
LwLink, LwMenuButton, LwSpeedButton

public class LwStButton
extends LwCanvas
implements LwMouseListener, LwMouseMotionListener, java.lang.Runnable

This is state button component. First of all, the component can have one of the following states that can be got by getState() method:

When the state of the component is changed stateChanged method will be called.

Second, the component tries to use a view for appropriate state as follow:

The component generates LwActionEvent whenever the button has been pressed or released. Use addActionListener and removeActionListener methods to handle the events. Use fireByPress method to define what event should perform the action event: mouse released or mouse pressed event. Moreover, the component allows to set action event repeatable time. In this case the action event will be performed again if for example a mouse button is kept down certain time.

The sample below illustrates the component usage for creating tool bar button:

    ...
    LwStButton   b = new LwStButton();
    LwAdvViewMan m = new LwAdvViewMan();
    m.put ("st.over", new LwImgRender("over.gif"));
    m.put ("st.out", new LwImgRender("out.gif"));
    m.put ("st.pressed", new LwImgRender("out.gif"));
    b.setViewMan (m);
    ...
 


Field Summary
static int ST_DISABLED
          The DISABLED state.
static int ST_ONSURFACE
          The ONSURFACE state.
static int ST_OUTSURFACE
          The OUTSURFACE state.
static int ST_PRESSED
          The PRESSED state.
 
Fields inherited from class org.zaval.lw.LwCanvas
bits, height, insets, parent, psHeight, psWidth, skins, width, x, y
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwStButton()
          Constructs the class instance.
 
Method Summary
 void addActionListener(LwActionListener a)
          Adds the specified action listener to receive action events from this component.
 void endDragged(LwMouseMotionEvent e)
          Invoked when the mouse ends dragged.
 void fireByPress(boolean b, int time)
          Sets the trigger event to generate action event by the component and the given repeatable time.
 int getState()
          Gets the current button state.
 boolean isFireByPress()
          Tests if the action event will be perfomed by mouse pressed event.
 void mouseClicked(LwMouseEvent e)
          Invoked when the mouse button has been clicked on a light weight component.
 void mouseDragged(LwMouseMotionEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
 void mouseEntered(LwMouseEvent e)
          Invoked when the mouse enters a light weight component.
 void mouseExited(LwMouseEvent e)
          Invoked when the mouse exits a light weight component.
 void mouseMoved(LwMouseMotionEvent e)
          Invoked when the mouse pointer has been moved on a light weight component (with no buttons no down).
 void mousePressed(LwMouseEvent e)
          Invoked when the mouse button has been pressed on a light weight component.
 void mouseReleased(LwMouseEvent e)
          Invoked when the mouse button has been released on a light weight component.
protected  void perform(LwActionEvent e)
          Fires the specified action event to the registered listeners.
 void removeActionListener(LwActionListener a)
          Removes the specified action listener so it no longer receives action events from this component.
 void run()
           
 void setEnabled(boolean b)
          Enables or disables this component.
protected  void setState(int s)
          Sets the specified button state.
 void startDragged(LwMouseMotionEvent e)
          Invoked when the mouse starts dragged.
protected  void stateChanged(int state, int prevState)
          Invoked when the state of the component has been changed.
 void sync()
          Invoked whenever it is necessary to set appropriate state view for the current state.
protected  void viewManChanged()
          Invoked whenever the view manager has been changed.
 
Methods inherited from class org.zaval.lw.LwCanvas
calcPreferredSize, canHaveFocus, getBackground, getBounds, getHeight, getInsets, getLocation, getLwComponentAt, getLwParent, getOrigin, getPreferredSize, getSize, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, invalidate, isEnabled, isOpaque, isVisible, paint, recalc, repaint, repaint, requestFocus, setBackground, setInsets, setLocation, setLwParent, setOpaque, setPSSize, setSize, setViewMan, setVisible, toString, update, validate, vrp
 
Methods inherited from class org.zaval.util.ValidationObject
isValid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.zaval.util.Validationable
isValid
 

Field Detail

ST_ONSURFACE

public static final int ST_ONSURFACE
The ONSURFACE state.

ST_PRESSED

public static final int ST_PRESSED
The PRESSED state.

ST_OUTSURFACE

public static final int ST_OUTSURFACE
The OUTSURFACE state.

ST_DISABLED

public static final int ST_DISABLED
The DISABLED state.
Constructor Detail

LwStButton

public LwStButton()
Constructs the class instance.
Method Detail

isFireByPress

public boolean isFireByPress()
Tests if the action event will be perfomed by mouse pressed event.
Returns:
true if the action event is perfomrd by mouse pressed event; false if the action event is perfomrd by mouse released event;

fireByPress

public void fireByPress(boolean b,
                        int time)
Sets the trigger event to generate action event by the component and the given repeatable time.
Parameters:
b - true to set mouse pressed event as the trigger, false to set mouse released event as the trigger.
time - the repeatable time. The time defines an interval after the action event will be performed again if the trigger event is not switched off. Use -1 as the property value to disable the event repeating.

mouseClicked

public void mouseClicked(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been clicked on a light weight component.
Specified by:
mouseClicked in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseEntered

public void mouseEntered(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse enters a light weight component.
Specified by:
mouseEntered in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseExited

public void mouseExited(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse exits a light weight component.
Specified by:
mouseExited in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mousePressed

public void mousePressed(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been pressed on a light weight component.
Specified by:
mousePressed in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseReleased

public void mouseReleased(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been released on a light weight component.
Specified by:
mouseReleased in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

startDragged

public void startDragged(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when the mouse starts dragged.
Specified by:
startDragged in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

endDragged

public void endDragged(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when the mouse ends dragged.
Specified by:
endDragged in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

mouseMoved

public void mouseMoved(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when the mouse pointer has been moved on a light weight component (with no buttons no down).
Specified by:
mouseMoved in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

mouseDragged

public void mouseDragged(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when a mouse button is pressed on a component and then dragged. Mouse drag events will continue to be delivered to the component where the first originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).
Specified by:
mouseDragged in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

getState

public int getState()
Gets the current button state.
Returns:
a current button state.

addActionListener

public void addActionListener(LwActionListener a)
Adds the specified action listener to receive action events from this component.
Parameters:
a - the specified action listener.

removeActionListener

public void removeActionListener(LwActionListener a)
Removes the specified action listener so it no longer receives action events from this component.
Parameters:
a - the specified action listener.

setEnabled

public void setEnabled(boolean b)
Description copied from class: LwCanvas
Enables or disables this component. An enabled component can participate in events handling and performing processes. Component is enabled initially by default. The method performs appropriate LwComponentEvent.
Overrides:
setEnabled in class LwCanvas
Following copied from class: org.zaval.lw.LwCanvas
Parameters:
b - if true, this component is enabled; otherwise this component is disabled.

sync

public void sync()
Invoked whenever it is necessary to set appropriate state view for the current state.

run

public void run()
Specified by:
run in interface java.lang.Runnable

viewManChanged

protected void viewManChanged()
Description copied from class: LwCanvas
Invoked whenever the view manager has been changed. The method can be overrided to listen when the view manager is re-set.
Overrides:
viewManChanged in class LwCanvas

setState

protected void setState(int s)
Sets the specified button state.
Parameters:
s - the specified button state.

stateChanged

protected void stateChanged(int state,
                            int prevState)
Invoked when the state of the component has been changed. Use the method to listen state changing.
Parameters:
state - the new state of the component.
prevState - the previous state of the component.

perform

protected void perform(LwActionEvent e)
Fires the specified action event to the registered listeners.
Parameters:
e - the specified action event.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org