提交 20d6a1d1 编写于 作者: M Mathieu Bastian

Decouple canvas initialization from instances initialization

上级 ef1f9546
......@@ -83,6 +83,11 @@ public class OffscreenCanvas extends GLAbstractListener implements TileRendererB
this.transparentBackground = transparentBackground;
}
@Override
protected GLAutoDrawable initDrawable() {
return drawable;
}
@Override
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
......
......@@ -49,6 +49,7 @@ import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLDrawable;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.glu.GLU;
......@@ -59,6 +60,8 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPopupMenu;
import javax.swing.ToolTipManager;
import org.gephi.lib.gleem.linalg.Vec3f;
import org.gephi.visualization.VizArchitecture;
import org.gephi.visualization.VizController;
......@@ -82,7 +85,7 @@ public abstract class GLAbstractListener implements GLEventListener, VizArchitec
public final float viewField = 30.0f;
public final float nearDistance = 1.0f;
public final float farDistance = 150000f;
public Component graphComponent;
protected Component graphComponent;
//Architecture
protected GLAutoDrawable drawable;
protected VizController vizController;
......@@ -116,10 +119,7 @@ public abstract class GLAbstractListener implements GLEventListener, VizArchitec
this.vizController = VizController.getInstance();
}
protected void initDrawable(GLAutoDrawable drawable) {
this.drawable = drawable;
drawable.addGLEventListener(this);
}
protected abstract GLAutoDrawable initDrawable();
@Override
public void initArchitecture() {
......@@ -129,8 +129,6 @@ public abstract class GLAbstractListener implements GLEventListener, VizArchitec
cameraLocation = vizController.getVizConfig().getDefaultCameraPosition();
cameraTarget = vizController.getVizConfig().getDefaultCameraTarget();
initMouseEvents();
}
@Override
......@@ -544,7 +542,19 @@ public abstract class GLAbstractListener implements GLEventListener, VizArchitec
}
@Override
public Component getGraphComponent() {
public synchronized Component getGraphComponent() {
if (this.drawable == null) {
// Also expected to init the graphComponent
this.drawable = initDrawable();
//False lets the components appear on top of the canvas
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
drawable.addGLEventListener(this);
initMouseEvents();
}
return graphComponent;
}
......
......@@ -43,6 +43,7 @@
package org.gephi.visualization.swing;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.util.gl2.GLUT;
......@@ -58,28 +59,21 @@ import org.gephi.ui.utils.UIUtils;
*/
public class GraphCanvas extends GLAbstractListener {
private final GLCanvas glCanvas;
private final GLUT glut = new GLUT();
public GraphCanvas() {
super();
glCanvas = new GLCanvas(getCaps());
super.initDrawable(glCanvas);
@Override
protected GLAutoDrawable initDrawable() {
GLCanvas glCanvas = new GLCanvas(getCaps());
// glCanvas.setMinimumSize(new Dimension(0, 0)); //Fix Canvas resize Issue
//Basic init
graphComponent = (Component) glCanvas;
// graphComponent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
graphComponent = glCanvas;
//False lets the components appear on top of the canvas
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
return glCanvas;
}
@Override
protected void init(GL2 gl) {
globalScale = glCanvas.getCurrentSurfaceScale(new float[2])[0];
globalScale = ((GLCanvas)drawable).getCurrentSurfaceScale(new float[2])[0];
engine.startDisplay();
}
......
......@@ -45,6 +45,7 @@ package org.gephi.visualization.swing;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.util.gl2.GLUT;
......@@ -58,18 +59,15 @@ import org.gephi.ui.utils.UIUtils;
*/
public class NewtGraphCanvas extends GLAbstractListener {
private final NewtCanvasAWT glCanvas;
private final GLWindow glWindow;
private final GLUT glut = new GLUT();
public NewtGraphCanvas() {
super();
glWindow = GLWindow.create(getCaps());
@Override
protected GLAutoDrawable initDrawable() {
GLWindow glWindow = GLWindow.create(getCaps());
// glWindow.setSurfaceScale(new float[]{ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE});
glCanvas = new HighDPIFixCanvas(glWindow);
NewtCanvasAWT glCanvas = new HighDPIFixCanvas(glWindow);
// glCanvas = new NewtCanvasAWT(glWindow);
super.initDrawable(glWindow);
// glCanvas.setFocusable(true);
// glCanvas.setIgnoreRepaint(true);
// glCanvas.setMinimumSize(new Dimension(0, 0)); //Fix Canvas resize Issue
......@@ -80,15 +78,13 @@ public class NewtGraphCanvas extends GLAbstractListener {
window = glWindow;
// graphComponent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//False lets the components appear on top of the canvas
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
return glWindow;
}
@Override
protected void init(GL2 gl) {
// globalScale = glWindow.getCurrentSurfaceScale(new float[2])[0];
globalScale = (float) glCanvas.getGraphicsConfiguration().getDefaultTransform().getScaleX();
globalScale = (float) ((NewtCanvasAWT)drawable).getGraphicsConfiguration().getDefaultTransform().getScaleX();
engine.startDisplay();
}
......@@ -97,8 +93,9 @@ public class NewtGraphCanvas extends GLAbstractListener {
if (UIUtils.isAquaLookAndFeel()) {
// Only used when collapse panel is set visible
// Workaround for JOGL bug 1274
glCanvas.setNEWTChild(null);
glCanvas.setNEWTChild(glWindow);
// glCanvas.setNEWTChild(null);
// glCanvas.setNEWTChild(glWindow);
} else {
// Fix issue when closing the collapse panel
Container c = graphComponent.getParent();
......@@ -145,7 +142,7 @@ public class NewtGraphCanvas extends GLAbstractListener {
@Override
public void destroy() {
super.destroy();
glCanvas.getNEWTChild().destroy();
((NewtCanvasAWT)drawable).getNEWTChild().destroy();
}
public class HighDPIFixCanvas extends NewtCanvasAWT {
......
......@@ -69,7 +69,6 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
//Architecture
protected GLAbstractListener graphDrawable;
protected Component graphComponent;
protected AbstractEngine engine;
protected VizEventManager vizEventManager;
protected VizController vizController;
......@@ -92,7 +91,6 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
@Override
public void initArchitecture() {
this.graphDrawable = (GLAbstractListener) VizController.getInstance().getDrawable();
this.graphComponent = graphDrawable.graphComponent;
this.engine = VizController.getInstance().getEngine();
this.vizEventManager = VizController.getInstance().getVizEventManager();
this.vizController = VizController.getInstance();
......@@ -133,7 +131,7 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
rightButtonMoving[1] = y;
//Change cursor
graphComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
graphDrawable.getGraphComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
}
//Dispatch event
......@@ -179,7 +177,7 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
vizEventManager.stopDrag();
} else {
//Set default cursor
graphComponent.setCursor(Cursor.getDefaultCursor());
graphDrawable.getGraphComponent().setCursor(Cursor.getDefaultCursor());
}
//Dispatch event
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册