sim.portrayal.simple
Class CircledPortrayal2D

java.lang.Object
  extended bysim.portrayal.SimplePortrayal2D
      extended bysim.portrayal.simple.CircledPortrayal2D
All Implemented Interfaces:
Portrayal, Portrayal2D, java.io.Serializable

public class CircledPortrayal2D
extends SimplePortrayal2D

A wrapper for other Portrayal2Ds which also draws a big circle around them -- useful for distinguishing one object from other similar-looking objects. When you create this CirclePortrayal2D, you will pass in an underlying Portrayal2D which is supposed to draw the actual object; CirclePortrayal2D will then add on the circle. If the object will draw itself (it's its own Portrayal2D), you can signify this by passing in null for the underlying Portrayal2D.

There are certain guidelines you can specify for when the circle is to be drawn. At construction time you can state that the circle should only be drawn when the object is selected. Additionally if you call the setCircleShowing(...) function, you can turn off or on circle drawing entirely for this CirclePortrayal2D.

You may specify a color or paint for the circle (the default is blue).

The circle is drawn centered at the object's [info.draw.x, info.draw.y] origin and with the radius:


   radius:     (int)(or * max(info.draw.width,info.draw.height)) + dr;
   

... that is, or is a value which scales when you zoom in, and dr adds additional fixed pixels. The default is or = 1.0, dr = 0. This draws the circle at twice the expected width and height of the object.

Note: One oddity of CircledPortrayal2D is due to the fact that the circle is only drawn if the object is being drawn. While most FieldPortrayals ask objects just off-screen to draw themselves just to be careful, if an object is significantly off-screen, it may not be asked to draw itself, and so the circle will not be drawn -- even though part of the circle could be on-screen at the time! C'est la vie.

See Also:
Serialized Form

Field Summary
 SimplePortrayal2D child
           
static int DEFAULT_DR
           
static double DEFAULT_OR
           
 int dr
          The post-scaling radius offset
 double or
          The pre-scaling radius
 java.awt.Paint paint
          The Paint or Color of the circle
 
Constructor Summary
CircledPortrayal2D(SimplePortrayal2D child)
          Draw a circle of radius or = 1.0, dr = 0, in blue.
CircledPortrayal2D(SimplePortrayal2D child, int dr, double or, java.awt.Paint paint, boolean onlyCircleWhenSelected)
          If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.
CircledPortrayal2D(SimplePortrayal2D child, java.awt.Paint paint, boolean onlyCircleWhenSelected)
          Draw a circle of radius or = 1.0, dr = 0.
 
Method Summary
 void draw(java.lang.Object object, java.awt.Graphics2D graphics, DrawInfo2D info)
          Draw a portrayed object centered at the origin in info, and with the given scaling factors.
 SimplePortrayal2D getChild(java.lang.Object object)
           
 Inspector getInspector(LocationWrapper wrapper, GUIState state)
          Provide an inspector for an object.
 java.lang.String getName(LocationWrapper wrapper)
          Returns a static, one-line name for the given object that is useful for a human to distinguish it from other objects.
 boolean getOnlyCircleWhenSelected()
           
 boolean hitObject(java.lang.Object object, DrawInfo2D range)
          If drawing area intersects selected area, return true.
 boolean isCircleShowing()
           
 void setCircleShowing(boolean val)
           
 void setOnlyCircleWhenSelected(boolean val)
           
 boolean setSelected(LocationWrapper wrapper, boolean selected)
          Change the portrayal state to reflect the fact that you've been selected or not selected.
 
Methods inherited from class sim.portrayal.SimplePortrayal2D
getStatus, move
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_OR

public static final double DEFAULT_OR
See Also:
Constant Field Values

DEFAULT_DR

public static final int DEFAULT_DR
See Also:
Constant Field Values

or

public double or
The pre-scaling radius


dr

public int dr
The post-scaling radius offset


paint

public java.awt.Paint paint
The Paint or Color of the circle


child

public SimplePortrayal2D child
Constructor Detail

CircledPortrayal2D

public CircledPortrayal2D(SimplePortrayal2D child,
                          int dr,
                          double or,
                          java.awt.Paint paint,
                          boolean onlyCircleWhenSelected)
If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.


CircledPortrayal2D

public CircledPortrayal2D(SimplePortrayal2D child)
Draw a circle of radius or = 1.0, dr = 0, in blue. Draw the circle regardless of selection. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.


CircledPortrayal2D

public CircledPortrayal2D(SimplePortrayal2D child,
                          java.awt.Paint paint,
                          boolean onlyCircleWhenSelected)
Draw a circle of radius or = 1.0, dr = 0. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.

Method Detail

setOnlyCircleWhenSelected

public void setOnlyCircleWhenSelected(boolean val)

getOnlyCircleWhenSelected

public boolean getOnlyCircleWhenSelected()

isCircleShowing

public boolean isCircleShowing()

setCircleShowing

public void setCircleShowing(boolean val)

getChild

public SimplePortrayal2D getChild(java.lang.Object object)

draw

public void draw(java.lang.Object object,
                 java.awt.Graphics2D graphics,
                 DrawInfo2D info)
Description copied from interface: Portrayal2D
Draw a portrayed object centered at the origin in info, and with the given scaling factors. It is possible that object is null.

Specified by:
draw in interface Portrayal2D
Overrides:
draw in class SimplePortrayal2D

hitObject

public boolean hitObject(java.lang.Object object,
                         DrawInfo2D range)
Description copied from class: SimplePortrayal2D
If drawing area intersects selected area, return true. The default computes the intersection with the (-0.5,-0.5) to (0.5,0.5) rectangle.

Overrides:
hitObject in class SimplePortrayal2D

setSelected

public boolean setSelected(LocationWrapper wrapper,
                           boolean selected)
Description copied from interface: Portrayal
Change the portrayal state to reflect the fact that you've been selected or not selected. Always return true, except if you've received a setSelected(true) and in fact do not wish to be selectable, in which case return false in that sole situation.

Specified by:
setSelected in interface Portrayal
Overrides:
setSelected in class SimplePortrayal2D

getInspector

public Inspector getInspector(LocationWrapper wrapper,
                              GUIState state)
Description copied from interface: Portrayal
Provide an inspector for an object.

Specified by:
getInspector in interface Portrayal
Overrides:
getInspector in class SimplePortrayal2D

getName

public java.lang.String getName(LocationWrapper wrapper)
Description copied from interface: Portrayal
Returns a static, one-line name for the given object that is useful for a human to distinguish it from other objects. A simple default would be just to return "" + object.

Specified by:
getName in interface Portrayal
Overrides:
getName in class SimplePortrayal2D