Class LayerManager
- java.lang.Object
-
- adams.gui.visualization.segmentation.layer.LayerManager
-
- All Implemented Interfaces:
UndoHandler,UndoHandlerWithQuickAccess,UndoListener,Serializable,EventListener
public class LayerManager extends Object implements Serializable, UndoHandlerWithQuickAccess, UndoListener
For managing the layers.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected BackgroundLayerm_BackgroundLayerthe background layer.protected Set<ChangeListener>m_BestFitRedonethe listeners if the best fit is being redone.protected CanvasPanelm_CanvasPanelthe canvas panel.protected Set<ChangeListener>m_ChangeListenersthe change listeners.protected CombinedLayerm_CombinedLayerthe combined layer.protected booleanm_IgnoreUpdateswhether to ignore updates.protected ImageLayerm_ImageLayerthe image layer.protected Markersm_Markersthe marker points to draw.protected List<OverlayLayer>m_Overlaysthe overlay layers.protected booleanm_RedoBestFitwhether bestfit zoom needs to be redone.protected intm_Rotationthe current rotation.protected booleanm_SplitLayerswhether to use separate overlay layers or a combined layer.protected Undom_Undothe undo manager.protected doublem_Zoomthe zoom (1.0 = 100%).
-
Constructor Summary
Constructors Constructor Description LayerManager(CanvasPanel canvasPanel)Initializes the layer manager using split layers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(OverlayLayer layer)Activates the specified overlay layer.voidaddBestFitRedoneListener(ChangeListener l)Adds listener to get notified when the best fit has been redone.voidaddChangeListener(ChangeListener l)Adds the change listener.CombinedLayeraddCombined(String name, Color color, float alpha)Adds an overlay layer with no image.CombinedLayeraddCombined(String name, Color color, float alpha, BufferedImage image)Adds an overlay layer with image.OverlayLayeraddOverlay(String name, Color color, float alpha)Adds an overlay layer with no image.OverlayLayeraddOverlay(String name, Color color, float alpha, BufferedImage image)Adds an overlay layer with image.voidaddUndoPoint(String comment)Adds an undo point with the given comment.voidbestFitZoom()Fits the image into the view port.voidclear()Removes all layers, clears the underlying image and the undo.voiddraw(Graphics2D g2d)Calls the draw method of all layers.voiddraw(Graphics2D g2d, double zoom)Calls the draw method of all layers.protected voiddrawMarkers(Graphics2D g2d)Draws the markers.voidfinishUpdate(boolean update)Reenables automatic updatesagain.OverlayLayergetActiveOverlay()Returns the active overlay layer, if any.OverlayLayergetActiveOverlay(boolean mustBeEnabled)Returns the active overlay layer, if any.intgetActualHeight()Returns the actual height, taking the zoom into account.intgetActualWidth()Returns the actual width, taking the zoom into account.BackgroundLayergetBackgroundLayer()Returns the background layer.CanvasPanelgetCanvasPanel()Returns the canvas panel.CombinedLayergetCombinedLayer()Returns the image layer.intgetHeight()Returns the height.ImageLayergetImageLayer()Returns the image layer.AbstractLayergetLayer(String name)Returns the layer with the specified name.List<AbstractLayer>getLayers()Returns all the layers.MarkersgetMarkers()Returns the markers manager.OverlayLayergetOverlay(String name)Returns the overlay with the specified name.List<OverlayLayer>getOverlays()Returns the overlay layers in use.intgetRotation()Returns the current rotation in degrees.List<AbstractLayer.AbstractLayerState>getSettings()Returns the current state.booleangetSplitLayers()Returns whether split layers are used (overlay) or not (combined).List<AbstractLayer.AbstractLayerState>getState()Returns the current state.UndogetUndo()Returns the current undo manager, can be null.intgetWidth()Returns the width.doublegetZoom()Returns the zoom in use.booleanhasActiveOverlay()Returns whether an overlay layer is currently active.booleanhasLayer(String name)Checks whether a layer with the specified name is present.booleanhasOverlay(String name)Checks whether an overlay with the specified name is present.voidhideAllLayers()Hides all layers (excl image/background).booleanignoreUpdates()Returns whether updates are currently ignored.voidinvertLayers()Inverts the visibility state of all layers (excl image/background).booleanisUndoSupported()Returns whether an Undo manager is currently available.protected voidnotifyBestFitRedoneListeners()Notifies all the listener that the best fit has been redone.protected voidnotifyChangeListeners()Notifies all change listenersvoidredo()performs a redo if possible.voidremoveBestFitRedoneListener(ChangeListener l)Removes listener to get notified when the best fit has been redone.voidremoveChangeListener(ChangeListener l)Removes the change listener.OverlayLayerremoveOverlay(String name)Removes an overlay layer.voidrepaint()Repaints everything.voidrevertRotation()Reverts any rotation.voidrotate(int degrees)Rotates the images by the specified number of degrees.voidsetImage(String name, BufferedImage image)Sets the image to display.voidsetSettings(List<AbstractLayer.AbstractLayerState> settings)Restores the settings.voidsetSplitLayers(boolean value)Sets whether to use split layers.voidsetState(List<AbstractLayer.AbstractLayerState> states)Restores the state.voidsetUndo(Undo value)Sets the undo manager to use, can be null if no undo-support wanted.voidsetZoom(double value)Sets the zoom to use.voidshowAllLayers()Shows all layers (excl image/background).voidstartUpdate()Whether a larger update is to start and updates should be ignored since an explicit update() call will occur.StringsuggestName(String name)Suggests a new name.voidundo()performs an undo if possible.voidundoOccurred(UndoEvent e)An undo event, like add or remove, has occurred.voidupdate()Notifies all change listeners and triggers a repaint.
-
-
-
Field Detail
-
m_SplitLayers
protected boolean m_SplitLayers
whether to use separate overlay layers or a combined layer.
-
m_BackgroundLayer
protected BackgroundLayer m_BackgroundLayer
the background layer.
-
m_ImageLayer
protected ImageLayer m_ImageLayer
the image layer.
-
m_CombinedLayer
protected CombinedLayer m_CombinedLayer
the combined layer.
-
m_Overlays
protected List<OverlayLayer> m_Overlays
the overlay layers.
-
m_CanvasPanel
protected CanvasPanel m_CanvasPanel
the canvas panel.
-
m_ChangeListeners
protected Set<ChangeListener> m_ChangeListeners
the change listeners.
-
m_Zoom
protected double m_Zoom
the zoom (1.0 = 100%).
-
m_Undo
protected Undo m_Undo
the undo manager.
-
m_RedoBestFit
protected boolean m_RedoBestFit
whether bestfit zoom needs to be redone.
-
m_BestFitRedone
protected Set<ChangeListener> m_BestFitRedone
the listeners if the best fit is being redone.
-
m_IgnoreUpdates
protected boolean m_IgnoreUpdates
whether to ignore updates.
-
m_Markers
protected Markers m_Markers
the marker points to draw.
-
m_Rotation
protected int m_Rotation
the current rotation.
-
-
Constructor Detail
-
LayerManager
public LayerManager(CanvasPanel canvasPanel)
Initializes the layer manager using split layers.- Parameters:
canvasPanel- the panel to draw on
-
-
Method Detail
-
setSplitLayers
public void setSplitLayers(boolean value)
Sets whether to use split layers. Also clears everything.- Parameters:
value- true if split layers- See Also:
clear()
-
getSplitLayers
public boolean getSplitLayers()
Returns whether split layers are used (overlay) or not (combined).- Returns:
- true if split layers
-
startUpdate
public void startUpdate()
Whether a larger update is to start and updates should be ignored since an explicit update() call will occur.
-
finishUpdate
public void finishUpdate(boolean update)
Reenables automatic updatesagain.- Parameters:
update- whether to trigger an update
-
ignoreUpdates
public boolean ignoreUpdates()
Returns whether updates are currently ignored.- Returns:
- true if ignored
-
clear
public void clear()
Removes all layers, clears the underlying image and the undo.
-
setUndo
public void setUndo(Undo value)
Sets the undo manager to use, can be null if no undo-support wanted.- Specified by:
setUndoin interfaceUndoHandler- Parameters:
value- the undo manager to use
-
getUndo
public Undo getUndo()
Returns the current undo manager, can be null.- Specified by:
getUndoin interfaceUndoHandler- Returns:
- the undo manager, if any
-
isUndoSupported
public boolean isUndoSupported()
Returns whether an Undo manager is currently available.- Specified by:
isUndoSupportedin interfaceUndoHandler- Returns:
- true if an undo manager is set
-
undo
public void undo()
performs an undo if possible.- Specified by:
undoin interfaceUndoHandlerWithQuickAccess
-
redo
public void redo()
performs a redo if possible.- Specified by:
redoin interfaceUndoHandlerWithQuickAccess
-
addUndoPoint
public void addUndoPoint(String comment)
Adds an undo point with the given comment.- Specified by:
addUndoPointin interfaceUndoHandlerWithQuickAccess- Parameters:
comment- the comment for the undo point
-
undoOccurred
public void undoOccurred(UndoEvent e)
An undo event, like add or remove, has occurred.- Specified by:
undoOccurredin interfaceUndoListener- Parameters:
e- the trigger event
-
getState
public List<AbstractLayer.AbstractLayerState> getState()
Returns the current state.- Returns:
- the state
-
setState
public void setState(List<AbstractLayer.AbstractLayerState> states)
Restores the state.- Parameters:
states- the state to restore
-
getSettings
public List<AbstractLayer.AbstractLayerState> getSettings()
Returns the current state.- Returns:
- the settings
-
setSettings
public void setSettings(List<AbstractLayer.AbstractLayerState> settings)
Restores the settings.- Parameters:
settings- the settings to restore
-
addBestFitRedoneListener
public void addBestFitRedoneListener(ChangeListener l)
Adds listener to get notified when the best fit has been redone.- Parameters:
l- the listener to add
-
removeBestFitRedoneListener
public void removeBestFitRedoneListener(ChangeListener l)
Removes listener to get notified when the best fit has been redone.- Parameters:
l- the listener to remove
-
notifyBestFitRedoneListeners
protected void notifyBestFitRedoneListeners()
Notifies all the listener that the best fit has been redone.
-
setZoom
public void setZoom(double value)
Sets the zoom to use.- Parameters:
value- the zoom (1.0 = 100%)
-
getZoom
public double getZoom()
Returns the zoom in use.- Returns:
- the zoom (1.0 = 100%)
-
bestFitZoom
public void bestFitZoom()
Fits the image into the view port.
-
getWidth
public int getWidth()
Returns the width.- Returns:
- the width
-
getActualWidth
public int getActualWidth()
Returns the actual width, taking the zoom into account.- Returns:
- the width
-
getHeight
public int getHeight()
Returns the height.- Returns:
- the height
-
getActualHeight
public int getActualHeight()
Returns the actual height, taking the zoom into account.- Returns:
- the height
-
getCanvasPanel
public CanvasPanel getCanvasPanel()
Returns the canvas panel.- Returns:
- the canvas
-
getLayers
public List<AbstractLayer> getLayers()
Returns all the layers.- Returns:
- all layers (background, image, overlays)
-
hasLayer
public boolean hasLayer(String name)
Checks whether a layer with the specified name is present.- Parameters:
name- the name of the layer- Returns:
- true if present
-
getLayer
public AbstractLayer getLayer(String name)
Returns the layer with the specified name.- Parameters:
name- the name of the layer- Returns:
- the overlay, null if not found
-
getBackgroundLayer
public BackgroundLayer getBackgroundLayer()
Returns the background layer.- Returns:
- the layer
-
setImage
public void setImage(String name, BufferedImage image)
Sets the image to display.- Parameters:
name- the name to useimage- the image
-
getImageLayer
public ImageLayer getImageLayer()
Returns the image layer.- Returns:
- the layer
-
addOverlay
public OverlayLayer addOverlay(String name, Color color, float alpha)
Adds an overlay layer with no image.- Parameters:
name- the namecolor- the coloralpha- the alpha value
-
addOverlay
public OverlayLayer addOverlay(String name, Color color, float alpha, BufferedImage image)
Adds an overlay layer with image.- Parameters:
name- the namecolor- the coloralpha- the alpha valueimage- the image, can be null
-
removeOverlay
public OverlayLayer removeOverlay(String name)
Removes an overlay layer.- Parameters:
name- the name- Returns:
- the overlay layer if successfully removed
-
getOverlays
public List<OverlayLayer> getOverlays()
Returns the overlay layers in use.- Returns:
- the layers
-
hasOverlay
public boolean hasOverlay(String name)
Checks whether an overlay with the specified name is present.- Parameters:
name- the name of the overlay- Returns:
- true if present
-
getOverlay
public OverlayLayer getOverlay(String name)
Returns the overlay with the specified name.- Parameters:
name- the name of the overlay- Returns:
- the overlay, null if not found
-
activate
public void activate(OverlayLayer layer)
Activates the specified overlay layer.- Parameters:
layer- the layer to activate
-
addCombined
public CombinedLayer addCombined(String name, Color color, float alpha)
Adds an overlay layer with no image.- Parameters:
name- the namecolor- the coloralpha- the alpha value
-
addCombined
public CombinedLayer addCombined(String name, Color color, float alpha, BufferedImage image)
Adds an overlay layer with image.- Parameters:
name- the namecolor- the coloralpha- the alpha valueimage- the image, can be null
-
getCombinedLayer
public CombinedLayer getCombinedLayer()
Returns the image layer.- Returns:
- the layer
-
hasActiveOverlay
public boolean hasActiveOverlay()
Returns whether an overlay layer is currently active.- Returns:
- true if active
-
getActiveOverlay
public OverlayLayer getActiveOverlay()
Returns the active overlay layer, if any. Must be enabled, too.- Returns:
- the layer, null if none active
-
getActiveOverlay
public OverlayLayer getActiveOverlay(boolean mustBeEnabled)
Returns the active overlay layer, if any.- Parameters:
mustBeEnabled- whether the layer must be enabled as well- Returns:
- the layer, null if none active
-
repaint
public void repaint()
Repaints everything.
-
draw
public void draw(Graphics2D g2d)
Calls the draw method of all layers.- Parameters:
g2d- the context to use
-
draw
public void draw(Graphics2D g2d, double zoom)
Calls the draw method of all layers.- Parameters:
g2d- the context to usezoom- the zoom to use (1.0 = 100%)
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds the change listener.- Parameters:
l- the listener to add
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes the change listener.- Parameters:
l- the listener to remove
-
notifyChangeListeners
protected void notifyChangeListeners()
Notifies all change listeners
-
update
public void update()
Notifies all change listeners and triggers a repaint.
-
suggestName
public String suggestName(String name)
Suggests a new name.- Parameters:
name- the old name- Returns:
- the suggested name
-
getMarkers
public Markers getMarkers()
Returns the markers manager.
-
drawMarkers
protected void drawMarkers(Graphics2D g2d)
Draws the markers.- Parameters:
g2d- the graphics context
-
showAllLayers
public void showAllLayers()
Shows all layers (excl image/background).
-
hideAllLayers
public void hideAllLayers()
Hides all layers (excl image/background).
-
invertLayers
public void invertLayers()
Inverts the visibility state of all layers (excl image/background).
-
rotate
public void rotate(int degrees)
Rotates the images by the specified number of degrees.- Parameters:
degrees- the rotation
-
revertRotation
public void revertRotation()
Reverts any rotation.
-
getRotation
public int getRotation()
Returns the current rotation in degrees.- Returns:
- the current rotation
-
-