UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.satin.objects
Class GraphicalObjectCollectionImpl

java.lang.Object
  |
  +--edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollectionImpl
All Implemented Interfaces:
Cloneable, GraphicalObjectCollection, SatinConstants, Serializable, Watcher

public class GraphicalObjectCollectionImpl
extends Object
implements GraphicalObjectCollection

A sample implementation of a Graphical Object Collection. A Collection is just a collection of GraphicalObjects, with no additional semantics attached. This differs from a GraphicalObjectGroup in that GObGroups can be rendered, while GObCollections cannot.

This software is distributed under the Berkeley Software License.

 Revisions:  - SATIN-v1.0-1.0.0, Apr 05 1999, JH
               Created class
             - SATIN-v2.1-1.0.0, Aug 11 2000, JH
               Touched for SATIN release
 

Since:
JDK 1.2
Version:
SATIN-v2.1-1.0.0, Aug 11 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )
See Also:
Serialized Form

Inner classes inherited from class edu.berkeley.guir.lib.satin.SatinConstants
SatinConstants.ObjectPoolAffineTransform, SatinConstants.ObjectPoolPoint2D, SatinConstants.ObjectPoolPolygon2D, SatinConstants.ObjectPoolRectangle2D, SatinConstants.ObjectPoolStringBuffer, SatinConstants.UniqueAffineTransform, SatinConstants.UniquePoint2D, SatinConstants.UniquePolygon2D, SatinConstants.UniqueRectangle2D
 
Fields inherited from interface edu.berkeley.guir.lib.satin.SatinConstants
ABOVE, ALL, BAR, BELOW, clipboard, clprops, cmdqueue, cmdsubsys, CONTAINEDBY, CONTAINS, COORD_ABS, COORD_LOCAL, COORD_REL, DAMAGE_LATER, DAMAGE_NOW, DEBUG_GRAPHICS_OFFSET, DEBUG_STYLE_FILE, DEBUG_STYLE_GPROPERTY, DEEP, DEFAULT_POINT2D_POOL_SIZE, DEFAULT_POLYGON2D_POOL_SIZE, DEFAULT_RECTANGLE_POOL_SIZE, DEFAULT_REPAINT_THRESHOLD, DEFAULT_SELECT_THRESHOLD, DEFAULT_STRINGBUFFER_POOL_SIZE, DEFAULT_TRANSFORM_POOL_SIZE, DIR_CENTER, DIR_DOWN, DIR_DOWN_LEFT, DIR_DOWN_RIGHT, DIR_LEFT, DIR_RIGHT, DIR_UP, DIR_UP_LEFT, DIR_UP_RIGHT, FILTER_THRESHOLD, FIRST, FLOATING_PT_TOLERANCE, glprops, INTERSECTS, KEY_STYLE_DASHARRAY, KEY_STYLE_DASHPHASE, KEY_STYLE_DRAWCOLOR, KEY_STYLE_DRAWFONT, KEY_STYLE_DRAWTRANSPARENCY, KEY_STYLE_ENDCAP, KEY_STYLE_FILLCOLOR, KEY_STYLE_FILLTRANSPARENCY, KEY_STYLE_LINEJOIN, KEY_STYLE_LINEWIDTH, KEY_STYLE_MITERLIMIT, NEAR, NOTIFY_BOUNDS, NOTIFY_LAYER, NOTIFY_LOCATION, NOTIFY_STYLE, NOTIFY_TRANSFORM, poolPoints, poolPolys, poolRects, poolStrbuf, poolTx, rand, SATIN_DATA_DIRECTORY_DEFAULT, SATIN_DATA_DIRECTORY_GPROPERTY, SATIN_PROPERTIES_FILENAME, SHALLOW
 
Constructor Summary
GraphicalObjectCollectionImpl()
          Create a new, empty collection.
GraphicalObjectCollectionImpl(GraphicalObjectCollectionImpl gobcol)
          Make a shallow clone.
 
Method Summary
 GraphicalObject add(GraphicalObject gob)
          Same as addToFront.
 GraphicalObject add(int index, GraphicalObject gob)
          Add a Graphical Object to the specified location.
 GraphicalObject addToBack(GraphicalObject gob)
          Add a GraphicalObject to the back of the list.
 GraphicalObject addToFront(GraphicalObject gob)
          Add a GraphicalObject to the front of the list.
 void clear()
          Clear out all Graphical Objects in this collection.
 Object clone()
          Make a shallow clone.
protected  GraphicalObjectCollectionImpl clone(GraphicalObjectCollectionImpl gobcolClone)
          Make a shallow clone.
 boolean contains(GraphicalObject gob)
          See if this Graphical Object Collection contains the specified Graphical Object.
 Object deepClone()
          Make a deep clone of this GraphicalObjectCollection.
protected  GraphicalObjectCollectionImpl deepClone(GraphicalObjectCollectionImpl newGobcol)
          For deep-clone chaining purposes.
 GraphicalObject get(int index)
          Get the Graphical Object at the specified index.
 Rectangle2D getCollectionBounds2D(int cdsys)
          Get the union of the bounds of the GraphicalObjects contained in this collection.
 Rectangle2D getCollectionBounds2D(int cdsys, Rectangle2D rect)
          Get the bounds, put them in the specified Rectangle.
 GraphicalObject getFirst()
          Get the first Graphical Object.
 Iterator getForwardIterator()
          Get an iterator that goes forward thru the collection.
 GraphicalObject getID(int id)
          Retrieve the GraphicalObject with the specified unique ID.
 GraphicalObject getLast()
          Get the last Graphical Object.
protected  OrderedList getOrderedList()
          Get the Ordered List.
 Iterator getReverseIterator()
          Get an iterator that goes backwards thru the collection.
 int indexOf(GraphicalObject gob)
          Find the index of the specified Graphical Object.
 boolean isEmpty()
          Is this collection empty?
static void main(String[] argv)
           
 int numElements()
          Get the number of elements contained in this collection.
 void onDelete(Watchable w)
          Callback method for notifications of deletions, that is this Graphical Object has been deleted and you should remove it.
 void onNotify(Watchable w, Object arg)
          Callback method for generic notifications.
 void onRepaint(GraphicalObject gob)
           
 void onRepaint(Rectangle rect)
           
 void onUpdate(Watchable w, Object arg)
          Callback method for notifications.
 void onUpdate(Watchable w, String strProperty, Object oldVal, Object newVal)
          Callback method for notifications.
 GraphicalObject remove(GraphicalObject gob)
          Remove a Graphical Object from this collection.
 void sort(Comparator c)
          Sort the list given the specified comparator.
 String toString()
          Print it out.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphicalObjectCollectionImpl

public GraphicalObjectCollectionImpl()
Create a new, empty collection.

GraphicalObjectCollectionImpl

public GraphicalObjectCollectionImpl(GraphicalObjectCollectionImpl gobcol)
Make a shallow clone.
Method Detail

getOrderedList

protected OrderedList getOrderedList()
Get the Ordered List.

getCollectionBounds2D

public Rectangle2D getCollectionBounds2D(int cdsys)
Description copied from interface: GraphicalObjectCollection
Get the union of the bounds of the GraphicalObjects contained in this collection. Asking for local bounds is useless.
Asking for relative bounds is useful only if all of the GraphicalObjects have the same parent.
Asking for absolute bounds will always work.
Specified by:
getCollectionBounds2D in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
cdsys - is the coordinate system to use.
Returns:
Rectangle representing the union of bounds.

getCollectionBounds2D

public Rectangle2D getCollectionBounds2D(int cdsys,
                                         Rectangle2D rect)
Description copied from interface: GraphicalObjectCollection
Get the bounds, put them in the specified Rectangle.
Specified by:
getCollectionBounds2D in interface GraphicalObjectCollection

add

public GraphicalObject add(GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
Same as addToFront.
Specified by:
add in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
gob - is the GraphicalObject to add.
Returns:
a reference to the GraphicalObject added.

addToBack

public GraphicalObject addToBack(GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
Add a GraphicalObject to the back of the list.
Specified by:
addToBack in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
gob - is the Graphical Object to add.
Returns:
a reference to the GraphicalObject added.

addToFront

public GraphicalObject addToFront(GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
Add a GraphicalObject to the front of the list.
Specified by:
addToFront in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
gob - is the Graphical Object to add.
Returns:
a reference to the GraphicalObject added.

add

public GraphicalObject add(int index,
                           GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
Add a Graphical Object to the specified location.
Specified by:
add in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
index - is the location to add to (zero-based). It is up to the programmer to ensure that this is a valid value.
gob - is the Graphical Object to add.

clear

public void clear()
Description copied from interface: GraphicalObjectCollection
Clear out all Graphical Objects in this collection.
Specified by:
clear in interface GraphicalObjectCollection

contains

public boolean contains(GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
See if this Graphical Object Collection contains the specified Graphical Object. Please note that this is NOT the same as calling GraphicalObject.shapeContains(GraphicalObject).
Specified by:
contains in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
true if it contains the specified Graphical Object, false otherwise.

get

public GraphicalObject get(int index)
Description copied from interface: GraphicalObjectCollection
Get the Graphical Object at the specified index.
Specified by:
get in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
index - is the location to look at (zero-based). It is up to the programmer to ensure that this is a valid value.
Returns:
the Graphical Object at the specified index.

getFirst

public GraphicalObject getFirst()
Description copied from interface: GraphicalObjectCollection
Get the first Graphical Object.
Specified by:
getFirst in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
null if nothing is there.

getLast

public GraphicalObject getLast()
Description copied from interface: GraphicalObjectCollection
Get the last Graphical Object.
Specified by:
getLast in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
null if nothing is there.

getID

public GraphicalObject getID(int id)
Description copied from interface: GraphicalObjectCollection
Retrieve the GraphicalObject with the specified unique ID.
Specified by:
getID in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
id - is the unique ID of the GraphicalObject to retrieve.
Returns:
the GraphicalObject with that ID, or null if it isn't here.

indexOf

public int indexOf(GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
Find the index of the specified Graphical Object.
Specified by:
indexOf in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
gob - is the Graphical Object to look for.
Returns:
the index of the Graphical Object in this collection (zero-based) or -1 if it is not here.

isEmpty

public boolean isEmpty()
Description copied from interface: GraphicalObjectCollection
Is this collection empty?
Specified by:
isEmpty in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
true if empty, false otherwise.

numElements

public int numElements()
Description copied from interface: GraphicalObjectCollection
Get the number of elements contained in this collection.

I realize that this should have been called size(), but there already exists a deprecated method in Component named size().

Specified by:
numElements in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
the number of elements contained.

remove

public GraphicalObject remove(GraphicalObject gob)
Description copied from interface: GraphicalObjectCollection
Remove a Graphical Object from this collection.
Specified by:
remove in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Parameters:
gob - is the Graphical Object ot remove.

getForwardIterator

public Iterator getForwardIterator()
Description copied from interface: GraphicalObjectCollection
Get an iterator that goes forward thru the collection.
Specified by:
getForwardIterator in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
an Iterator.

getReverseIterator

public Iterator getReverseIterator()
Description copied from interface: GraphicalObjectCollection
Get an iterator that goes backwards thru the collection.
Specified by:
getReverseIterator in interface GraphicalObjectCollection
Following copied from interface: edu.berkeley.guir.lib.satin.objects.GraphicalObjectCollection
Returns:
an Iterator.

sort

public void sort(Comparator c)
Description copied from interface: GraphicalObjectCollection
Sort the list given the specified comparator. One useful one is the LayerComparator, which sorts by layers.
Specified by:
sort in interface GraphicalObjectCollection

onNotify

public void onNotify(Watchable w,
                     Object arg)
Description copied from interface: Watcher
Callback method for generic notifications. This typically won't be used.
Specified by:
onNotify in interface Watcher
Following copied from interface: edu.berkeley.guir.lib.satin.watch.Watcher
Parameters:
w - is the Watchable object notifying you.
arg - is some agreed upon argument.
See Also:
Watchable.notifyWatchers(), Watchable.notifyWatchers(java.lang.Object)

onUpdate

public void onUpdate(Watchable w,
                     Object arg)
Description copied from interface: Watcher
Callback method for notifications.
Specified by:
onUpdate in interface Watcher
Following copied from interface: edu.berkeley.guir.lib.satin.watch.Watcher
Parameters:
w - is the Watchable object that has been updated.
arg - is some agreed upon argument.
See Also:
Watchable.notifyWatchersUpdate(Object)

onUpdate

public void onUpdate(Watchable w,
                     String strProperty,
                     Object oldVal,
                     Object newVal)
Description copied from interface: Watcher
Callback method for notifications.
Specified by:
onUpdate in interface Watcher
Following copied from interface: edu.berkeley.guir.lib.satin.watch.Watcher
Parameters:
w - is the Watchable object that has been updated.
strProperty - is the name of the property to update.
oldVal - is the old value of the property. This should usually be a clone of the old value, so that modifying this value should have no effect. Whether this is a copy or a reference should be defined in the SatinConstants file.
newVal - is the new value of the property. This should usually be a clone of the old value, so that modifying this value should have no effect. However, don't clone if it is prohibitively expensive to do so. Whether this is a copy or a reference should be defined in the SatinConstants file.
See Also:
SatinConstants, Watchable.notifyWatchersUpdate(String, Object, Object)

onRepaint

public void onRepaint(GraphicalObject gob)

onRepaint

public void onRepaint(Rectangle rect)

onDelete

public void onDelete(Watchable w)
Description copied from interface: Watcher
Callback method for notifications of deletions, that is this Graphical Object has been deleted and you should remove it.
Specified by:
onDelete in interface Watcher
Following copied from interface: edu.berkeley.guir.lib.satin.watch.Watcher
Parameters:
w - is the Watchable object to be deleted.
See Also:
Watchable.notifyWatchersDelete()

toString

public String toString()
Print it out.
Overrides:
toString in class Object

clone

public Object clone()
Make a shallow clone.
Specified by:
clone in interface GraphicalObjectCollection
Overrides:
clone in class Object
See Also:
deepClone()

clone

protected GraphicalObjectCollectionImpl clone(GraphicalObjectCollectionImpl gobcolClone)
Make a shallow clone. You should be aware that this adds another watcher to all of the GraphicalObjects already in the collection.

deepClone

public Object deepClone()
Make a deep clone of this GraphicalObjectCollection.
Specified by:
deepClone in interface GraphicalObjectCollection
See Also:
clone()

deepClone

protected GraphicalObjectCollectionImpl deepClone(GraphicalObjectCollectionImpl newGobcol)
For deep-clone chaining purposes.
Parameters:
newGobcol - is the object that will be a clone of the current object. That is, we copy our parameters into newGobcol.

main

public static void main(String[] argv)

Copyright Information