Class Rubberband
- java.lang.Object
-
- java.awt.Component
-
- gov.nih.mipav.view.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.MouseListenerAn 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.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanactiveDOCUMENT ME!protected java.awt.PointanchorPtDOCUMENT ME!protected java.awt.ComponentcomponentDOCUMENT ME!protected java.awt.PointendPtDOCUMENT ME!private booleanfirstStretchDOCUMENT ME!protected java.awt.PointlastPtDOCUMENT ME!protected floatpresetHueDOCUMENT ME!private static longserialVersionUIDUse serialVersionUID for interoperability.protected java.awt.PointstretchedPtDOCUMENT ME!protected booleanusableComponentDOCUMENT ME!protected intxMaxDOCUMENT ME!protected intxSDOCUMENT ME!protected intyMaxDOCUMENT ME!protected intySDOCUMENT ME!
-
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 voidanchor(java.awt.Point p)Anchors the rubberband to this point.voiddispose()Sets parent component image to null.protected static doubledistance(int x1, int x2, int y1, int y2)Calculates the 2D euclidian distance between two points.abstract voiddrawLast(java.awt.Graphics g)Draws the appropriate geometric shape at the last rubberband location.abstract voiddrawNext(java.awt.Graphics g)Draws the appropriate geometric shape at the next rubberband location.voidend(java.awt.Point p)Sets the end point to this point.java.awt.PointgetAnchor()Returns the anchor point of the rubberband.java.awt.RectanglegetBounds()Gets a rectangle that is the bounds of the rubberband.java.awt.PointgetEnd()Returns the end point of the rubberband.java.awt.PointgetLast()Returns the last point of the rubberband.java.awt.PointgetStretched()Returns the stretched point of the rubberband.booleanisActive()Returns a boolean indicating activity.java.awt.RectanglelastBounds()Gets the last bounds of the rubberband.voidmouseClicked(java.awt.event.MouseEvent mouseEvent)Gets the end point of the rubberband.voidmouseDragged(java.awt.event.MouseEvent mouseEvent)Gets the stretch point of the rubberband.voidmouseEntered(java.awt.event.MouseEvent mouseEvent)Unchanged.voidmouseExited(java.awt.event.MouseEvent mouseEvent)Unchanged.voidmouseMoved(java.awt.event.MouseEvent mouseEvent)Unchanged.voidmousePressed(java.awt.event.MouseEvent mouseEvent)Gets the anchor point of the rubberband.voidmouseReleased(java.awt.event.MouseEvent mouseEvent)Gets the end point of the rubberband.voidsetActive(boolean b)Sets the rubberband to active or not active.voidsetComponent(java.awt.Component c)Sets the component to the parameter.voidsetPresetHue(float presetHue)Sets the presetHue.voidstretch(java.awt.Point p)Stretch the rubberband to this point.protected booleantestPoint(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
-
-
-
-
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!
-
-
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:
getBoundsin classjava.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:
mouseClickedin interfacejava.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:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Parameters:
mouseEvent- event that triggered function
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent mouseEvent)
Unchanged.- Specified by:
mouseMovedin interfacejava.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:
mousePressedin interfacejava.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:
mouseReleasedin interfacejava.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 coordinatex2- second x coordinatey1- first y coordinatey2- 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
-
-