ks.common.view
Class RectangleHierarchy

java.lang.Object
  extended byks.common.view.RectangleHierarchy

public class RectangleHierarchy
extends java.lang.Object

Manages a Tree of rectangles that represent the non-widget elements on the container.

Assuming an outer boundary rectangle (x,y,width,height), this class keeps track of 'negative space' assuming that each inserted rectangle represents 'positive space'.

For example, given the root (x,y,width,height) and the rectangle (u,v,l,m) is inserted, this node has four children R0, R1, R2, R3.

R0 = (x,y,width,v-y) ;; top horizontal slice
R1 = (x,v,u-1,m) ;; rectangle slice to the left of the
;; inserted rectangle
R2 = (u+m,v,width-m-(u-x)) ;; rectangle slice to the right of the
;; inserted rectangle
R3 = (x,v+m,width,height-m-(v-y)) ;; bottom horizontal slice.

insert (Rectangle r) is a recursive method, enabling partialling intersecting rectangles to be modeled.


Constructor Summary
RectangleHierarchy(java.awt.Rectangle initialBounds)
          RectangleHierarchy constructor.
 
Method Summary
 void accept(RectangleHierarchyVisitor visitor)
          Accept visitor and use double dispatching to pass ourselves in as a parameter to the visitor.
 void accept(RectangleHierarchyVisitor visitor, java.awt.Rectangle clip)
          Accept visitor and use double dispatching to pass ourselves in as a parameter to the visitor.
 java.awt.Rectangle getBounds()
          Return bounds of this node.
 RectangleHierarchy[] getChildren()
          Return all children of the given node in array (or null if there are no children).
 boolean insert(java.awt.Rectangle r)
          Insert the given rectangle into the hierarchy.
 java.lang.String toString()
          Convert to String the hierarchy root Rectangle.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RectangleHierarchy

public RectangleHierarchy(java.awt.Rectangle initialBounds)
RectangleHierarchy constructor.

Method Detail

accept

public void accept(RectangleHierarchyVisitor visitor)
Accept visitor and use double dispatching to pass ourselves in as a parameter to the visitor.

Parameters:
visitor - ks.common.view.RectangleHierarchyVisitor

accept

public void accept(RectangleHierarchyVisitor visitor,
                   java.awt.Rectangle clip)
Accept visitor and use double dispatching to pass ourselves in as a parameter to the visitor.

Clip all drawing to this clip Rect. [clip is unaffected by this invocation.]

Parameters:
visitor - ks.common.view.RectangleHierarchyVisitor
clip - Rectangle

getBounds

public java.awt.Rectangle getBounds()
Return bounds of this node.

The rectangle returned is the actual rectangle. DO NOT MODIFY THIS OBJECT.

Returns:
Rectangle

getChildren

public RectangleHierarchy[] getChildren()
Return all children of the given node in array (or null if there are no children).

Returns:
ks.common.view.RectangleHierarchy[]

insert

public boolean insert(java.awt.Rectangle r)
Insert the given rectangle into the hierarchy.

The rectangle represents the bounds of a widget. We essentially need to model the other portions that remain as rectangles. Consider the widget as positive space; the RectangleHierarchy models the negative space.

Parameters:
r - Rectangle
Returns:
boolean

toString

public java.lang.String toString()
Convert to String the hierarchy root Rectangle.

Returns:
java.lang.String