net.paulhertz.aifile
Class DisplayComponent

java.lang.Object
  extended by net.paulhertz.aifile.DisplayComponent
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
BezShape, CustomComponent, DocumentComponent, GroupComponent, LayerComponent, PointText

public abstract class DisplayComponent
extends Object
implements Visitable

The base class for all components. Do not invoke this class directly. Components form a tree structure with the DocumentComponent at the top. A document may have several layers (LayerComponent). Each layer can contain shapes (BezShape), text (PointText) or groups (GroupComponent). The GroupComponent can contain shapes or text or nested groups.

The draw, write, and transform commands all cascade down the tree. Thus a draw command given to a document, layer, or group will eventually reach all the children of that component, and cause them to draw their geometry or text to the screen. Similarly, the write command from the document level will write out a complete Adobe Illustrator file. Transform executed at any level, or on terminal components such as BezShape and PointText, will execute a supplied geometric transform.


Constructor Summary
DisplayComponent()
           
 
Method Summary
abstract  void add(ArrayList<? extends DisplayComponent> comps)
          Adds all components in a list to this component, throws an UnsupportedOperationException if component is terminal.
abstract  void add(DisplayComponent component)
          Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal.
 List<DisplayComponent> children()
           
abstract  void draw()
          Draws geometry or text to the Processing window.
abstract  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.
 void hide()
          Sets the isVisible attribute of this component to true.
 int id()
           
 boolean isLocked()
           
abstract  boolean isTerminal()
           
 boolean isVisible()
           
 Iterator<DisplayComponent> iterator()
          Returns an iterator over children, throws an UnsupportedOperationException if component is terminal.
 DisplayComponent parentComponent()
           
 boolean remove(DisplayComponent component)
          Removes a component from children of this component, throws an UnsupportedOperationException if component is terminal.
 void setLocked(boolean isLocked)
           
 void setParentComponent(DisplayComponent newParentComponent)
          Sets the parent component of this component to the supplied component.
 void setVisible(boolean isVisible)
           
 void show()
          Sets the isVisible attribute of this component to true.
abstract  void transform(Matrix3 matx)
          Transforms geometry of shapes and location of text using the supplied matrix.
abstract  void write(PrintWriter pw)
          Writes an Adobe Illustrator 7.0 file format encoding structure, geometry and text.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.paulhertz.aifile.Visitable
accept, accept
 

Constructor Detail

DisplayComponent

public DisplayComponent()
Method Detail

add

public abstract void add(DisplayComponent component)
Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal.

Parameters:
component - DisplayComponent to add to this component's children

add

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

Parameters:
comps - an ArrayList of DisplayComponents

remove

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

Parameters:
component - DisplayComponent to remove from this component's children
Returns:
true if component was found and removed, false otherwise.

get

public DisplayComponent get(int index)
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).

Parameters:
index - index to component
Returns:
the DisplayComponent at the supplied index

iterator

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

Returns:
an Iterator over the children array of this component

parentComponent

public DisplayComponent parentComponent()
Returns:
the parent component of this component, or null if this is the root component

setParentComponent

public void setParentComponent(DisplayComponent newParentComponent)
Sets the parent component of this component to the supplied component. There is generally no need to do this, constructors take care of it for you.

Parameters:
newParentComponent - component to set as parent of this component.

children

public List<DisplayComponent> children()
Returns:
the children of this component (may be an empty list)
Since:
Nov. 3, 2011 -- return an empty List instead of null. Return value changed to List interface.

id

public int id()

isTerminal

public abstract boolean isTerminal()
Returns:
true if this is a terminal (leaf) component, false if it is a composite component (i.e. a component that can add sub-components to a children array)

isLocked

public boolean isLocked()
Returns:
the isLocked

setLocked

public void setLocked(boolean isLocked)
Parameters:
isLocked - the isLocked to set

isVisible

public boolean isVisible()
Returns:
the isVisible

setVisible

public void setVisible(boolean isVisible)
Parameters:
isVisible - the isVisible to set

show

public void show()
Sets the isVisible attribute of this component to true. draw() command will execute.


hide

public void hide()
Sets the isVisible attribute of this component to true. draw() command will not execute. write() command will bracket component as not visible, with subsequent components visible.


draw

public abstract void draw()
Draws geometry or text to the Processing window. Component must be flagged as visible (the default).


draw

public abstract void draw(PGraphics pg)
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.

Parameters:
pg - a PGraphics instance

write

public abstract void write(PrintWriter pw)
Writes an Adobe Illustrator 7.0 file format encoding structure, geometry and text.

Parameters:
pw - a PrintWriter for file output.

transform

public abstract void transform(Matrix3 matx)
Transforms geometry of shapes and location of text using the supplied matrix.

Parameters:
matx - a Matrix3 that encapsulates an affine geometric transform.


Processing library IgnoCodeLib by Paul Hertz. (C) 2013