simtools.ui
Class GenericMapper

java.lang.Object
  extended by simtools.ui.GenericMapper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
AutomatonActionMapper, ColorMapper, DoubleValueMapper, ImageMapper, SvgMapper, TextMapper

public class GenericMapper
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class maps data sources and index to generic java Objects. The mapping is user defined, and based on the value of the data source. The data source shall not be saved into the object. Rather, this class goal is to implement a mapping independent of the data source given.

See Also:
Serialized Form

Nested Class Summary
protected static class GenericMapper.Expression
           
static class GenericMapper.ExpressionDialog
           
protected static class GenericMapper.ExpressionEditor
           
protected  class GenericMapper.ExpressionMappingTable
          Copied from Java Tutorial on tables, they had the very good idea to set up a colored cell table :))))
static class GenericMapper.Interval
          Associate a value for a data interval.
protected  class GenericMapper.MapperTableModel
           
 
Field Summary
protected  java.lang.Object defaultValue
           
protected  java.util.Vector intervals
           
protected  ListenerManager listeners
           
protected  java.util.TreeMap map
          Associate a mappedValue for a data value of any type
protected  java.lang.String name
           
static java.util.ResourceBundle resources
           
 
Constructor Summary
GenericMapper()
           
GenericMapper(java.lang.String name)
           
 
Method Summary
 void addListener(MapperListener l)
           
 java.lang.Object clone()
           
static GenericMapper createMapperDialog(javax.swing.JDialog owner)
           
 GenericMapper.MapperTableModel createModel()
           
protected  java.lang.Object createNewValue()
          For subclasses to specialize, create a new object of the specialized type
 javax.swing.JPanel createPanel(javax.swing.JDialog owner, java.awt.event.ActionListener listener)
          Creates a panel to configure this Mapper.
protected  GenericMapper.ExpressionMappingTable createTable(javax.swing.JDialog parent)
          For subclasses to specialize
 void editDialog(javax.swing.JDialog owner)
           
 boolean equals(java.lang.Object obj)
           
protected  java.util.ArrayList getAllMapperValues()
           
 java.lang.Object getDefaultValue()
          The value returned when nothing match
 java.util.Vector getIntervals()
           
 java.util.TreeMap getMap()
           
 java.lang.Object getMapping(DataSource ds)
          Realizes the mapping, and returns the object for this data source and index
 java.lang.Object getMapping(DataSource ds, long index)
          Realizes the mapping, and returns the object for this data source and index
 java.lang.Object getMapping(java.lang.Object value)
           
protected  void notifyListeners()
           
 void removeListener(MapperListener l)
           
 void setDefaultValue(java.lang.Object defaultValue)
          The value to return when nothing match
protected  void setMapperValues(GenericMapper m)
           
 void setMapping(boolean isMore, double value, boolean boundIncluded, java.lang.Object mappedValue)
          Associate a mappedValue with a double value infinite range.
 void setMapping(boolean isMore, double value, java.lang.Object mappedValue)
          Associate a mappedValue with a double value infinite range (bound included).
 void setMapping(boolean isMore, long value, boolean boundIncluded, java.lang.Object mappedValue)
          Associate a mappedValue with a long value infinite range.
 void setMapping(boolean isMore, long value, java.lang.Object mappedValue)
          Associate a mappedValue with a long value infinite range (bound included).
 void setMapping(boolean isMore, java.lang.String value, boolean boundIncluded, java.lang.Object mappedValue)
          Associate a mappedValue with a String value infinite range.
 void setMapping(boolean isMore, java.lang.String value, java.lang.Object mappedValue)
          Associate a mappedValue with a String value infinite range (bound included).
 void setMapping(double minvalue, boolean boundedMin, double maxvalue, boolean boundedMax, java.lang.Object mappedValue)
          Associate a mappedValue with a double value interval.
 void setMapping(double minvalue, double maxvalue, java.lang.Object mappedValue)
          Associate a mappedValue with a double value interval (bounds included)
 void setMapping(long minvalue, boolean boundedMin, long maxvalue, boolean boundedMax, java.lang.Object mappedValue)
          Associate a mappedValue with a long value interval.
 void setMapping(long minvalue, long maxvalue, java.lang.Object mappedValue)
          Associate a mappedValue with a long value interval (bounds included)
 void setMapping(java.lang.Object value, java.lang.Object mappedValue)
          Associate a mappedValue with a value
 void setMapping(java.lang.String minvalue, boolean boundedMin, java.lang.String maxvalue, boolean boundedMax, java.lang.Object mappedValue)
          Associate a mappedValue with a String value interval.
 void setMapping(java.lang.String minvalue, java.lang.String maxvalue, java.lang.Object mappedValue)
          Associate a mappedValue with a String value interval (bounds included)
 void setName(java.lang.String name)
          Set mapper name
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resources

public static java.util.ResourceBundle resources

map

protected java.util.TreeMap map
Associate a mappedValue for a data value of any type


intervals

protected java.util.Vector intervals

name

protected java.lang.String name

defaultValue

protected java.lang.Object defaultValue

listeners

protected transient ListenerManager listeners
Constructor Detail

GenericMapper

public GenericMapper()

GenericMapper

public GenericMapper(java.lang.String name)
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

setMapperValues

protected void setMapperValues(GenericMapper m)

getAllMapperValues

protected java.util.ArrayList getAllMapperValues()
Returns:
all values the mapper can provide

addListener

public void addListener(MapperListener l)

removeListener

public void removeListener(MapperListener l)

notifyListeners

protected void notifyListeners()

getMapping

public java.lang.Object getMapping(DataSource ds,
                                   long index)
Realizes the mapping, and returns the object for this data source and index

Parameters:
ds - The data source to map
index - The index in the data source (may be used, or not)
Returns:
the mapped object, or null

getMapping

public java.lang.Object getMapping(DataSource ds)
Realizes the mapping, and returns the object for this data source and index

Parameters:
ds - The data source to map
index - The index in the data source (may be used, or not, and defaults to the last index is used)
Returns:
the mapped object, or null

getMapping

public java.lang.Object getMapping(java.lang.Object value)

setDefaultValue

public void setDefaultValue(java.lang.Object defaultValue)
The value to return when nothing match


getDefaultValue

public java.lang.Object getDefaultValue()
The value returned when nothing match


setMapping

public void setMapping(java.lang.Object value,
                       java.lang.Object mappedValue)
Associate a mappedValue with a value


setMapping

public void setMapping(double minvalue,
                       double maxvalue,
                       java.lang.Object mappedValue)
Associate a mappedValue with a double value interval (bounds included)


setMapping

public void setMapping(double minvalue,
                       boolean boundedMin,
                       double maxvalue,
                       boolean boundedMax,
                       java.lang.Object mappedValue)
Associate a mappedValue with a double value interval. Interval bounds are specified


setMapping

public void setMapping(boolean isMore,
                       double value,
                       java.lang.Object mappedValue)
Associate a mappedValue with a double value infinite range (bound included).

Parameters:
isMore - if true, the interval is x >= value, else it is x <= value

setMapping

public void setMapping(boolean isMore,
                       double value,
                       boolean boundIncluded,
                       java.lang.Object mappedValue)
Associate a mappedValue with a double value infinite range.

Parameters:
isMore - if true, the interval is x >= value, else it is x <= value

setMapping

public void setMapping(long minvalue,
                       long maxvalue,
                       java.lang.Object mappedValue)
Associate a mappedValue with a long value interval (bounds included)


setMapping

public void setMapping(long minvalue,
                       boolean boundedMin,
                       long maxvalue,
                       boolean boundedMax,
                       java.lang.Object mappedValue)
Associate a mappedValue with a long value interval. Interval bounds are specified


setMapping

public void setMapping(boolean isMore,
                       long value,
                       java.lang.Object mappedValue)
Associate a mappedValue with a long value infinite range (bound included).

Parameters:
isMore - if true, the interval is x >= value, else it is x <= value

setMapping

public void setMapping(boolean isMore,
                       long value,
                       boolean boundIncluded,
                       java.lang.Object mappedValue)
Associate a mappedValue with a long value infinite range.

Parameters:
isMore - if true, the interval is x >= value, else it is x <= value

setMapping

public void setMapping(java.lang.String minvalue,
                       java.lang.String maxvalue,
                       java.lang.Object mappedValue)
Associate a mappedValue with a String value interval (bounds included)


setMapping

public void setMapping(java.lang.String minvalue,
                       boolean boundedMin,
                       java.lang.String maxvalue,
                       boolean boundedMax,
                       java.lang.Object mappedValue)
Associate a mappedValue with a String value interval. Interval bounds are specified


setMapping

public void setMapping(boolean isMore,
                       java.lang.String value,
                       java.lang.Object mappedValue)
Associate a mappedValue with a String value infinite range (bound included).

Parameters:
isMore - if true, the interval is x >= value, else it is x <= value

setMapping

public void setMapping(boolean isMore,
                       java.lang.String value,
                       boolean boundIncluded,
                       java.lang.Object mappedValue)
Associate a mappedValue with a String value infinite range.

Parameters:
isMore - if true, the interval is x >= value, else it is x <= value

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setName

public void setName(java.lang.String name)
Set mapper name

Parameters:
name -

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

createMapperDialog

public static GenericMapper createMapperDialog(javax.swing.JDialog owner)

createModel

public GenericMapper.MapperTableModel createModel()

createTable

protected GenericMapper.ExpressionMappingTable createTable(javax.swing.JDialog parent)
For subclasses to specialize


createNewValue

protected java.lang.Object createNewValue()
For subclasses to specialize, create a new object of the specialized type


createPanel

public javax.swing.JPanel createPanel(javax.swing.JDialog owner,
                                      java.awt.event.ActionListener listener)
Creates a panel to configure this Mapper.

Parameters:
owner - An optional owner frame
listener - An optional listener for the title and the OK button. If null, these components won't be displayed

The action listener can be sent two action id:

  • 1 => the text field content changed. The new text is available in the action "command" string
  • 2 => the ok button was pressed
the action source is the returned panel


editDialog

public void editDialog(javax.swing.JDialog owner)

getIntervals

public java.util.Vector getIntervals()

getMap

public java.util.TreeMap getMap()