Class LayerManager

    • 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_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 interface UndoHandler
        Parameters:
        value - the undo manager to use
      • getUndo

        public Undo getUndo()
        Returns the current undo manager, can be null.
        Specified by:
        getUndo in interface UndoHandler
        Returns:
        the undo manager, if any
      • isUndoSupported

        public boolean isUndoSupported()
        Returns whether an Undo manager is currently available.
        Specified by:
        isUndoSupported in interface UndoHandler
        Returns:
        true if an undo manager is set
      • addUndoPoint

        public void addUndoPoint​(String comment)
        Adds an undo point with the given comment.
        Specified by:
        addUndoPoint in interface UndoHandlerWithQuickAccess
        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 interface UndoListener
        Parameters:
        e - the trigger event
      • 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 use
        image - 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 name
        color - the color
        alpha - the alpha value
      • addOverlay

        public OverlayLayer addOverlay​(String name,
                                       Color color,
                                       float alpha,
                                       BufferedImage image)
        Adds an overlay layer with image.
        Parameters:
        name - the name
        color - the color
        alpha - the alpha value
        image - 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 name
        color - the color
        alpha - the alpha value
      • addCombined

        public CombinedLayer addCombined​(String name,
                                         Color color,
                                         float alpha,
                                         BufferedImage image)
        Adds an overlay layer with image.
        Parameters:
        name - the name
        color - the color
        alpha - the alpha value
        image - 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).