extracting a SwingChart to ease the use of CanvasSwing (although deprecated)

This commit is contained in:
Martin Pernollet 2013-06-06 14:43:48 +02:00
parent 295102e0a2
commit b0e799367d
10 changed files with 407 additions and 191 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/tests"/> <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/api"/>
<classpathentry including="**/*.java" kind="src" path="src/bridge"/> <classpathentry including="**/*.java" kind="src" path="src/bridge"/>
<classpathentry including="**/*.java" kind="src" path="src/awt"/> <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 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-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"/> <classpathentry exported="true" kind="var" path="M2_REPO/org/jogamp/gluegen/gluegen-rt/2.0-rc11/gluegen-rt-2.0-rc11.jar"/>

View File

@ -4,28 +4,34 @@ import java.util.Date;
import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilities;
import org.apache.log4j.Logger;
import org.jzy3d.bridge.IFrame; import org.jzy3d.bridge.IFrame;
import org.jzy3d.chart.Chart; import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartScene; import org.jzy3d.chart.ChartScene;
import org.jzy3d.chart.ChartView; import org.jzy3d.chart.ChartView;
import org.jzy3d.chart.controllers.keyboard.camera.AWTCameraKeyController; 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.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;
import org.jzy3d.chart.controllers.keyboard.screenshot.IScreenshotKeyController.IScreenshotEventListener; 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.keyboard.screenshot.NewtScreenshotKeyController;
import org.jzy3d.chart.controllers.mouse.camera.AWTCameraMouseController; 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.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.BoundingBox3d;
import org.jzy3d.maths.Coord3d; import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Dimension;
import org.jzy3d.maths.Rectangle; import org.jzy3d.maths.Rectangle;
import org.jzy3d.maths.Utils; import org.jzy3d.maths.Utils;
import org.jzy3d.plot3d.primitives.axes.AxeBase; import org.jzy3d.plot3d.primitives.axes.AxeBase;
import org.jzy3d.plot3d.primitives.axes.IAxe; 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.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.OffscreenCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality; 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.AbstractOrderingStrategy;
import org.jzy3d.plot3d.rendering.ordering.BarycentreOrderingStrategy; import org.jzy3d.plot3d.rendering.ordering.BarycentreOrderingStrategy;
import org.jzy3d.plot3d.rendering.scene.Scene; 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.View;
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout; 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 class ChartComponentFactory implements IChartComponentFactory {
public static Chart chart(Quality quality, Toolkit toolkit){ public static Chart chart(Quality quality, Toolkit toolkit){
ChartComponentFactory f = new ChartComponentFactory(); ChartComponentFactory f = new ChartComponentFactory();
return f.newChart(quality, toolkit); 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 @Override
public Chart newChart(Quality quality, Toolkit toolkit){ 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 @Override
public ChartScene newScene(boolean sort) { public ChartScene newScene(boolean sort) {
return new ChartScene(sort, this); return new ChartScene(sort, this);
@ -71,14 +86,18 @@ public class ChartComponentFactory implements IChartComponentFactory {
return new Renderer3d(view, traceGL, debugGL); return new Renderer3d(view, traceGL, debugGL);
} }
@Override @Override
public Renderer3d newRenderer(View view) {
return newRenderer(view, false, false);
}
@Override
public AbstractOrderingStrategy newOrderingStrategy() { public AbstractOrderingStrategy newOrderingStrategy() {
return new BarycentreOrderingStrategy(); return new BarycentreOrderingStrategy();
} }
@Override @Override
public ICanvas newCanvas(Scene scene, Quality quality, String chartType, public ICanvas newCanvas(Scene scene, Quality quality, String chartType,
GLCapabilities capabilities) { GLCapabilities capabilities) {
return initializeCanvas(scene, quality, chartType, capabilities, false, return new VoidCanvas(this, scene, quality);
false);
} }
@Override @Override

View File

@ -22,35 +22,25 @@ import org.jzy3d.plot3d.rendering.view.View;
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout; import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
public interface IChartComponentFactory { public interface IChartComponentFactory {
public abstract Chart newChart(Quality quality, Toolkit toolkit); public Chart newChart(Quality quality, Toolkit toolkit);
public Chart newChart(Quality quality, String toolkit);
public abstract ChartScene newScene(boolean sort); public Chart newChart(IChartComponentFactory factory, Quality quality, String toolkit);
public abstract View newView(Scene scene, ICanvas canvas, Quality quality); public ChartScene newScene(boolean sort);
public View newView(Scene scene, ICanvas canvas, Quality quality);
public abstract Camera newCamera(Coord3d center); public Camera newCamera(Coord3d center);
public IAxe newAxe(BoundingBox3d box, View view);
public abstract IAxe newAxe(BoundingBox3d box, View view); public Renderer3d newRenderer(View view);
public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL);
public abstract Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL); public AbstractOrderingStrategy newOrderingStrategy();
public ICanvas newCanvas(Scene scene, Quality quality, String chartType, GLCapabilities capabilities);
public abstract AbstractOrderingStrategy newOrderingStrategy();
public abstract ICanvas newCanvas(Scene scene, Quality quality, String chartType, GLCapabilities capabilities);
public ICameraMouseController newMouseController(Chart chart); public ICameraMouseController newMouseController(Chart chart);
public ICameraKeyController newKeyController(Chart chart); public ICameraKeyController newKeyController(Chart chart);
public IScreenshotKeyController newScreenshotKeyController(Chart chart); public IScreenshotKeyController newScreenshotKeyController(Chart chart);
public IFrame newFrame(Chart chart, Rectangle bounds, String title); public IFrame newFrame(Chart chart, Rectangle bounds, String title);
public IViewportLayout newViewportLayout(); public IViewportLayout newViewportLayout();
public static enum Toolkit { public static enum Toolkit {
awt, swing, newt, offscreen awt, swing, newt, offscreen
}; };
} }

View File

@ -16,11 +16,23 @@ import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Renderer3d; import org.jzy3d.plot3d.rendering.view.Renderer3d;
import org.jzy3d.plot3d.rendering.view.View; 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.TextureData;
import com.jogamp.opengl.util.texture.TextureIO; 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 class OffscreenCanvas implements ICanvas {
public OffscreenCanvas(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height) { public OffscreenCanvas(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height) {
this(factory, scene, quality, capabilities, width, height, false, false); this(factory, scene, quality, capabilities, width, height, false, false);

View File

@ -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";
}

View File

@ -27,32 +27,31 @@ import org.jzy3d.plot3d.rendering.view.layout.ColorbarViewportLayout;
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout; import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
public class AWTChartComponentFactory extends ChartComponentFactory { public class AWTChartComponentFactory extends ChartComponentFactory {
public static Chart chart(Quality quality){ public static Chart chart(Quality quality) {
AWTChartComponentFactory f = new AWTChartComponentFactory(); AWTChartComponentFactory f = new AWTChartComponentFactory();
return f.newChart(quality, Toolkit.newt); return f.newChart(quality, Toolkit.newt);
} }
public static Chart chart(String toolkit){
public static Chart chart(String toolkit) {
AWTChartComponentFactory f = new AWTChartComponentFactory(); 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){ 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){
AWTChartComponentFactory f = new AWTChartComponentFactory(); AWTChartComponentFactory f = new AWTChartComponentFactory();
return f.newChart(quality, toolkit); return f.newChart(quality, toolkit);
} }
@Override public static Chart chart(Quality quality, String toolkit) {
public Chart newChart(Quality quality, Toolkit toolkit){ AWTChartComponentFactory f = new AWTChartComponentFactory();
return new AWTChart(this, quality, toolkit.toString()); 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 @Override
@ -61,166 +60,143 @@ public class AWTChartComponentFactory extends ChartComponentFactory {
axe.setView(view); axe.setView(view);
return axe; return axe;
} }
@Override @Override
public IViewportLayout newViewportLayout() { public IViewportLayout newViewportLayout() {
return new ColorbarViewportLayout(); 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 @Override
// They will not be available for Android 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")) @Override
return newFrameAWT(chart, bounds, title, null); // FrameSWT works as public IFrame newFrame(Chart chart, Rectangle bounds, String title) {
// well Object canvas = chart.getCanvas();
else if (canvas instanceof CanvasNewtAwt)
return newFrameAWT(chart, bounds, title, "[Newt]"); // FrameSWT // Use reflexion to access AWT dependant classes
// works as // They will not be available for Android
// well
else if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasSwing")) if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasAWT"))
return newFrameSwing(chart, bounds, title); return newFrameAWT(chart, bounds, title, null); // FrameSWT works as
else // well
throw new RuntimeException( else if (canvas instanceof CanvasNewtAwt)
"No default frame could be found for the given Chart canvas: " return newFrameAWT(chart, bounds, title, "[Newt]"); // FrameSWT
+ canvas.getClass()); // works as
} // well
else if (canvas.getClass().getName().equals("org.jzy3d.plot3d.rendering.canvas.CanvasSwing"))
@Override return newFrameSwing(chart, bounds, title);
protected ICanvas initializeCanvas(Scene scene, Quality quality, else
String windowingToolkit, GLCapabilities capabilities, throw new RuntimeException("No default frame could be found for the given Chart canvas: " + canvas.getClass());
boolean traceGL, boolean debugGL) { }
@Override
public ICanvas newCanvas(Scene scene, Quality quality, String windowingToolkit, GLCapabilities capabilities) {
boolean traceGL = false;
boolean debugGL = false;
Toolkit chartType = getToolkit(windowingToolkit); Toolkit chartType = getToolkit(windowingToolkit);
switch (chartType) { switch (chartType) {
case awt: case awt:
return newCanvasAWT(this, scene, quality, capabilities, traceGL, return newCanvasAWT(this, scene, quality, capabilities, traceGL, debugGL);
debugGL);
case swing: case swing:
Logger.getLogger(ChartComponentFactory.class).warn( Logger.getLogger(ChartComponentFactory.class).warn("Swing canvas is deprecated. Use Newt instead");
"Swing canvas is deprecated. Use Newt instead"); return newCanvasSwing(this, scene, quality, capabilities, traceGL, debugGL);
return newCanvasSwing(this, scene, quality, capabilities, traceGL,
debugGL);
case newt: case newt:
return new CanvasNewtAwt(this, scene, quality, capabilities, traceGL, return new CanvasNewtAwt(this, scene, quality, capabilities, traceGL, debugGL);
debugGL);
case offscreen: case offscreen:
Dimension dimension = getCanvasDimension(windowingToolkit); Dimension dimension = getCanvasDimension(windowingToolkit);
return new OffscreenCanvas(this, scene, quality, capabilities, return new OffscreenCanvas(this, scene, quality, capabilities, dimension.width, dimension.height, traceGL, debugGL);
dimension.width, dimension.height, traceGL, debugGL);
default: default:
throw new RuntimeException("unknown chart type:" + chartType); throw new RuntimeException("unknown chart type:" + chartType);
} }
} }
/* UTILS */ /* UTILS */
private IFrame newFrameSwing(Chart chart, Rectangle bounds, String title) {
try { protected IFrame newFrameSwing(Chart chart, Rectangle bounds, String title) {
Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameSwing"); try {
IFrame frame = (IFrame) frameClass.newInstance(); Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameSwing");
frame.initialize(chart, bounds, title); 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) { protected Toolkit getToolkit(String windowingToolkit) {
e.printStackTrace(); if (windowingToolkit.startsWith("offscreen")) {
throw new RuntimeException("newFrameSwing", e); return Toolkit.offscreen;
} }
} return Toolkit.valueOf(windowingToolkit);
}
private IFrame newFrameAWT(Chart chart, Rectangle bounds, String title, protected Dimension getCanvasDimension(String windowingToolkit) {
String message) { if (windowingToolkit.startsWith("offscreen")) {
try { Pattern pattern = Pattern.compile("offscreen,(\\d+),(\\d+)");
Class frameClass = Class.forName("org.jzy3d.bridge.awt.FrameAWT"); Matcher matcher = pattern.matcher(windowingToolkit);
IFrame frame = (IFrame) frameClass.newInstance(); if (matcher.matches()) {
if (message != null) { int width = Integer.parseInt(matcher.group(1));
frame.initialize(chart, bounds, title, message); int height = Integer.parseInt(matcher.group(2));
} else { return new Dimension(width, height);
frame.initialize(chart, bounds, title); } else {
} return new Dimension(500, 500);
return frame; }
}
return null;
}
} catch (Exception e) { protected ICanvas newCanvasSwing(ChartComponentFactory chartComponentFactory, Scene scene, Quality quality, GLCapabilities capabilities, boolean traceGL, boolean debugGL) {
e.printStackTrace(); Class canvasSwingDefinition;
throw new RuntimeException("newFrameSwing", e); 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) { try {
if (windowingToolkit.startsWith("offscreen")) { canvasSwingDefinition = Class.forName("org.jzy3d.plot3d.rendering.canvas.CanvasSwing");
return Toolkit.offscreen; constructor = canvasSwingDefinition.getConstructor(constrArgsClass);
}
return Toolkit.valueOf(windowingToolkit);
}
protected Dimension getCanvasDimension(String windowingToolkit) { return (ICanvas) constructor.newInstance(constrArgs);
if (windowingToolkit.startsWith("offscreen")) { } catch (Exception e) {
Pattern pattern = Pattern.compile("offscreen,(\\d+),(\\d+)"); e.printStackTrace();
Matcher matcher = pattern.matcher(windowingToolkit); throw new RuntimeException("newCanvasSwing", e);
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;
}
private ICanvas newCanvasSwing(ChartComponentFactory chartComponentFactory, protected ICanvas newCanvasAWT(ChartComponentFactory chartComponentFactory, Scene scene, Quality quality, GLCapabilities capabilities, boolean traceGL, boolean debugGL) {
Scene scene, Quality quality, GLCapabilities capabilities, Class canvasAWTDefinition;
boolean traceGL, boolean debugGL) { 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; try {
Class[] constrArgsClass = new Class[] { IChartComponentFactory.class, canvasAWTDefinition = Class.forName("org.jzy3d.plot3d.rendering.canvas.CanvasAWT");
Scene.class, Quality.class, GLCapabilitiesImmutable.class, constructor = canvasAWTDefinition.getConstructor(constrArgsClass);
boolean.class, boolean.class };
Object[] constrArgs = new Object[] { chartComponentFactory, scene,
quality, capabilities, traceGL, debugGL };
Constructor constructor;
ICanvas canvas;
try { return (ICanvas) constructor.newInstance(constrArgs);
canvasSwingDefinition = Class } catch (Exception e) {
.forName("org.jzy3d.plot3d.rendering.canvas.CanvasSwing"); e.printStackTrace();
constructor = canvasSwingDefinition.getConstructor(constrArgsClass); throw new RuntimeException("newCanvasAWT", e);
}
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);
}
}
} }

View File

@ -45,15 +45,17 @@ import org.jzy3d.plot3d.text.renderers.TextBitmapRenderer;
*/ */
public class TextOverlay implements Renderer2d{ public class TextOverlay implements Renderer2d{
public TextOverlay(ICanvas canvas){ public TextOverlay(ICanvas canvas){
if(canvas instanceof CanvasAWT) init(canvas);
initComponent((Component)canvas); }
else if(canvas instanceof CanvasSwing)
protected void init(ICanvas canvas) {
if(canvas instanceof CanvasAWT)
initComponent((Component)canvas); initComponent((Component)canvas);
else else
throw new RuntimeException("TextRenderer not implemented for this Canvas implementation"); 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); textList = new ArrayList<TextDescriptor>(50);
target = c; target = c;
target.addComponentListener(resizeListener); target.addComponentListener(resizeListener);

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}