Class CircledPortrayal2D

All Implemented Interfaces:
Serializable, Portrayal, Portrayal2D

public class CircledPortrayal2D extends OvalPortrayal2D
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:


   x diameter:     (int)(scale * info.draw.width + offset);
   y diameter:     (int)(scale * info.draw.height + offset);
   

... that is, scale is a value which scales when you zoom in, and offset adds additional fixed pixels. The default is scale = 2.0, offset = 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:
  • Field Details

  • Constructor Details

    • CircledPortrayal2D

      public CircledPortrayal2D(SimplePortrayal2D child, double offset, double scale, 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 scale = 2.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, Paint paint, boolean onlyCircleWhenSelected)
      Draw a circle of radius or = 2.0, dr = 0. If child is null, then the underlying model object is presumed to be a Portrayal2D and will be used.
  • Method Details

    • setOnlyCircleWhenSelected

      public void setOnlyCircleWhenSelected(boolean val)
    • getOnlyCircleWhenSelected

      public boolean getOnlyCircleWhenSelected()
    • isCircleShowing

      public boolean isCircleShowing()
    • setCircleShowing

      public void setCircleShowing(boolean val)
    • getChild

      public SimplePortrayal2D getChild(Object object)
    • draw

      public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
      Description copied from interface: Portrayal2D
      Draw a the given object with an origin at (info.draw.x, info.draw.y), and with the coordinate system scaled by so that 1 unit is in the x and y directions are equal to info.draw.width and info.draw.height respectively in pixels. The rectangle given by info.clip specifies the only region in which it is necessary to draw. If info.precise is true, try to draw using real-valued high-resolution drawing rather than faster integer drawing. It is possible that object is null. The location of the object in the field may (and may not) be stored in info.location. The form of that location varies depending on the kind of field used.
      Specified by:
      draw in interface Portrayal2D
      Overrides:
      draw in class OvalPortrayal2D
    • hitObject

      public boolean hitObject(Object object, DrawInfo2D range)
      Description copied from class: OvalPortrayal2D
      If drawing area intersects selected area, add last portrayed object to the bag
      Overrides:
      hitObject in class OvalPortrayal2D
    • 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 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
    • handleMouseEvent

      public boolean handleMouseEvent(GUIState guistate, Manipulating2D manipulating, LocationWrapper wrapper, MouseEvent event, DrawInfo2D fieldPortrayalDrawInfo, int type)
      Description copied from class: SimplePortrayal2D
      Optionally handles a mouse event. At present, events are sent to SimplePortrayal2Ds representing objects which have been either selected or are presently hit by the event coordinates. The wrapper provides the field portrayal, object location, and object. Also provided are the display, event, the DrawInfo2D for the field portrayal, and the type of mouse event situation (either because the object was SELECTED or because it was HIT).

      To indicate that the event was handled, return true. The default blank implementation of this method simply returns false. Events are first sent to portrayals selected objects, until one of them handles the event. If none handled the event, then events are sent to portrayals of objects hit by the event, until one of *them* handles the event. If still no one has handled the event, then the Display2D will route the event to built-in mechanisms such selecting the object or inspecting it.

      If you're modifying or querying the model as a result of this event, be sure to lock on guistate.state.schedule before you do so.

      Overrides:
      handleMouseEvent in class SimplePortrayal2D