Class ZoomPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- com.biomatters.geneious.publicapi.components.ZoomPanel
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
public class ZoomPanel extends javax.swing.JPanel
A panel for displaying and setting a zoom level. The zoom level is represented in the code by a double but displayed as a percentage. e.g. 0.5 = 50%, 1.0 = 100%, 1.5 = 150% etc This class is not thread safe. All methods should be called from the Swing (event dispatch) thread.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(javax.swing.event.ChangeListener listener)
Add a listener to be notified when the zoom changes.void
addKeyStrokesToTooltips(javax.swing.KeyStroke zoomIn, javax.swing.KeyStroke zoomOut, javax.swing.KeyStroke zoomToSelection, javax.swing.KeyStroke zoomTo100Percent, javax.swing.KeyStroke fitToScreen)
Add a textual representation of a shortcut key to the tooltip for each button.void
addZoomToSelectionActionListener(java.awt.event.ActionListener actionListener)
Add an actionListener to the zoom to selection button.void
fitToScreen()
A convenience method forsetZoomLevel(zoomPanel.getFitToScreenZoomLevel())
double
getFitToScreenZoomLevel()
double
getMaxZoomLevel()
double
getMinZoomLevel()
double
getZoomLevel()
javax.swing.JSlider
getZoomSlider()
Gets a slider that also controls zooming.boolean
isAtMinimumZoom()
void
removeChangeListener(javax.swing.event.ChangeListener listener)
Remove a listener from the list of listeners.void
removeZoomToSelectionActionListener(java.awt.event.ActionListener actionListener)
void
setForceFitToScreenButtonEnabled(boolean forceFitToScreenButtonEnabled)
void
setMaximumZoomLevel(double maxZoomLevel)
Set the maxiumum (most zoomed in) zoom levelvoid
setMinimumAndFitToScreenZoomLevel(double zoomLevel)
void
setMinimumAndMaximumAndCurrentZoomLevels(double minimum, double maximum, double current, boolean fireChanges)
Set the minimum, maximum and current zoom level.void
setMinimumAndMaximumAndCurrentZoomLevels(double minimum, double fitToScreenZoomLevel, double maximum, double current, boolean fireChanges)
Set the minimum, maximum, fit to screen and current zoom level.void
setTargetZoomLevel(double targetZoomLevel)
Sets the zoom level which is used for calculating the next zoom level from when pressing the 'zoom in' or 'zoom out' buttons.void
setZoomLevel(double zoomLevel)
void
setZoomLevel(double zoomLevel, boolean firechanges)
Sets the zoom level.void
zoomIn()
A convenience method forzoomIn(0)
void
zoomIn(int amountToReduceZoomFactorBy)
Changes zoom level to a larger number and notifies listeners that the zoom level has changed.void
zoomOut()
A convenience method forzoomOut(0)
void
zoomOut(int amountToReduceZoomFactorBy)
Changes zoom level to a smaller number and notifies listeners that the zoom level has changed.void
zoomTo100Percent()
A convenience method forsetZoomLevel(1.0)
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, paintComponent, 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, update
-
Methods inherited from class java.awt.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, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
ZoomPanel
public ZoomPanel()
-
ZoomPanel
public ZoomPanel(boolean showZoomButtons, boolean showZoomCompletelyButtons, boolean showZoomToSelectionButton, int spinnerIncrement)
- Parameters:
showZoomButtons
- true to show the "zoom in" and "zoom out" buttons on the leftshowZoomCompletelyButtons
- true to show the "zoom to 100% and "fit to screen" buttons on the rightshowZoomToSelectionButton
- true to show the "zoom to selection button" on the right. To make this button function an actionListener must then be added viaaddZoomToSelectionActionListener(ActionListener)
.spinnerIncrement
- the spinner model step size. SeeSpinnerNumberModel.getStepSize()
-
-
Method Detail
-
addChangeListener
public void addChangeListener(javax.swing.event.ChangeListener listener)
Add a listener to be notified when the zoom changes. Events fired are instances of aZoomChangeEvent
in Geneious 2019.0.0 and later.- Parameters:
listener
- the listener to be notified
-
removeChangeListener
public void removeChangeListener(javax.swing.event.ChangeListener listener)
Remove a listener from the list of listeners.- Parameters:
listener
- the listener added usingaddChangeListener(ChangeListener)
.
-
addZoomToSelectionActionListener
public void addZoomToSelectionActionListener(java.awt.event.ActionListener actionListener)
Add an actionListener to the zoom to selection button. This actionListener should calculate the required zoom then set it on this zoomPanel.- Parameters:
actionListener
- the actionListener to be added
-
removeZoomToSelectionActionListener
public void removeZoomToSelectionActionListener(java.awt.event.ActionListener actionListener)
- Parameters:
actionListener
- the actionListener added usingaddZoomToSelectionActionListener(ActionListener)
-
getMinZoomLevel
public double getMinZoomLevel()
- Returns:
- the minimum (most zoomed out) zoom level
-
getMaxZoomLevel
public double getMaxZoomLevel()
- Returns:
- the maxiumum (most zoomed in) zoom level
-
getFitToScreenZoomLevel
public double getFitToScreenZoomLevel()
- Returns:
- the zoom level that fits the entire thing to be viewed
-
setMaximumZoomLevel
public void setMaximumZoomLevel(double maxZoomLevel)
Set the maxiumum (most zoomed in) zoom level- Parameters:
maxZoomLevel
- the maxiumum (most zoomed in) zoom level
-
setMinimumAndFitToScreenZoomLevel
public void setMinimumAndFitToScreenZoomLevel(double zoomLevel)
- Parameters:
zoomLevel
- the value to set the minimum and fit to screen zoom levels to
-
setMinimumAndMaximumAndCurrentZoomLevels
public void setMinimumAndMaximumAndCurrentZoomLevels(double minimum, double maximum, double current, boolean fireChanges)
Set the minimum, maximum and current zoom level. The fit to screen zoom level is set to be the same as the minimum. CallssetMinimumAndMaximumAndCurrentZoomLevels(minimum, minimum, maximum, current, fireChanges)
- Parameters:
minimum
- the minimum (most zoomed out) zoom levelmaximum
- the maxiumum (most zoomed in) zoom levelcurrent
- the zoom level to set as the current zoom levelfireChanges
- whether to notify the listeners added byaddChangeListener(ChangeListener)
-
setMinimumAndMaximumAndCurrentZoomLevels
public void setMinimumAndMaximumAndCurrentZoomLevels(double minimum, double fitToScreenZoomLevel, double maximum, double current, boolean fireChanges)
Set the minimum, maximum, fit to screen and current zoom level.- Parameters:
minimum
- the minimum (most zoomed out) zoom levelfitToScreenZoomLevel
- the zoom level where everything fits nicely on the screenmaximum
- the maxiumum (most zoomed in) zoom levelcurrent
- the zoom level to set as the current zoom levelfireChanges
- whether to notify the listeners added byaddChangeListener(ChangeListener)
-
setTargetZoomLevel
public void setTargetZoomLevel(double targetZoomLevel)
Sets the zoom level which is used for calculating the next zoom level from when pressing the 'zoom in' or 'zoom out' buttons. Generally this is the same as the current zoom level, except in cases when the viewport is gradually zooming towards a desired zoom level and the user presses zoom again before the first zoom is complete. In this case we should zoom relative to the target zoom instead of the current zoom- Parameters:
targetZoomLevel
- the target zoom level between 0 and 1- Since:
- API 4.702 (Geneious 7.0.2)
-
addKeyStrokesToTooltips
public void addKeyStrokesToTooltips(javax.swing.KeyStroke zoomIn, javax.swing.KeyStroke zoomOut, javax.swing.KeyStroke zoomToSelection, javax.swing.KeyStroke zoomTo100Percent, javax.swing.KeyStroke fitToScreen)
Add a textual representation of a shortcut key to the tooltip for each button. Calls GuiUtilities#getStringForKeyStroke(KeyStroke) for each KeyStroke parameter and adds this string to the end of each button's tooltip text. NB this only sets the tooltip text, it doesn't associate the keystroke with the action performed by the button.- Parameters:
zoomIn
- the key stroke for zoomIn. May be nullzoomOut
- the key stroke for zoomIn. May be nullzoomToSelection
- the key stroke for zoomIn. May be nullzoomTo100Percent
- the key stroke for zoomIn. May be nullfitToScreen
- the key stroke for zoomIn. May be null- See Also:
GeneiousActionOptions.getShortcut()
-
getZoomLevel
public double getZoomLevel()
- Returns:
- zoom level as a decimal fraction. i.e. 1.0 = 100%
-
setZoomLevel
public void setZoomLevel(double zoomLevel)
- Parameters:
zoomLevel
- the zoom level to set
-
setForceFitToScreenButtonEnabled
public void setForceFitToScreenButtonEnabled(boolean forceFitToScreenButtonEnabled)
- Parameters:
forceFitToScreenButtonEnabled
- true forces the "fit to screen" button to be enabled, independent of the current zoom level. false causes the button to be only enabled when the zoom level is not currently at the "fit to screen" zoom level.- Since:
- API 4.201900 (Geneious 2019.0.0)
-
setZoomLevel
public void setZoomLevel(double zoomLevel, boolean firechanges)
Sets the zoom level. If the requested zoom level is < minZoomLevel or > maxZoomLevel the zoom is set to minZoomLevel or maxZoomLevel respectively.- Parameters:
zoomLevel
- the zoom level to setfirechanges
- whether to notify the listeners added byaddChangeListener(ChangeListener)
-
zoomIn
public void zoomIn()
A convenience method forzoomIn(0)
-
zoomIn
public void zoomIn(int amountToReduceZoomFactorBy)
Changes zoom level to a larger number and notifies listeners that the zoom level has changed. Snaps to the maximum, minimum and fit to screen zoom levels when near these values.- Parameters:
amountToReduceZoomFactorBy
- takes this many square roots of the standard zoom factor before it is applied to the current zoom level
-
zoomOut
public void zoomOut()
A convenience method forzoomOut(0)
-
zoomOut
public void zoomOut(int amountToReduceZoomFactorBy)
Changes zoom level to a smaller number and notifies listeners that the zoom level has changed. Snaps to the maximum, minimum and fit to screen zoom levels when near these values.- Parameters:
amountToReduceZoomFactorBy
- takes this many square roots of the standard zoom factor before it is applied to the current zoom level
-
zoomTo100Percent
public void zoomTo100Percent()
A convenience method forsetZoomLevel(1.0)
-
fitToScreen
public void fitToScreen()
A convenience method forsetZoomLevel(zoomPanel.getFitToScreenZoomLevel())
-
isAtMinimumZoom
public boolean isAtMinimumZoom()
- Returns:
- zoomPanel.getZoomLevel() == zoomPanel.getMinZoomLevel()}
-
getZoomSlider
public javax.swing.JSlider getZoomSlider()
Gets a slider that also controls zooming. This is not added to the zoom panel itself, it needs to be layed out somewhere else.- Returns:
- a slider that also controls zooming
- Since:
- API 4.50 (Geneious 5.5.0)
-
-