net.sf.jaxodraw.object
Class JaxoObjectList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList
              extended by net.sf.jaxodraw.object.JaxoObjectList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess, JaxoList

public class JaxoObjectList
extends java.util.ArrayList
implements JaxoList

Implementation of JaxoList. This should ensure that only JaxoObjects are added as elements by throwing a ClassCastException if something else is attempted.

Since:
2.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
JaxoObjectList()
          Just calls super().
JaxoObjectList(java.util.Collection c)
          Add all elements of c to this List.
JaxoObjectList(int initialCapacity)
          Just calls super(initialCapacity).
 
Method Summary
 void add(int index, java.lang.Object element)
          Add a JaxoObject to this list.
 boolean add(java.lang.Object o)
          Add a JaxoObject to this list.
 boolean addAll(java.util.Collection c)
          Add a Collection of JaxoObjects to this list.
 boolean addAll(int index, java.util.Collection c)
          Add a Collection of JaxoObjects to this list.
 JaxoList copyOf()
          Returns a copy of this JaxoList, i.e., a new JaxoList with copies of equal JaxoObjects at equal positions.
 java.awt.Rectangle getBounds()
          Returns the smallest bounding box that contains all the JaxoObjects of this JaxoList.
 java.awt.Rectangle getBoundsExcept(java.util.Collection excludes)
          Returns the smallest bounding box that contains all the JaxoObjects of this JaxoList except the ones contained in 'except'.
 java.awt.Rectangle intersection(java.awt.Rectangle inside)
          Intersection of the bounding box of this JaxoList with the given Rectangle.
 boolean isCopy(JaxoList list)
          Determines if this JaxoList is a copy of the specified one.
 void move(int index, int newIndex)
          Move the object at 'index' to 'newIndex', leaving all other elements in order.
 void moveAllObjects(int deltaX, int deltaY)
          Displaces all JaxoObjects by the same amount.
 void paint(JaxoGraphics2D g)
          Call paint(g) on all elements of JaxoObjects.
 void paintClipped(JaxoGraphics2D g)
          Call paint on all elements of JaxoObjects if they intersect the current clipping area of the given graphics context.
 void paintClippedExcept(java.util.Collection excludes, JaxoGraphics2D g)
          Call paint on all elements of JaxoObjects that are not contained in 'excludes' and that intersect the current clipping area of the given graphics context.
 void paintExcept(java.util.Collection excludes, JaxoGraphics2D g)
          Call paint on all elements of JaxoObjects that are not contained in 'excludes'.
 boolean removeMarkedObjects()
          Removes all marked JaxoObjects from this list.
 java.lang.Object set(int index, java.lang.Object element)
          Replace the object at the given position with the specified object.
 void setColor(java.awt.Color c)
          Sets the color of all JaxoObjects in this list.
 boolean toEnd(JaxoObject object)
          Moves the specified JaxoObject to the last position in this list.
 boolean toFront(JaxoObject object)
          Moves the specified JaxoObject to the first position in this list.
 
Methods inherited from class java.util.ArrayList
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeRange, retainAll, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, size, subList, toArray, toArray
 

Constructor Detail

JaxoObjectList

public JaxoObjectList()
Just calls super().


JaxoObjectList

public JaxoObjectList(java.util.Collection c)
Add all elements of c to this List. Throws a ClassCastException if c contains elements that are not JaxoObjects.

Parameters:
c - the collection whose elements are to be placed into this list.

JaxoObjectList

public JaxoObjectList(int initialCapacity)
Just calls super(initialCapacity).

Parameters:
initialCapacity - the initial capacity of the list.
Method Detail

add

public boolean add(java.lang.Object o)
Add a JaxoObject to this list. A ClassCastException is thrown if o is not a JaxoObject.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.ArrayList
Parameters:
o - the object to add.
Returns:
true.
See Also:
ArrayList.add(java.lang.Object)

add

public void add(int index,
                java.lang.Object element)
Add a JaxoObject to this list. A ClassCastException is thrown if o is not a JaxoObject.

Specified by:
add in interface java.util.List
Overrides:
add in class java.util.ArrayList
Parameters:
index - index at which the object is to be inserted.
element - the object to add.
See Also:
ArrayList.add(int,java.lang.Object)

addAll

public boolean addAll(java.util.Collection c)
Add a Collection of JaxoObjects to this list. A ClassCastException is thrown if c contains non-JaxoObjects.

Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.ArrayList
Parameters:
c - the collection to add.
Returns:
true if this list is changed as a result of the call.
See Also:
ArrayList.addAll(java.util.Collection)

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Add a Collection of JaxoObjects to this list. A ClassCastException is thrown if c contains non-JaxoObjects.

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.ArrayList
Parameters:
index - index at which the object is to be inserted.
c - the collection to add.
Returns:
true if this list is changed as a result of the call.
See Also:
ArrayList.addAll(int,java.util.Collection)

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Replace the object at the given position with the specified object. A ClassCastException is thrown if element is not a JaxoObject.

Specified by:
set in interface java.util.List
Overrides:
set in class java.util.ArrayList
Parameters:
index - index of the object to be replaced.
element - the object to be stored at the given position.
Returns:
the object that was previously at the specified position.
See Also:
ArrayList.set(int,java.lang.Object)

paint

public void paint(JaxoGraphics2D g)
Call paint(g) on all elements of JaxoObjects.

Specified by:
paint in interface JaxoList
Parameters:
g - The graphics context to paint to.
See Also:
JaxoObject.paint(JaxoGraphics2D)

paintClipped

public void paintClipped(JaxoGraphics2D g)
Call paint on all elements of JaxoObjects if they intersect the current clipping area of the given graphics context.

Specified by:
paintClipped in interface JaxoList
Parameters:
g - The graphics context to paint to.
See Also:
JaxoObject.paint(JaxoGraphics2D), Graphics.hitClip(int,int,int,int)

paintExcept

public void paintExcept(java.util.Collection excludes,
                        JaxoGraphics2D g)
Call paint on all elements of JaxoObjects that are not contained in 'excludes'.

Specified by:
paintExcept in interface JaxoList
Parameters:
excludes - The JaxoObjects to exlude.
g - The graphics context to paint to.
See Also:
JaxoObject.paint(JaxoGraphics2D)

paintClippedExcept

public void paintClippedExcept(java.util.Collection excludes,
                               JaxoGraphics2D g)
Call paint on all elements of JaxoObjects that are not contained in 'excludes' and that intersect the current clipping area of the given graphics context.

Specified by:
paintClippedExcept in interface JaxoList
Parameters:
excludes - The JaxoObjects to exlude.
g - The graphics context to paint to.
See Also:
JaxoObject.paint(JaxoGraphics2D), Graphics.hitClip(int,int,int,int)

copyOf

public JaxoList copyOf()
Returns a copy of this JaxoList, i.e., a new JaxoList with copies of equal JaxoObjects at equal positions.

Specified by:
copyOf in interface JaxoList
Returns:
A copy of this JaxoList.

isCopy

public boolean isCopy(JaxoList list)
Determines if this JaxoList is a copy of the specified one.

Specified by:
isCopy in interface JaxoList
Parameters:
list - The JaxoList to compare against.
Returns:
True if the JaxoLists contain identical JaxoObjects at equal positions.

moveAllObjects

public void moveAllObjects(int deltaX,
                           int deltaY)
Displaces all JaxoObjects by the same amount.

Specified by:
moveAllObjects in interface JaxoList
Parameters:
deltaX - The displacement in x direction
deltaY - The displacement in y direction

setColor

public void setColor(java.awt.Color c)
Sets the color of all JaxoObjects in this list.

Specified by:
setColor in interface JaxoList
Parameters:
c - The color to set.

move

public void move(int index,
                 int newIndex)
Move the object at 'index' to 'newIndex', leaving all other elements in order.

Specified by:
move in interface JaxoList
Parameters:
index - The index of the object to move.
newIndex - The new index of the object.

toEnd

public boolean toEnd(JaxoObject object)
Moves the specified JaxoObject to the last position in this list.

Specified by:
toEnd in interface JaxoList
Parameters:
object - The JaxoObject to move.
Returns:
True if the object was already in the last position, i.e., the JaxoList has not been modified.

toFront

public boolean toFront(JaxoObject object)
Moves the specified JaxoObject to the first position in this list.

Specified by:
toFront in interface JaxoList
Parameters:
object - The JaxoObject to move.
Returns:
True if the JaxoObject was already in the first position, i.e., the JaxoList has not been modified.

removeMarkedObjects

public boolean removeMarkedObjects()
Removes all marked JaxoObjects from this list.

Specified by:
removeMarkedObjects in interface JaxoList
Returns:
True if the list was modified by this operation, i.e., there were marked objects in the list.

getBounds

public java.awt.Rectangle getBounds()
Returns the smallest bounding box that contains all the JaxoObjects of this JaxoList.

Specified by:
getBounds in interface JaxoList
Returns:
A Rectangle holding the bounds of this JaxoList, or null if the List is empty (ie contains no objects).

getBoundsExcept

public java.awt.Rectangle getBoundsExcept(java.util.Collection excludes)
Returns the smallest bounding box that contains all the JaxoObjects of this JaxoList except the ones contained in 'except'.

Specified by:
getBoundsExcept in interface JaxoList
Parameters:
excludes - objects to exclude, may be null.
Returns:
A Rectangle holding the bounds of the current JaxoList, or null if the List is empty (ie contains no objects).

intersection

public java.awt.Rectangle intersection(java.awt.Rectangle inside)
Intersection of the bounding box of this JaxoList with the given Rectangle. This returns null if either any of the two rectangles are null, or if they do not intersect.

Specified by:
intersection in interface JaxoList
Parameters:
inside - The Rectangle to intersect with.
Returns:
The intersection, or null if either any of the two rectangles are null, or if they do not intersect.
See Also:
JaxoList.getBounds()


Licensed under GPL. For more information, see http://jaxodraw.sourceforge.net/license.html or the LICENSE file in the jaxodraw distribution.