org.geotoolkit.gui.swing
Class ZoomPane

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by ZoomPane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, DeformableViewer
Direct Known Subclasses:
ImagePane, Plot2D

public abstract class ZoomPane
extends JComponent
implements DeformableViewer

Base class for widget with a zoomable content. User can perform zooms using keyboard, menu or mouse. Subclasses must provide the content to be paint with the following methods, which need to be overridden:

The "preferred area" is initially the same as getArea(). The user can specify a different preferred area with setPreferredArea(Rectangle2D). The user can also reduce zoomable bounds by inserting an empty border around the widget, e.g.:
setBorder(BorderFactory.createEmptyBorder(top, left, bottom, right));


Zoom actions
Whatever action is performed by the user, all zoom commands are translated as calls to transform(AffineTransform). Derived classes can redefine this method if they want to take particular actions during zooms, for example, modifying the minimum and maximum of a graph's axes. The table below shows the keyboard presses assigned to each zoom:

Key Purpose Action name
Scroll up "Up"
Scroll down "Down"
Scroll left "Left"
Scroll right"Right"
Key Purpose Action name
Zoom in "ZoomIn"
Zoom out "ZoomOut"
Maximal zoom"Zoom"
Default zoom"Reset"
KeyPurposeAction name
Ctrl+Anti-clockwise rotation"RotateLeft"
Ctrl+Clockwise rotation"RotateRight"

In this table, the last column gives the Strings that identify the different actions which manage the zooms. For example, to zoom in, we must write getActionMap().get("ZoomIn").


Scroll pane
JScrollPane objects are not suitable for adding scrollbars to a ZoomPane object. Instead, use createScrollPane(). Once again, all movements performed by the user through the scrollbars will be translated by calls to transform(AffineTransform).


Demo
The image on the left side gives an example with a simple implementation drawing a few geometric shapes. The menu and the optional magnifier glass are produced by this ZoomPane class.

To try this component in your browser, see the demonstration applet.

Since:
1.1
Version:
3.00
Author:
Martin Desruisseaux (MPO, IRD)
See Also:
Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int DEFAULT_ZOOM
          Constant indicating default zoom close to the maximum permitted zoom.
static int RESET
          Constant indicating the resetting of scale, rotation and translation to a default value which makes the whole graphic appear in a window.
static int ROTATE
          Constant indicating a rotation.
static int SCALE_X
          Constant indicating the scale changes on the x axis.
static int SCALE_Y
          Constant indicating the scale changes on the y axis.
static int TRANSLATE_X
          Constant indicating the translations on the x axis.
static int TRANSLATE_Y
          Constant indicating the translations on the y axis.
static int UNIFORM_SCALE
          Constant indicating the scale changes on the x and y axes, with the added condition that these changes must be uniform.
protected  AffineTransform zoom
          Affine transform containing zoom factors, translations and rotations.
 
Fields inherited from class JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ZoomPane(int allowedActions)
          Constructs a ZoomPane.
 
Method Summary
 void addMouseListener(MouseListener listener)
          Adds an object to the list of objects interested in being notified about mouse events.
 void addZoomChangeListener(ZoomChangeListener listener)
          Adds an object to the list of objects interested in being notified about zoom changes.
 void buildNavigationMenu(JMenu menu)
          Adds navigation options to the specified menu.
 void correctApparentPixelPosition(Point2D point)
          Corrects a pixel's coordinates for removing the effect of the magnifying glass.
 JComponent createScrollPane()
          Returns an object which displays this ZoomPane with the scrollbars.
protected  void fireZoomChanged(AffineTransform change)
          Signals that a zoom change has taken place.
abstract  Rectangle2D getArea()
          Returns a bounding box that contains the logical coordinates of all data that may be displayed in this ZoomPane.
protected  Dimension getDefaultSize()
          Returns the default size for this component.
 Insets getInsets()
          Returns the Insets of this component.
 Paint getMagnifierBorder()
          Returns the color of the magnifying glass's border.
 Paint getMagnifierGlass()
          Returns the color with which to tint magnifying glass.
protected  JPopupMenu getMagnifierMenu(MouseEvent event)
          Method called automatically when the user clicks on the right mouse button inside the magnifying glass.
protected  Shape getMouseSelectionShape(Point2D point)
          Returns the geometric shape to be used to delimitate an area.
protected  JPopupMenu getPopupMenu(MouseEvent event)
          Method called automatically when the user clicks on the right mouse button.
 Rectangle2D getPreferredArea()
          Returns the logical coordinates of the region that we want to see displayed the first time that ZoomPane appears on the screen.
protected  Dimension2D getPreferredPixelSize()
          Returns the preferred pixel size for a close zoom.
 double getScaleFactor()
          Returns the current zoom scale factor.
 AffineTransform getTransform()
          Returns a clone of the current zoom transform.
 Rectangle2D getVisibleArea()
          Returns the logical coordinates of the region visible on the screen.
protected  Rectangle getZoomableBounds(Rectangle bounds)
          Returns the bounding box (in pixel coordinates) of the zoomable area.
 boolean hasPreferredArea()
          Indicates whether the logical coordinates of a region have been defined.
 boolean isMagnifierEnabled()
          Indicates whether or not the magnifying glass is allowed to be displayed on this component.
 boolean isMagnifierVisible()
          Indicates whether or not the magnifying glass is visible.
 boolean isPaintingWhileAdjusting()
          Indicates whether or not this ZoomPane object should be repainted when the user moves the scrollbar slider.
protected  void mouseSelectionPerformed(Shape area)
          Method called automatically after the user selects an area with the mouse.
protected  void paintComponent(Graphics graphics)
          Paints this component.
protected abstract  void paintComponent(Graphics2D graphics)
          Paints this component.
protected  void paintMagnifier(Graphics2D graphics)
          Paints the magnifying glass.
protected  void printComponent(Graphics graphics)
          Prints this component.
protected  void printComponent(Graphics2D graphics)
          Prints this component.
 void removeZoomChangeListener(ZoomChangeListener listener)
          Removes an object from the list of objects interested in being notified about zoom changes.
 void repaint(long tm, int x, int y, int width, int height)
          Declares that a part of this pane needs to be repainted.
 void reset()
          Reinitializes the zoom affine transform in order to cancel any zoom, rotation or translation.
protected  void reset(Rectangle zoomableBounds, boolean yAxisUpward)
          Reinitializes the affine transform zoom in order to cancel any zoom, rotation or translation.
 void scrollRectToVisible(Rectangle rect)
          Modifies the position in pixels of the visible part of ZoomPane.
 void setMagnifierBorder(Paint color)
          Sets the color of the magnifying glass's border.
 void setMagnifierEnabled(boolean enabled)
          Specifies whether or not the magnifying glass is allowed to be displayed on this component.
 void setMagnifierGlass(Paint color)
          Sets the color with which to tint magnifying glass.
 void setMagnifierVisible(boolean visible)
          Displays or hides the magnifying glass.
 void setPaintingWhileAdjusting(boolean flag)
          Defines whether or not this ZoomPane object should repaint the map when the user moves the scrollbar slider.
 void setPreferredArea(Rectangle2D area)
          Specifies the logical coordinates of the region that we want to see displayed the first time that ZoomPane appears on the screen.
protected  void setResetPolicy(boolean fill)
          Sets the policy for the zoom when the content is initially drawn or when the user resets the zoom.
 void setTransform(AffineTransform tr)
          Sets the zoom transform to the given value.
 void setVisibleArea(Rectangle2D logicalBounds)
          Defines the limits of the visible part, in logical coordinates.
 void tieModels(BoundedRangeModel x, BoundedRangeModel y)
          Synchronises the position and the range of the models x and y with the position of the zoom.
 void transform(AffineTransform change)
          Changes the zoom by applying an affine transform.
 void transformPixels(AffineTransform change)
          Changes the zoom by applying an affine transform.
 void untieModels(BoundedRangeModel x, BoundedRangeModel y)
          Cancels the synchronization between the specified x and y models and the zoom of this ZoomPane object.
 void updateUI()
          Informs ZoomPane that the GUI has changed.
 
Methods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, 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, update
 
Methods inherited from class Container
add, 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, 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, hide, 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, transferFocusUpCycle
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCALE_X

public static final int SCALE_X
Constant indicating the scale changes on the x axis.

See Also:
Constant Field Values

SCALE_Y

public static final int SCALE_Y
Constant indicating the scale changes on the y axis.

See Also:
Constant Field Values

UNIFORM_SCALE

public static final int UNIFORM_SCALE
Constant indicating the scale changes on the x and y axes, with the added condition that these changes must be uniform. This flag combines SCALE_X and SCALE_Y. The inverse, however, (SCALE_X|SCALE_Y) doesn't imply UNIFORM_SCALE.

See Also:
Constant Field Values

TRANSLATE_X

public static final int TRANSLATE_X
Constant indicating the translations on the x axis.

See Also:
Constant Field Values

TRANSLATE_Y

public static final int TRANSLATE_Y
Constant indicating the translations on the y axis.

See Also:
Constant Field Values

ROTATE

public static final int ROTATE
Constant indicating a rotation.

See Also:
Constant Field Values

RESET

public static final int RESET
Constant indicating the resetting of scale, rotation and translation to a default value which makes the whole graphic appear in a window. This command is translated by a call to reset().

See Also:
Constant Field Values

DEFAULT_ZOOM

public static final int DEFAULT_ZOOM
Constant indicating default zoom close to the maximum permitted zoom. This zoom should allow details of the graphic to be seen without being overly big.

Note: this flag will only have any effect if at least one of the SCALE_X and SCALE_Y flags is not also specified.

See Also:
Constant Field Values

zoom

protected final AffineTransform zoom
Affine transform containing zoom factors, translations and rotations. During the painting of a component, this affine transform should be combined with a call to Graphics2D.transform(zoom).

Constructor Detail

ZoomPane

public ZoomPane(int allowedActions)
         throws IllegalArgumentException
Constructs a ZoomPane.

Parameters:
allowedActions - Allowed zoom actions. It can be a bitwise combination of the following constants: SCALE_X, SCALE_Y, UNIFORM_SCALE, TRANSLATE_X, TRANSLATE_Y, ROTATE, RESET and DEFAULT_ZOOM.
Throws:
IllegalArgumentException - If type is invalid.
Method Detail

reset

public void reset()
Reinitializes the zoom affine transform in order to cancel any zoom, rotation or translation. The default implementation performs the initialisation in such a way that the y axis point upwards and make the whole of the region covered by the getPreferredArea() logical coordinates appears in the panel.
Note: reset() is the only method of ZoomPane which doesn't have to pass through the transform(AffineTransform) method to modify the zoom. This exception is necessary to avoid falling into an infinite loop.


reset

protected void reset(Rectangle zoomableBounds,
                     boolean yAxisUpward)
Reinitializes the affine transform zoom in order to cancel any zoom, rotation or translation. The argument yAxisUpward indicates whether the y axis should point upwards. The value false lets it point downwards. This method is offered for convenience sake for derived classes which want to redefine reset().

Parameters:
zoomableBounds - Coordinates, in pixels, of the screen space in which to draw. This argument will usually be getZoomableBounds(null).
yAxisUpward - true if the y axis should point upwards rather than downwards.

setResetPolicy

protected void setResetPolicy(boolean fill)
Sets the policy for the zoom when the content is initially drawn or when the user resets the zoom. Value true means that the panel should initially be completely filled, even if the content partially falls outside the panel's bounds. Value false means that the full content should appear in the panel, even if some space is not used. Default value is false.

Parameters:
fill - true if the panel should be initially completely filled.

getArea

public abstract Rectangle2D getArea()
Returns a bounding box that contains the logical coordinates of all data that may be displayed in this ZoomPane. For example, if this ZoomPane is to display a geographic map, then this method should return the map's bounds in degrees of latitude and longitude (if the underlying CRS is geographic), in metres (if the underlying CRS is projected) or some other geodetic units. This bounding box is completely independent of any current zoom setting and will change only if the content changes.

Returns:
A bounding box for the logical coordinates of all contents that are going to be drawn in this ZoomPane. If this bounding box is unknown, then this method can return null (but this is not recommended).

hasPreferredArea

public final boolean hasPreferredArea()
Indicates whether the logical coordinates of a region have been defined. This method returns true if setPreferredArea(java.awt.geom.Rectangle2D) has been called with a non null argument.

Returns:
true if a preferred area has been set.

getPreferredArea

public final Rectangle2D getPreferredArea()
Returns the logical coordinates of the region that we want to see displayed the first time that ZoomPane appears on the screen. This region will also be displayed each time the method reset() is called. The default implementation goes as follows:

Returns:
The logical coordinates of the region to be initially displayed, or null if these coordinates are unknown.

setPreferredArea

public final void setPreferredArea(Rectangle2D area)
Specifies the logical coordinates of the region that we want to see displayed the first time that ZoomPane appears on the screen. This region will also be displayed the first time that the reset() method is called.

Parameters:
area - The logical coordinates of the region to be initially displayed,

getVisibleArea

public final Rectangle2D getVisibleArea()
Returns the logical coordinates of the region visible on the screen. In the case of a geographic map, for example, the logical coordinates can be expressed in degrees of latitude/longitude or in metres if a cartographic projection has been defined.

Returns:
The region visible on the screen, in logical coordinates.

setVisibleArea

public void setVisibleArea(Rectangle2D logicalBounds)
                    throws IllegalArgumentException
Defines the limits of the visible part, in logical coordinates. This method will modify the zoom and the translation in order to display the specified region. If zoom contains a rotation, this rotation will not be modified.

Parameters:
logicalBounds - Logical coordinates of the region to be displayed.
Throws:
IllegalArgumentException - if source is empty.

getZoomableBounds

protected Rectangle getZoomableBounds(Rectangle bounds)
Returns the bounding box (in pixel coordinates) of the zoomable area. This method is similar to JComponent.getBounds(Rectangle), except that the zoomable area may be smaller than the whole widget area. For example, a chart needs to keep some space for axes around the zoomable area. Another difference is that pixel coordinates are relative to the widget, i.e. the (0,0) coordinate lies on the ZoomPane upper left corner, no matter what its location on screen.

ZoomPane invokes getZoomableBounds when it needs to set up an initial zoom value. Subclasses should also set the clip area to this bounding box in their paintComponent(Graphics2D) method before setting the graphics transform. For example:

graphics.clip(getZoomableBounds(null));
graphics.transform(zoom);

Parameters:
bounds - An optional pre-allocated rectangle, or null to create a new one. This argument is useful if the caller wants to avoid allocating a new object on the heap.
Returns:
The bounding box of the zoomable area, in pixel coordinates relative to this ZoomPane widget.

getDefaultSize

protected Dimension getDefaultSize()
Returns the default size for this component. This is the size returned by JComponent.getPreferredSize() if no preferred size has been explicitly set with JComponent.setPreferredSize(java.awt.Dimension).

Returns:
The default size for this component.

getPreferredPixelSize

protected Dimension2D getPreferredPixelSize()
Returns the preferred pixel size for a close zoom. For image rendering, the preferred pixel size is the image's pixel size in logical units. For other kinds of rendering, this "pixel" size should be some reasonable resolution. The default implementation computes a default value from getArea().

Returns:
The preferred pixel size for a close zoom, in logical units.

getScaleFactor

public double getScaleFactor()
Returns the current zoom scale factor. A value of 1/100 means that 100 metres are displayed as 1 pixel (assuming that the logical coordinates of getArea() are expressed in metres). Scale factors for X and Y axes can be computed separately using the following equations:

X scale = Y scale =

This method combines scale along both axes, which is correct if this ZoomPane has been constructed with the UNIFORM_SCALE type.

Returns:
The current scale factor calculated from the zoom affine transform.

getTransform

public AffineTransform getTransform()
Returns a clone of the current zoom transform.

Returns:
A clone of the current transform.
Since:
3.00

setTransform

public void setTransform(AffineTransform tr)
Sets the zoom transform to the given value. The default implementation computes an affine transform which is the change needed for going from the current zoom to the given transform, then calls transform(AffineTransform) with that change. This is done that way for giving listeners a chance to track the changes.

Parameters:
tr - The new transform.
Since:
3.00

transform

public void transform(AffineTransform change)
Changes the zoom by applying an affine transform. The change transform must express a change in logical units, for example, a translation in metres. This method is conceptually similar to the following code:
zoom.concatenate(change);
fireZoomChanged(change);
repaint(getZoomableBounds(null));

Parameters:
change - The zoom change, as an affine transform in logical coordinates. If change is the identity transform, then this method does nothing and listeners are not notified.

transformPixels

public void transformPixels(AffineTransform change)
Changes the zoom by applying an affine transform. The change transform must express a change in pixel units, for example, a scrolling of 6 pixels toward right. This method is conceptually similar to the following code:
zoom.preConcatenate(change);
// Converts the change from pixel to logical units
AffineTransform logical = zoom.createInverse();
logical.concatenate(change);
logical.concatenate(zoom);
fireZoomChanged(logical);
repaint(getZoomableBounds(null));

Parameters:
change - The zoom change, as an affine transform in pixel coordinates. If change is the identity transform, then this method does nothing and listeners are not notified.
Since:
2.1

addZoomChangeListener

public void addZoomChangeListener(ZoomChangeListener listener)
Adds an object to the list of objects interested in being notified about zoom changes.

Parameters:
listener - The change listener to add.

removeZoomChangeListener

public void removeZoomChangeListener(ZoomChangeListener listener)
Removes an object from the list of objects interested in being notified about zoom changes.

Parameters:
listener - The change listener to remove.

addMouseListener

public void addMouseListener(MouseListener listener)
Adds an object to the list of objects interested in being notified about mouse events.

Overrides:
addMouseListener in class Component
Parameters:
listener - The mouse listener to add.

fireZoomChanged

protected void fireZoomChanged(AffineTransform change)
Signals that a zoom change has taken place. Every object registered by the addZoomChangeListener(ZoomChangeListener) method will be notified of the change as soon as possible.

If oldZoom and newZoom are the affine transforms of the old and new zoom respectively, the change is computed in such a way that the following relation is respected within rounding errors:

newZoom = oldZoom.concatenate(change)
Note: This method may modify the given change transform to combine several consecutive calls of fireZoomChanged in a single transformation.

Parameters:
change - Affine transform which represents the change in the zoom. The value of this argument may be changed by this method call.

mouseSelectionPerformed

protected void mouseSelectionPerformed(Shape area)
Method called automatically after the user selects an area with the mouse. The default implementation zooms to the selected area. Derived classes can redefine this method in order to carry out another action.

Parameters:
area - Area selected by the user, in logical coordinates.

getMouseSelectionShape

protected Shape getMouseSelectionShape(Point2D point)
Returns the geometric shape to be used to delimitate an area. This shape is generally a rectangle but could also be an ellipse or another shape. The coordinates of the returned shape won't be taken into account. In fact, these coordinates will often be overwritten. The only things that matter are the class of the returned shape (e.g. Ellipse2D vs Rectangle2D) and any of its parameters not related to its position (e.g. arc size in a RoundRectangle2D).

The returned shape will generally be an instance of RectangularShape, but can also be an instance of Line2D. Any other class risks throwing a ClassCastException at execution.

The default implementation always returns a Rectangle2D object.

Parameters:
point - Logical coordinates of the mouse at the moment the button is pressed. This information can be used by subclasses that wish to consider the mouse position before choosing a geometric shape.
Returns:
Shape as an instance of RectangularShape or Line2D, or null to indicate that we do not want to select with the mouse.

isMagnifierEnabled

public boolean isMagnifierEnabled()
Indicates whether or not the magnifying glass is allowed to be displayed on this component. By default, it is allowed.

Returns:
true if the magniying glass is allowed to be displayed.

setMagnifierEnabled

public void setMagnifierEnabled(boolean enabled)
Specifies whether or not the magnifying glass is allowed to be displayed on this component. Calling this method with the value false will hide the magnifying glass, delete the choice "Display magnifying glass" from the contextual menu and lead to all calls to setMagnifierVisible(true) being ignored.

Parameters:
enabled - true if the magniying glass is allowed to be displayed.

isMagnifierVisible

public boolean isMagnifierVisible()
Indicates whether or not the magnifying glass is visible. By default, it is not visible. Call setMagnifierVisible(boolean) to make it appear.

Returns:
true if the magniying glass is currently visible.

setMagnifierVisible

public void setMagnifierVisible(boolean visible)
Displays or hides the magnifying glass. If the magnifying glass is not visible and this method is called with the argument true, the magnifying glass will appear at the centre of the window.

Parameters:
visible - true for making the magniying glass visible.

getMagnifierGlass

public Paint getMagnifierGlass()
Returns the color with which to tint magnifying glass.

Returns:
The current color of the magnifying glass interior.

setMagnifierGlass

public void setMagnifierGlass(Paint color)
Sets the color with which to tint magnifying glass.

Parameters:
color - The new color of the magnifying glass interior.

getMagnifierBorder

public Paint getMagnifierBorder()
Returns the color of the magnifying glass's border.

Returns:
The current color of the magnifying glass border.

setMagnifierBorder

public void setMagnifierBorder(Paint color)
Sets the color of the magnifying glass's border.

Parameters:
color - The new color of the magnifying glass border.

correctApparentPixelPosition

public void correctApparentPixelPosition(Point2D point)
Corrects a pixel's coordinates for removing the effect of the magnifying glass. Without this method, transformations from pixels to geographic coordinates would not give accurate results for pixels inside the magnifying glass since the glass moves the pixel's apparent position. Invoking this method will remove deformation effects using the following steps:

Specified by:
correctApparentPixelPosition in interface DeformableViewer
Parameters:
point - In input, a pixel's coordinate as it appears on the screen. In output, the coordinate that the same pixel would have if the magnifying glass wasn't presents.

buildNavigationMenu

public void buildNavigationMenu(JMenu menu)
Adds navigation options to the specified menu. Menus such as "Zoom in" and "Zoom out" will be automatically added to the menu together with the appropriate short-cut keys.

Parameters:
menu - The menu in which to add navigation options.

getPopupMenu

protected JPopupMenu getPopupMenu(MouseEvent event)
Method called automatically when the user clicks on the right mouse button. The default implementation displays a contextual menu containing navigation options.

Parameters:
event - Mouse event. This object contains the mouse coordinates in geographic coordinates (as well as pixel coordinates).
Returns:
The contextual menu, or null to avoid displaying the menu.

getMagnifierMenu

protected JPopupMenu getMagnifierMenu(MouseEvent event)
Method called automatically when the user clicks on the right mouse button inside the magnifying glass. The default implementation displays a contextual menu which contains magnifying glass options.

Parameters:
event - Mouse event containing amongst others, the mouse position.
Returns:
The contextual menu, or null to avoid displaying the menu.

createScrollPane

public JComponent createScrollPane()
Returns an object which displays this ZoomPane with the scrollbars.

Returns:
A swing component displaying this ZoomPane together with scrollbars.

tieModels

public void tieModels(BoundedRangeModel x,
                      BoundedRangeModel y)
Synchronises the position and the range of the models x and y with the position of the zoom. The models x and y are generally associated with horizontal and vertical scrollbars. When the position of a scrollbar is adjusted, the zoom is consequently adjusted. Inversely, when the zoom is modified, the positions and ranges of the scrollbars are consequently adjusted.

Parameters:
x - Model of the horizontal scrollbar or null if there isn't one.
y - Model of the vertical scrollbar or null if there isn't one.

untieModels

public void untieModels(BoundedRangeModel x,
                        BoundedRangeModel y)
Cancels the synchronization between the specified x and y models and the zoom of this ZoomPane object. The ChangeListener and ZoomChangeListener objects that were created are deleted.

Parameters:
x - Model of the horizontal scrollbar or null if there isn't one.
y - Model of the vertical scrollbar or null if there isn't one.

scrollRectToVisible

public void scrollRectToVisible(Rectangle rect)
Modifies the position in pixels of the visible part of ZoomPane. viewSize is the size ZoomPane would be (in pixels) if its visible surface covered the whole of the getArea() region with the current zoom (Note: viewSize can be obtained by JComponent.getPreferredSize() if JComponent.setPreferredSize(java.awt.Dimension) hasn't been called with a non-null value). Therefore, by definition, the region getArea() converted into pixel space would give the rectangle bounds = Rectangle(0, 0, viewSize.width, viewSize.height).

This scrollRectToVisible method allows us to define the sub-region of bounds which must appear in the ZoomPane window.

Overrides:
scrollRectToVisible in class JComponent
Parameters:
rect - The region to be made visible.

isPaintingWhileAdjusting

public boolean isPaintingWhileAdjusting()
Indicates whether or not this ZoomPane object should be repainted when the user moves the scrollbar slider. The scrollbars (or other models) involved are those which have been synchronised with this ZoomPane object through the tieModels(javax.swing.BoundedRangeModel, javax.swing.BoundedRangeModel) method. The default value is false, which means that ZoomPane will wait until the user releases the slider before repainting.

Returns:
true if the zoom pane is painted while the user is scrolling.

setPaintingWhileAdjusting

public void setPaintingWhileAdjusting(boolean flag)
Defines whether or not this ZoomPane object should repaint the map when the user moves the scrollbar slider. A fast computer is recommended if this flag is to be set to true.

Parameters:
flag - true if the zoom pane should be painted while the user is scrolling.

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int width,
                    int height)
Declares that a part of this pane needs to be repainted. This method simply redefines the method of the parent class in order to take into account a case where the magnifying glass is displayed.

Overrides:
repaint in class JComponent

paintMagnifier

protected void paintMagnifier(Graphics2D graphics)
Paints the magnifying glass. This method is invoked after paintComponent(Graphics2D) if a magnifying glass is visible.

Parameters:
graphics - The graphics where to paint the magnifying glass.

paintComponent

protected abstract void paintComponent(Graphics2D graphics)
Paints this component. Subclass must override this method in order to draw the ZoomPane content. For most implementations, the first line in this method will be graphics.transform(zoom).

Parameters:
graphics - The graphics where to paint this component.

printComponent

protected void printComponent(Graphics2D graphics)
Prints this component. The default implementation invokes paintComponent(Graphics2D).

Parameters:
graphics - The graphics where to print this component.

paintComponent

protected final void paintComponent(Graphics graphics)
Paints this component. This method is declared final in order to avoid unintentional overriding. Override paintComponent(Graphics2D) instead.

Overrides:
paintComponent in class JComponent
Parameters:
graphics - The graphics where to paint this component.

printComponent

protected final void printComponent(Graphics graphics)
Prints this component. This method is declared final in order to avoid unintentional overriding. Override printComponent(Graphics2D) instead.

Overrides:
printComponent in class JComponent
Parameters:
graphics - The graphics where to print this component.

getInsets

public final Insets getInsets()
Returns the Insets of this component. This method is declared final in order to avoid confusion. If you want to return other Insets you must redefine JComponent.getInsets(Insets).

Overrides:
getInsets in class JComponent

updateUI

public void updateUI()
Informs ZoomPane that the GUI has changed. The user doesn't have to call this method directly.

Overrides:
updateUI in class JComponent


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.