DESY ACOP Beans Home

com.cosylab.gui.components.ledder
Class BitmaskField

java.lang.Object
  extended by com.cosylab.gui.components.ledder.BitmaskField
All Implemented Interfaces:
java.io.Serializable

public class BitmaskField
extends java.lang.Object
implements java.io.Serializable

This is generic class providing access to the BitDescriptor. In most cases this implementation should provide all neccessary access to the model. This class is designed for convenient access and minimal overhead.

Version:
$id$
Author:
Ales Pucelj
See Also:
Serialized Form

Field Summary
static int IGNORE_MASK
          DOCUMENT ME!
 
Constructor Summary
BitmaskField()
          Default constructor for BitmaskField.
BitmaskField(BitDescriptor ledModel)
          Constructor for BitmaskField that also initialized the values to the specified model.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds property change listener.
protected  BitDescriptor createDefaultModel()
          Creates default model.
protected  void firePropertyChange(java.lang.String property, long old, long now)
          Convenience method that fires property change event with long parameters.
protected  void flushBitCount()
          Resets the cache for the getBitCount() method.
 int getBitCount()
          Returns number of bits defined by mask.
 BitDescriptor getBitDescriptor()
          Returns current model used to represent the bit values.
 long getBits()
          Returns the bit pattern currently set.
 java.awt.Color[] getColorsWhenOff()
          Returns array of colors to be used for rendering the individual led's OFF state.
 java.awt.Color[] getColorsWhenOn()
          Returns array of colors to be used for rendering the individual led's ON state.
 long getCompactValue()
          Returns bit pattern by ignoring all zeros in the mask.
 java.lang.String[] getDescriptions()
          Returns array containing descriptions for the leds.
 long getMask()
          Returns the mask.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes property change listener.
 void setBitDescriptor(BitDescriptor newModel)
          Sets the model to represent bit values.
 void setBits(long value)
          Sets the new bit pattern.
 void setMask(long value)
          Sets the mask to use.
 java.awt.Color[] toColor()
          Returns array of colors corresponding to current state of bit pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IGNORE_MASK

public static final int IGNORE_MASK
DOCUMENT ME!

See Also:
Constant Field Values
Constructor Detail

BitmaskField

public BitmaskField()
Default constructor for BitmaskField.


BitmaskField

public BitmaskField(BitDescriptor ledModel)
Constructor for BitmaskField that also initialized the values to the specified model.

Parameters:
ledModel - BitDescriptor Initial model to use.
Method Detail

createDefaultModel

protected BitDescriptor createDefaultModel()
Creates default model. Override this method to create a different implementation of BitDescriptor by default. This method will be called whenever it is neccessary to create a new model ensuring the model always exists.

Returns:
BitDescriptor

getBitDescriptor

public BitDescriptor getBitDescriptor()
Returns current model used to represent the bit values.

Returns:
BitDescriptor

setBitDescriptor

public void setBitDescriptor(BitDescriptor newModel)
Sets the model to represent bit values. If the new model is null, default model will be used as created by createDefaultModel() method. Also, setting the same instance of the model multiple times will not cause any change to occur. If the new model is null, a new instance of model will be created using createDefaultModel() method.

Parameters:
newModel - BitDescriptor

getBitCount

public int getBitCount()
Returns number of bits defined by mask. Counts each bit in mask and increases the counter for each value of 1.

If the mask is defined as 0010110111, getBitCount returns 6.

Always returns non-negative integer.

This method may be used to discover the number of leds to display. If the mask is not defined, the return value will be the number of leds in the model. Value of leds is cached to avoid calculation each time the method is called and will be changed whenever the model changes.

Returns:
int Number of leds

flushBitCount

protected final void flushBitCount()
Resets the cache for the getBitCount() method. This should be called whenever the number of leds changes.


setBits

public void setBits(long value)
Sets the new bit pattern. To avoid unneccesary updates, the property change event will only be fired if the actual value has changed.

Parameters:
value - long New bit pattern.

getBits

public long getBits()
Returns the bit pattern currently set.

Returns:
long Bit pattern.

setMask

public void setMask(long value)
Sets the mask to use. This may be bitwise specification of which bits in the bit pattern are valid or IGNORE_MASK constant. In the latter case mask parameter will be ignored entirely.

Parameters:
value - long New mask.

getMask

public long getMask()
Returns the mask. The return value will be bitwise pattern indicating active bits or IGNORE_MASK constant.

Returns:
long Current mask.

getDescriptions

public java.lang.String[] getDescriptions()
Returns array containing descriptions for the leds. This is a convenience method. To avoid creation of new String array, query the BitDescriptor directly.

Returns:
String[] Descriptions of the leds.

getColorsWhenOn

public java.awt.Color[] getColorsWhenOn()
Returns array of colors to be used for rendering the individual led's ON state. This is a convenience method. To avoid creation of new Color array, query the BitDescriptor directly.

Returns:
Color[] Colors indicating the ON state.

getColorsWhenOff

public java.awt.Color[] getColorsWhenOff()
Returns array of colors to be used for rendering the individual led's OFF state. This is a convenience method. To avoid creation of new Color array, query the BitDescriptor directly.

Returns:
Color[] Colors indicating the OFF state.

toColor

public java.awt.Color[] toColor()
Returns array of colors corresponding to current state of bit pattern. This is a convenience method. To avoid creation of new Color array, query the BitDescriptor directly.

Returns:
Color[]

getCompactValue

public long getCompactValue()
Returns bit pattern by ignoring all zeros in the mask. If mask is set to IGNORE_MASK, return value is equal to bits parameter.

Example:
mask = XX10101 bits = XX10010 getCompactValue() = XXXXX100

Returns:
long Compact representation of the bit pattern.

firePropertyChange

protected void firePropertyChange(java.lang.String property,
                                  long old,
                                  long now)
Convenience method that fires property change event with long parameters. To avoid unneccesary creation of Long objects the event is only fired if any listeners have been registered.

Parameters:
property - String
old - long
now - long

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds property change listener.

Parameters:
listener - PropertyChangeListener

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes property change listener.

Parameters:
listener - PropertyChangeListener


Copyright © 2010. All Rights Reserved.