public class Viewer extends JPanel
Painter interface may be
added to this viewer and perform painting operations. Their
paint
method will receive the world-to-screen transform, as determined by the
current translation, rotation and zoom of the viewer. Painter is added using the addPainter(Painter, int)
method. The Painter instances will be called starting at the
lowest layer. Inside one layer, the Painters will be called in
the order in which they have been added.MouseControl interface, and has been set using
setMouseControl(MouseControl). These classes are responsible for
making sure that these methods are called with valid parameters.
Particularly, they should not be called with NaN or
infinite values, and the zooming factors should not be 0.0. The viewer
class itself does not perform any sanity checks on these arguments.JPanel.AccessibleJPanelJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategylistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
Viewer()
Creates a new Viewer with a
default MouseControl, where rotation is allowed. |
Viewer(boolean defaultMouseControl,
boolean rotationAllowed)
Creates a new viewer.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addPainter(Painter painter)
Add the given
Painter, which will perform painting
operations in the paintComponent(Graphics) method. |
boolean |
addPainter(Painter painter,
int layer)
Add the given
Painter, which will perform painting
operations in the paintComponent(Graphics) method,
on the specified layer. |
AffineTransform |
getScreenToWorld()
Returns a copy of the screen-to-world transform
|
AffineTransform |
getWorldToScreen()
Returns a copy of the current world-to-screen transform
|
boolean |
isAntialiasing()
Return whether the antialiasing rendering hint is enabled
by default
|
boolean |
isFlippedVertically()
Set whether the y-axis is flipped to point from the bottom of the
screen to the top
|
boolean |
isMaintainAspectRatio()
Returns whether the aspect ratio is maintained during resize operations
or when
setDisplayedWorldArea(Rectangle2D) is called |
boolean |
isResizingContents()
Returns whether this viewer is configured so that the contents
should be resized when the screen is resized.
|
protected void |
paintComponent(Graphics gr) |
boolean |
removePainter(Painter painter)
Remove the given
Painter from all layers that it is contained
in |
boolean |
removePainter(Painter painter,
int layer)
Remove the given
Painter from the specified layer |
void |
resetTransform()
Reset this viewer to the identity transform
|
void |
rotate(double screenCenterX,
double screenCenterY,
double angleRad)
Rotate about the specified point (in screen coordinates)
by the given angle (in radians)
|
void |
setAntialiasing(boolean antialiasing)
Set whether the antialiasing rendering hint should be enabled
by default
|
void |
setDisplayedWorldArea(Rectangle2D newWorldArea)
Set the area (in world coordinates) that should be shown.
|
void |
setFlippedVertically(boolean flippedVertically)
Set whether the y-axis should be flipped to point from the
bottom of the screen to the top
|
void |
setMaintainAspectRatio(boolean maintainAspectRatio)
Set whether the aspect ratio of the displayed world area is
maintained during resize operations of this panel, or when
setDisplayedWorldArea(Rectangle2D) is called. |
void |
setMouseControl(MouseControl newMouseControl)
Set the given
MouseControl as a MouseListener,
MouseMotionListener and MouseWheelListener
for this viewer. |
void |
setResizingContents(boolean resizingContents)
Set whether the contents should be resized when the screen
is resized.
|
void |
setTransform(AffineTransform t)
Set the world-to-screen transform of this viewer to the given transform.
|
void |
transform(AffineTransform t)
Transform the contents of this viewer with the given transform
|
void |
translate(double screenDx,
double screenDy)
Translate this viewer by the given delta, in screen
coordinates
|
void |
zoom(double screenCenterX,
double screenCenterY,
double factorX,
double factorY)
Zoom about the specified point (in screen coordinates) by the given
factor.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic Viewer()
default MouseControl, where rotation is allowed.isResizingContents() is falseisMaintainAspectRatio() is trueisAntialiasing() is truepublic Viewer(boolean defaultMouseControl,
boolean rotationAllowed)
isResizingContents() is falseisMaintainAspectRatio() is trueisAntialiasing() is truedefaultMouseControl - Whether the
default MouseControl should be installed.rotationAllowed - Whether rotations are allowed in the default
mouse controlpublic final void setMouseControl(MouseControl newMouseControl)
MouseControl as a MouseListener,
MouseMotionListener and MouseWheelListener
for this viewer. Any previously registered MouseControl will
be removed.newMouseControl - The MouseControl to setpublic final void setFlippedVertically(boolean flippedVertically)
flippedVertically - Whether the y-axis should be flippedpublic final boolean isFlippedVertically()
public final void setResizingContents(boolean resizingContents)
true, then resizing
this panel will adjust the scale factors accordingly, so that
the world area that is displayed remains the same while resizing.setMaintainAspectRatio(boolean)
was set to false.resizingContents - The resizing behaviorpublic final boolean isResizingContents()
setResizingContents(boolean).public final void setMaintainAspectRatio(boolean maintainAspectRatio)
setDisplayedWorldArea(Rectangle2D) is called. false when
setResizingContents(boolean) is set to true.maintainAspectRatio - Whether the aspect ratio is maintainedpublic final boolean isMaintainAspectRatio()
setDisplayedWorldArea(Rectangle2D) is calledpublic final void setAntialiasing(boolean antialiasing)
antialiasing - Whether antialiasing should be enabledpublic final boolean isAntialiasing()
public final boolean addPainter(Painter painter)
Painter, which will perform painting
operations in the paintComponent(Graphics) method.
The painter will be added at the default layer (0). If the
given painter is null, then this call will have
no effect and false will be returned.painter - The Painter to addpublic final boolean addPainter(Painter painter, int layer)
Painter, which will perform painting
operations in the paintComponent(Graphics) method,
on the specified layer. If the given painter is null,
then this call will have no effect and false will be
returned.public final boolean removePainter(Painter painter)
Painter from all layers that it is contained
inpainter - The Painter to removepublic final boolean removePainter(Painter painter, int layer)
Painter from the specified layerpainter - The Painter to removelayer - The layer from which the painter should be removedprotected void paintComponent(Graphics gr)
paintComponent in class JComponentpublic final AffineTransform getWorldToScreen()
public final AffineTransform getScreenToWorld()
public final void transform(AffineTransform t)
t - The transformNullPointerException - if the given transform is nullIllegalArgumentException - if the determinant of the given
transform is 0.0, or NaN, or infinitepublic final void resetTransform()
public final void setTransform(AffineTransform t)
t - The transform to setNullPointerException - if the given transform is nullIllegalArgumentException - if the determinant of the given
transform is 0.0, or NaN, or infinitepublic final void zoom(double screenCenterX,
double screenCenterY,
double factorX,
double factorY)
screenCenterX - The x-coordinate of the zooming center,
in screen coordinatesscreenCenterY - The y-coordinate of the zooming center,
in screen coordinatesfactorX - The zooming factor for the x-axisfactorY - The zooming factor for the y-axispublic final void translate(double screenDx,
double screenDy)
screenDx - The movement delta in x-direction, in screen coordinatesscreenDy - The movement delta in y-direction, in screen coordinatespublic final void rotate(double screenCenterX,
double screenCenterY,
double angleRad)
screenCenterX - The x-coordinate of the zooming center,
in screen coordinatesscreenCenterY - The y-coordinate of the zooming center,
in screen coordinatesangleRad - The angle, in radianspublic final void setDisplayedWorldArea(Rectangle2D newWorldArea)
newWorldArea - The world areaCopyright © 2015. All rights reserved.