jsynoptic.builtin
Class AutomatonShape

java.lang.Object
  extended by simtools.shapes.AbstractShape
      extended by jsynoptic.builtin.AutomatonShape
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable, ContextualActionProvider, Linkable, DataSourceListener, EndNotificationListener, Resizable, NamedProperties

public class AutomatonShape
extends AbstractShape
implements Resizable, DataSourceListener, ContextualActionProvider, Linkable, EndNotificationListener

A 2D automaton, driven by a data source. It consists in a grid which cells have configurable background and label. Actions are associated to data source values or ranges. They are processed dynamically when data arrives.

See Also:
Serialized Form

Nested Class Summary
static class AutomatonShape.Cell
           
 class AutomatonShape.PropertiesPanel
          A JPanel do display and change the properties of the SimpleShape
 
Nested classes/interfaces inherited from class simtools.shapes.AbstractShape
AbstractShape.AbstractShapePropertiesNames
 
Field Summary
protected  int activeX
           
protected  int activeY
           
protected  boolean allowResize
           
protected  AutomatonShape.Cell[][] cells
           
protected  boolean dirtyState
           
protected  boolean fixedRatio
           
protected  long index
           
protected  java.lang.String link
           
protected  AutomatonActionMapper mapper
           
static int MIN_CELL_HEIGHT
           
static int MIN_CELL_WIDTH
           
protected  double ratio
           
protected static int referenceBaseline
           
protected static java.awt.Font referenceFont
           
protected static int referenceHeight
          Reference font and dimensions used to compute sizes when resizing
protected static int referenceWidth
           
static java.util.ResourceBundle resources
           
protected  DataSource source
           
 
Fields inherited from class simtools.shapes.AbstractShape
_h, _ox, _oy, _propertyNames, _w, _x, _y, ANTI_ALIASING, currentDialogBox, FONT_NAMES, listeners, REFRESH_PERIOD
 
Fields inherited from interface jsynoptic.base.ContextualActionProvider
EDITOR_CONTEXT, MOUSE_OUT_CONTEXT, MOUSE_OVER_CONTEXT, MOUSE_PRESSED_CONTEXT, SHAPELIST_CONTEXT, SOURCELIST_CONTEXT
 
Constructor Summary
AutomatonShape(int ox, int oy)
           
AutomatonShape(int ox, int oy, int nx, int ny)
           
AutomatonShape(int ox, int oy, int nx, int ny, int width, int height)
           
 
Method Summary
 void applyRules()
          Apply the automaton rules on the active cell
 boolean canDoAction(double x, double y, java.lang.Object o, java.lang.String action, int context)
          Returns true if, and only if, it is possible to do the action right now
 AutomatonShape.PropertiesPanel createPanel()
           
 void DataSourceIndexRangeChanged(DataSource ds, long startIndex, long lastIndex)
          Called when the range of valid index changed
 void DataSourceInfoChanged(DataSource ds, DataInfo newInfo)
          Called when the information about the data source changed
 void DataSourceOrderChanged(DataSource ds, int newOrder)
          If defined, called when the order of the source changed.
 void DataSourceReplaced(DataSource oldData, DataSource newData)
          Called when a data source is replaced by another one
 void DataSourceValueChanged(DataSource ds, long minIndex, long maxIndex)
          Called when at least a value changed in the data source.
 void DataSourceValueRangeChanged(DataSource ds)
          Called when the range of possible values changed, if defined.
 boolean doAction(double x, double y, java.lang.Object o, java.lang.String action, javax.swing.undo.CompoundEdit undoableEdit)
          Do one of the actions previously declared by getAction.
 void draw(java.awt.Graphics2D g)
          Draws the shape
 java.lang.String[] getActions(double x, double y, java.lang.Object o, int context)
          Return list of possible actions the contect information may be used, or not.
static java.awt.Font getFontToFitText(java.lang.String text, int width, int height)
          Utility method that returns a Font object, as would be used to draw the text according to widht and height May return null if the desired operation results in no visible text.
 java.lang.String getLink()
           
 void notificationEnd(java.lang.Object referer)
          This callback is called after all notifications were processed.
 void resize(int dx, int dy)
          Resize the component
 void setLink(java.lang.String link)
           
 
Methods inherited from class simtools.shapes.AbstractShape
addListener, cloneShape, contains, contains, contains, contains, getAnchor, getBounds, getBounds2D, getInnerProperties, getMax, getMaxTranslated, getMin, getPathIterator, getPathIterator, getPropertyNames, getPropertyValue, intersects, intersects, notifyChange, notifyChange, refresh, removeListener, setAnchor, setAnchor, setProperties, setPropertyValue, translate, wipeOff
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resources

public static java.util.ResourceBundle resources

MIN_CELL_WIDTH

public static int MIN_CELL_WIDTH

MIN_CELL_HEIGHT

public static int MIN_CELL_HEIGHT

mapper

protected AutomatonActionMapper mapper

source

protected transient DataSource source

index

protected transient long index

allowResize

protected boolean allowResize

fixedRatio

protected boolean fixedRatio

ratio

protected double ratio

activeX

protected int activeX

activeY

protected int activeY

referenceHeight

protected static int referenceHeight
Reference font and dimensions used to compute sizes when resizing


referenceWidth

protected static int referenceWidth

referenceBaseline

protected static int referenceBaseline

referenceFont

protected static java.awt.Font referenceFont

link

protected java.lang.String link

cells

protected AutomatonShape.Cell[][] cells

dirtyState

protected transient boolean dirtyState
Constructor Detail

AutomatonShape

public AutomatonShape(int ox,
                      int oy)

AutomatonShape

public AutomatonShape(int ox,
                      int oy,
                      int nx,
                      int ny)

AutomatonShape

public AutomatonShape(int ox,
                      int oy,
                      int nx,
                      int ny,
                      int width,
                      int height)
Method Detail

getLink

public java.lang.String getLink()
Specified by:
getLink in interface Linkable

setLink

public void setLink(java.lang.String link)
Specified by:
setLink in interface Linkable

draw

public void draw(java.awt.Graphics2D g)
Description copied from class: AbstractShape
Draws the shape

Specified by:
draw in class AbstractShape
Parameters:
g - the graphics context

getFontToFitText

public static java.awt.Font getFontToFitText(java.lang.String text,
                                             int width,
                                             int height)
Utility method that returns a Font object, as would be used to draw the text according to widht and height May return null if the desired operation results in no visible text.


getActions

public java.lang.String[] getActions(double x,
                                     double y,
                                     java.lang.Object o,
                                     int context)
Description copied from interface: ContextualActionProvider
Return list of possible actions the contect information may be used, or not.

Specified by:
getActions in interface ContextualActionProvider
Parameters:
x - Coordinate, mouse position in the same unit as contains(x,y)
y - Coordinate, mouse position in the same unit as contains(x,y)
o - Object the actions should work on. Possibly null => default or all actions
context - one of the context defined in the ContextualActionProvider class
Returns:
The list of possible actions, possibly null or an empty array

doAction

public boolean doAction(double x,
                        double y,
                        java.lang.Object o,
                        java.lang.String action,
                        javax.swing.undo.CompoundEdit undoableEdit)
Description copied from interface: ContextualActionProvider
Do one of the actions previously declared by getAction.

Specified by:
doAction in interface ContextualActionProvider
Parameters:
x - Coordinate, for example mouse position
y - Coordinate, for example mouse position
o - Object the action should work on.
action - An action returned by a previous getActions call with the same x, y, o parameters It may be null, in which case the default action is requested for this x,y,o.
undoableEdit - current edit for undo/redo operation If not null, this action is undoable.
Returns:
true if the action could be performed

canDoAction

public boolean canDoAction(double x,
                           double y,
                           java.lang.Object o,
                           java.lang.String action,
                           int context)
Description copied from interface: ContextualActionProvider
Returns true if, and only if, it is possible to do the action right now

Specified by:
canDoAction in interface ContextualActionProvider
Parameters:
x - Coordinate, for example mouse position
y - Coordinate, for example mouse position
o - Object the action should work on.
action - An action returned by a previous getActions call with the same x, y, o parameters It may be null, in which case the default action is requested for this x,y,o.
context - one of the context defined in the ContextualActionProvider class
Returns:
true if the action can be performed

createPanel

public AutomatonShape.PropertiesPanel createPanel()
Returns:

applyRules

public void applyRules()
Apply the automaton rules on the active cell


DataSourceIndexRangeChanged

public void DataSourceIndexRangeChanged(DataSource ds,
                                        long startIndex,
                                        long lastIndex)
Description copied from interface: DataSourceListener
Called when the range of valid index changed

Specified by:
DataSourceIndexRangeChanged in interface DataSourceListener
Parameters:
ds - The data source that changed
startIndex - The new start Index
lastIndex - The new last index

DataSourceInfoChanged

public void DataSourceInfoChanged(DataSource ds,
                                  DataInfo newInfo)
Description copied from interface: DataSourceListener
Called when the information about the data source changed

Specified by:
DataSourceInfoChanged in interface DataSourceListener
Parameters:
ds - The data source that changed

DataSourceOrderChanged

public void DataSourceOrderChanged(DataSource ds,
                                   int newOrder)
Description copied from interface: DataSourceListener
If defined, called when the order of the source changed. See the sortedOrder() in the Datasource class for more information.

Specified by:
DataSourceOrderChanged in interface DataSourceListener
Parameters:
ds - The data source that changed

DataSourceValueChanged

public void DataSourceValueChanged(DataSource ds,
                                   long minIndex,
                                   long maxIndex)
Description copied from interface: DataSourceListener
Called when at least a value changed in the data source. The listener shall then get the values in the given range again, if it is interested by the values in that range.

Specified by:
DataSourceValueChanged in interface DataSourceListener
Parameters:
ds - The data source that changed
minIndex - Lower bound of the range where values changed
maxIndex - Higher bound of the range where values changed

DataSourceValueRangeChanged

public void DataSourceValueRangeChanged(DataSource ds)
Description copied from interface: DataSourceListener
Called when the range of possible values changed, if defined.

Specified by:
DataSourceValueRangeChanged in interface DataSourceListener
Parameters:
ds - The data source that changed

DataSourceReplaced

public void DataSourceReplaced(DataSource oldData,
                               DataSource newData)
Description copied from interface: DataSourceListener
Called when a data source is replaced by another one

Specified by:
DataSourceReplaced in interface DataSourceListener

notificationEnd

public void notificationEnd(java.lang.Object referer)
Description copied from interface: EndNotificationListener
This callback is called after all notifications were processed. The referer object is the one to decide what the end means. For example, it may be a single data source notifying both a range change and a value change. Or it could be a collection notifying all its sources.

Specified by:
notificationEnd in interface EndNotificationListener

resize

public void resize(int dx,
                   int dy)
Description copied from interface: Resizable
Resize the component

Specified by:
resize in interface Resizable
Parameters:
dx - value on x axis
dy - value on y axis