mirror of https://github.com/rusefi/jzy3d-api.git
extracting a SwingChart to ease the use of CanvasSwing (although deprecated)
This commit is contained in:
parent
295102e0a2
commit
b0e799367d
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/tests"/>
|
||||
<classpathentry kind="src" path="src/swing"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/api"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/bridge"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/awt"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="src/swing"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry exported="true" kind="var" path="M2_REPO/org/jogamp/gluegen/gluegen-rt-main/2.0-rc11/gluegen-rt-main-2.0-rc11.jar"/>
|
||||
<classpathentry exported="true" kind="var" path="M2_REPO/org/jogamp/gluegen/gluegen-rt/2.0-rc11/gluegen-rt-2.0-rc11.jar"/>
|
||||
|
|
|
@ -4,28 +4,34 @@ import java.util.Date;
|
|||
|
||||
import javax.media.opengl.GLCapabilities;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jzy3d.bridge.IFrame;
|
||||
import org.jzy3d.chart.Chart;
|
||||
import org.jzy3d.chart.ChartScene;
|
||||
import org.jzy3d.chart.ChartView;
|
||||
import org.jzy3d.chart.controllers.keyboard.camera.AWTCameraKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.camera.NewtCameraKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.camera.ICameraKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.camera.NewtCameraKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.screenshot.AWTScreenshotKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.screenshot.IScreenshotKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.screenshot.IScreenshotKeyController.IScreenshotEventListener;
|
||||
import org.jzy3d.chart.controllers.keyboard.screenshot.AWTScreenshotKeyController;
|
||||
import org.jzy3d.chart.controllers.keyboard.screenshot.NewtScreenshotKeyController;
|
||||
import org.jzy3d.chart.controllers.mouse.camera.AWTCameraMouseController;
|
||||
import org.jzy3d.chart.controllers.mouse.camera.NewtCameraMouseController;
|
||||
import org.jzy3d.chart.controllers.mouse.camera.ICameraMouseController;
|
||||
import org.jzy3d.chart.controllers.mouse.camera.NewtCameraMouseController;
|
||||
import org.jzy3d.chart.factories.IChartComponentFactory.Toolkit;
|
||||
import org.jzy3d.maths.BoundingBox3d;
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
import org.jzy3d.maths.Dimension;
|
||||
import org.jzy3d.maths.Rectangle;
|
||||
import org.jzy3d.maths.Utils;
|
||||
import org.jzy3d.plot3d.primitives.axes.AxeBase;
|
||||
import org.jzy3d.plot3d.primitives.axes.IAxe;
|
||||
import org.jzy3d.plot3d.rendering.canvas.CanvasNewtAwt;
|
||||
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
|
||||
import org.jzy3d.plot3d.rendering.canvas.OffscreenCanvas;
|
||||
import org.jzy3d.plot3d.rendering.canvas.Quality;
|
||||
import org.jzy3d.plot3d.rendering.canvas.VoidCanvas;
|
||||
import org.jzy3d.plot3d.rendering.ordering.AbstractOrderingStrategy;
|
||||
import org.jzy3d.plot3d.rendering.ordering.BarycentreOrderingStrategy;
|
||||
import org.jzy3d.plot3d.rendering.scene.Scene;
|
||||
|
@ -34,21 +40,30 @@ import org.jzy3d.plot3d.rendering.view.Renderer3d;
|
|||
import org.jzy3d.plot3d.rendering.view.View;
|
||||
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
|
||||
|
||||
/** This {@link IChartComponentFactory} returns non-displayable charts.
|
||||
* @see AWTChartComponentFactory for a working implementation
|
||||
*/
|
||||
public class ChartComponentFactory implements IChartComponentFactory {
|
||||
public static Chart chart(Quality quality, Toolkit toolkit){
|
||||
ChartComponentFactory f = new ChartComponentFactory();
|
||||
return f.newChart(quality, toolkit);
|
||||
}
|
||||
|
||||
/** to be implemented */
|
||||
protected ICanvas initializeCanvas(Scene scene, Quality quality, String chartType, GLCapabilities capabilities, boolean b, boolean c){
|
||||
throw new RuntimeException("should be implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chart newChart(Quality quality, Toolkit toolkit){
|
||||
return new Chart(this, quality, toolkit.toString());
|
||||
return newChart(this, quality, toolkit.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chart newChart(Quality quality, String toolkit){
|
||||
return newChart(this, quality, toolkit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chart newChart(IChartComponentFactory factory, Quality quality, String toolkit){
|
||||
return new Chart(factory, quality, toolkit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChartScene newScene(boolean sort) {
|
||||
return new ChartScene(sort, this);
|
||||
|
@ -71,14 +86,18 @@ public class ChartComponentFactory implements IChartComponentFactory {
|
|||
return new Renderer3d(view, traceGL, debugGL);
|
||||
}
|
||||
@Override
|
||||
public Renderer3d newRenderer(View view) {
|
||||
return newRenderer(view, false, false);
|
||||
}
|
||||
@Override
|
||||
public AbstractOrderingStrategy newOrderingStrategy() {
|
||||
return new BarycentreOrderingStrategy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICanvas newCanvas(Scene scene, Quality quality, String chartType,
|
||||
GLCapabilities capabilities) {
|
||||
return initializeCanvas(scene, quality, chartType, capabilities, false,
|
||||
false);
|
||||
return new VoidCanvas(this, scene, quality);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,35 +22,25 @@ import org.jzy3d.plot3d.rendering.view.View;
|
|||
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
|
||||
|
||||
public interface IChartComponentFactory {
|
||||
public abstract Chart newChart(Quality quality, Toolkit toolkit);
|
||||
|
||||
public abstract ChartScene newScene(boolean sort);
|
||||
|
||||
public abstract View newView(Scene scene, ICanvas canvas, Quality quality);
|
||||
|
||||
public abstract Camera newCamera(Coord3d center);
|
||||
|
||||
public abstract IAxe newAxe(BoundingBox3d box, View view);
|
||||
|
||||
public abstract Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL);
|
||||
|
||||
public abstract AbstractOrderingStrategy newOrderingStrategy();
|
||||
|
||||
public abstract ICanvas newCanvas(Scene scene, Quality quality, String chartType, GLCapabilities capabilities);
|
||||
|
||||
public Chart newChart(Quality quality, Toolkit toolkit);
|
||||
public Chart newChart(Quality quality, String toolkit);
|
||||
public Chart newChart(IChartComponentFactory factory, Quality quality, String toolkit);
|
||||
|
||||
public ChartScene newScene(boolean sort);
|
||||
public View newView(Scene scene, ICanvas canvas, Quality quality);
|
||||
public Camera newCamera(Coord3d center);
|
||||
public IAxe newAxe(BoundingBox3d box, View view);
|
||||
public Renderer3d newRenderer(View view);
|
||||
public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL);
|
||||
public AbstractOrderingStrategy newOrderingStrategy();
|
||||
public ICanvas newCanvas(Scene scene, Quality quality, String chartType, GLCapabilities capabilities);
|
||||
public ICameraMouseController newMouseController(Chart chart);
|
||||
|
||||
public ICameraKeyController newKeyController(Chart chart);
|
||||
|
||||
public IScreenshotKeyController newScreenshotKeyController(Chart chart);
|
||||
|
||||
public IFrame newFrame(Chart chart, Rectangle bounds, String title);
|
||||
|
||||
public IViewportLayout newViewportLayout();
|
||||
|
||||
public static enum Toolkit {
|
||||
|
||||
awt, swing, newt, offscreen
|
||||
};
|
||||
|
||||
}
|
|
@ -16,11 +16,23 @@ import org.jzy3d.plot3d.rendering.scene.Scene;
|
|||
import org.jzy3d.plot3d.rendering.view.Renderer3d;
|
||||
import org.jzy3d.plot3d.rendering.view.View;
|
||||
|
||||
import com.jogamp.newt.event.KeyListener;
|
||||
import com.jogamp.newt.event.MouseListener;
|
||||
import com.jogamp.opengl.util.texture.TextureData;
|
||||
import com.jogamp.opengl.util.texture.TextureIO;
|
||||
|
||||
/**
|
||||
* An {@link ICanvas} implementation able to render the chart in an offscreen canvas,
|
||||
* meaning no frame or GUI is needed to get a chart.
|
||||
*
|
||||
* Subsequently, one will wish to generate chart images by calling:
|
||||
* <pre>
|
||||
* <code>
|
||||
* chart.screenshot();
|
||||
* </code>
|
||||
* </pre>
|
||||
*
|
||||
* @author Nils Hoffman
|
||||
* @author Martin Pernollet
|
||||
*/
|
||||
public class OffscreenCanvas implements ICanvas {
|
||||
public OffscreenCanvas(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height) {
|
||||
this(factory, scene, quality, capabilities, width, height, false, false);
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
package org.jzy3d.plot3d.rendering.canvas;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.media.opengl.GLCapabilities;
|
||||
import javax.media.opengl.GLDrawable;
|
||||
|
||||
import org.jzy3d.chart.factories.IChartComponentFactory;
|
||||
import org.jzy3d.plot3d.rendering.scene.Scene;
|
||||
import org.jzy3d.plot3d.rendering.view.Renderer3d;
|
||||
import org.jzy3d.plot3d.rendering.view.View;
|
||||
|
||||
import com.jogamp.opengl.util.texture.TextureData;
|
||||
|
||||
public class VoidCanvas implements ICanvas{
|
||||
public VoidCanvas(IChartComponentFactory factory, Scene scene, Quality quality) {
|
||||
view = scene.newView(this, quality);
|
||||
renderer = factory.newRenderer(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GLDrawable getDrawable() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRendererWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRendererHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderer3d getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceRepaint() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureData screenshot() {
|
||||
throw new RuntimeException("Unsupported: " + INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureData screenshot(File file) throws IOException {
|
||||
throw new RuntimeException("Unsupported: " + INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMouseController(Object o) {}
|
||||
|
||||
@Override
|
||||
public void addKeyController(Object o) {}
|
||||
|
||||
@Override
|
||||
public void removeMouseController(Object o) {}
|
||||
|
||||
@Override
|
||||
public void removeKeyController(Object o) {}
|
||||
|
||||
@Override
|
||||
public String getDebugInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected View view;
|
||||
protected Renderer3d renderer;
|
||||
|
||||
protected static String INFO = VoidCanvas.class + " is not able to render anything and simply let you use Jzy3d geometry model";
|
||||
}
|
|
@ -27,32 +27,31 @@ import org.jzy3d.plot3d.rendering.view.layout.ColorbarViewportLayout;
|
|||
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
|
||||
|
||||
public class AWTChartComponentFactory extends ChartComponentFactory {
|
||||
public static Chart chart(Quality quality){
|
||||
public static Chart chart(Quality quality) {
|
||||
AWTChartComponentFactory f = new AWTChartComponentFactory();
|
||||
return f.newChart(quality, Toolkit.newt);
|
||||
}
|
||||
public static Chart chart(String toolkit){
|
||||
|
||||
public static Chart chart(String toolkit) {
|
||||
AWTChartComponentFactory f = new AWTChartComponentFactory();
|
||||
return f.newChart(AWTChart.DEFAULT_QUALITY, toolkit);
|
||||
return f.newChart(Chart.DEFAULT_QUALITY, toolkit);
|
||||
}
|
||||
|
||||
public static Chart chart(Quality quality, Toolkit toolkit){
|
||||
AWTChartComponentFactory f = new AWTChartComponentFactory();
|
||||
return f.newChart(quality, toolkit);
|
||||
}
|
||||
|
||||
public static Chart chart(Quality quality, String toolkit){
|
||||
|
||||
public static Chart chart(Quality quality, Toolkit toolkit) {
|
||||
AWTChartComponentFactory f = new AWTChartComponentFactory();
|
||||
return f.newChart(quality, toolkit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chart newChart(Quality quality, Toolkit toolkit){
|
||||
return new AWTChart(this, quality, toolkit.toString());
|
||||
public static Chart chart(Quality quality, String toolkit) {
|
||||
AWTChartComponentFactory f = new AWTChartComponentFactory();
|
||||
return f.newChart(quality, toolkit);
|
||||
}
|
||||
|
||||
public Chart newChart(Quality quality, String toolkit){
|
||||
return new AWTChart(this, quality, toolkit.toString());
|
||||
/* */
|
||||
|
||||
@Override
|
||||
public Chart newChart(IChartComponentFactory factory, Quality quality, String toolkit){
|
||||
return new AWTChart(factory, quality, toolkit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,166 +60,143 @@ public class AWTChartComponentFactory extends ChartComponentFactory {
|
|||
axe.setView(view);
|
||||
return axe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IViewportLayout newViewportLayout() {
|
||||
return new ColorbarViewportLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Scene scene, ICanvas canvas, Quality quality) {
|
||||
return new AWTView(this, scene, canvas, quality);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFrame newFrame(Chart chart, Rectangle bounds, String title) {
|
||||
Object canvas = chart.getCanvas();
|
||||
|
||||
// Use reflexion to access AWT dependant classes
|
||||
// They will not be available for Android
|
||||
@Override
|
||||
public View newView(Scene scene, ICanvas canvas, Quality quality) {
|
||||
return new AWTView(this, scene, canvas, quality);
|
||||
}
|
||||
|
||||
if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasAWT"))
|
||||
return newFrameAWT(chart, bounds, title, null); // FrameSWT works as
|
||||
// well
|
||||
else if (canvas instanceof CanvasNewtAwt)
|
||||
return newFrameAWT(chart, bounds, title, "[Newt]"); // FrameSWT
|
||||
// works as
|
||||
// well
|
||||
else if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasSwing"))
|
||||
return newFrameSwing(chart, bounds, title);
|
||||
else
|
||||
throw new RuntimeException(
|
||||
"No default frame could be found for the given Chart canvas: "
|
||||
+ canvas.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ICanvas initializeCanvas(Scene scene, Quality quality,
|
||||
String windowingToolkit, GLCapabilities capabilities,
|
||||
boolean traceGL, boolean debugGL) {
|
||||
@Override
|
||||
public IFrame newFrame(Chart chart, Rectangle bounds, String title) {
|
||||
Object canvas = chart.getCanvas();
|
||||
|
||||
// Use reflexion to access AWT dependant classes
|
||||
// They will not be available for Android
|
||||
|
||||
if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasAWT"))
|
||||
return newFrameAWT(chart, bounds, title, null); // FrameSWT works as
|
||||
// well
|
||||
else if (canvas instanceof CanvasNewtAwt)
|
||||
return newFrameAWT(chart, bounds, title, "[Newt]"); // FrameSWT
|
||||
// works as
|
||||
// well
|
||||
else if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasSwing"))
|
||||
return newFrameSwing(chart, bounds, title);
|
||||
else
|
||||
throw new RuntimeException("No default frame could be found for the given Chart canvas: " + canvas.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICanvas newCanvas(Scene scene, Quality quality, String windowingToolkit, GLCapabilities capabilities) {
|
||||
boolean traceGL = false;
|
||||
boolean debugGL = false;
|
||||
Toolkit chartType = getToolkit(windowingToolkit);
|
||||
switch (chartType) {
|
||||
case awt:
|
||||
return newCanvasAWT(this, scene, quality, capabilities, traceGL,
|
||||
debugGL);
|
||||
return newCanvasAWT(this, scene, quality, capabilities, traceGL, debugGL);
|
||||
case swing:
|
||||
Logger.getLogger(ChartComponentFactory.class).warn(
|
||||
"Swing canvas is deprecated. Use Newt instead");
|
||||
return newCanvasSwing(this, scene, quality, capabilities, traceGL,
|
||||
debugGL);
|
||||
Logger.getLogger(ChartComponentFactory.class).warn("Swing canvas is deprecated. Use Newt instead");
|
||||
return newCanvasSwing(this, scene, quality, capabilities, traceGL, debugGL);
|
||||
case newt:
|
||||
return new CanvasNewtAwt(this, scene, quality, capabilities, traceGL,
|
||||
debugGL);
|
||||
return new CanvasNewtAwt(this, scene, quality, capabilities, traceGL, debugGL);
|
||||
case offscreen:
|
||||
Dimension dimension = getCanvasDimension(windowingToolkit);
|
||||
return new OffscreenCanvas(this, scene, quality, capabilities,
|
||||
dimension.width, dimension.height, traceGL, debugGL);
|
||||
return new OffscreenCanvas(this, scene, quality, capabilities, dimension.width, dimension.height, traceGL, debugGL);
|
||||
default:
|
||||
throw new RuntimeException("unknown chart type:" + chartType);
|
||||
}
|
||||
}
|
||||
|
||||
/* UTILS */
|
||||
private IFrame newFrameSwing(Chart chart, Rectangle bounds, String title) {
|
||||
try {
|
||||
Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameSwing");
|
||||
IFrame frame = (IFrame) frameClass.newInstance();
|
||||
frame.initialize(chart, bounds, title);
|
||||
/* UTILS */
|
||||
|
||||
protected IFrame newFrameSwing(Chart chart, Rectangle bounds, String title) {
|
||||
try {
|
||||
Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameSwing");
|
||||
IFrame frame = (IFrame) frameClass.newInstance();
|
||||
frame.initialize(chart, bounds, title);
|
||||
return frame;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newFrameSwing", e);
|
||||
}
|
||||
}
|
||||
|
||||
return frame;
|
||||
protected IFrame newFrameAWT(Chart chart, Rectangle bounds, String title, String message) {
|
||||
try {
|
||||
Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameAWT");
|
||||
IFrame frame = (IFrame) frameClass.newInstance();
|
||||
if (message != null) {
|
||||
frame.initialize(chart, bounds, title, message);
|
||||
} else {
|
||||
frame.initialize(chart, bounds, title);
|
||||
}
|
||||
return frame;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newFrameSwing", e);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newFrameSwing", e);
|
||||
}
|
||||
}
|
||||
protected Toolkit getToolkit(String windowingToolkit) {
|
||||
if (windowingToolkit.startsWith("offscreen")) {
|
||||
return Toolkit.offscreen;
|
||||
}
|
||||
return Toolkit.valueOf(windowingToolkit);
|
||||
}
|
||||
|
||||
private IFrame newFrameAWT(Chart chart, Rectangle bounds, String title,
|
||||
String message) {
|
||||
try {
|
||||
Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameAWT");
|
||||
IFrame frame = (IFrame) frameClass.newInstance();
|
||||
if (message != null) {
|
||||
frame.initialize(chart, bounds, title, message);
|
||||
} else {
|
||||
frame.initialize(chart, bounds, title);
|
||||
}
|
||||
return frame;
|
||||
protected Dimension getCanvasDimension(String windowingToolkit) {
|
||||
if (windowingToolkit.startsWith("offscreen")) {
|
||||
Pattern pattern = Pattern.compile("offscreen,(\\d+),(\\d+)");
|
||||
Matcher matcher = pattern.matcher(windowingToolkit);
|
||||
if (matcher.matches()) {
|
||||
int width = Integer.parseInt(matcher.group(1));
|
||||
int height = Integer.parseInt(matcher.group(2));
|
||||
return new Dimension(width, height);
|
||||
} else {
|
||||
return new Dimension(500, 500);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newFrameSwing", e);
|
||||
}
|
||||
}
|
||||
protected ICanvas newCanvasSwing(ChartComponentFactory chartComponentFactory, Scene scene, Quality quality, GLCapabilities capabilities, boolean traceGL, boolean debugGL) {
|
||||
Class canvasSwingDefinition;
|
||||
Class[] constrArgsClass = new Class[] { IChartComponentFactory.class, Scene.class, Quality.class, GLCapabilitiesImmutable.class, boolean.class, boolean.class };
|
||||
Object[] constrArgs = new Object[] { chartComponentFactory, scene, quality, capabilities, traceGL, debugGL };
|
||||
Constructor constructor;
|
||||
ICanvas canvas;
|
||||
|
||||
protected Toolkit getToolkit(String windowingToolkit) {
|
||||
if (windowingToolkit.startsWith("offscreen")) {
|
||||
return Toolkit.offscreen;
|
||||
}
|
||||
return Toolkit.valueOf(windowingToolkit);
|
||||
}
|
||||
try {
|
||||
canvasSwingDefinition = Class.forName("org.jzy3d.plot3d.rendering.canvas.CanvasSwing");
|
||||
constructor = canvasSwingDefinition.getConstructor(constrArgsClass);
|
||||
|
||||
protected Dimension getCanvasDimension(String windowingToolkit) {
|
||||
if (windowingToolkit.startsWith("offscreen")) {
|
||||
Pattern pattern = Pattern.compile("offscreen,(\\d+),(\\d+)");
|
||||
Matcher matcher = pattern.matcher(windowingToolkit);
|
||||
if (matcher.matches()) {
|
||||
int width = Integer.parseInt(matcher.group(1));
|
||||
int height = Integer.parseInt(matcher.group(2));
|
||||
return new Dimension(width, height);
|
||||
} else {
|
||||
return new Dimension(500, 500);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return (ICanvas) constructor.newInstance(constrArgs);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newCanvasSwing", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ICanvas newCanvasSwing(ChartComponentFactory chartComponentFactory,
|
||||
Scene scene, Quality quality, GLCapabilities capabilities,
|
||||
boolean traceGL, boolean debugGL) {
|
||||
protected ICanvas newCanvasAWT(ChartComponentFactory chartComponentFactory, Scene scene, Quality quality, GLCapabilities capabilities, boolean traceGL, boolean debugGL) {
|
||||
Class canvasAWTDefinition;
|
||||
Class[] constrArgsClass = new Class[] { IChartComponentFactory.class, Scene.class, Quality.class, GLCapabilitiesImmutable.class, boolean.class, boolean.class };
|
||||
Object[] constrArgs = new Object[] { chartComponentFactory, scene, quality, capabilities, traceGL, debugGL };
|
||||
Constructor constructor;
|
||||
ICanvas canvas;
|
||||
|
||||
Class canvasSwingDefinition;
|
||||
Class[] constrArgsClass = new Class[] { IChartComponentFactory.class,
|
||||
Scene.class, Quality.class, GLCapabilitiesImmutable.class,
|
||||
boolean.class, boolean.class };
|
||||
Object[] constrArgs = new Object[] { chartComponentFactory, scene,
|
||||
quality, capabilities, traceGL, debugGL };
|
||||
Constructor constructor;
|
||||
ICanvas canvas;
|
||||
try {
|
||||
canvasAWTDefinition = Class.forName("org.jzy3d.plot3d.rendering.canvas.CanvasAWT");
|
||||
constructor = canvasAWTDefinition.getConstructor(constrArgsClass);
|
||||
|
||||
try {
|
||||
canvasSwingDefinition = Class
|
||||
.forName("org.jzy3d.plot3d.rendering.canvas.CanvasSwing");
|
||||
constructor = canvasSwingDefinition.getConstructor(constrArgsClass);
|
||||
|
||||
return (ICanvas) constructor.newInstance(constrArgs);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newCanvasSwing", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ICanvas newCanvasAWT(ChartComponentFactory chartComponentFactory,
|
||||
Scene scene, Quality quality, GLCapabilities capabilities,
|
||||
boolean traceGL, boolean debugGL) {
|
||||
|
||||
Class canvasAWTDefinition;
|
||||
Class[] constrArgsClass = new Class[] { IChartComponentFactory.class,
|
||||
Scene.class, Quality.class, GLCapabilitiesImmutable.class,
|
||||
boolean.class, boolean.class };
|
||||
Object[] constrArgs = new Object[] { chartComponentFactory, scene,
|
||||
quality, capabilities, traceGL, debugGL };
|
||||
Constructor constructor;
|
||||
ICanvas canvas;
|
||||
|
||||
try {
|
||||
canvasAWTDefinition = Class
|
||||
.forName("org.jzy3d.plot3d.rendering.canvas.CanvasAWT");
|
||||
constructor = canvasAWTDefinition.getConstructor(constrArgsClass);
|
||||
|
||||
return (ICanvas) constructor.newInstance(constrArgs);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newCanvasAWT", e);
|
||||
}
|
||||
}
|
||||
return (ICanvas) constructor.newInstance(constrArgs);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("newCanvasAWT", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,15 +45,17 @@ import org.jzy3d.plot3d.text.renderers.TextBitmapRenderer;
|
|||
*/
|
||||
public class TextOverlay implements Renderer2d{
|
||||
public TextOverlay(ICanvas canvas){
|
||||
if(canvas instanceof CanvasAWT)
|
||||
initComponent((Component)canvas);
|
||||
else if(canvas instanceof CanvasSwing)
|
||||
init(canvas);
|
||||
}
|
||||
|
||||
protected void init(ICanvas canvas) {
|
||||
if(canvas instanceof CanvasAWT)
|
||||
initComponent((Component)canvas);
|
||||
else
|
||||
throw new RuntimeException("TextRenderer not implemented for this Canvas implementation");
|
||||
}
|
||||
}
|
||||
|
||||
private void initComponent(Component c){
|
||||
protected void initComponent(Component c){
|
||||
textList = new ArrayList<TextDescriptor>(50);
|
||||
target = c;
|
||||
target.addComponentListener(resizeListener);
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.jzy3d.chart;
|
||||
|
||||
import javax.media.opengl.GLCapabilities;
|
||||
|
||||
import org.jzy3d.chart.factories.IChartComponentFactory;
|
||||
import org.jzy3d.chart.factories.SwingChartComponentFactory;
|
||||
import org.jzy3d.chart.factories.IChartComponentFactory.Toolkit;
|
||||
import org.jzy3d.plot3d.rendering.canvas.Quality;
|
||||
import org.jzy3d.plot3d.rendering.view.AWTView;
|
||||
import org.jzy3d.plot3d.rendering.view.Renderer2d;
|
||||
|
||||
public class SwingChart extends Chart {
|
||||
public SwingChart(Quality quality) {
|
||||
super(new SwingChartComponentFactory(), quality);
|
||||
}
|
||||
|
||||
public SwingChart(IChartComponentFactory factory, Quality quality, GLCapabilities capabilities) {
|
||||
super(factory, quality, Toolkit.swing.toString(), capabilities);
|
||||
}
|
||||
|
||||
public SwingChart(IChartComponentFactory factory, Quality quality, String toolkit) {
|
||||
super(factory, quality, toolkit);
|
||||
}
|
||||
|
||||
|
||||
public SwingChart() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SwingChart(IChartComponentFactory factory, Quality quality) {
|
||||
super(factory, quality);
|
||||
}
|
||||
|
||||
public SwingChart(String windowingToolkit) {
|
||||
super(windowingToolkit);
|
||||
}
|
||||
|
||||
public void addRenderer(Renderer2d renderer2d) {
|
||||
getAWTView().addRenderer2d(renderer2d);
|
||||
}
|
||||
|
||||
public void removeRenderer(Renderer2d renderer2d) {
|
||||
getAWTView().removeRenderer2d(renderer2d);
|
||||
}
|
||||
|
||||
protected AWTView getAWTView() {
|
||||
return (AWTView) view;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package org.jzy3d.chart.factories;
|
||||
|
||||
import javax.media.opengl.GLCapabilities;
|
||||
|
||||
import org.jzy3d.chart.Chart;
|
||||
import org.jzy3d.chart.SwingChart;
|
||||
import org.jzy3d.plot3d.rendering.canvas.CanvasSwing;
|
||||
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
|
||||
import org.jzy3d.plot3d.rendering.canvas.Quality;
|
||||
import org.jzy3d.plot3d.rendering.scene.Scene;
|
||||
|
||||
public class SwingChartComponentFactory extends AWTChartComponentFactory {
|
||||
@Override
|
||||
public Chart newChart(IChartComponentFactory factory, Quality quality, String toolkit){
|
||||
return new SwingChart(factory, quality, toolkit.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICanvas newCanvas(Scene scene, Quality quality, String windowingToolkit, GLCapabilities capabilities) {
|
||||
boolean traceGL = false;
|
||||
boolean debugGL = false;
|
||||
return new CanvasSwing(this, scene, quality, capabilities, traceGL, debugGL);
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
public static Chart chart(Quality quality){
|
||||
IChartComponentFactory f = new SwingChartComponentFactory();
|
||||
return f.newChart(quality, Toolkit.newt);
|
||||
}
|
||||
public static Chart chart(String toolkit){
|
||||
IChartComponentFactory f = new SwingChartComponentFactory();
|
||||
return f.newChart(SwingChart.DEFAULT_QUALITY, toolkit);
|
||||
}
|
||||
|
||||
public static Chart chart(Quality quality, Toolkit toolkit){
|
||||
IChartComponentFactory f = new SwingChartComponentFactory();
|
||||
return f.newChart(quality, toolkit);
|
||||
}
|
||||
|
||||
public static Chart chart(Quality quality, String toolkit){
|
||||
IChartComponentFactory f = new SwingChartComponentFactory();
|
||||
return f.newChart(quality, toolkit);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.jzy3d.plot3d.text.overlay;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.List;
|
||||
|
||||
import javax.media.opengl.GL;
|
||||
import javax.media.opengl.glu.GLU;
|
||||
|
||||
import org.jzy3d.colors.Color;
|
||||
import org.jzy3d.maths.Coord2d;
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
import org.jzy3d.plot3d.rendering.canvas.CanvasSwing;
|
||||
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
|
||||
import org.jzy3d.plot3d.rendering.view.Camera;
|
||||
import org.jzy3d.plot3d.text.align.Halign;
|
||||
import org.jzy3d.plot3d.text.align.Valign;
|
||||
|
||||
|
||||
public class SwingTextOverlay extends TextOverlay{
|
||||
public SwingTextOverlay(ICanvas canvas){
|
||||
super(canvas);
|
||||
}
|
||||
|
||||
protected void init(ICanvas canvas) {
|
||||
if(canvas instanceof CanvasSwing)
|
||||
initComponent((Component)canvas);
|
||||
else
|
||||
super.init(canvas);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue