Class ContourPlot.CoordSysRenderer

  • All Implemented Interfaces:
    ContourPlot.PDFRenderer, ContourPlot.Renderer
    Enclosing class:
    ContourPlot

    public class ContourPlot.CoordSysRenderer
    extends java.lang.Object
    implements ContourPlot.Renderer
    The CoordSysRenderer is a ContourPlot.Renderer that displays a coordinate system. This coordinate system is enclosed by 4 axes that form a rectangle around the area that displays the contents of the coordinate system.

    The upper x-axis and right y-axis feature the labels (names) of the axes. The lower x-axis and the left y-axis feature tick marks and labels that help to orientate and read off coordinates. The positioning and labeling of the tick marks is done by a ContourPlot.TickMarkGenerator which is per default an instance of ContourPlot.ExtendedWilkinson. For each tick a vertical or horizontal guide line is drawn across the area of the coordinate system.

    What coordinate range the coordinate system area corresponds to is controlled by the coordinate view (see setCoordinateView(double, double, double, double)) and defaults to [-1,1] for both axes. The contents that are drawn inside the coordinate area are rendered by the content renderer (see setContent(Renderer)). If that renderer implements the ContourPlot.AdaptableView interface it will be passed the view matrix corresponding to the coordinate view. The content renderer will be able to draw within the viewport defined by the coordinate system area of this CoordSysRenderer.

    Optionally a ContourPlot.Renderer for drawing a legend (such as the ContourPlot.Legend class) can be set to either the bottom or right hand side of the coordinate system (can also use both areas at once). Use #setLegendBottom(Renderer) or setLegendRight(Renderer) to do so. The legend area size can be partially controlled by #setLegendBottomHeight(int) and setLegendRightWidth(int) if this is needed.

    The overlay renderer (#setOverlay(Renderer)) can be used to finally draw over all of the renderer viewport.

    For interacting with this ContourPlot.CoordSysRenderer there already exist implementations of MouseListeners for panning and zooming (see ContourPlot.CoordSysPanning and ContourPlot.CoordSysScrollZoom).

    Author:
    hageldave
    • Constructor Detail

      • CoordSysRenderer

        public CoordSysRenderer()
        Sets up a CoordSysRenderer with the default color scheme
    • Method Detail

      • setupCoordSysRenderer

        protected void setupCoordSysRenderer()
        Helper method to setup the CoordSysRenderer
      • updateColors

        protected ContourPlot.CoordSysRenderer updateColors()
        Helper method to update the colors if the color scheme is changed.
        Returns:
        this for chaining
      • setDirty

        public void setDirty()
        Sets the isDirty state of this CoordSysRenderer to true. This indicates that axis locations, tick marks, labels and guides have to be recomputed. The recomputing will be done during #render(int, int, int, int) which will set the isDirty state back to false.
      • updateLegendColorScheme

        protected void updateLegendColorScheme​(ContourPlot.Renderer legend)
        Parameters:
        legend - color scheme of the legend will be updated if it is from type ContourPlot.Legend
      • setupAndLayout

        protected void setupAndLayout()
        Sets up pretty much everything.
        • the bounds of the coordinate system frame (coordsysAreaLB, coordsysAreaRT)
        • the tick mark values and labels
        • the tick mark guides
        • the location of the axis labels
        • the areas for the legends (right and bottom legend)
      • renderFallback

        public void renderFallback​(java.awt.Graphics2D g,
                                   java.awt.Graphics2D p,
                                   int w,
                                   int h)
        Description copied from interface: ContourPlot.Renderer
        Renders this ContourPlot.Renderer's 'scene'. This is the fallback path in case OpenGL based rendering through #render(int, int, int, int) is not available.
        Specified by:
        renderFallback in interface ContourPlot.Renderer
        Parameters:
        g - main graphics object for drawing onto the framebuffer
        p - graphics object for drawing onto the picking framebuffer (invisible but used for picking)
        w - width of the current viewport in pixels
        h - height of the current viewport in pixels
      • renderPDF

        public void renderPDF​(org.apache.pdfbox.pdmodel.PDDocument doc,
                              org.apache.pdfbox.pdmodel.PDPage page,
                              int x,
                              int y,
                              int w,
                              int h)
        Description copied from interface: ContourPlot.PDFRenderer
        Renders this PDFRenderers contents, that is creating pdf elements and appending them to the specified page within the corresponding document.
        Specified by:
        renderPDF in interface ContourPlot.PDFRenderer
        Parameters:
        doc - the PDF document holding the page
        page - page in pdf doc to which elements are to be appended
        x - x coordinate of the current viewport
        y - y coordinate of the current viewport
        w - width of the current viewport
        h - height of the current viewport
      • isEnabled

        public boolean isEnabled()
        Description copied from interface: ContourPlot.Renderer
        Whether this renderer is enabled or not. By default a renderer is enabled and will render upon #render(int, int, int, int) or #renderSVG(org.w3c.dom.Document, org.w3c.dom.Element, int, int). When disabled those methods return right away and will not render anything.
        Specified by:
        isEnabled in interface ContourPlot.Renderer
        Returns:
        true when active
      • getxAxisLabel

        public java.lang.String getxAxisLabel()
        Returns:
        "X" if xAxisLabel is null or the actual axis label.
      • getyAxisLabel

        public java.lang.String getyAxisLabel()
        Returns:
        "Y" if yAxisLabel is null or the actual axis label.
      • setCoordinateView

        public ContourPlot.CoordSysRenderer setCoordinateView​(double minX,
                                                              double minY,
                                                              double maxX,
                                                              double maxY)
        Sets the coordinate view. This is the range of x and y coordinates that is displayed by this ContourPlot.CoordSysRenderer. It is not the rectangular area in which the content appears on screen but what coordinates that area corresponds to as a coordinate system.

        This determines what range of coordinates is visible when rendering the content. By default the coordinate view covers the range [-1,1] for both x and y coordinates. When the resulting value ranges maxX-minX or maxY-minY fall below 1e-9, the method refuses to set the view accordingly to prevent unrecoverable zooming and inaccurate or broken renderings due to floating point precision.

        This method also sets the isDirty state of this ContourPlot.CoordSysRenderer to true.

        When ContourPlot.CoordinateViewListener are registered to this renderer, they will be notified before this method returns.

        Parameters:
        minX - minimum x coordinate visible in the coordinate system
        minY - minimum y coordinate visible in the coordinate system
        maxX - maximum x coordinate visible in the coordinate system
        maxY - maximum y coordinate visible in the coordinate system
        Returns:
        this for chaining
      • getCoordinateView

        public java.awt.geom.Rectangle2D getCoordinateView()
        Returns the coordinate view, which is the range of x and y coordinates visible in the coordinate system. See setCoordinateView(double, double, double, double).
        Returns:
        the coordinate view
      • setContent

        public ContourPlot.Renderer setContent​(ContourPlot.Renderer content)
        Sets the content renderer that will draw into the area of the coordinate system.
        Parameters:
        content - the content renderer
        Returns:
        the previous content renderer (which may need to be closed to free GL resources), null if none was set
      • setLegendRight

        public ContourPlot.Renderer setLegendRight​(ContourPlot.Renderer legend)
        Sets the renderer that will draw the legend to the right of the coordinate system. The view port area for this renderer will start at the top edge of the coordinate system, be #getLegendRightWidth() wide and extend to the bottom (-padding).
        Parameters:
        legend - renderer for right side of coordinate system
        Returns:
        the previous legend renderer (which may need to be closed to free GL resources), null if none was set
      • setLegendRightWidth

        public ContourPlot.CoordSysRenderer setLegendRightWidth​(int legendRightWidth)
        Sets the width of the legend area right to the coordinate system. (height is determined by the space available until the bottom of the renderer's viewport)
        Parameters:
        legendRightWidth - width of the right legend area. (default is 70 px)
        Returns:
        this for chaining
      • getCoordSysArea

        public java.awt.geom.Rectangle2D getCoordSysArea()
        Returns:
        the area of this renderer in which the coordinate system contents are rendered. It is the viewPort for the content renderer which is enclosed by the coordinate system axes.
      • transformAWT2CoordSys

        public java.awt.geom.Point2D transformAWT2CoordSys​(java.awt.geom.Point2D awtPoint,
                                                           int canvasheight)
        Transforms a location in AWT coordinates (y axis extends to bottom) on this renderer to the corresponding coordinates in the coordinate system view (in GL coords).
        Parameters:
        awtPoint - to be transformed
        canvasheight - height of the canvas this ContourPlot.CoordSysRenderer is drawn to
        Returns:
        transformed location
      • transformGL2CoordSys

        public java.awt.geom.Point2D transformGL2CoordSys​(java.awt.geom.Point2D point)
        Transforms a location in GL coordinates on this renderer to the corresponding coordinates in the coordinate system view.
        Parameters:
        point - to be transformed
        Returns:
        transformed location