Class Rubberband
- All Implemented Interfaces:
MouseListener,MouseMotionListener,ImageObserver,MenuContainer,Serializable,EventListener
- Direct Known Subclasses:
RubberbandEllipse,RubberbandLine,RubberbandLivewire,RubberbandPolyline,RubberbandProtractor,RubberbandRectangle
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanDOCUMENT ME!protected PointDOCUMENT ME!protected ComponentDOCUMENT ME!protected PointDOCUMENT ME!private booleanDOCUMENT ME!protected PointDOCUMENT ME!protected floatDOCUMENT ME!private static final longUse serialVersionUID for interoperability.protected PointDOCUMENT ME!protected booleanDOCUMENT ME!protected intDOCUMENT ME!protected intDOCUMENT ME!protected intDOCUMENT ME!protected intDOCUMENT ME!Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, does nothing.Sets the parent component that the rubberband is for. -
Method Summary
Modifier and TypeMethodDescriptionvoidAnchors the rubberband to this point.voiddispose()Sets parent component image to null.protected static final doubledistance(int x1, int x2, int y1, int y2) Calculates the 2D euclidian distance between two points.abstract voidDraws the appropriate geometric shape at the last rubberband location.abstract voidDraws the appropriate geometric shape at the next rubberband location.voidSets the end point to this point.Returns the anchor point of the rubberband.Gets a rectangle that is the bounds of the rubberband.getEnd()Returns the end point of the rubberband.getLast()Returns the last point of the rubberband.Returns the stretched point of the rubberband.booleanisActive()Returns a boolean indicating activity.Gets the last bounds of the rubberband.voidmouseClicked(MouseEvent mouseEvent) Gets the end point of the rubberband.voidmouseDragged(MouseEvent mouseEvent) Gets the stretch point of the rubberband.voidmouseEntered(MouseEvent mouseEvent) Unchanged.voidmouseExited(MouseEvent mouseEvent) Unchanged.voidmouseMoved(MouseEvent mouseEvent) Unchanged.voidmousePressed(MouseEvent mouseEvent) Gets the anchor point of the rubberband.voidmouseReleased(MouseEvent mouseEvent) Gets the end point of the rubberband.voidsetActive(boolean b) Sets the rubberband to active or not active.voidSets the component to the parameter.voidsetPresetHue(float presetHue) Sets the presetHue.voidStretch the rubberband to this point.protected booleanTests 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 Details
-
serialVersionUID
private static final long serialVersionUIDUse serialVersionUID for interoperability.- See Also:
-
anchorPt
DOCUMENT ME! -
component
DOCUMENT ME! -
endPt
DOCUMENT ME! -
lastPt
DOCUMENT ME! -
presetHue
protected float presetHueDOCUMENT ME! -
stretchedPt
DOCUMENT ME! -
usableComponent
protected boolean usableComponentDOCUMENT ME! -
xMax
protected int xMaxDOCUMENT ME! -
xS
protected int xSDOCUMENT ME! -
yMax
protected int yMaxDOCUMENT ME! -
yS
protected int ySDOCUMENT ME! -
active
private boolean activeDOCUMENT ME! -
firstStretch
private boolean firstStretchDOCUMENT ME!
-
-
Constructor Details
-
Rubberband
public Rubberband()Default constructor, does nothing. -
Rubberband
Sets the parent component that the rubberband is for.- Parameters:
c- Component that the rubberband is for
-
-
Method Details
-
drawLast
Draws the appropriate geometric shape at the last rubberband location.- Parameters:
g- DOCUMENT ME!
-
drawNext
Draws the appropriate geometric shape at the next rubberband location.- Parameters:
g- DOCUMENT ME!
-
anchor
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
Sets the end point to this point.- Parameters:
p- point to set the end to
-
getAnchor
Returns the anchor point of the rubberband.- Returns:
- the anchor point
-
getBounds
Gets a rectangle that is the bounds of the rubberband. -
getEnd
Returns the end point of the rubberband.- Returns:
- the end point
-
getLast
Returns the last point of the rubberband.- Returns:
- the last 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
Gets the last bounds of the rubberband.- Returns:
- rectangle of the bounds
-
mouseClicked
Gets the end point of the rubberband.- Specified by:
mouseClickedin interfaceMouseListener- Parameters:
mouseEvent- event that triggered function
-
mouseDragged
Gets the stretch point of the rubberband.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Parameters:
mouseEvent- event that triggered function
-
mouseEntered
Unchanged.- Specified by:
mouseEnteredin interfaceMouseListener- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseExited
Unchanged.- Specified by:
mouseExitedin interfaceMouseListener- Parameters:
mouseEvent- DOCUMENT ME!
-
mouseMoved
Unchanged.- Specified by:
mouseMovedin interfaceMouseMotionListener- Parameters:
mouseEvent- DOCUMENT ME!
-
mousePressed
Gets the anchor point of the rubberband.- Specified by:
mousePressedin interfaceMouseListener- Parameters:
mouseEvent- event that triggered function
-
mouseReleased
Gets the end point of the rubberband.- Specified by:
mouseReleasedin interfaceMouseListener- 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
Sets the component to the parameter.- Parameters:
c- the component
-
setPresetHue
public void setPresetHue(float presetHue) Sets the presetHue.- Parameters:
presetHue- DOCUMENT ME!
-
stretch
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
Tests the point for validity within the image.- Parameters:
pt- point to test- Returns:
- boolean result of test
-