Graphics: allow interactions when axes are in a frame 46/14346/2
Calixte DENIZET [Fri, 4 Apr 2014 14:39:40 +0000 (16:39 +0200)]
Change-Id: I04cd368957aebb34b7ecec1501fdb7563d7abac2

scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/frame/SwingScilabFrame.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/AxesHandler.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/CommonHandler.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/DataEditor.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/EntityPicker.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/GEDPicker.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/DrawerVisitor.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java

index b59f8f1..fd83192 100644 (file)
@@ -76,6 +76,7 @@ import org.scilab.modules.gui.checkbox.CheckBox;
 import org.scilab.modules.gui.console.Console;
 import org.scilab.modules.gui.dockable.Dockable;
 import org.scilab.modules.gui.editbox.EditBox;
+import org.scilab.modules.gui.editor.EditorEventListener;
 import org.scilab.modules.gui.events.callback.CommonCallBack;
 import org.scilab.modules.gui.frame.Frame;
 import org.scilab.modules.gui.frame.SimpleFrame;
@@ -111,6 +112,7 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
     protected boolean hasLayout = false;
     private Border defaultBorder = null;
     private SwingScilabCanvas canvas = null;
+    private EditorEventListener editorEventHandler = null;
 
     /**
      * Constructor
@@ -225,8 +227,14 @@ public class SwingScilabFrame extends JPanel implements SwingViewObject, SimpleF
 
         if (member instanceof SwingScilabAxes) {
             if (canvas == null) {
+                editorEventHandler = new EditorEventListener(getId());
                 AxesContainer frame = (AxesContainer) GraphicModel.getModel().getObjectFromId(getId());
                 canvas = new SwingScilabCanvas(frame);
+                canvas.addEventHandlerKeyListener(editorEventHandler);
+                canvas.addEventHandlerMouseListener(editorEventHandler);
+                canvas.addEventHandlerMouseMotionListener(editorEventHandler);
+                editorEventHandler.setEnable(true);
+
                 setLayout(new GridLayout(1, 1));
                 hasLayout = true;
                 add(canvas);
index da05d07..abca19a 100644 (file)
 package org.scilab.modules.gui.editor;
 
 import java.lang.Math;
+
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 import org.scilab.modules.graphic_objects.axes.Axes;
+import org.scilab.modules.graphic_objects.axes.AxesContainer;
 import org.scilab.modules.graphic_objects.ScilabNativeView;
 
 import org.scilab.modules.gui.editor.ObjectSearcher;
 import org.scilab.modules.gui.editor.PolylineHandler;
 
-
-
-
 /**
 * Implements all axes manipulation functions for the editor.
 *
@@ -60,7 +60,9 @@ public class AxesHandler {
         if (axes == null) {
             return lastAxes;
         }
-        Integer[] figureSize = (Integer[])GraphicController.getController().getProperty(figure, GraphicObjectProperties.__GO_AXES_SIZE__);
+
+        AxesContainer container = (AxesContainer) GraphicController.getController().getObjectFromId(figure);
+        Integer[] figureSize = container.getAxesSize();
 
         for (Integer i = 0; i < axes.length; i++) {
             Double[] axesBound = (Double[])GraphicController.getController().getProperty(axes[i], GraphicObjectProperties.__GO_AXES_BOUNDS__);
index b03eaa5..e7ff664 100644 (file)
@@ -254,8 +254,8 @@ public class CommonHandler {
      * @return the parent igure UID
      */
     public static Integer getParentFigure(Integer object) {
-
-        return (Integer)GraphicController.getController().getProperty(object, GraphicObjectProperties.__GO_PARENT_FIGURE__);
+        GraphicObject go = GraphicController.getController().getObjectFromId(object);
+        return go.getParentFrameOrFigure();
     }
 
     /**
index cebbc0c..54648f6 100644 (file)
@@ -20,6 +20,7 @@ import java.awt.event.ActionEvent;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 import org.scilab.modules.graphic_objects.axes.Axes;
 import org.scilab.modules.renderer.CallRenderer;
@@ -209,14 +210,16 @@ public class DataEditor {
     public void onLeftMouseDown(MouseEvent event) {
         picked = picker.pickPoint(curPolyline, event.getX(), event.getY());
         if (picked != null && picked.point != -1) {
-            Integer figureUid = (Integer) GraphicController.getController().getProperty(curPolyline, GraphicObjectProperties.__GO_PARENT_FIGURE__);
+            GraphicObject go =         GraphicController.getController().getObjectFromId(curPolyline);
+            Integer figureUid = go.getParentFrameOrFigure();
             DrawerVisitor.getVisitor(figureUid).getInteractionManager().setTranslationEnable(false);
         }
     }
 
     public void onLeftMouseRelease(MouseEvent event) {
         if (picked != null && picked.point != -1) {
-            Integer figureUid = (Integer) GraphicController.getController().getProperty(curPolyline, GraphicObjectProperties.__GO_PARENT_FIGURE__);
+            GraphicObject go =         GraphicController.getController().getObjectFromId(curPolyline);
+            Integer figureUid = go.getParentFrameOrFigure();
             DrawerVisitor.getVisitor(figureUid).getInteractionManager().setTranslationEnable(true);
         }
     }
index 89bae2a..6afbd20 100644 (file)
@@ -20,6 +20,7 @@ import org.scilab.modules.graphic_objects.CallGraphicController;
 import org.scilab.modules.renderer.CallRenderer;
 
 import org.scilab.modules.graphic_objects.axes.Axes;
+import org.scilab.modules.graphic_objects.axes.AxesContainer;
 import org.scilab.modules.renderer.JoGLView.axes.AxesDrawer;
 import org.scilab.modules.renderer.JoGLView.DrawerVisitor;
 import org.scilab.forge.scirenderer.tranformations.Vector3d;
@@ -474,7 +475,6 @@ public class EntityPicker {
      * @return The LegendInfo if picked a legend null otherwise.
      */
     public LegendInfo pickLegend(Integer figure, Integer[] position) {
-
         Integer axes = AxesHandler.clickedAxes(figure, position);
         if (axes == null) {
             return null;
@@ -489,7 +489,9 @@ public class EntityPicker {
         Double delta;
         Double[] axesBounds = { 0., 0. }, dPosition = { 0., 0. }, legendPos = { 0., 0. }, legendBounds = { 0., 0., 0., 0. }, dimension = { 0., 0. };
 
-        axesSize = (Integer[])GraphicController.getController().getProperty(figure, GraphicObjectProperties.__GO_AXES_SIZE__);
+        AxesContainer container = (AxesContainer) GraphicController.getController().getObjectFromId(figure);
+        axesSize = container.getAxesSize();
+
         axesBounds = (Double[])GraphicController.getController().getProperty(axes, GraphicObjectProperties.__GO_AXES_BOUNDS__);
         legendPos = (Double[])GraphicController.getController().getProperty(legend, GraphicObjectProperties.__GO_POSITION__);
         links = (Integer[])GraphicController.getController().getProperty(legend, GraphicObjectProperties.__GO_LINKS__);
index fa79bc2..e5b40b1 100644 (file)
@@ -15,6 +15,7 @@ package org.scilab.modules.gui.editor;
 
 
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 import org.scilab.modules.graphic_objects.CallGraphicController;
 import org.scilab.modules.renderer.CallRenderer;
@@ -247,8 +248,8 @@ public class GEDPicker {
      * @return true if picked the surface otherwise returns false
      */
     boolean getSurface(Integer obj, Integer[] position) {
-
-        Integer figure = (Integer)GraphicController.getController().getProperty(obj, GraphicObjectProperties.__GO_PARENT_FIGURE__);
+        GraphicObject go = GraphicController.getController().getObjectFromId(obj);
+        Integer figure = go.getParentFrameOrFigure();
         double[] mat = DrawerVisitor.getVisitor(figure).getAxesDrawer().getProjection(axesUID).getMatrix();
         double[][] factors = axes.getScaleTranslateFactors();
 
@@ -276,12 +277,12 @@ public class GEDPicker {
      * @return true if picked the legend otherwise returns false
      */
     boolean getLegend(Integer obj, Integer[] position) {
-
         Integer[] axesSize = {0, 0};
         Double delta;
         Double[] axesBounds = { 0., 0. }, dPosition = { 0., 0. }, legendPos = { 0., 0. }, legendBounds = { 0., 0., 0., 0. }, dimension = { 0., 0. };
 
-        Integer figure = (Integer)GraphicController.getController().getProperty(obj, GraphicObjectProperties.__GO_PARENT_FIGURE__);
+        GraphicObject go = GraphicController.getController().getObjectFromId(obj);
+        Integer figure = go.getParentFrameOrFigure();
         axesSize = (Integer[])GraphicController.getController().getProperty(figure, GraphicObjectProperties.__GO_AXES_SIZE__);
         axesBounds = (Double[])GraphicController.getController().getProperty(axesUID, GraphicObjectProperties.__GO_AXES_BOUNDS__);
         legendPos = (Double[])GraphicController.getController().getProperty(obj, GraphicObjectProperties.__GO_POSITION__);
index ad95dd0..342d305 100755 (executable)
@@ -969,7 +969,7 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
                 openGLChildren.put(id, updatedOpenGLChildren);
             }
         }
-        
+
         try {
             if (needUpdate(id, property)) {
                 if (GraphicObjectProperties.__GO_COLORMAP__ == property) {
@@ -1006,7 +1006,7 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
                         } else {
                             canvas.redraw();
                         }
-                    } 
+                    }
                 }
             }
 
@@ -1114,7 +1114,7 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
             return true;
         }
         // Special case if top level figure colormap/immediate_drawing has been updated, force redraw
-        if ((property == GraphicObjectProperties.__GO_COLORMAP__ ||  property == GraphicObjectProperties.__GO_IMMEDIATE_DRAWING__) 
+        if ((property == GraphicObjectProperties.__GO_COLORMAP__ ||  property == GraphicObjectProperties.__GO_IMMEDIATE_DRAWING__)
                 && id.intValue() == figure.getParentFigure().intValue()) {
             return true;
         }
index 8756d75..b4da513 100644 (file)
@@ -905,7 +905,7 @@ public class AxesDrawer {
     public static double[] compute2dViewCoordinates(Axes axes, double[] coordinates) {
         // used in geom3d
 
-        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
         AxesDrawer axesDrawer;
         Transformation projection;
         Transformation projection2d;
@@ -950,7 +950,7 @@ public class AxesDrawer {
     public static double[] computePixelFrom2dViewCoordinates(Axes axes, double[] coordinates) {
         // used by xchange
 
-        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
         AxesDrawer axesDrawer;
         double[] coords2dView = new double[] {0.0, 0.0, 0.0};
 
@@ -996,7 +996,7 @@ public class AxesDrawer {
         Transformation projection;
         Transformation projection2d;
 
-        currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
         boolean[] logFlags = { axes.getXAxisLogFlag(), axes.getYAxisLogFlag(), axes.getZAxisLogFlag()};
         double[][] factors = axes.getScaleTranslateFactors();
 
@@ -1029,7 +1029,7 @@ public class AxesDrawer {
      * @returns the pixel coordinates (2-element array: x, y).
      */
     public static double[][] computePixelFrom3dCoordinates(Axes axes, double[] coordsX, double[] coordsY, double[] coordsZ) {
-        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
 
         if (currentVisitor != null) {
             AxesDrawer axesDrawer = currentVisitor.getAxesDrawer();
@@ -1072,7 +1072,7 @@ public class AxesDrawer {
      * @returns the 3d view coordinates (3-element array).
      */
     public static double[] compute3dViewCoordinates(Axes axes, double[] coordinates) {
-        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
         AxesDrawer axesDrawer;
         Transformation projection;
         Transformation projection2d;
@@ -1128,7 +1128,7 @@ public class AxesDrawer {
         AxesDrawer axesDrawer;
         double[] coords2dView = new double[] {0.0, 0.0, 0.0};
 
-        currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
 
         if (currentVisitor != null) {
             boolean[] logFlags = { axes.getXAxisLogFlag(), axes.getYAxisLogFlag(), axes.getZAxisLogFlag()};
@@ -1165,7 +1165,7 @@ public class AxesDrawer {
      * @return The un-projected point.
      */
     public static Vector3d unProject(Axes axes, Vector3d point) {
-        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        DrawerVisitor currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
 
         if (currentVisitor != null) {
             AxesDrawer axesDrawer = currentVisitor.getAxesDrawer();
@@ -1192,7 +1192,7 @@ public class AxesDrawer {
 
         double[] viewingArea = new double[] {0.0, 0.0, 0.0, 0.0};
 
-        currentVisitor = DrawerVisitor.getVisitor(axes.getParentFigure());
+        currentVisitor = DrawerVisitor.getVisitor(axes.getParentFrameOrFigure());
 
         if (currentVisitor != null) {
             double width = currentVisitor.getCanvas().getDimension().getWidth();