Remove non-working Scalar property get.
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / GraphicObjectBuilder.java
index 4042a9a..664c151 100644 (file)
@@ -1,6 +1,8 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2010 - DIGITEO - Bruno JOFRET
+ * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+ * Copyright (C) 2013 - Scilab Enterprises - Bruno JOFRET
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
@@ -25,31 +27,31 @@ import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 public final class GraphicObjectBuilder {
 
     public static Figure createNewFigureWithAxes(Integer id) {
+        GraphicController controller = GraphicController.getController();
+        
         final int[] props = new int[] {GraphicObjectProperties.__GO_X_AXIS_LABEL__, GraphicObjectProperties.__GO_Y_AXIS_LABEL__, GraphicObjectProperties.__GO_Z_AXIS_LABEL__, GraphicObjectProperties.__GO_TITLE__};
         String figureModelUID = GraphicModel.getModel().getFigureModel().getIdentifier();
         String axesModelUID = GraphicModel.getModel().getAxesModel().getIdentifier();
-        String newFID = GraphicController.getController().createUID().toString();
-        String newAID = GraphicController.getController().createUID().toString();
+        String newFID = controller.createUID().toString();
+        String newAID = controller.createUID().toString();
         GraphicModel.getModel().cloneObject(figureModelUID, newFID);
         GraphicModel.getModel().cloneObject(axesModelUID, newAID);
 
-        int iid = id == null ? ScilabNativeView.ScilabNativeView__getValidDefaultFigureId() : id.intValue();
-
-        CallGraphicController.setGraphicObjectProperty(newFID, GraphicObjectProperties.__GO_ID__, id);
-        CallGraphicController.setGraphicObjectRelationship(newFID, newAID);
-        CallGraphicController.setGraphicObjectProperty(newFID, GraphicObjectProperties.__GO_SELECTED_CHILD__, newAID);
+        controller.setProperty(newFID, GraphicObjectProperties.__GO_ID__, id);
+        controller.setGraphicObjectRelationship(newFID, newAID);
+        controller.setProperty(newFID, GraphicObjectProperties.__GO_SELECTED_CHILD__, newAID);
 
         for (Integer type : props) {
             final double[] position = new double[] {1, 1, 1};
-            String modelLabelUID = CallGraphicController.getGraphicObjectPropertyAsString(axesModelUID, type);
-            String pobjUID = GraphicController.getController().createUID().toString();
+            String modelLabelUID = (String) controller.getProperty(axesModelUID, type);
+            String pobjUID = controller.createUID().toString();
             GraphicModel.getModel().cloneObject(modelLabelUID, pobjUID);
-            CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_POSITION__, position);
+            controller.setProperty(pobjUID, GraphicObjectProperties.__GO_POSITION__, position);
 
-            int autoPosition = CallGraphicController.getGraphicObjectPropertyAsBoolean(modelLabelUID, GraphicObjectProperties.__GO_AUTO_POSITION__);
-            CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_AUTO_POSITION__, autoPosition == 1);
+            Boolean autoPosition = (Boolean ) controller.getProperty(modelLabelUID, GraphicObjectProperties.__GO_AUTO_POSITION__);
+            controller.setProperty(pobjUID, GraphicObjectProperties.__GO_AUTO_POSITION__, autoPosition);
 
-            CallGraphicController.setGraphicObjectProperty(newAID, type, pobjUID);
+            controller.setProperty(newAID, type, pobjUID);
             CallGraphicController.setGraphicObjectRelationship(newAID, pobjUID);
         }
 
@@ -59,18 +61,20 @@ public final class GraphicObjectBuilder {
         ScilabNativeView.ScilabNativeView__setCurrentSubWin(newAID);
         ScilabNativeView.ScilabNativeView__setCurrentFigure(newFID);
 
-        int[] axesSize = CallGraphicController.getGraphicObjectPropertyAsIntegerVector(figureModelUID, GraphicObjectProperties.__GO_AXES_SIZE__);
-        CallGraphicController.setGraphicObjectProperty(newFID, GraphicObjectProperties.__GO_AXES_SIZE__, axesSize);
+        Integer[] axesSize = (Integer[]) controller.getProperty(figureModelUID, GraphicObjectProperties.__GO_AXES_SIZE__);
+        controller.setProperty(newFID, GraphicObjectProperties.__GO_AXES_SIZE__, axesSize);
 
-        return (Figure) GraphicController.getController().getObjectFromId(newFID);
+        return (Figure) controller.getObjectFromId(newFID);
     }
 
     public static String constructRectangles(String pparentsubwinUID, double x, double y, double height, double width, int foreground, int background, int isfilled, int isline) {
-        double[] clipRegion;
-        int visible = 0;
-        int clipRegionSet = 0;
-        int clipState = 0;
-        int iMarkMode = 0;
+        GraphicController controller = GraphicController.getController();
+        
+        Double[] clipRegion;
+        Boolean visible = false;
+        Boolean clipRegionSet = false;
+        Integer clipState = 0;
+        Boolean iMarkMode = false;
 
         if (height < 0 || width < 0) {
             return null;
@@ -84,27 +88,27 @@ public final class GraphicObjectBuilder {
          */
         //setGraphicObjectProperty(pobjUID, __GO_PARENT__, pparentsubwinUID, jni_string, 1);
 
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_UPPER_LEFT_POINT__, new double[] {x, y, 0});
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_HEIGHT__, height);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_WIDTH__, width);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_UPPER_LEFT_POINT__, new Double[] {x, y, 0.0});
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_HEIGHT__, height);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_WIDTH__, width);
 
-        visible = CallGraphicController.getGraphicObjectPropertyAsBoolean(pparentsubwinUID, GraphicObjectProperties.__GO_VISIBLE__);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_VISIBLE__, visible == 1);
+        visible = (Boolean) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_VISIBLE__);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_VISIBLE__, visible);
 
         /* Clip state and region */
         /* To be checked for consistency */
 
-        clipRegion = CallGraphicController.getGraphicObjectPropertyAsDoubleVector(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX__);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX__, clipRegion);
+        clipRegion = (Double[]) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX__);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX__, clipRegion);
 
-        clipRegionSet = CallGraphicController.getGraphicObjectPropertyAsBoolean(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__,  clipRegionSet == 1);
+        clipRegionSet = (Boolean) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__,  clipRegionSet);
 
-        clipState = CallGraphicController.getGraphicObjectPropertyAsInteger(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_STATE__);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_STATE__, clipState);
+        clipState = (Integer) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_STATE__);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_STATE__, clipState);
 
-        iMarkMode = CallGraphicController.getGraphicObjectPropertyAsBoolean(pparentsubwinUID, GraphicObjectProperties.__GO_MARK_MODE__);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_MARK_MODE__, iMarkMode == 1);
+        iMarkMode = (Boolean) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_MARK_MODE__);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_MARK_MODE__, iMarkMode);
 
         /*
          * Initializes the contour properties (background, foreground, etc)
@@ -113,15 +117,15 @@ public final class GraphicObjectBuilder {
         cloneGraphicContext(pparentsubwinUID, pobjUID);
 
         /* Contour settings */
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_LINE_MODE__, isline == 1);
-        CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_FILL_MODE__, isfilled == 1);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_LINE_MODE__, isline == 1);
+        controller.setProperty(pobjUID, GraphicObjectProperties.__GO_FILL_MODE__, isfilled == 1);
 
         if (foreground != -1) {
-            CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
+            controller.setProperty(pobjUID, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
         }
 
         if (background != -1) {
-            CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_BACKGROUND__, background);
+            controller.setProperty(pobjUID, GraphicObjectProperties.__GO_BACKGROUND__, background);
         }
 
         /* Parent reset to the null object */
@@ -137,51 +141,52 @@ public final class GraphicObjectBuilder {
     }
 
     public static int cloneGraphicContext(String sourceIdentifier, String destIdentifier) {
-        int lineMode = 0;
-        int foreground = 0;
-        int lineStyle = 0;
-        int background = 0;
-        int markForeground = 0;
-        int markBackground = 0;
-        int markStyle = 0;
-        int markSize = 0;
-        int markSizeUnit = 0;
-        double lineThickness = 0.;
+        GraphicController controller = GraphicController.getController();
+        Integer lineMode = 0;
+        Integer foreground = 0;
+        Integer lineStyle = 0;
+        Integer background = 0;
+        Integer markForeground = 0;
+        Integer markBackground = 0;
+        Integer markStyle = 0;
+        Integer markSize = 0;
+        Integer markSizeUnit = 0;
+        Double lineThickness = 0.;
 
         /*
          * All these properties are passed by value thus do not care to release them
          * and do not call releaseGraphicObjectProperty on purpose.
          */
 
-        lineMode = CallGraphicController.getGraphicObjectPropertyAsBoolean(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
-        foreground = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
-        lineThickness = CallGraphicController.getGraphicObjectPropertyAsDouble(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
-        lineStyle = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
+        lineMode = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
+        foreground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
+        lineThickness = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
+        lineStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
 
-        background = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
+        background = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
 
-        markForeground = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
+        markForeground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
 
-        markBackground = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
+        markBackground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
 
-        markStyle = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
+        markStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
 
-        markSize = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
+        markSize = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
 
-        markSizeUnit = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
+        markSizeUnit = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
 
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode == 1);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode == 1);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
 
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
 
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
-        CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
+        controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);
 
         return 0;
     }