jmri.jmrit.symbolicprog
Class VariableValue

java.lang.Object
  extended by jmri.jmrit.symbolicprog.AbstractValue
      extended by jmri.jmrit.symbolicprog.VariableValue
All Implemented Interfaces:
PropertyChangeListener, EventListener
Direct Known Subclasses:
ConstantValue, DecVariableValue, EnumVariableValue, IndexedEnumVariableValue, IndexedPairVariableValue, IndexedVariableValue, LongAddrVariableValue, SpeedTableVarValue, SplitVariableValue

public abstract class VariableValue
extends AbstractValue
implements PropertyChangeListener

Represents a single Variable value; abstract base class.

The "changed" parameter (non-bound, accessed via isChanged) indicates whether a "write changes" or "read changes" operation should handle this object.

Author:
Bob Jacobsen Copyright (C) 2001, 2002, 2003, 2004, 2005, Howard G. Penny Copyright (C) 2005

Field Summary
protected  Vector<CvValue> _cvVector
           
protected  JLabel _status
           
protected  String _tooltipText
           
 
Fields inherited from class jmri.jmrit.symbolicprog.AbstractValue
DIFF, EDITED, FROMFILE, READ, SAME, STORED, UNKNOWN
 
Constructor Summary
protected VariableValue()
          Create a null object.
  VariableValue(String label, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, int cvNum, String mask, Vector<CvValue> v, JLabel status, String item)
           
 
Method Summary
 void confirmAll()
          Confirm the contents of this Variable
static boolean considerChanged(CvValue c)
          Default implementation for subclasses to tell if a CV meets a common definition of "changed".
 String cvName()
           
abstract  void dispose()
           
 String getComment()
           
abstract  Component getCommonRep()
           
 int getCvNum()
           
 boolean getInfoOnly()
           
abstract  int getIntValue()
          Get the value as a single number.
 String getMask()
           
abstract  Component getNewRep(String format)
           
 boolean getOpsOnly()
           
 boolean getReadOnly()
           
 int getState()
           
 String getTextValue()
           
abstract  Object getValueObject()
           
abstract  String getValueString()
           
 boolean getWriteOnly()
           
 boolean isBusy()
          A variable is busy during read, write operations
abstract  boolean isChanged()
          Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.
 boolean isToRead()
          Simple implementation for the case of a single CV.
 boolean isToWrite()
          Simple implementation for the case of a single CV.
 String item()
           
 String label()
           
protected  int maskVal(String maskString)
           
protected  int newValue(int oldCv, int newVal, String maskString)
           
protected  int offsetVal(String maskString)
          Find number of places to shift a value left to align if with a mask.
abstract  void propertyChange(PropertyChangeEvent e)
           
abstract  Object rangeVal()
           
abstract  void readAll()
          Always read the contents of this Variable
abstract  void readChanges()
          Read the contents of this Variable if it's in a state that indicates it was "changed"
protected  void setBusy(boolean newBusy)
           
abstract  void setCvState(int state)
          Propogate a state change here to the CVs that are related, which will in turn propagate back to here
abstract  void setIntValue(int i)
          Set the value from a single number.
 void setState(int state)
           
 void setToolTipText(String t)
          Set tooltip text to be used by both the "value" and representations of this Variable.
 void setToRead(boolean state)
          Simple implementation for the case of a single CV.
 void setToWrite(boolean state)
          Simple implementation for the case of a single CV.
protected  JComponent updateRepresentation(JComponent c)
          Add the proper tooltip text to a graphical rep before returning it, sets the visibility
abstract  CvValue[] usesCVs()
          Provide access to CVs referenced by this operation
abstract  void writeAll()
          Always write the contents of this Variable
abstract  void writeChanges()
          Write the contents of this Variable if it's in a state that indicates it was "changed"
 
Methods inherited from class jmri.jmrit.symbolicprog.AbstractValue
addPropertyChangeListener, getAvailable, removePropertyChangeListener, setAvailable, stateNameFromValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_cvVector

protected Vector<CvValue> _cvVector

_status

protected JLabel _status

_tooltipText

protected String _tooltipText
Constructor Detail

VariableValue

public VariableValue(String label,
                     String comment,
                     String cvName,
                     boolean readOnly,
                     boolean infoOnly,
                     boolean writeOnly,
                     boolean opsOnly,
                     int cvNum,
                     String mask,
                     Vector<CvValue> v,
                     JLabel status,
                     String item)

VariableValue

protected VariableValue()
Create a null object. Normally only used for tests and to pre-load classes.

Method Detail

getCommonRep

public abstract Component getCommonRep()

getNewRep

public abstract Component getNewRep(String format)

getValueString

public abstract String getValueString()
Returns:
String that can (usually) be interpreted as an integer

getValueObject

public abstract Object getValueObject()
Returns:
Value as a native-form Object

getTextValue

public String getTextValue()
Returns:
User-desired value, which may or may not be an integer

setIntValue

public abstract void setIntValue(int i)
Set the value from a single number. In some cases, e.g. speed tables, this will result in complex behavior, where setIntValue(getIntValue()) results in something unexpected.


getIntValue

public abstract int getIntValue()
Get the value as a single number. In some cases, e.g. speed tables, this will result in complex behavior, where setIntValue(getIntValue()) results in something unexpected.


readAll

public abstract void readAll()
Always read the contents of this Variable


writeAll

public abstract void writeAll()
Always write the contents of this Variable


confirmAll

public void confirmAll()
Confirm the contents of this Variable


readChanges

public abstract void readChanges()
Read the contents of this Variable if it's in a state that indicates it was "changed"

See Also:
isChanged()

writeChanges

public abstract void writeChanges()
Write the contents of this Variable if it's in a state that indicates it was "changed"

See Also:
isChanged()

isChanged

public abstract boolean isChanged()
Determine whether this Variable is "changed", so that "read changes" and "write changes" will act on it.

See Also:
considerChanged(jmri.jmrit.symbolicprog.CvValue)

considerChanged

public static boolean considerChanged(CvValue c)
Default implementation for subclasses to tell if a CV meets a common definition of "changed". This implementation will only consider a variable to be changed if the underlying CV(s) state is EDITTED, e.g. if the CV(s) has been manually editted.

Parameters:
c - CV to be examined
Returns:
true if to be considered changed

propertyChange

public abstract void propertyChange(PropertyChangeEvent e)
Specified by:
propertyChange in interface PropertyChangeListener

dispose

public abstract void dispose()

rangeVal

public abstract Object rangeVal()

label

public String label()

item

public String item()

cvName

public String cvName()

setToolTipText

public void setToolTipText(String t)
Set tooltip text to be used by both the "value" and representations of this Variable.

This is expected to be overridden in subclasses to change their internal info.

Parameters:
t -
See Also:
updateRepresentation(javax.swing.JComponent)

updateRepresentation

protected JComponent updateRepresentation(JComponent c)
Add the proper tooltip text to a graphical rep before returning it, sets the visibility

Parameters:
c -

getComment

public String getComment()

getReadOnly

public boolean getReadOnly()

getInfoOnly

public boolean getInfoOnly()

getWriteOnly

public boolean getWriteOnly()

getOpsOnly

public boolean getOpsOnly()

getCvNum

public int getCvNum()

getMask

public String getMask()

getState

public int getState()

setState

public void setState(int state)

setToRead

public void setToRead(boolean state)
Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.

Overrides:
setToRead in class AbstractValue

isToRead

public boolean isToRead()
Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.

Overrides:
isToRead in class AbstractValue

setToWrite

public void setToWrite(boolean state)
Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.

Overrides:
setToWrite in class AbstractValue

isToWrite

public boolean isToWrite()
Simple implementation for the case of a single CV. Intended to be sufficient for many subclasses.

Overrides:
isToWrite in class AbstractValue

setCvState

public abstract void setCvState(int state)
Propogate a state change here to the CVs that are related, which will in turn propagate back to here


isBusy

public boolean isBusy()
A variable is busy during read, write operations


setBusy

protected void setBusy(boolean newBusy)

maskVal

protected int maskVal(String maskString)

offsetVal

protected int offsetVal(String maskString)
Find number of places to shift a value left to align if with a mask. For example, as mask of "XXVVVXXX" means that the value 5 needs to be shifted left 3 places before being masked and stored as XX101XXX


newValue

protected int newValue(int oldCv,
                       int newVal,
                       String maskString)
Parameters:
oldCv - Value of the CV before this update is applied
newVal - Value for this variable (e.g. not the CV value)
maskString - The bit mask for this variable in character form
Returns:
int new value for the CV

usesCVs

public abstract CvValue[] usesCVs()
Provide access to CVs referenced by this operation



Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads