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 BackgroundLayer
m_BackgroundLayer
the background layer.protected Set<ChangeListener>
m_BestFitRedone
the listeners if the best fit is being redone.protected CanvasPanel
m_CanvasPanel
the canvas panel.protected Set<ChangeListener>
m_ChangeListeners
the change listeners.protected CombinedLayer
m_CombinedLayer
the combined layer.protected boolean
m_IgnoreUpdates
whether to ignore updates.protected ImageLayer
m_ImageLayer
the image layer.protected Markers
m_Markers
the marker points to draw.protected List<OverlayLayer>
m_Overlays
the overlay layers.protected boolean
m_RedoBestFit
whether bestfit zoom needs to be redone.protected boolean
m_SplitLayers
whether to use separate overlay layers or a combined layer.protected Undo
m_Undo
the undo manager.protected double
m_Zoom
the 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 void
activate(OverlayLayer layer)
Activates the specified overlay layer.void
addBestFitRedoneListener(ChangeListener l)
Adds listener to get notified when the best fit has been redone.void
addChangeListener(ChangeListener l)
Adds the change listener.CombinedLayer
addCombined(String name, Color color, float alpha)
Adds an overlay layer with no image.CombinedLayer
addCombined(String name, Color color, float alpha, BufferedImage image)
Adds an overlay layer with image.OverlayLayer
addOverlay(String name, Color color, float alpha)
Adds an overlay layer with no image.OverlayLayer
addOverlay(String name, Color color, float alpha, BufferedImage image)
Adds an overlay layer with image.void
addUndoPoint(String comment)
Adds an undo point with the given comment.void
bestFitZoom()
Fits the image into the view port.void
clear()
Removes all layers, clears the underlying image and the undo.void
draw(Graphics2D g2d)
Calls the draw method of all layers.protected void
drawMarkers(Graphics2D g2d)
Draws the markers.void
finishUpdate(boolean update)
Reenables automatic updatesagain.OverlayLayer
getActiveOverlay()
Returns the active overlay layer, if any.int
getActualHeight()
Returns the actual height, taking the zoom into account.int
getActualWidth()
Returns the actual width, taking the zoom into account.BackgroundLayer
getBackgroundLayer()
Returns the background layer.CanvasPanel
getCanvasPanel()
Returns the canvas panel.CombinedLayer
getCombinedLayer()
Returns the image layer.int
getHeight()
Returns the height.ImageLayer
getImageLayer()
Returns the image layer.AbstractLayer
getLayer(String name)
Returns the layer with the specified name.List<AbstractLayer>
getLayers()
Returns all the layers.Markers
getMarkers()
Returns the markers manager.OverlayLayer
getOverlay(String name)
Returns the overlay with the specified name.List<OverlayLayer>
getOverlays()
Returns the overlay layers in use.List<AbstractLayer.AbstractLayerState>
getSettings()
Returns the current state.boolean
getSplitLayers()
Returns whether split layers are used (overlay) or not (combined).List<AbstractLayer.AbstractLayerState>
getState()
Returns the current state.Undo
getUndo()
Returns the current undo manager, can be null.int
getWidth()
Returns the width.double
getZoom()
Returns the zoom in use.boolean
hasActiveOverlay()
Returns whether an overlay layer is currently active.boolean
hasLayer(String name)
Checks whether a layer with the specified name is present.boolean
hasOverlay(String name)
Checks whether an overlay with the specified name is present.void
hideAllLayers()
Hides all layers (excl image/background).boolean
ignoreUpdates()
Returns whether updates are currently ignored.void
invertLayers()
Inverts the visibility state of all layers (excl image/background).boolean
isUndoSupported()
Returns whether an Undo manager is currently available.protected void
notifyBestFitRedoneListeners()
Notifies all the listener that the best fit has been redone.protected void
notifyChangeListeners()
Notifies all change listenersvoid
redo()
performs a redo if possible.void
removeBestFitRedoneListener(ChangeListener l)
Removes listener to get notified when the best fit has been redone.void
removeChangeListener(ChangeListener l)
Removes the change listener.OverlayLayer
removeOverlay(String name)
Removes an overlay layer.void
repaint()
Repaints everything.void
setImage(String name, BufferedImage image)
Sets the image to display.void
setSettings(List<AbstractLayer.AbstractLayerState> settings)
Restores the settings.void
setSplitLayers(boolean value)
Sets whether to use split layers.void
setState(List<AbstractLayer.AbstractLayerState> states)
Restores the state.void
setUndo(Undo value)
Sets the undo manager to use, can be null if no undo-support wanted.void
setZoom(double value)
Sets the zoom to use.void
showAllLayers()
Shows all layers (excl image/background).void
startUpdate()
Whether a larger update is to start and updates should be ignored since an explicit update() call will occur.String
suggestName(String name)
Suggests a new name.void
undo()
performs an undo if possible.void
undoOccurred(UndoEvent e)
An undo event, like add or remove, has occurred.void
update()
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.
-
-
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:
setUndo
in interfaceUndoHandler
- Parameters:
value
- the undo manager to use
-
getUndo
public Undo getUndo()
Returns the current undo manager, can be null.- Specified by:
getUndo
in interfaceUndoHandler
- Returns:
- the undo manager, if any
-
isUndoSupported
public boolean isUndoSupported()
Returns whether an Undo manager is currently available.- Specified by:
isUndoSupported
in interfaceUndoHandler
- Returns:
- true if an undo manager is set
-
undo
public void undo()
performs an undo if possible.- Specified by:
undo
in interfaceUndoHandlerWithQuickAccess
-
redo
public void redo()
performs a redo if possible.- Specified by:
redo
in interfaceUndoHandlerWithQuickAccess
-
addUndoPoint
public void addUndoPoint(String comment)
Adds an undo point with the given comment.- Specified by:
addUndoPoint
in 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:
undoOccurred
in 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
-
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
-
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).
-
-