CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.cubetwister.doc
Class NotationModel

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by ch.randelshofer.cubetwister.doc.EntityModel
          extended by ch.randelshofer.cubetwister.doc.InfoModel
              extended by ch.randelshofer.cubetwister.doc.NotationModel
All Implemented Interfaces:
Notation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.event.UndoableEditListener, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class NotationModel
extends InfoModel
implements Notation

NotationModel.

Version:
2.2 2009-07-05 Added static method getUsefulLayers.
2.1 2007-08-11 Moved "name" property into superclass.
2.0 2004-04-03 Support for many new tokens and expressions added.
1.1 2003-01-03 Only tokens marked as supported may be passed to the parser.
1.0 2001-09-28 Created.
Author:
Werner Randelshofer.
See Also:
Serialized Form

Field Summary
static java.lang.String PROP_STATEMENT_TOKEN
           
static java.lang.String PROP_SYMBOL_SUPPORTED
           
static java.lang.String PROP_SYNTAX
           
static java.lang.String PROP_TWIST_TOKEN
           
 
Fields inherited from class ch.randelshofer.cubetwister.doc.InfoModel
author, date, description, name, PROP_AUTHOR, PROP_DATE, PROP_DESCRIPTION, PROP_NAME
 
Fields inherited from class ch.randelshofer.cubetwister.doc.EntityModel
PROP_CHILD_COUNT
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
NotationModel()
          Creates new CubeNotation
 
Method Summary
 void basicSetMoveSupported(Move key, boolean newValue)
           
 void basicSetMoveToken(Move key, java.lang.String newValue)
           
 void basicSetSupported(Symbol key, boolean newValue)
           
 void basicSetSyntax(Symbol s, Syntax newValue)
           
 void basicSetToken(Symbol key, java.lang.String newValue)
           
 java.lang.Object clone()
          Returns a shallow copy of this model.
 void configureMoveFromToken(MoveNode twist, java.lang.String twistToken)
          Configures a MoveNode from the specified twist token.
 java.util.Set<Move> getAllMoveSymbols()
           
 java.lang.String getAllTokens(Symbol key)
          Returns all token for the specified symbol.
 java.lang.String getAllTwistTokens(Move key)
           
 java.lang.String getEquivalentMacro(Cube cube, java.util.Map localMacros)
          Returns a macro which performs the same transformation as the cube parameter.
 int getLayerCount()
          /** Returns the number of layers supported by this notation.
 javax.swing.tree.DefaultMutableTreeNode getMacroModels()
           
 java.util.List<MacroNode> getMacros()
          Returns the macros defined by this notation.
 java.lang.String getMoveToken(Move key)
           
 ScriptParser getParser(java.util.List<MacroNode> localMacros)
           
 Symbol getSymbolFor(java.lang.String token, Symbol compositeSymbol)
          Returns a symbol for the specified token.
 Syntax getSyntax(Symbol s)
          Returns the syntax for the specified symbol.
 java.lang.String getToken(Move s)
          Returns a token for the specified move.
 java.lang.String getToken(Symbol key)
          Returns a token for the specified symbol.
static int[] getUsefulLayers(int layerCount)
          Returns an array of 'useful' layerMask values for cubes with the specified layer count.
 boolean isDefaultNotation()
           
 boolean isRemovable()
          Returns true if the node may be removed from its parent.
 boolean isSupported(Symbol s)
          Returns true, if this notation supports the specified symbol.
 boolean isToken(java.lang.String token)
          Returns true, if the specified String is a token of this notation.
 boolean isTokenFor(java.lang.String token, Symbol symbol)
          Returns true, if the specified String is a token for the specified symbol.
 boolean isTwistSupported()
           
 boolean isTwistSupported(Move key)
           
static int reverseLayerMask(int layerMask, int layerCount)
          Returns a reversed (mirrored) layerMask for cubes with the specified layer count.
 void setLayerCount(int newValue)
          Returns the number of layers supported by this notation.
 void setMoveSupported(Move key, boolean newValue)
           
 void setMoveToken(Move key, java.lang.String newValue)
           
 void setSupported(Symbol key, boolean newValue)
           
 void setSyntax(Symbol s, Syntax newValue)
          Sets the syntax for the specified symbol.
 void setToken(Symbol key, java.lang.String newValue)
           
 void writeToken(java.io.PrintWriter w, int axis, int layerMask, int angle)
          Writes a token for the specified transformation to the print writer.
 void writeToken(java.io.PrintWriter w, Symbol symbol)
          Writes a token for the specified symbol to the print writer.
 
Methods inherited from class ch.randelshofer.cubetwister.doc.InfoModel
basicSetAuthor, basicSetDate, basicSetDescription, basicSetName, dispose, getAuthor, getAuthorDocument, getDate, getDateDocument, getDescription, getDescriptionDocument, getName, getNameDocument, getUserObject, setAuthor, setDate, setDescription, setName, setUserObject, toString, undoableEditHappened
 
Methods inherited from class ch.randelshofer.cubetwister.doc.EntityModel
addPropertyChangeListener, children, fireNodeChanged, fireNodeStructureChanged, firePropertyChange, firePropertyChange, firePropertyChange, fireUndoableEditHappened, getDocument, hasPropertyListeners, insert, isDefaultCube, remove, removePropertyChangeListener, setRemovable
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObjectPath, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_STATEMENT_TOKEN

public static final java.lang.String PROP_STATEMENT_TOKEN
See Also:
Constant Field Values

PROP_TWIST_TOKEN

public static final java.lang.String PROP_TWIST_TOKEN
See Also:
Constant Field Values

PROP_SYNTAX

public static final java.lang.String PROP_SYNTAX
See Also:
Constant Field Values

PROP_SYMBOL_SUPPORTED

public static final java.lang.String PROP_SYMBOL_SUPPORTED
See Also:
Constant Field Values
Constructor Detail

NotationModel

public NotationModel()
Creates new CubeNotation

Method Detail

getUsefulLayers

public static int[] getUsefulLayers(int layerCount)
Returns an array of 'useful' layerMask values for cubes with the specified layer count. This layerMask does not include mirrored layers.


reverseLayerMask

public static int reverseLayerMask(int layerMask,
                                   int layerCount)
Returns a reversed (mirrored) layerMask for cubes with the specified layer count.

Parameters:
layerMask -
layerCount -
Returns:
reversed layer mask.

getLayerCount

public int getLayerCount()
/** Returns the number of layers supported by this notation.

Specified by:
getLayerCount in interface Notation

setLayerCount

public void setLayerCount(int newValue)
Returns the number of layers supported by this notation.


getMacros

public java.util.List<MacroNode> getMacros()
Description copied from interface: Notation
Returns the macros defined by this notation.

Specified by:
getMacros in interface Notation
Returns:
macros.

getMacroModels

public javax.swing.tree.DefaultMutableTreeNode getMacroModels()

isTwistSupported

public boolean isTwistSupported()

isTwistSupported

public boolean isTwistSupported(Move key)

basicSetMoveSupported

public void basicSetMoveSupported(Move key,
                                  boolean newValue)

setMoveSupported

public void setMoveSupported(Move key,
                             boolean newValue)

basicSetSupported

public void basicSetSupported(Symbol key,
                              boolean newValue)

setSupported

public void setSupported(Symbol key,
                         boolean newValue)

getAllMoveSymbols

public java.util.Set<Move> getAllMoveSymbols()

getMoveToken

public java.lang.String getMoveToken(Move key)

getAllTwistTokens

public java.lang.String getAllTwistTokens(Move key)

setMoveToken

public void setMoveToken(Move key,
                         java.lang.String newValue)

basicSetMoveToken

public void basicSetMoveToken(Move key,
                              java.lang.String newValue)

basicSetToken

public void basicSetToken(Symbol key,
                          java.lang.String newValue)

setToken

public void setToken(Symbol key,
                     java.lang.String newValue)

getParser

public ScriptParser getParser(java.util.List<MacroNode> localMacros)

isRemovable

public boolean isRemovable()
Returns true if the node may be removed from its parent.

Overrides:
isRemovable in class EntityModel

getEquivalentMacro

public java.lang.String getEquivalentMacro(Cube cube,
                                           java.util.Map localMacros)
Returns a macro which performs the same transformation as the cube parameter. Returns null if no macro is available.

Specified by:
getEquivalentMacro in interface Notation
Parameters:
cube - A transformed cube.
localMacros - A Map with local macros.

writeToken

public void writeToken(java.io.PrintWriter w,
                       Symbol symbol)
                throws java.io.IOException
Writes a token for the specified symbol to the print writer.

Specified by:
writeToken in interface Notation
Throws:
java.io.IOException - If the symbol is not supported by the notation, and if no alternative symbols could be found.

writeToken

public void writeToken(java.io.PrintWriter w,
                       int axis,
                       int layerMask,
                       int angle)
                throws java.io.IOException
Writes a token for the specified transformation to the print writer.

Specified by:
writeToken in interface Notation
Throws:
java.io.IOException

isSupported

public boolean isSupported(Symbol s)
Returns true, if this notation supports the specified symbol.

Specified by:
isSupported in interface Notation

getSyntax

public Syntax getSyntax(Symbol s)
Returns the syntax for the specified symbol. Note: This makes only sense for composite symbols.

Specified by:
getSyntax in interface Notation

basicSetSyntax

public void basicSetSyntax(Symbol s,
                           Syntax newValue)

setSyntax

public void setSyntax(Symbol s,
                      Syntax newValue)
Sets the syntax for the specified symbol. Note: This makes only sense for composite symbols.


isToken

public boolean isToken(java.lang.String token)
Returns true, if the specified String is a token of this notation.

Specified by:
isToken in interface Notation

isTokenFor

public boolean isTokenFor(java.lang.String token,
                          Symbol symbol)
Returns true, if the specified String is a token for the specified symbol.

Specified by:
isTokenFor in interface Notation

getToken

public java.lang.String getToken(Symbol key)
Returns a token for the specified symbol. If the symbol has more than one token, the first token is returned. Returns null, if symbol is not supported.

Specified by:
getToken in interface Notation

getAllTokens

public java.lang.String getAllTokens(Symbol key)
Returns all token for the specified symbol. Returns the token regardless whether the symbol is supported or not. Returns null if the token is not defined.


getSymbolFor

public Symbol getSymbolFor(java.lang.String token,
                           Symbol compositeSymbol)
Returns a symbol for the specified token. The compositeSymbol must be specified do disambiguate tokens. If the compositeSymbol is null, then the token must be unambiguous. Returns null, if the token is not a token for the specified compositeSymbol.

Specified by:
getSymbolFor in interface Notation

configureMoveFromToken

public void configureMoveFromToken(MoveNode twist,
                                   java.lang.String twistToken)
Configures a MoveNode from the specified twist token.

Specified by:
configureMoveFromToken in interface Notation

clone

public java.lang.Object clone()
Description copied from class: InfoModel
Returns a shallow copy of this model. All references to other models are maintained. The new model has no parent or children and no property change listeners.

Overrides:
clone in class InfoModel

getToken

public java.lang.String getToken(Move s)
Description copied from interface: Notation
Returns a token for the specified move. If the move has more than one token, the first token is returned. Returns null, if move is not supported.

Specified by:
getToken in interface Notation

isDefaultNotation

public boolean isDefaultNotation()
Overrides:
isDefaultNotation in class EntityModel

(c) Werner Randelshofer.
All rights reserved.