Search this API

y.view
Class MagnifierViewMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.MagnifierViewMode
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class MagnifierViewMode
extends ViewMode

View mode that lets you zoom into a view region locally, while preserving the original viewport of the view. The effect is similar to a magnifier that is moved over the view.

 

Field Summary
 
Fields inherited from class y.view.ViewMode
ACTIVE_PROPERTY, ACTIVE_VIEW_PROPERTY, CHILD_MODE_PROPERTY, EDITING_PROPERTY, GRAB_FOCUS_ENABLED_PROPERTY, lastClickEvent, lastDragEvent, lastMoveEvent, lastPressEvent, lastReleaseEvent, MODIFIER_MASK_PROPERTY, NAME_PROPERTY, originalX, originalY, PARENT_MODE_PROPERTY, view
 
Constructor Summary
MagnifierViewMode()
          Creates a new MagnifierViewMode instance.
 
Method Summary
 void activate(boolean activate)
          Upon activation or deactivation the set of registered mouse wheel listeners will be changed.
protected  int calcRadius(int radius, int amount)
          Calculates and returns an updated magnifier radius.
protected  double calcZoom(double zoom, int amount)
          Calculates and returns an updated magnifier zoom level.
protected  Graph2DView createMagnifierView()
          Creates, configures, and returns a Graph2DView that is used to render the view content for the magnifier.
 int getMagnifierRadius()
          Returns the radius of the magnifying glass.
 double getMagnifierZoomFactor()
          Returns the zoom factor used for the magnifier view.
 boolean isMouseWheelEnabled()
          Returns whether or not to activate mouse wheel functionality.
 void mouseDraggedLeft(double x, double y)
          Updates the location of the magnifier.
 void mouseDraggedRight(double x, double y)
          Updates the location of the magnifier.
 void mouseExited(java.awt.event.MouseEvent e)
          Removes the magnifier from the view.
 void mouseMoved(double x, double y)
          Updates the location of the magnifier.
 void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
          Invoked when the mouse wheel is rotated.
 void setMagnifierRadius(int radius)
          Sets the radius of the magnifying glass.
 void setMagnifierZoomFactor(double zoomFactor)
          Sets the zoom factor used for the magnifier view.
 void setMouseWheelEnabled(boolean mouseWheelEnabled)
          Whether or not to activate mouse wheel functionality.
 
Methods inherited from class y.view.ViewMode
addPropertyChangeListener, addPropertyChangeListener, cancelEditing, deactivateChild, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastClickEvent, getLastDragEvent, getLastHitInfo, getLastMoveEvent, getLastPressEvent, getLastReleaseEvent, getModifierMask, getName, getParent, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseEntered, mouseMoved, mousePressed, mousePressedLeft, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleased, mouseReleasedLeft, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, removePropertyChangeListener, removePropertyChangeListener, setActiveView, setChild, setChild, setEditing, setGrabFocusEnabled, setGridMode, setLastHitInfo, setModifierMask, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagnifierViewMode

public MagnifierViewMode()
Creates a new MagnifierViewMode instance.

Method Detail

mouseMoved

public void mouseMoved(double x,
                       double y)
Updates the location of the magnifier.

Overrides:
mouseMoved in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseDraggedLeft

public void mouseDraggedLeft(double x,
                             double y)
Updates the location of the magnifier.

Overrides:
mouseDraggedLeft in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseDraggedRight

public void mouseDraggedRight(double x,
                              double y)
Updates the location of the magnifier.

Overrides:
mouseDraggedRight in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Removes the magnifier from the view.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class ViewMode

createMagnifierView

protected Graph2DView createMagnifierView()
Creates, configures, and returns a Graph2DView that is used to render the view content for the magnifier.

By default this method adopts various settings of the mode's associated Graph2DView instance view. It also sets the paintDetailThreshold to 0.0.

Returns:
a configured Graph2DView instance for magnified display of graphs.

activate

public void activate(boolean activate)
Upon activation or deactivation the set of registered mouse wheel listeners will be changed.

Overrides:
activate in class ViewMode
Parameters:
activate - set true when mode was activated false otherwise
See Also:
setMouseWheelEnabled(boolean)

setMagnifierZoomFactor

public void setMagnifierZoomFactor(double zoomFactor)
Sets the zoom factor used for the magnifier view. The zoom factor will be multiplied with the current zoom factor of the main view to obtain the final zoom factor applied to the magnified items.

By default a zoom factor of 2.0 is used.

Parameters:
zoomFactor - the magnification factor

getMagnifierZoomFactor

public double getMagnifierZoomFactor()
Returns the zoom factor used for the magnifier view.

Returns:
the magnification factor.
See Also:
setMagnifierZoomFactor(double)

setMagnifierRadius

public void setMagnifierRadius(int radius)
Sets the radius of the magnifying glass. The radius is measured in view coordinates (pixel space), and not in world coordinates.

By default a radius of 100 is used.

Parameters:
radius - the radius of of the magnifying glass.

getMagnifierRadius

public int getMagnifierRadius()
Returns the radius of the magnifying glass.

Returns:
the radius of the magnifying glass.
See Also:
setMagnifierRadius(int)

mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Invoked when the mouse wheel is rotated.

Parameters:
e - the triggering mouse wheel event.

calcRadius

protected int calcRadius(int radius,
                         int amount)
Calculates and returns an updated magnifier radius. This method is invoked upon a radius change request triggered by a mouse wheel action. Subclasses may override this method to implement customized behavior.

Parameters:
radius - the current magnifier radius
amount - the amount of scroll wheel rotation or units to scroll. This value can be positive and negative.
Returns:
the new magnifier radius.

calcZoom

protected double calcZoom(double zoom,
                          int amount)
Calculates and returns an updated magnifier zoom level. This method is invoked upon a radius change request triggered by a mouse wheel action. Subclasses may override this method to implement customized behavior.

Parameters:
zoom - the current magnifier zoom level
amount - the amount of scroll wheel rotation or units to scroll. This value can be positive and negative.
Returns:
the new magnification factor.

isMouseWheelEnabled

public boolean isMouseWheelEnabled()
Returns whether or not to activate mouse wheel functionality.

Returns:
true if mouse wheel support is active; false otherwise.

setMouseWheelEnabled

public void setMouseWheelEnabled(boolean mouseWheelEnabled)
Whether or not to activate mouse wheel functionality. If enabled, a mouse wheel listener will be added to the main view that will allow to change the radius and zoom factor of the magnifying glass interactively. By default, the mouse wheel changes the zoom factor. If, additionally, the CTRL key is pressed, the mouse wheel changes the radius.

Note that when this feature is enabled, already registered mouse wheel listeners will be deregistered until this mode is deactivated again.

Parameters:
mouseWheelEnabled - if true mouse wheel support is activated; if false mouse wheel support is deactivated.

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.