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 canvasComponent
for use with JPlotterContourPlot.Renderer
s such asBlankCanvas
orContourPlot.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
orContourPlot.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 Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default java.awt.event.WindowListener
addCleanupOnWindowClosingListener(java.awt.Window window)
Adds aWindowListener
to the specified window that takes care of cleanup (GL resources) when the window is about to close.default java.awt.Component
asComponent()
Implicit cast of this canvas to a class extendingComponent
.void
enablePDFAsImageRendering(boolean enable)
En/disables PDF rendering as image.void
enableSvgAsImageRendering(boolean enable)
En/disables SVG rendering as image.int
getPixel(int x, int y, boolean picking, int areaSize)
Reads the color value of the pixel at the specified location if areaSize == 1.ContourPlot.Renderer
getRenderer()
boolean
isPDFAsImageRenderingEnabled()
boolean
isSvgAsImageRenderingEnabled()
static int
mostProminentColor(int[] colors, int areaSize)
Determines the most prominent value in a square shaped area.default void
paintToPDF(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.PDPage page, int w, int h)
Renders thisContourPlot.JPlotterCanvas
in terms of PDF elements to the specified page of the specified PDF document.void
repaint()
Deprecated.void
scheduleRepaint()
Schedules a repaint call on the AWT event dispatch thread.ContourPlot.JPlotterCanvas
setRenderer(ContourPlot.Renderer renderer)
Sets the renderer of this canvas.ContourPlot.Img
toImg()
Fetches the current contents of the framebuffer and returns them as anContourPlot.Img
.
-
-
-
Method Detail
-
repaint
@Deprecated void repaint()
Deprecated.On AWT event dispatch thread:
Uses the setContourPlot.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 implementingComponent
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.
-
isSvgAsImageRenderingEnabled
boolean isSvgAsImageRenderingEnabled()
- Returns:
- true when enabled
- See Also:
enableSvgAsImageRendering(boolean)
-
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 anContourPlot.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 locationy
- coordinate of the pixels locationpicking
- 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 thisContourPlot.JPlotterCanvas
in terms of PDF elements to the specified page of the specified PDF document.- Parameters:
document
- PDF document holding the pagepage
- page in the document to create PDF elements inw
- width of the pageh
- height of the page
-
setRenderer
ContourPlot.JPlotterCanvas setRenderer(ContourPlot.Renderer renderer)
Sets the renderer of this canvas.- Parameters:
renderer
- to draw contents.- Returns:
- this for chaining
-
getRenderer
ContourPlot.Renderer getRenderer()
- Returns:
- the current renderer
-
asComponent
default java.awt.Component asComponent()
Implicit cast of this canvas to a class extendingComponent
. This implies that the implementing class is aComponent
.- 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 bygetPixel(int, int, boolean, int)
implementations.- Parameters:
colors
- of the square shaped areaareaSize
- 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 aWindowListener
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 ofFBOCanvas
which uses GL resources (seeFBOCanvas#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
-
-