Ensure EmulGLPainter is able to return its appropriate target windowing toolkit (AWT)

This commit is contained in:
Martin Pernollet 2022-07-28 14:04:14 +02:00
parent fecb536c59
commit 9208118d4d
2 changed files with 24 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.Array;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.os.WindowingToolkit;
import org.jzy3d.plot3d.pipelines.NotImplementedException;
import org.jzy3d.plot3d.primitives.PolygonFill;
import org.jzy3d.plot3d.primitives.PolygonMode;
@ -39,6 +40,16 @@ public class EmulGLPainter extends AbstractPainter implements IPainter {
/** A 1x1 image used for processing text length in pixel if no context is available */
protected BufferedImage textLengthFallbackImage;
protected FontMetrics fontMetricsFallback;
@Override
public WindowingToolkit getWindowingToolkit() {
String name = getCanvas().getClass().getSimpleName();
if (name.indexOf("EmulGLCanvas") >= 0) {
return WindowingToolkit.AWT;
}
return WindowingToolkit.UNKOWN;
}
public GL getGL() {

View File

@ -1,5 +1,6 @@
package org.jzy3d.painters;
import static org.mockito.Mockito.mock;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@ -13,10 +14,12 @@ import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.chart.factories.IPainterFactory;
import org.jzy3d.junit.ChartTester;
import org.jzy3d.maths.Range;
import org.jzy3d.os.WindowingToolkit;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.SurfaceBuilder;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas;
public class TestEmulGLPainterFactory {
@Test
@ -67,4 +70,14 @@ public class TestEmulGLPainterFactory {
surface.setFaceDisplayed(true);
return surface;
}
@Test
public void detectAWT() {
IPainterFactory p = new EmulGLPainterFactory();
IPainter painter = p.newPainter();
painter.setCanvas(mock(EmulGLCanvas.class));
Assert.assertEquals(WindowingToolkit.AWT, painter.getWindowingToolkit());
}
}