Class Rubberband

  • All Implemented Interfaces:
    java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener
    Direct Known Subclasses:
    RubberbandEllipse, RubberbandLine, RubberbandLivewire, RubberbandPolyline, RubberbandProtractor, RubberbandRectangle

    public abstract class Rubberband
    extends java.awt.Component
    implements java.awt.event.MouseMotionListener, java.awt.event.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:
    RubberbandEllipse, RubberbandLine, RubberbandPolyline, RubberbandRectangle, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean active
      DOCUMENT ME!
      protected java.awt.Point anchorPt
      DOCUMENT ME!
      protected java.awt.Component component
      DOCUMENT ME!
      protected java.awt.Point endPt
      DOCUMENT ME!
      private boolean firstStretch
      DOCUMENT ME!
      protected java.awt.Point lastPt
      DOCUMENT ME!
      protected float presetHue
      DOCUMENT ME!
      private static long serialVersionUID
      Use serialVersionUID for interoperability.
      protected java.awt.Point stretchedPt
      DOCUMENT ME!
      protected boolean usableComponent
      DOCUMENT ME!
      protected int xMax
      DOCUMENT ME!
      protected int xS
      DOCUMENT ME!
      protected int yMax
      DOCUMENT ME!
      protected int yS
      DOCUMENT ME!
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      Rubberband()
      Default constructor, does nothing.
      Rubberband​(java.awt.Component c)
      Sets the parent component that the rubberband is for.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void anchor​(java.awt.Point p)
      Anchors the rubberband to this point.
      void dispose()
      Sets parent component image to null.
      protected static double distance​(int x1, int x2, int y1, int y2)
      Calculates the 2D euclidian distance between two points.
      abstract void drawLast​(java.awt.Graphics g)
      Draws the appropriate geometric shape at the last rubberband location.
      abstract void drawNext​(java.awt.Graphics g)
      Draws the appropriate geometric shape at the next rubberband location.
      void end​(java.awt.Point p)
      Sets the end point to this point.
      java.awt.Point getAnchor()
      Returns the anchor point of the rubberband.
      java.awt.Rectangle getBounds()
      Gets a rectangle that is the bounds of the rubberband.
      java.awt.Point getEnd()
      Returns the end point of the rubberband.
      java.awt.Point getLast()
      Returns the last point of the rubberband.
      java.awt.Point getStretched()
      Returns the stretched point of the rubberband.
      boolean isActive()
      Returns a boolean indicating activity.
      java.awt.Rectangle lastBounds()
      Gets the last bounds of the rubberband.
      void mouseClicked​(java.awt.event.MouseEvent mouseEvent)
      Gets the end point of the rubberband.
      void mouseDragged​(java.awt.event.MouseEvent mouseEvent)
      Gets the stretch point of the rubberband.
      void mouseEntered​(java.awt.event.MouseEvent mouseEvent)
      Unchanged.
      void mouseExited​(java.awt.event.MouseEvent mouseEvent)
      Unchanged.
      void mouseMoved​(java.awt.event.MouseEvent mouseEvent)
      Unchanged.
      void mousePressed​(java.awt.event.MouseEvent mouseEvent)
      Gets the anchor point of the rubberband.
      void mouseReleased​(java.awt.event.MouseEvent mouseEvent)
      Gets the end point of the rubberband.
      void setActive​(boolean b)
      Sets the rubberband to active or not active.
      void setComponent​(java.awt.Component c)
      Sets the component to the parameter.
      void setPresetHue​(float presetHue)
      Sets the presetHue.
      void stretch​(java.awt.Point p)
      Stretch the rubberband to this point.
      protected boolean testPoint​(java.awt.Point pt)
      Tests the point for validity within the image.
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

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

        protected java.awt.Point anchorPt
        DOCUMENT ME!
      • component

        protected java.awt.Component component
        DOCUMENT ME!
      • endPt

        protected java.awt.Point endPt
        DOCUMENT ME!
      • lastPt

        protected java.awt.Point lastPt
        DOCUMENT ME!
      • presetHue

        protected float presetHue
        DOCUMENT ME!
      • stretchedPt

        protected java.awt.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 Detail

      • Rubberband

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

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

      • drawLast

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

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

        public void anchor​(java.awt.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​(java.awt.Point p)
        Sets the end point to this point.
        Parameters:
        p - point to set the end to
      • getAnchor

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

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

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

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

        public java.awt.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 java.awt.Rectangle lastBounds()
        Gets the last bounds of the rubberband.
        Returns:
        rectangle of the bounds
      • mouseClicked

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

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

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

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

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

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

        public void mouseReleased​(java.awt.event.MouseEvent mouseEvent)
        Gets the end point of the rubberband.
        Specified by:
        mouseReleased in interface java.awt.event.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​(java.awt.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​(java.awt.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​(java.awt.Point pt)
        Tests the point for validity within the image.
        Parameters:
        pt - point to test
        Returns:
        boolean result of test