algoanim.primitives
Class SourceCode

java.lang.Object
  extended by algoanim.primitives.Primitive
      extended by algoanim.primitives.SourceCode

public class SourceCode
extends Primitive

Represents a source code element defined by its upper left corner and source code lines, which can be added.

Author:
Stephan Mehlhase

Field Summary
protected  java.lang.Integer actRow
           
protected  SourceCodeGenerator generator
           
protected  java.util.Vector<java.lang.String> highlightedLabels
           
protected  java.util.HashMap<java.lang.String,java.lang.Integer> labelLines
           
protected  java.util.HashMap<java.lang.String,java.lang.Integer> labelRows
           
protected  java.util.LinkedList<java.lang.String> lines
           
protected  SourceCodeProperties properties
           
protected  Node upperLeft
           
 
Fields inherited from class algoanim.primitives.Primitive
gen
 
Constructor Summary
SourceCode(SourceCodeGenerator generator, Node upperLeft, java.lang.String name, DisplayOptions display, SourceCodeProperties properties)
          Instantiates the SourceCode and calls the create() method of the associated SourceCodeGenerator.
 
Method Summary
 int addCodeElement(java.lang.String code, java.lang.String label, boolean noSpaceSeparator, int indentation, Timing delay)
          Adds a new code element to this SourceCode element.
 int addCodeElement(java.lang.String code, java.lang.String label, int indentation, Timing delay)
          Adds a new code element to this SourceCode element.
 int addCodeLine(java.lang.String code, java.lang.String label, int indentation, Timing delay)
          Adds a new code line to this SourceCode element.
 SourceCodeProperties getProperties()
          Returns the properties of this SourceCode element.
 Node getUpperLeft()
          Returns the upper left corner of this SourceCode element.
 void highlight(int lineNo)
          Highlights a line in this SourceCode element.
 void highlight(int lineNo, int colNo, boolean context)
          Highlights a line in this SourceCode element.
 void highlight(int lineNo, int colNo, boolean context, Timing delay, Timing duration)
          Highlights a line in this SourceCode element.
 void highlight(java.lang.String label)
          Highlights a line in this SourceCode element.
 void highlight(java.lang.String label, boolean context)
          Highlights a line in this SourceCode element.
 void highlight(java.lang.String label, boolean context, Timing delay, Timing duration)
          Highlights a line in this SourceCode element.
 void registerLabel(java.lang.String label, int lineNo)
          short form without row
 void registerLabel(java.lang.String label, int lineNo, int rowNo)
           
 void setName(java.lang.String newName)
          Sets the name of this Primitive.
 void toggleHighlight(int oldLine, int newLine)
          Toggles the highlight from one component to the next.
 void toggleHighlight(int oldLine, int oldColumn, boolean switchToContextMode, int newLine, int newColumn)
          Toggles the highlight from one component to the next.
 void toggleHighlight(int oldLine, int oldColumn, boolean switchToContextMode, int newLine, int newColumn, Timing delay, Timing duration)
          Toggles the highlight from one component to the next.
 void toggleHighlight(java.lang.String label)
           
 void toggleHighlight(java.lang.String oldLabel, boolean switchToContextMode, java.lang.String newLabel)
          Toggles the highlight from one component to the next.
 void toggleHighlight(java.lang.String oldLabel, boolean switchToContextMode, java.lang.String newLabel, Timing delay, Timing duration)
          Toggles the highlight from one component to the next.
 void toggleHighlight(java.lang.String oldLabel, java.lang.String newLabel)
          Toggles the highlight from one component to the next.
 void unhighlight(int lineNo)
          Unhighlights a line in this SourceCode element.
 void unhighlight(int lineNo, int colNo, boolean context)
          Unhighlights a line in this SourceCode element.
 void unhighlight(int lineNo, int colNo, boolean context, Timing delay, Timing duration)
          Unhighlights a line in this SourceCode element.
 void unhighlight(java.lang.String label)
          Unhighlights a line in this SourceCode element.
 void unhighlight(java.lang.String label, boolean context)
          Unhighlights a line in this SourceCode element.
 void unhighlight(java.lang.String label, boolean context, Timing delay, Timing duration)
          Unhighlights a line in this SourceCode element.
 
Methods inherited from class algoanim.primitives.Primitive
changeColor, exchange, getDisplayOptions, getName, hide, hide, moveBy, moveTo, moveVia, rotate, rotate, show, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected SourceCodeProperties properties

generator

protected SourceCodeGenerator generator

upperLeft

protected Node upperLeft

lines

protected java.util.LinkedList<java.lang.String> lines

labelLines

protected java.util.HashMap<java.lang.String,java.lang.Integer> labelLines

labelRows

protected java.util.HashMap<java.lang.String,java.lang.Integer> labelRows

actRow

protected java.lang.Integer actRow

highlightedLabels

protected java.util.Vector<java.lang.String> highlightedLabels
Constructor Detail

SourceCode

public SourceCode(SourceCodeGenerator generator,
                  Node upperLeft,
                  java.lang.String name,
                  DisplayOptions display,
                  SourceCodeProperties properties)
Instantiates the SourceCode and calls the create() method of the associated SourceCodeGenerator.

Parameters:
generator - the appropriate code Generator.
upperLeft - the upper left corner of this SourceCode element.
name - the name of this SourceCode element.
display - [optional] the DisplayOptions of this SourceCode element.
properties - [optional] the properties of this SourceCode element.
Method Detail

setName

public void setName(java.lang.String newName)
Description copied from class: Primitive
Sets the name of this Primitive.

Overrides:
setName in class Primitive
Parameters:
newName - the new name for this Primitive.
See Also:
Primitive.setName(java.lang.String)

registerLabel

public void registerLabel(java.lang.String label,
                          int lineNo)
short form without row


registerLabel

public void registerLabel(java.lang.String label,
                          int lineNo,
                          int rowNo)

getProperties

public SourceCodeProperties getProperties()
Returns the properties of this SourceCode element.

Returns:
the properties of this SourceCode element.

getUpperLeft

public Node getUpperLeft()
Returns the upper left corner of this SourceCode element.

Returns:
the upper left corner of thisSourceCode element.

addCodeLine

public int addCodeLine(java.lang.String code,
                       java.lang.String label,
                       int indentation,
                       Timing delay)
                throws java.lang.NullPointerException
Adds a new code line to this SourceCode element.

Parameters:
code - the actual code.
label - a distinct name for the line.
indentation - the indentation to apply to this line.
delay - [optional] the delay after which this operation shall be performed.
Returns:
the line number of the added code line to be able to reference it later on.
Throws:
java.lang.NullPointerException

addCodeElement

public int addCodeElement(java.lang.String code,
                          java.lang.String label,
                          boolean noSpaceSeparator,
                          int indentation,
                          Timing delay)
                   throws java.lang.NullPointerException
Adds a new code element to this SourceCode element.

Parameters:
code - the actual code.
label - a distinct name for the line.
indentation - the indentation to apply to this line.
delay - [optional] the delay after which this operation shall be performed.
Returns:
the line number of that line, to which this element was added, to be able to reference it later on.
Throws:
java.lang.NullPointerException

addCodeElement

public int addCodeElement(java.lang.String code,
                          java.lang.String label,
                          int indentation,
                          Timing delay)
                   throws java.lang.NullPointerException
Adds a new code element to this SourceCode element.

Parameters:
code - the actual code.
label - a distinct name for the line.
indentation - the indentation to apply to this line.
delay - [optional] the delay after which this operation shall be performed.
Returns:
the line number of that line, to which this element was added, to be able to reference it later on.
Throws:
java.lang.NullPointerException

highlight

public void highlight(java.lang.String label)
               throws LineNotExistsException
Highlights a line in this SourceCode element.

Parameters:
label - the name of the line to highlight
Throws:
LineNotExistsException

highlight

public void highlight(java.lang.String label,
                      boolean context)
               throws LineNotExistsException
Highlights a line in this SourceCode element.

Parameters:
label - the name of the line to highlight
context - use the code context color instead of the code highlight color.
Throws:
LineNotExistsException

highlight

public void highlight(java.lang.String label,
                      boolean context,
                      Timing delay,
                      Timing duration)
               throws LineNotExistsException
Highlights a line in this SourceCode element.

Parameters:
label - the name of the line to highlight
context - use the code context color instead of the code highlight color.
delay - [optional] the delay to apply to this operation.
duration - [optional] the duration of the action.
Throws:
LineNotExistsException

highlight

public void highlight(int lineNo)
               throws LineNotExistsException
Highlights a line in this SourceCode element.

Parameters:
lineNo - the line to highlight
Throws:
LineNotExistsException

highlight

public void highlight(int lineNo,
                      int colNo,
                      boolean context)
               throws LineNotExistsException
Highlights a line in this SourceCode element.

Parameters:
lineNo - the line to highlight
colNo - the code element to highlight
context - use the code context color instead of the code highlight color.
Throws:
LineNotExistsException

highlight

public void highlight(int lineNo,
                      int colNo,
                      boolean context,
                      Timing delay,
                      Timing duration)
               throws LineNotExistsException
Highlights a line in this SourceCode element.

Parameters:
lineNo - the line to highlight
colNo - the code element to highlight
context - use the code context color instead of the code highlight color.
delay - [optional] the delay to apply to this operation.
duration - [optional] the duration of the action.
Throws:
LineNotExistsException

unhighlight

public void unhighlight(java.lang.String label)
                 throws LineNotExistsException
Unhighlights a line in this SourceCode element.

Parameters:
label - the name of the line to unhighlight
Throws:
LineNotExistsException

unhighlight

public void unhighlight(java.lang.String label,
                        boolean context)
                 throws LineNotExistsException
Unhighlights a line in this SourceCode element.

Parameters:
label - the name of the line to unhighlight
context - use the code context color instead of the code highlight color.
Throws:
LineNotExistsException

unhighlight

public void unhighlight(java.lang.String label,
                        boolean context,
                        Timing delay,
                        Timing duration)
                 throws LineNotExistsException
Unhighlights a line in this SourceCode element.

Parameters:
label - the name of the line to unhighlight
context - use the code context color instead of the code highlight color.
delay - [optional] the delay to apply to this operation.
duration - [optional] the duration of the action.
Throws:
LineNotExistsException

unhighlight

public void unhighlight(int lineNo)
                 throws LineNotExistsException
Unhighlights a line in this SourceCode element.

Parameters:
lineNo - the line to unhighlight
Throws:
LineNotExistsException

unhighlight

public void unhighlight(int lineNo,
                        int colNo,
                        boolean context)
                 throws LineNotExistsException
Unhighlights a line in this SourceCode element.

Parameters:
lineNo - the line to unhighlight
colNo - the code element to unhighlight
context - use the code context color instead of the code highlight color.
Throws:
LineNotExistsException

unhighlight

public void unhighlight(int lineNo,
                        int colNo,
                        boolean context,
                        Timing delay,
                        Timing duration)
                 throws LineNotExistsException
Unhighlights a line in this SourceCode element.

Parameters:
lineNo - the line to unhighlight
colNo - the code element to unhighlight
context - use the code context color instead of the code highlight color.
delay - [optional] the delay to apply to this operation.
duration - [optional] the duration of the action.
Throws:
LineNotExistsException

toggleHighlight

public void toggleHighlight(java.lang.String label)

toggleHighlight

public void toggleHighlight(java.lang.String oldLabel,
                            java.lang.String newLabel)
                     throws LineNotExistsException
Toggles the highlight from one component to the next.

Parameters:
oldLabel - the name of the line which should no longer be highlighted
newLabel - the name of the new line to highlight
Throws:
LineNotExistsException

toggleHighlight

public void toggleHighlight(java.lang.String oldLabel,
                            boolean switchToContextMode,
                            java.lang.String newLabel)
                     throws LineNotExistsException
Toggles the highlight from one component to the next.

Parameters:
oldLabel - the name of the line which should no longer be highlighted
switchToContextMode - determines if highlighting should be turned off for the previous element, of it it should be put into context mode
newLabel - the name of the new line to highlight
Throws:
LineNotExistsException

toggleHighlight

public void toggleHighlight(java.lang.String oldLabel,
                            boolean switchToContextMode,
                            java.lang.String newLabel,
                            Timing delay,
                            Timing duration)
                     throws LineNotExistsException
Toggles the highlight from one component to the next.

Parameters:
oldLabel - the name of the line which should no longer be highlighted
switchToContextMode - determines if highlighting should be turned off for the previous element, of it it should be put into context mode
newLabel - the name of the new line to highlight
delay - [optional] the delay to apply to this operation.
duration - [optional] the duration of the action.
Throws:
LineNotExistsException

toggleHighlight

public void toggleHighlight(int oldLine,
                            int newLine)
                     throws LineNotExistsException
Toggles the highlight from one component to the next.

Parameters:
oldLine - the line which should no longer be highlighted
newLine - the new line to highlight
Throws:
LineNotExistsException

toggleHighlight

public void toggleHighlight(int oldLine,
                            int oldColumn,
                            boolean switchToContextMode,
                            int newLine,
                            int newColumn)
                     throws LineNotExistsException
Toggles the highlight from one component to the next.

Parameters:
oldLine - the line which should no longer be highlighted
oldColumn - the code element to unhighlight
switchToContextMode - determines if highlighting should be turned off for the previous element, of it it should be put into context mode
newLine - the new line to highlight
newColumn - the code element to highlight
Throws:
LineNotExistsException

toggleHighlight

public void toggleHighlight(int oldLine,
                            int oldColumn,
                            boolean switchToContextMode,
                            int newLine,
                            int newColumn,
                            Timing delay,
                            Timing duration)
                     throws LineNotExistsException
Toggles the highlight from one component to the next.

Parameters:
oldLine - the line which should no longer be highlighted
oldColumn - the code element to unhighlight
switchToContextMode - determines if highlighting should be turned off for the previous element, of it it should be put into context mode
newLine - the new line to highlight
newColumn - the code element to highlight
delay - [optional] the delay to apply to this operation.
duration - [optional] the duration of the action.
Throws:
LineNotExistsException