com.miginfocom.util.states
Class StateHandler

java.lang.Object
  extended by com.miginfocom.util.states.StateHandler

public class StateHandler
extends java.lang.Object

Handles bitwise states. Eg. mouseover and selected states.

Has logic for the different states and interaction between them. The class "remembers" which StateObservable it sets an on-state on, to be able to clear that state later, automatically or manually.

This class is also good for centralized state event listening on StateObservable objects, if the states are changed through this class that is (preferrable). The states handles is listed in States, E.g. GenericStates.DRAGGING_BIT.


Constructor Summary
StateHandler(StatePropagator statePropagator)
          Constructor
 
Method Summary
 void addStateListener(java.beans.PropertyChangeListener l)
          Adds a listener that is notified of all changes to the states.
 void addStateListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener that is notified of all changes to the states.
 void clearAllStates()
          Clears all state for the activities that currently has a state setted to on.
protected  void fireStateEvent(StateObservable stateObservable, int oldStates, int newStates)
          Fires a states change event to all registerd listeners.
 java.util.List getHandled()
          Returns all handled objects in a newly created list.
 java.util.List getList(int states, boolean allStatesSet, java.lang.Class cls)
          Returns a new list of all StateObservable objects with the state(s) state.
 void handleStateObservable(StateObservable st)
           
 void removeStateListener(java.beans.PropertyChangeListener l)
          Removes a listener
 void setState(int state, boolean b, StateObservable stateable, java.lang.Boolean multiSelectHint)
          Sets the state of StateObservable and possibly unsets the state for stateables in the handled list with the same state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateHandler

public StateHandler(StatePropagator statePropagator)
Constructor

Parameters:
statePropagator - An object that handles state interactions. Can not be null
See Also:
StatePropagator, ActivityStatePropagator
Method Detail

setState

public void setState(int state,
                     boolean b,
                     StateObservable stateable,
                     java.lang.Boolean multiSelectHint)
Sets the state of StateObservable and possibly unsets the state for stateables in the handled list with the same state.

Parameters:
state - The state (or states or:en together) to set. eg. GenericStates.MOUSE_OVER_BIT
stateable - The object to set the state on. If null and exclusive is true all activities with this state are unset.
multiSelectHint - If != null it's a hint whether to select more (true) or deselect others. If null the implementation decides entierly.

getList

public java.util.List getList(int states,
                              boolean allStatesSet,
                              java.lang.Class cls)
Returns a new list of all StateObservable objects with the state(s) state.

Parameters:
states - The state (or states, they can be or:ed together)
allStatesSet - If true all (I.e. AND) of states must be set for the StateObservables to be returned in the list. If false only one of the (or) must be set.
cls - If non-null only object that are same or subclasses of this class are returned.
Returns:
A new list of all StateObservables with the state state. Never null.

getHandled

public java.util.List getHandled()
Returns all handled objects in a newly created list.

Returns:
All handled objects in a newly created list. Not null but might be empty.

handleStateObservable

public void handleStateObservable(StateObservable st)

clearAllStates

public void clearAllStates()
Clears all state for the activities that currently has a state setted to on.


addStateListener

public void addStateListener(java.beans.PropertyChangeListener l)
Adds a listener that is notified of all changes to the states. States.PROPERTY_NAME will be the property name. New and old value are the or:ed stated and the changes StateObservable is the source.

Parameters:
l - The listener
See Also:
ListenerSet

addStateListener

public void addStateListener(java.beans.PropertyChangeListener l,
                             boolean asWeakRef)
Adds a listener that is notified of all changes to the states. States.PROPERTY_NAME will be the property name. New and old value are the or:ed stated and the changes StateObservable is the source.

Parameters:
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.
l - The listener
See Also:
ListenerSet

removeStateListener

public void removeStateListener(java.beans.PropertyChangeListener l)
Removes a listener

Parameters:
l - the listener

fireStateEvent

protected void fireStateEvent(StateObservable stateObservable,
                              int oldStates,
                              int newStates)
Fires a states change event to all registerd listeners. Can be called to note that the structure has changed and all should be recreated. Doesn't do anything if events is turned off.



Copyright © 2009 MiG InfoCom AB. All Rights Reserved.