jfree / fxgraphics2d Goto Github PK
View Code? Open in Web Editor NEWA JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.
Home Page: http://www.jfree.org/fxgraphics2d
License: Other
A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.
Home Page: http://www.jfree.org/fxgraphics2d
License: Other
I would like to be able to draw javafx nodes to a Graphics2D so I can draw these in frameworks that use Graphics2D. Sofar I do not have a solution, perhaps overriding JFXPanel#paintComponent is a good starting point.
Directly on the README.md we have instructions to run demo program:
java -cp fxgraphics2d-1.5-demo.jar org.jfree.fx.demo.FXGraphics2DDemo1
The class does exist but is not included in any jar file by mvn package.
Copied this report which was entered against the wrong repo:
"I'm using javafx from JFreeChart. I notice that plotting 2M points took 4m while 4M points took 83m. That is due to JFreeChart's drawFirstPassShape and drawSecondaryPass use of setPaint() for each item. setPaint calls writePaint which adds to a GrowableDataBuffer which expands incrementally. That results in n^2 performance. Maybe javafx providing a better hint or allowing clients to provide a hint... I hacked a hint into javafx's Canvas.getBuffer. That reduced the time to 30s.
Cross posted to javafx. I expect it is more of a javafx issue, but wanted to provide a heads up...
jfreechart 1.0.19 javafx 1.8.0_45
Duane Tiemann"
This doesn't happen if the XYPlot is added to the CombinedDomainXYPlot after it contains a series.
Adding a second series results in a correct image.
Duane Tiemann
jfreechart-1.0.19.jar as distributed
Code provided in OneSeriesProblem.txt because .java is not allowed.
Code provided in OneSeriesProblem.txt since .java is not allowed.
The latest version is currently 1.7, but the home page (http://www.jfree.org/fxgraphics2d/index.html) only has a link to download version 1.5. And on github there's only the source code.
When running the Graphics2DTester, after some iterations the following exception is triggered:
Elapsed: 150.929
FPS: 3.364
java.lang.ClassCastException: class com.sun.prism.paint.Color cannot be cast to class java.lang.String (com.sun.prism.paint.Color is in module javafx.graphics@20-ea of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGCanvas.handleRenderOp(NGCanvas.java:1375)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGCanvas.renderStream(NGCanvas.java:1104)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGCanvas.renderContent(NGCanvas.java:610)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.renderForClip(NGNode.java:2313)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.renderRectClip(NGNode.java:2207)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.renderClip(NGNode.java:2233)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.CacheFilter.renderNodeToCache(CacheFilter.java:683)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.CacheFilter.render(CacheFilter.java:587)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.renderCached(NGNode.java:2377)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2063)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:270)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:579)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2072)
at javafx.graphics@20-ea/com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1964)
at javafx.graphics@20-ea/com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:480)
at javafx.graphics@20-ea/com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:321)
at javafx.graphics@20-ea/com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:92)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
at javafx.graphics@20-ea/com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at javafx.graphics@20-ea/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:126)
at java.base/java.lang.Thread.run(Thread.java:1589)
The draw(Shape) method, when the RenderingHints.KEY_STROKE_CONTROL is set to something other than RenderingHints.VALUE_STROKE_PURE, alters the state of input Rectangle2D and Line2D shapes. The code below demonstrates this:
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import org.jfree.fx.FXGraphics2D;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
public class DrawNormalize extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("DrawStrokeNormalize");
Group root = new Group();
Canvas canvas = new Canvas(640, 480);
GraphicsContext gc = canvas.getGraphicsContext2D();
FXGraphics2D g2d = new FXGraphics2D(gc);
/*
* Set the stroke control rendering hint to something other than
* VALUE_STROKE_PURE to trigger the issue.
*/
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
Line2D.Double line = new Line2D.Double(10.15, 10.15, 470.92, 470.92);
printLine(line);
g2d.draw(line);
printLine(line); // line's state has changed
Rectangle2D.Double rect = new Rectangle2D.Double(20.57, 20.57, 590.01, 430.3);
printRect(rect);
g2d.draw(rect);
printRect(rect); // rect's state has changed
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
static void printLine(Line2D line) {
System.out.println(String.format("(%5.3f, %5.3f) -> (%5.3f, %5.3f)",
line.getX1(), line.getY1(), line.getX2(), line.getY2()));
}
static void printRect(Rectangle2D rect) {
System.out.println(String.format("(%5.3f, %5.3f) -> (%5.3f, %5.3f)",
rect.getMinX(), rect.getMinY(),
rect.getMaxX(), rect.getMaxY()));
}
}
It's not clear that this is exactly a problem that needs to be addressed, but we found the behavior surprising. It was straightforward enough to work around in our code, but I've attached a patch for your consideration that I believe corrects the issue while preserving the original intent of the source:
The setClip() method, when invoked after font, paint, color or stroke details are altered, incorrectly restores the prior state. The following code demonstrates the issue:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Rectangle;
import org.jfree.fx.FXGraphics2D;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.stage.Stage;
/**
* Simple code example demonstrating the issue with setClip()
*/
public class SetClipIssue extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("SetClipIssue");
Group root = new Group();
Canvas canvas = new Canvas(640, 480);
GraphicsContext gc = canvas.getGraphicsContext2D();
FXGraphics2D g2d = new FXGraphics2D(gc);
g2d.setFont(g2d.getFont().deriveFont(20f));
g2d.setColor(Color.RED);
g2d.setStroke(new BasicStroke(2.0f));
g2d.setClip(new Rectangle(50, 50, 540, 380));
g2d.drawString("Red 20pt", 100, 100);
g2d.draw(new Rectangle(55, 75, 25, 25));
g2d.setFont(g2d.getFont().deriveFont(30f));
g2d.setColor(Color.BLUE);
g2d.setStroke(new BasicStroke(1.0f));
/*
* This clip set incorrectly restores the previous state of color, font, and
* stroke.
*/
g2d.setClip(new Rectangle(49, 49, 542, 382));
g2d.drawString("Blue 30pt?", 100, 200);
g2d.draw(new Rectangle(55, 175, 25, 25));
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
This patch resolved the issue in both the sample code above and in our application where we originally discovered the problem:
Would be great if you could add this badge to your readme:
[![JFXCentral](https://img.shields.io/badge/Find_me_on-JFXCentral-blue?logo=googlechrome&logoColor=white)](https://www.jfx-central.com/libraries/fxgraphics2d)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.