Interface ContourPlot.JPlotterCanvas

  • All Known Implementing Classes:
    ContourPlot.BlankCanvasFallback
    Enclosing class:
    ContourPlot

    public static interface ContourPlot.JPlotterCanvas
    This interface defines the methods required by an implementation of a canvas Component for use with JPlotter ContourPlot.Renderers such as BlankCanvas or ContourPlot.BlankCanvasFallback. The most important required operations on such a component are:
    • setting a ContourPlot.Renderer that takes care of generating the displayed content
    • exporting what the component displays to an image
    • querying a pixel color at a specific location of the component (especially important for picking)
    • scheduling a repaint operation of the component
    • getting this as an awt Component (implicit cast) since implementations have to be an instance of this class

    This interface is intended to enable development without explicitly choosing between BlankCanvas or ContourPlot.BlankCanvasFallback. This way a fallback mode for an application can be easily realized, e.g. for macOS which is not supported by lwjgl3-awt and thus cannot use the OpenGL backed BlankCanvas.

    JPlotterCanvas also provides the ability to export to scalable vector graphics (SVG) and portable document format (PDF) with the #paintSVG() and #paintPDF() methods.

    Author:
    hageldave
    • Method Detail

      • repaint

        @Deprecated
        void repaint()
        Deprecated.
        On AWT event dispatch thread:
        Uses the set ContourPlot.Renderer render to render display contents, then calls super.repaint() to display rendered content.

        Schedules a repaint call call on the AWT event dispatch thread if not on it.

        This method is only deprecated for calling directly, call scheduleRepaint() instead.
        Of course super.repaint() is implemented by the implementing Component already.

      • scheduleRepaint

        void scheduleRepaint()
        Schedules a repaint call on the AWT event dispatch thread. If a repaint is already pending, this method will not schedule an additional call until the render method within repaint is about to be executed.
      • enableSvgAsImageRendering

        void enableSvgAsImageRendering​(boolean enable)
        En/disables SVG rendering as image. When rendering to SVG and this is enabled, instead of translating the contents of the renderers into SVG elements, the current framebuffer image is used and put into the dom.

        This can be useful for example when too many SVG elements would be created resulting in a huge dom and file size when exporting as SVG.

        Parameters:
        enable - true when no SVG elements should be created from the content of this JPlotterCanvas but instead a simple image element with the framebuffer's content.
      • enablePDFAsImageRendering

        void enablePDFAsImageRendering​(boolean enable)
        En/disables PDF rendering as image. When rendering to PDF and this is enabled, instead of translating the contents of the renderers into PDF elements, the current framebuffer image is used and put into the pdf document.

        This can be useful for example when too many PDF elements would be created resulting in a huge dom and file size when exporting as PDF.

        Parameters:
        enable - true when no PDF elements should be created from the content of this JPlotterCanvas but instead a simple image element with the framebuffer's content.
      • isPDFAsImageRenderingEnabled

        boolean isPDFAsImageRenderingEnabled()
        Returns:
        true when enabled
        See Also:
        (boolean)
      • toImg

        ContourPlot.Img toImg()
        Fetches the current contents of the framebuffer and returns them as an ContourPlot.Img.
        Returns:
        image of the current framebuffer.
      • getPixel

        int getPixel​(int x,
                     int y,
                     boolean picking,
                     int areaSize)
        Reads the color value of the pixel at the specified location if areaSize == 1. This can be used to get the color or picking color under the mouse cursor.

        Since the cursor placement may be inexact and thus miss the location the user was actually interested in, the areaSize parameter can be increased to create a window of pixels around the specified location. This window area will be examined and the most prominent non zero color value will be returned.

        Parameters:
        x - coordinate of the pixels location
        y - coordinate of the pixels location
        picking - whether the picking color or the visible color should be retrieved.
        areaSize - width and height of the area around the specified location.
        Returns:
        the most prominent color in the area as integer packed ARGB value. If the returned value is to be used as an object id from picking color, then the alpha value probably has to be discarded first using 0x00ffffff & returnValue.
      • paintToPDF

        default void paintToPDF​(org.apache.pdfbox.pdmodel.PDDocument document,
                                org.apache.pdfbox.pdmodel.PDPage page,
                                int w,
                                int h)
        Renders this ContourPlot.JPlotterCanvas in terms of PDF elements to the specified page of the specified PDF document.
        Parameters:
        document - PDF document holding the page
        page - page in the document to create PDF elements in
        w - width of the page
        h - height of the page
      • asComponent

        default java.awt.Component asComponent()
        Implicit cast of this canvas to a class extending Component. This implies that the implementing class is a Component.
        Returns:
        this, but cast to Component
      • mostProminentColor

        static int mostProminentColor​(int[] colors,
                                      int areaSize)
        Determines the most prominent value in a square shaped area. This method should be used by getPixel(int, int, boolean, int) implementations.
        Parameters:
        colors - of the square shaped area
        areaSize - widht or height of the area
        Returns:
        mode of colors, with +1 count for the center color
      • addCleanupOnWindowClosingListener

        default java.awt.event.WindowListener addCleanupOnWindowClosingListener​(java.awt.Window window)
        Adds a WindowListener to the specified window that takes care of cleanup (GL resources) when the window is about to close.

        This method only has an effect when this ContourPlot.JPlotterCanvas is an instance of FBOCanvas which uses GL resources (see FBOCanvas#createCleanupOnWindowClosingListener()). Otherwise no WindowListener is created or added.

        Parameters:
        window - the window to add the listener to (should be the window containing this canvas)
        Returns:
        the added listener when this is an FBOCanvas, else null