Package ej.microui.event.generator
Class States
- java.lang.Object
-
- ej.microui.event.EventGenerator
-
- ej.microui.event.generator.States
-
public class States extends EventGenerator
A states event generator is usually associated to a group of physical devices holding a position (switch, rotary wheel encoder, ...) and allows to generate events relating to them. This class generatesEVENT_TYPEevents and allows to retrieve for each state its current value. Each instance can manage at most256states and each state can have a value between0and255.
A state has a unique identifier between0andgetNumberOfStates()-1
-
-
Field Summary
Fields Modifier and Type Field Description static intEVENT_TYPEThe STATE event type returned bygetEventType().
-
Constructor Summary
Constructors Constructor Description States(int[] nbValues, int[] initialValues)Creates a states generator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intbuildEvent(int stateId, int value)Builds a MicroUI event for the given state identifier on its value.intgetCurrentValue(int stateId)Gets the current value of the given state.intgetEventType()Gets the event type associated with the event generatorintgetNumberOfStates()Gets the number of states managed by this instance.intgetNumberOfValues(int stateId)Gets the total number of values for the given state.static intgetStateId(int event)Gets the state's identifier held by the state event.static intgetStateValue(int event)Gets the state's value held by the state event.voidsend(int stateId, int value)Stores the given state value and sends a MicroUIEVENT_TYPEto the States's listener.-
Methods inherited from class ej.microui.event.EventGenerator
addToSystemPool, get, get, get, getEventHandler, getId, removeFromSystemPool, sendEvent, setEventHandler
-
-
-
-
Field Detail
-
EVENT_TYPE
public static final int EVENT_TYPE
The STATE event type returned bygetEventType().- See Also:
- Constant Field Values
-
-
Constructor Detail
-
States
public States(int[] nbValues, int[] initialValues)Creates a states generator.- Parameters:
nbValues- number of values for each state.initialValues- initial value for each state.- Throws:
IllegalArgumentException- if both arrays don't have the same length.IndexOutOfBoundsException- if arrays length is greater than 255.IndexOutOfBoundsException- ifnbValues[i] < 0ornbValues[i] > 255.IndexOutOfBoundsException- ifinitialValues[i] < 0orinitialValues[i] >= nbValues[i].
-
-
Method Detail
-
getStateId
public static int getStateId(int event)
Gets the state's identifier held by the state event.- Parameters:
event- the state event to decode.- Returns:
- id between
0and255.
-
getStateValue
public static int getStateValue(int event)
Gets the state's value held by the state event.- Parameters:
event- the state event to decode.- Returns:
- value between
0and255.
-
getEventType
public int getEventType()
Description copied from class:EventGeneratorGets the event type associated with the event generator- Specified by:
getEventTypein classEventGenerator- Returns:
- the event type
-
getNumberOfValues
public int getNumberOfValues(int stateId)
Gets the total number of values for the given state.- Parameters:
stateId- the state identifier value.- Returns:
- the total number of values for the given state.
- Throws:
IndexOutOfBoundsException- when stateId is out of[0,.getNumberOfStates()-1]
-
getCurrentValue
public int getCurrentValue(int stateId)
Gets the current value of the given state.- Parameters:
stateId- the state identifier value.- Returns:
- a number between
0and.getNumberOfValues(int)-1 - Throws:
IndexOutOfBoundsException- when stateId is out of[0,.getNumberOfStates()-1]
-
getNumberOfStates
public int getNumberOfStates()
Gets the number of states managed by this instance.- Returns:
- the number of states managed by this instance.
-
buildEvent
public int buildEvent(int stateId, int value)Builds a MicroUI event for the given state identifier on its value.- Parameters:
stateId- the state identifier value.value- the new state value- Returns:
- the MicroUI event
-
send
public void send(int stateId, int value)Stores the given state value and sends a MicroUIEVENT_TYPEto the States's listener.- Parameters:
stateId- the state identifier value.value- the new state value- Throws:
IndexOutOfBoundsException- whenstateIdis out of[0,.getNumberOfStates()-1]IndexOutOfBoundsException- whenvalueis out of[0,.getNumberOfValues(int)-1]
-
-