Class FXCanvas

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable

    public class FXCanvas
    extends JComponent
    FXCanvas component which represents a blank rectangular area of the screen onto which the application can draw or from which the component can trap input events from the user. Note: this component capture Esc key to clear the selection if any
    Author:
    Kiyut
    See Also:
    Serialized Form
    • Field Detail

      • ZOOM_FACTOR_PROPERTY

        public static final String ZOOM_FACTOR_PROPERTY
        Identifies a change to setZoomFactor factor
        See Also:
        Constant Field Values
      • IMAGE_FILE_PROPERTY

        public static final String IMAGE_FILE_PROPERTY
        Identifies a change to image file
        See Also:
        Constant Field Values
      • zoomFactor

        protected double zoomFactor
        the zoomFactor for this component.
      • fitSize

        protected boolean fitSize
        the fit size for this component.
      • renderer

        protected FXRenderer renderer
        FXRenderer
      • context

        protected FXContext context
        context
      • transform

        protected AffineTransform transform
        this canvas current transform
      • imageBounds

        protected Rectangle2D imageBounds
        imageBounds
      • transformValid

        protected boolean transformValid
        flag for canvas current transform validity
      • backgroundCheckerboard

        protected boolean backgroundCheckerboard
        flag for checkerboard background
      • checkerColor1

        protected Color checkerColor1
        background checker color 1 for alpha
      • checkerColor2

        protected Color checkerColor2
        background checker color 2 for alpha
      • borderStroke

        protected Stroke borderStroke
        border Stroke
      • renderThread

        protected Thread renderThread
        render thread
      • openFile

        protected boolean openFile
        boolean indicate opening new File
    • Constructor Detail

      • FXCanvas

        public FXCanvas()
        Create new instance of FXCanvas
    • Method Detail

      • paintCanvasBackground

        protected void paintCanvasBackground​(Graphics2D g2d)
        paint background
        Parameters:
        g2d - Graphics2D
      • paintImage

        protected void paintImage​(Graphics2D g2d)
      • paintTool

        protected void paintTool​(Graphics2D g2d)
        paint tool
        Parameters:
        g2d - Graphics2D
      • paintCanvasBorder

        protected void paintCanvasBorder​(Graphics2D g2d)
      • getTransform

        public AffineTransform getTransform()
        Return a copy of this canvas transform, incase the transform is modified externally
        Returns:
        AffineTransform
      • setZoomFactor

        public void setZoomFactor​(double zoomFactor)
        set the Zoom Factor
        Parameters:
        zoomFactor - the Zoom Factor
        See Also:
        getZoomFactor()
      • getZoomFactor

        public double getZoomFactor()
        Return Zoom Factor
        Returns:
        Zoom Factor
        See Also:
        setZoomFactor(double)
      • updateTransform

        protected void updateTransform()
        Update the transform
      • setImageFile

        public void setImageFile​(File file,
                                 boolean open)
        set the Image File
        Parameters:
        file - The File Image
        open - flag whether the image will be opened
        See Also:
        getImageFile()
      • isOpenFile

        public boolean isOpenFile()
        Return openFile status, the status is resetted at first render process.
        Returns:
        true or false
      • setFilterOp

        public void setFilterOp​(BufferedImageOp filterOp)
        Set the filterOp
        Parameters:
        filterOp - BufferedImageOp
      • setContext

        public void setContext​(FXContext context)
        Set Context
        Parameters:
        context - FXContext
        See Also:
        getContext()
      • setBackgroundCheckerboard

        public void setBackgroundCheckerboard​(boolean checkerboard)
        Set the background checkerboard true or false
        Parameters:
        checkerboard - true or false
        See Also:
        isBackgroundCheckerboard()
      • render

        public void render()
        Render will notify the interested listener using the addProgressListener. If there is a selected area, it will only render the selected area, otherwise the whole image. The rendering process is done in a thread.
        See Also:
        addProgressListener(ProgressListener)
      • crop

        public void crop​(Area area)
        Crop Rendered Image
        Parameters:
        area - the specified area for cropping
      • addProgressListener

        public void addProgressListener​(ProgressListener listener)
        Registers listener so that it will receive ProgressEvents when this component process the Image Filter Operation.
        Parameters:
        listener - the ProgressListener to register
      • removeProgressListener

        public void removeProgressListener​(ProgressListener listener)
        Unregisters listener so that it will receive ProgressEvents when this component process the Image Filter Operation.
        Parameters:
        listener - the ProgressListener to unregister
      • fireProgressStarted

        protected void fireProgressStarted()
        Notifies all listeners that have registered interest for notification on this event type.
      • fireProgressCompleted

        protected void fireProgressCompleted()
        Notifies all listeners that have registered interest for notification on this event type.
      • fireProgressCancelled

        protected void fireProgressCancelled()
        Notifies all listeners that have registered interest for notification on this event type.
      • fireProgressFailed

        protected void fireProgressFailed​(Exception ex)
        Notifies all listeners that have registered interest for notification on this event type.
        Parameters:
        ex - the Exception