Package org.eclipse.gef.editparts
Class ZoomManager
- java.lang.Object
-
- org.eclipse.gef.editparts.ZoomManager
-
public class ZoomManager extends java.lang.Object
Manage the primary zoom function in a graphical viewer. This class is used by the zoom contribution items, including:A ZoomManager controls how zoom in and zoom out are performed. It also determines the list of choices the user sees in the drop-down Combo on the toolbar. The zoom manager controls a
ScalableFigure
, which performs the actual zoom, and also aViewport
. The viewport is needed so that the scrolled location is preserved as the zoom level changes.NOTE: For the settings of
Page
,Width
andHeight
to work properly, the givenViewport
should have its scrollbars always visible or never visible. Otherwise, these settings may cause undesired effects.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ANIMATE_NEVER
Style bit meaning don't animate any zoomsstatic int
ANIMATE_ZOOM_IN_OUT
static java.lang.String
FIT_ALL
String constant for the "Page" zoom level.static java.lang.String
FIT_HEIGHT
String constant for the "Height" zoom level.static java.lang.String
FIT_WIDTH
String constant for the "Width" zoom level.
-
Constructor Summary
Constructors Constructor Description ZoomManager(org.eclipse.draw2d.ScalableFigure pane, org.eclipse.draw2d.Viewport viewport)
Creates a new ZoomManager.ZoomManager(org.eclipse.draw2d.ScalableFreeformLayeredPane pane, org.eclipse.draw2d.Viewport viewport)
Deprecated.UseZoomManager(ScalableFigure, Viewport)
instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addZoomListener(ZoomListener listener)
Adds the given ZoomListener to this ZoomManager's list of listeners.boolean
canZoomIn()
returnstrue
if the zoommanager can performzoomIn()
.boolean
canZoomOut()
returnstrue
if the zoommanager can performzoomOut()
.protected void
fireZoomChanged()
Notifies listeners that the zoom level has changed.protected double
getFitHeightZoomLevel()
Calculates and returns the zoom percent required so that the entire height of thescalable figure
is visible on the screen.protected double
getFitPageZoomLevel()
Calculates and returns the zoom percentage required to fit the entirescalable figure
on the screen.protected double
getFitWidthZoomLevel()
Calculates and returns the zoom percentage required so that the entire width of thescalable figure
is visible on the screen.double
getMaxZoom()
Returns the maxZoom.double
getMinZoom()
Returns the minZoom.double
getNextZoomLevel()
Returns the zoom level that is one level higher than the current level.org.eclipse.draw2d.ScalableFreeformLayeredPane
getPane()
Deprecated.UsegetScalableFigure()
instead.double
getPreviousZoomLevel()
Returns the zoom level that is one level higher than the current level.org.eclipse.draw2d.ScalableFigure
getScalableFigure()
Returns the figure which performs the actual zooming.double
getUIMultiplier()
Returns the mutltiplier.org.eclipse.draw2d.Viewport
getViewport()
Returns the viewport.double
getZoom()
Returns the current zoom level.java.lang.String
getZoomAsText()
Returns the current zoom level as a percentage formatted Stringjava.util.List
getZoomLevelContributions()
Returns the list of strings that should be appended to the list of numerical zoom levels.double[]
getZoomLevels()
Returns the zoomLevels.java.lang.String[]
getZoomLevelsAsText()
Returns the list of zoom levels as Strings in percent notation, plus any additional zoom levels that were contributed usingsetZoomLevelContributions(List)
.protected void
primSetZoom(double zoom)
Sets the zoom level to the given value.void
removeZoomListener(ZoomListener listener)
Removes the given ZoomListener from this ZoomManager's list of listeners.void
setUIMultiplier(double multiplier)
Sets the UI multiplier.void
setViewLocation(org.eclipse.draw2d.geometry.Point p)
Sets the Viewport's view associated with this ZoomManager to the passed Pointvoid
setZoom(double zoom)
Sets the zoom level to the given value.void
setZoomAnimationStyle(int style)
Sets which zoom methods get animated.void
setZoomAsText(java.lang.String zoomString)
Sets zoom to the passed string.void
setZoomLevelContributions(java.util.List contributions)
Sets the list of zoom level contributions (as strings).void
setZoomLevels(double[] zoomLevels)
Sets the zoomLevels.void
zoomIn()
Sets the zoom level to be one level highervoid
zoomOut()
Sets the zoom level to be one level lowervoid
zoomTo(org.eclipse.draw2d.geometry.Rectangle rect)
Currently does nothing.
-
-
-
Field Detail
-
ANIMATE_NEVER
public static final int ANIMATE_NEVER
Style bit meaning don't animate any zooms- See Also:
- Constant Field Values
-
ANIMATE_ZOOM_IN_OUT
public static final int ANIMATE_ZOOM_IN_OUT
- See Also:
- Constant Field Values
-
FIT_HEIGHT
public static final java.lang.String FIT_HEIGHT
String constant for the "Height" zoom level. At this zoom level, the zoom manager will adopt a zoom setting such that the entire height of the diagram will be visible on the screen.
-
FIT_WIDTH
public static final java.lang.String FIT_WIDTH
String constant for the "Width" zoom level. At this zoom level, the zoom manager will adopt a zoom setting such that the entire width of the diagram will be visible on the screen.
-
FIT_ALL
public static final java.lang.String FIT_ALL
String constant for the "Page" zoom level. At this zoom level, the zoom manager will adopt a zoom setting such that the entire diagram will be visible on the screen.
-
-
Constructor Detail
-
ZoomManager
public ZoomManager(org.eclipse.draw2d.ScalableFigure pane, org.eclipse.draw2d.Viewport viewport)
Creates a new ZoomManager.- Parameters:
pane
- The ScalableFigure associated with this ZoomManagerviewport
- The Viewport assoicated with this ZoomManager
-
ZoomManager
public ZoomManager(org.eclipse.draw2d.ScalableFreeformLayeredPane pane, org.eclipse.draw2d.Viewport viewport)
Deprecated.UseZoomManager(ScalableFigure, Viewport)
instead. Creates a new ZoomManager- Parameters:
pane
- The ScalableFreeformLayeredPane associated with this ZoomManagerviewport
- The Viewport assoicated with this viewport
-
-
Method Detail
-
addZoomListener
public void addZoomListener(ZoomListener listener)
Adds the given ZoomListener to this ZoomManager's list of listeners.- Parameters:
listener
- the ZoomListener to be added
-
canZoomIn
public boolean canZoomIn()
returnstrue
if the zoommanager can performzoomIn()
.- Returns:
- boolean true if zoomIn can be called
-
canZoomOut
public boolean canZoomOut()
returnstrue
if the zoommanager can performzoomOut()
.- Returns:
- boolean true if zoomOut can be called
-
fireZoomChanged
protected void fireZoomChanged()
Notifies listeners that the zoom level has changed.
-
getFitHeightZoomLevel
protected double getFitHeightZoomLevel()
Calculates and returns the zoom percent required so that the entire height of thescalable figure
is visible on the screen. This is the zoom level associated withFIT_HEIGHT
.- Returns:
- zoom setting required to fit the scalable figure vertically on the screen
-
getFitPageZoomLevel
protected double getFitPageZoomLevel()
Calculates and returns the zoom percentage required to fit the entirescalable figure
on the screen. This is the zoom setting associated withFIT_ALL
. It is the minimum ofgetFitHeightZoomLevel()
andgetFitWidthZoomLevel()
.- Returns:
- zoom setting required to fit the entire scalable figure on the screen
-
getFitWidthZoomLevel
protected double getFitWidthZoomLevel()
Calculates and returns the zoom percentage required so that the entire width of thescalable figure
is visible on the screen. This is the zoom setting associated withFIT_WIDTH
.- Returns:
- zoom setting required to fit the scalable figure horizontally on the screen
-
getMaxZoom
public double getMaxZoom()
Returns the maxZoom.- Returns:
- double
-
getMinZoom
public double getMinZoom()
Returns the minZoom.- Returns:
- double
-
getUIMultiplier
public double getUIMultiplier()
Returns the mutltiplier. This value is used to use zoom levels internally that are proportionally different than those displayed to the user. e.g. with a multiplier value of 2.0, the zoom level 1.0 will be displayed as "200%".- Returns:
- double The multiplier
-
getNextZoomLevel
public double getNextZoomLevel()
Returns the zoom level that is one level higher than the current level. If zoom level is at maximum, returns the maximum.- Returns:
- double The next zoom level
-
getPane
public org.eclipse.draw2d.ScalableFreeformLayeredPane getPane()
Deprecated.UsegetScalableFigure()
instead. Returns the pane.- Returns:
- the pane
-
getPreviousZoomLevel
public double getPreviousZoomLevel()
Returns the zoom level that is one level higher than the current level. If zoom level is at maximum, returns the maximum.- Returns:
- double The previous zoom level
-
getScalableFigure
public org.eclipse.draw2d.ScalableFigure getScalableFigure()
Returns the figure which performs the actual zooming.- Returns:
- the scalable figure
-
getViewport
public org.eclipse.draw2d.Viewport getViewport()
Returns the viewport.- Returns:
- Viewport
-
getZoom
public double getZoom()
Returns the current zoom level.- Returns:
- double the zoom level
-
getZoomAsText
public java.lang.String getZoomAsText()
Returns the current zoom level as a percentage formatted String- Returns:
- String The current zoom level as a String
-
getZoomLevelContributions
public java.util.List getZoomLevelContributions()
Returns the list of strings that should be appended to the list of numerical zoom levels. These could be things such as Fit Width, Fit Page, etc. May returnnull
.- Returns:
- the list of contributed zoom levels
-
getZoomLevels
public double[] getZoomLevels()
Returns the zoomLevels.- Returns:
- double[]
-
getZoomLevelsAsText
public java.lang.String[] getZoomLevelsAsText()
Returns the list of zoom levels as Strings in percent notation, plus any additional zoom levels that were contributed usingsetZoomLevelContributions(List)
.- Returns:
- List The list of zoom levels
-
primSetZoom
protected void primSetZoom(double zoom)
Sets the zoom level to the given value. Min-max range check is not done.- Parameters:
zoom
- the new zoom level
-
removeZoomListener
public void removeZoomListener(ZoomListener listener)
Removes the given ZoomListener from this ZoomManager's list of listeners.- Parameters:
listener
- the ZoomListener to be removed
-
setUIMultiplier
public void setUIMultiplier(double multiplier)
Sets the UI multiplier. The UI multiplier is applied to all zoom settings when they are presented to the user (getZoomAsText()
). Similarly, the multiplier is inversely applied when the user specifies a zoom level (setZoomAsText(String)
).When the UI multiplier is
1.0
, the User will see the exact zoom level that is being applied. If the value is2.0
, then a scale of0.5
will be labeled "100%" to the User.- Parameters:
multiplier
- The mutltiplier to set
-
setViewLocation
public void setViewLocation(org.eclipse.draw2d.geometry.Point p)
Sets the Viewport's view associated with this ZoomManager to the passed Point- Parameters:
p
- The new location for the Viewport's view.
-
setZoom
public void setZoom(double zoom)
Sets the zoom level to the given value. If the zoom is out of the min-max range, it will be ignored.- Parameters:
zoom
- the new zoom level
-
setZoomAnimationStyle
public void setZoomAnimationStyle(int style)
Sets which zoom methods get animated.- Parameters:
style
- the style bits determining the zoom methods to be animated.
-
setZoomAsText
public void setZoomAsText(java.lang.String zoomString)
Sets zoom to the passed string. The string must be composed of numeric characters only with the exception of a decimal point and a '%' as the last character. If the zoom level contribution list has been set, this method should be overridden to provide the appropriate zoom implementation for the new zoom levels.- Parameters:
zoomString
- The new zoom level
-
setZoomLevelContributions
public void setZoomLevelContributions(java.util.List contributions)
Sets the list of zoom level contributions (as strings). If you contribute something other thanFIT_HEIGHT
,FIT_WIDTH
andFIT_ALL
you must subclass this class and override this method to implement your contributed zoom function.- Parameters:
contributions
- the list of contributed zoom levels
-
setZoomLevels
public void setZoomLevels(double[] zoomLevels)
Sets the zoomLevels.- Parameters:
zoomLevels
- The zoomLevels to set
-
zoomIn
public void zoomIn()
Sets the zoom level to be one level higher
-
zoomTo
public void zoomTo(org.eclipse.draw2d.geometry.Rectangle rect)
Currently does nothing.- Parameters:
rect
- a rectangle
-
zoomOut
public void zoomOut()
Sets the zoom level to be one level lower
-
-