Class Rubberband

java.lang.Object
java.awt.Component
gov.nih.mipav.view.Rubberband
All Implemented Interfaces:
MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener
Direct Known Subclasses:
RubberbandEllipse, RubberbandLine, RubberbandLivewire, RubberbandPolyline, RubberbandProtractor, RubberbandRectangle

public abstract class Rubberband extends Component implements MouseMotionListener, MouseListener
An abstract base class for rubberbands.

Rubberbands do their rubberbanding inside of a Component, which must be specified at construction time.

Subclasses are responsible for implementing void drawLast(Graphics g) and void drawNext(Graphics g).

drawLast() draws the appropriate geometric shape at the last rubberband location, while drawNext() draws the appropriate geometric shape at the next rubberband location. All of the underlying support for rubberbanding is taken care of here, including handling XOR mode setting; extensions of Rubberband need not concern themselves with anything but drawing the last and next geometric shapes. Extensions may get information about where to draw their shape from getAnchor(), getStretched(), and getLast(), and getEnd(), all of which return a Point.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Use serialVersionUID for interoperability.
      See Also:
    • anchorPt

      protected Point anchorPt
      DOCUMENT ME!
    • component

      protected Component component
      DOCUMENT ME!
    • endPt

      protected Point endPt
      DOCUMENT ME!
    • lastPt

      protected Point lastPt
      DOCUMENT ME!
    • presetHue

      protected float presetHue
      DOCUMENT ME!
    • stretchedPt

      protected Point stretchedPt
      DOCUMENT ME!
    • usableComponent

      protected boolean usableComponent
      DOCUMENT ME!
    • xMax

      protected int xMax
      DOCUMENT ME!
    • xS

      protected int xS
      DOCUMENT ME!
    • yMax

      protected int yMax
      DOCUMENT ME!
    • yS

      protected int yS
      DOCUMENT ME!
    • active

      private boolean active
      DOCUMENT ME!
    • firstStretch

      private boolean firstStretch
      DOCUMENT ME!
  • Constructor Details

    • Rubberband

      public Rubberband()
      Default constructor, does nothing.
    • Rubberband

      public Rubberband(Component c)
      Sets the parent component that the rubberband is for.
      Parameters:
      c - Component that the rubberband is for
  • Method Details

    • drawLast

      public abstract void drawLast(Graphics g)
      Draws the appropriate geometric shape at the last rubberband location.
      Parameters:
      g - DOCUMENT ME!
    • drawNext

      public abstract void drawNext(Graphics g)
      Draws the appropriate geometric shape at the next rubberband location.
      Parameters:
      g - DOCUMENT ME!
    • anchor

      public void anchor(Point p)
      Anchors the rubberband to this point.
      Parameters:
      p - point to anchor the rubberband to
    • dispose

      public void dispose()
      Sets parent component image to null.
    • end

      public void end(Point p)
      Sets the end point to this point.
      Parameters:
      p - point to set the end to
    • getAnchor

      public Point getAnchor()
      Returns the anchor point of the rubberband.
      Returns:
      the anchor point
    • getBounds

      public Rectangle getBounds()
      Gets a rectangle that is the bounds of the rubberband.
      Overrides:
      getBounds in class Component
      Returns:
      rectangle of the bounds
    • getEnd

      public Point getEnd()
      Returns the end point of the rubberband.
      Returns:
      the end point
    • getLast

      public Point getLast()
      Returns the last point of the rubberband.
      Returns:
      the last point
    • getStretched

      public Point getStretched()
      Returns the stretched point of the rubberband.
      Returns:
      the stretched point
    • isActive

      public boolean isActive()
      Returns a boolean indicating activity.
      Returns:
      boolean indicating activity
    • lastBounds

      public Rectangle lastBounds()
      Gets the last bounds of the rubberband.
      Returns:
      rectangle of the bounds
    • mouseClicked

      public void mouseClicked(MouseEvent mouseEvent)
      Gets the end point of the rubberband.
      Specified by:
      mouseClicked in interface MouseListener
      Parameters:
      mouseEvent - event that triggered function
    • mouseDragged

      public void mouseDragged(MouseEvent mouseEvent)
      Gets the stretch point of the rubberband.
      Specified by:
      mouseDragged in interface MouseMotionListener
      Parameters:
      mouseEvent - event that triggered function
    • mouseEntered

      public void mouseEntered(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mouseEntered in interface MouseListener
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mouseExited

      public void mouseExited(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mouseExited in interface MouseListener
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mouseMoved

      public void mouseMoved(MouseEvent mouseEvent)
      Unchanged.
      Specified by:
      mouseMoved in interface MouseMotionListener
      Parameters:
      mouseEvent - DOCUMENT ME!
    • mousePressed

      public void mousePressed(MouseEvent mouseEvent)
      Gets the anchor point of the rubberband.
      Specified by:
      mousePressed in interface MouseListener
      Parameters:
      mouseEvent - event that triggered function
    • mouseReleased

      public void mouseReleased(MouseEvent mouseEvent)
      Gets the end point of the rubberband.
      Specified by:
      mouseReleased in interface MouseListener
      Parameters:
      mouseEvent - event that triggered function
    • setActive

      public void setActive(boolean b)
      Sets the rubberband to active or not active.
      Parameters:
      b - boolean indicating activity
    • setComponent

      public void setComponent(Component c)
      Sets the component to the parameter.
      Parameters:
      c - the component
    • setPresetHue

      public void setPresetHue(float presetHue)
      Sets the presetHue.
      Parameters:
      presetHue - DOCUMENT ME!
    • stretch

      public void stretch(Point p)
      Stretch the rubberband to this point.
      Parameters:
      p - point to stretch to
    • distance

      protected static final double distance(int x1, int x2, int y1, int y2)
      Calculates the 2D euclidian distance between two points.
      Parameters:
      x1 - first x coordinate
      x2 - second x coordinate
      y1 - first y coordinate
      y2 - second y coordinate
      Returns:
      returns the distance
    • testPoint

      protected boolean testPoint(Point pt)
      Tests the point for validity within the image.
      Parameters:
      pt - point to test
      Returns:
      boolean result of test