com.miginfocom.util.states
Class States

java.lang.Object
  extended by com.miginfocom.util.states.States
All Implemented Interfaces:
StatesI

public class States
extends java.lang.Object
implements StatesI

Maintains the different states of of something, normally activities. Eg. if it has mouse over or is selected. Uses bitwise operations. Supports 31 states since there is no unsigned int and states should not be negative. What the states actually denote is up to the user of this class.


Field Summary
protected  int _states
          The states or:ed together
static java.lang.String PROPERTY_NAME
           
 
Constructor Summary
States()
          Constructor with no logging
 
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.
 boolean areStatesSet(int states, boolean allStatesSet)
          Returns the status of a state (or states).
protected  void fireStateEvent(int oldStates, int newStates)
          Fires a states change event to all registerd listeners.
 int[] getStateArray()
          Takes the state integer and split them up with a call to splitStates(int)
 int getStatesSet()
          Returns the states packed in an int
 boolean isAnyStateSet()
          Returns true if any state is set.
 boolean isStateSet(int state)
          Returns the status of a state.
 void removeStateListener(java.beans.PropertyChangeListener l)
          Removes a listener
 boolean setStates(int states, boolean b)
          Sets the status of a state (or states).
static int[] splitStates(int states)
          Returns the states and singe state ints (only one state per int in the arra)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_NAME

public static final java.lang.String PROPERTY_NAME
See Also:
Constant Field Values

_states

protected int _states
The states or:ed together

Constructor Detail

States

public States()
Constructor with no logging

Method Detail

isStateSet

public boolean isStateSet(int state)
Description copied from interface: StatesI
Returns the status of a state. This is a short for StatesI.areStatesSet(int, boolean) but only handles ONE state so and or or doesn't matter.

Specified by:
isStateSet in interface StatesI
Parameters:
state - The state to be tested if it is on. eg. GenericStates.MOUSE_OVER_BIT
Returns:
true if the state was set (on), false otherwise.

areStatesSet

public boolean areStatesSet(int states,
                            boolean allStatesSet)
Description copied from interface: StatesI
Returns the status of a state (or states).

Specified by:
areStatesSet in interface StatesI
Parameters:
states - The state or states to be tested if they are all/some on. eg. GenericStates.MOUSE_OVER_BIT or (GenericStates.SELECTED_BIT | GenericStates.DRAGGING_BIT)
allStatesSet - If true all (and) of states must be set for true to be returned. If false only one of the (or) must be set for true to be returned.
Returns:
true if all (or some, depending on allStatesSet) states in state was on (set to true)

setStates

public boolean setStates(int states,
                         boolean b)
Description copied from interface: StatesI
Sets the status of a state (or states).

Specified by:
setStates in interface StatesI
Parameters:
states - The state or states to be set to on (set to true). eg. GenericStates.MOUSE_OVER_BIT or (GenericStates.SELECTED_BIT | GenericStates.DRAGGING_BIT)
b - true means on
Returns:
If the state/states for the activity actually changed

isAnyStateSet

public boolean isAnyStateSet()
Description copied from interface: StatesI
Returns true if any state is set.

Specified by:
isAnyStateSet in interface StatesI
Returns:
true if any state is set.

getStatesSet

public int getStatesSet()
Description copied from interface: StatesI
Returns the states packed in an int

Specified by:
getStatesSet in interface StatesI
Returns:
The states packed in an int

getStateArray

public int[] getStateArray()
Description copied from interface: StatesI
Takes the state integer and split them up with a call to splitStates(int)

Specified by:
getStateArray in interface StatesI
Returns:
The states splitted into an array

splitStates

public static int[] splitStates(int states)
Returns the states and singe state ints (only one state per int in the arra)

Parameters:
states - The states or:ed together
Returns:
An array, never null but may be of length 0 if states == 0.

addStateListener

public void addStateListener(java.beans.PropertyChangeListener l)
Adds a listener that is notified of all changes to the states. PROPERTY_NAME will be the property name. New and old value are the or:ed stated and this 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. PROPERTY_NAME will be the property name. New and old value are the or:ed stated and this 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(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.