net.paulhertz.aifile
Class CustomComponent

java.lang.Object
  extended by net.paulhertz.aifile.DisplayComponent
      extended by net.paulhertz.aifile.CustomComponent
All Implemented Interfaces:
Visitable

public class CustomComponent
extends DisplayComponent

Permits the addition of arbitrary, non-printing, custom information to file output.


Constructor Summary
CustomComponent()
          PApplet used for calls to the Processing environment is obtained from IgnoCodeLib, which must be correctly initialized in setup.
CustomComponent(PApplet parent)
           
CustomComponent(PApplet parent, String tagIdentifier, String tagValue)
           
 
Method Summary
 void accept(ComponentVisitor visitor)
          Accepts a ComponentVisitor that traverses a document structure tree.
 void accept(ComponentVisitor visitor, boolean order)
          Accepts a ComponentVisitor that traverses a document structure tree in preorder or postorder.
 void add(ArrayList<? extends DisplayComponent> comps)
          Adds all components in a list to this component, throws an UnsupportedOperationException if component is terminal.
 void add(DisplayComponent component)
          Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal.
 List<DisplayComponent> children()
           
 void draw()
          Draws geometry or text to the Processing window.
 void draw(PGraphics pg)
          Draws a component to a supplied PGraphics.
 DisplayComponent get(int index)
          Returns the component at index from the children of this component, throws an UnsupportedOperationException if component is terminal.
 boolean isTerminal()
           
 Iterator<DisplayComponent> iterator()
          Returns an iterator over children, throws an UnsupportedOperationException if component is terminal.
 boolean remove(DisplayComponent component)
          Removes a component from children of this component, throws an UnsupportedOperationException if component is terminal.
 void setTagIdentifier(String tagIdentifier)
          Sets key used to identify custom data.
 void setTagValue(String tagValue)
           
 String tagIdentifier()
           
 String tagValue()
          Sets the value of custom data.
 void transform(Matrix3 matx)
          Transforms geometry of shapes and location of text using the supplied matrix.
 void write(PrintWriter pw)
          Writes an Adobe Illustrator 7.0 file format encoding structure, geometry and text.
 
Methods inherited from class net.paulhertz.aifile.DisplayComponent
hide, id, isLocked, isVisible, parentComponent, setLocked, setParentComponent, setVisible, show
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomComponent

public CustomComponent()
PApplet used for calls to the Processing environment is obtained from IgnoCodeLib, which must be correctly initialized in setup. If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.


CustomComponent

public CustomComponent(PApplet parent)
Parameters:
parent - PApplet used for calls to the Processing environment, notably for drawing

CustomComponent

public CustomComponent(PApplet parent,
                       String tagIdentifier,
                       String tagValue)
Parameters:
tagIdentifier - String to identify custom data
tagValue - Custom data to save to file (non-printing).
Method Detail

tagIdentifier

public String tagIdentifier()
Returns:
the tagIdentifier

setTagIdentifier

public void setTagIdentifier(String tagIdentifier)
Sets key used to identify custom data.

Parameters:
tagIdentifier - the tagIdentifier to set

tagValue

public String tagValue()
Sets the value of custom data.

Returns:
the tagValue

setTagValue

public void setTagValue(String tagValue)
Parameters:
tagValue - the tagValue to set

add

public void add(DisplayComponent component)
Description copied from class: DisplayComponent
Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal.

Specified by:
add in class DisplayComponent
Parameters:
component - DisplayComponent to add to this component's children
Throws:
UnsupportedOperationException, - CustomComponent is a terminal (leaf) node

add

public void add(ArrayList<? extends DisplayComponent> comps)
Description copied from class: DisplayComponent
Adds all components in a list to this component, throws an UnsupportedOperationException if component is terminal.

Specified by:
add in class DisplayComponent
Parameters:
comps - an ArrayList of DisplayComponents
Throws:
UnsupportedOperationException, - CustomComponent is a terminal (leaf) node

remove

public boolean remove(DisplayComponent component)
Description copied from class: DisplayComponent
Removes a component from children of this component, throws an UnsupportedOperationException if component is terminal.

Overrides:
remove in class DisplayComponent
Parameters:
component - DisplayComponent to remove from this component's children
Returns:
true if component was found and removed, false otherwise.
Throws:
UnsupportedOperationException, - CustomComponent is a terminal (leaf) node

get

public DisplayComponent get(int index)
Description copied from class: DisplayComponent
Returns the component at index from the children of this component, throws an UnsupportedOperationException if component is terminal. Throws an IndexOutOfBoundsException if index is out of range (index < 0 || index >= size).

Overrides:
get in class DisplayComponent
Parameters:
index - index to component
Returns:
the DisplayComponent at the supplied index
Throws:
UnsupportedOperationException, - CustomComponent is a terminal (leaf) node

iterator

public Iterator<DisplayComponent> iterator()
Description copied from class: DisplayComponent
Returns an iterator over children, throws an UnsupportedOperationException if component is terminal.

Overrides:
iterator in class DisplayComponent
Returns:
an Iterator over the children array of this component
Throws:
UnsupportedOperationException, - CustomComponent is a terminal (leaf) node

children

public List<DisplayComponent> children()
Overrides:
children in class DisplayComponent
Returns:
the children of this component (may be an empty list)

isTerminal

public boolean isTerminal()
Specified by:
isTerminal in class DisplayComponent
Returns:
true, this is a terminal component.
See Also:
DisplayComponent.isTerminal()

draw

public void draw()
Description copied from class: DisplayComponent
Draws geometry or text to the Processing window. Component must be flagged as visible (the default).

Specified by:
draw in class DisplayComponent

draw

public void draw(PGraphics pg)
Description copied from class: DisplayComponent
Draws a component to a supplied PGraphics. Except for the document component, a component must be visible (the default) to draw. Structural components simply iterate over their children. Graphic components should call beginShape and endShape on their own. It's up to the user to call beginDraw() and endDraw() on the PGraphics instance.

Specified by:
draw in class DisplayComponent
Parameters:
pg - a PGraphics instance

write

public void write(PrintWriter pw)
Description copied from class: DisplayComponent
Writes an Adobe Illustrator 7.0 file format encoding structure, geometry and text.

Specified by:
write in class DisplayComponent
Parameters:
pw - a PrintWriter for file output.

transform

public void transform(Matrix3 matx)
Description copied from class: DisplayComponent
Transforms geometry of shapes and location of text using the supplied matrix.

Specified by:
transform in class DisplayComponent
Parameters:
matx - a Matrix3 that encapsulates an affine geometric transform.

accept

public void accept(ComponentVisitor visitor)
Description copied from interface: Visitable
Accepts a ComponentVisitor that traverses a document structure tree.

When called from an object that implements the Visitable interface:

  1. each visited object passes a reference to itself back to the visitor
  2. each visited object calls accept( visitor ) on all its children

The reference is passed back to the visitor through a method of the form visitor.visit<ComponentClassName>( this ); See ComponentVisitor

The order of steps 1 and 2 determines if traversal of the composite structure is preorder or postorder. As shown above, it's preorder. Depending on what you want to do, one traversal may be better suited than the other. Preorder visits parents first, postorder visits children first.

Parameters:
visitor - a ComponentVisitor

accept

public void accept(ComponentVisitor visitor,
                   boolean order)
Description copied from interface: Visitable
Accepts a ComponentVisitor that traverses a document structure tree in preorder or postorder.

Parameters:
visitor - a ComponentVisitor
order - boolean to determine if traversal is preorder or postorder accept( visitor ) should implement the default order of traversal, accept( visitor, <false> ) should implement the other order.


Processing library IgnoCodeLib by Paul Hertz. (C) 2013