figure may be null during xml loading 47/13947/2
Antoine ELIAS [Fri, 7 Mar 2014 09:44:18 +0000 (10:44 +0100)]
Change-Id: Id4dd568be2c2fd8cf81e542e3d0638b0dd2c29f5

scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java

index d1dc124..f383ac6 100644 (file)
@@ -158,6 +158,12 @@ public class AxesDrawer {
      */
     public void computeRulers(Axes axes) {
         Figure figure = (Figure) GraphicController.getController().getObjectFromId(axes.getParentFigure());
+
+        //figure may be null during xml loading
+        if (figure == null) {
+            return;
+        }
+
         final ColorMap colorMap = figure.getColorMap();
         try {
             Dimension dims = visitor.getCanvas().getDimension();
@@ -455,10 +461,10 @@ public class AxesDrawer {
         double[] matrix = transformation.getMatrix();
         try {
             return TransformationFactory.getScaleTransformation(
-                matrix[2] < 0 ? 1 : -1,
-                matrix[6] < 0 ? 1 : -1,
-                matrix[10] < 0 ? 1 : -1
-                );
+                       matrix[2] < 0 ? 1 : -1,
+                       matrix[6] < 0 ? 1 : -1,
+                       matrix[10] < 0 ? 1 : -1
+                   );
         } catch (DegenerateMatrixException e) {
             // Should never happen.
             return TransformationFactory.getIdentity();
@@ -519,29 +525,29 @@ public class AxesDrawer {
     private Transformation computeDataTransformation(Axes axes) throws DegenerateMatrixException {
         // Reverse data if needed.
         Transformation transformation = TransformationFactory.getScaleTransformation(
-            axes.getAxes()[0].getReverse() ? 1 : -1,
-            axes.getAxes()[1].getReverse() ? 1 : -1,
-            axes.getAxes()[2].getReverse() ? 1 : -1
-            );
+                                            axes.getAxes()[0].getReverse() ? 1 : -1,
+                                            axes.getAxes()[1].getReverse() ? 1 : -1,
+                                            axes.getAxes()[2].getReverse() ? 1 : -1
+                                        );
 
         if (axes.getZoomEnabled()) {
             Double[] bounds = axes.getCorrectedBounds();
 
             // Scale data.
             Transformation scaleTransformation = TransformationFactory.getScaleTransformation(
-                2.0 / (bounds[1] - bounds[0]),
-                2.0 / (bounds[3] - bounds[2]),
-                2.0 / (bounds[5] - bounds[4])
-                );
+                    2.0 / (bounds[1] - bounds[0]),
+                    2.0 / (bounds[3] - bounds[2]),
+                    2.0 / (bounds[5] - bounds[4])
+                                                 );
             transformation = transformation.rightTimes(scaleTransformation);
 
 
             // Translate data.
             Transformation translateTransformation = TransformationFactory.getTranslateTransformation(
-                -(bounds[0] + bounds[1]) / 2.0,
-                -(bounds[2] + bounds[3]) / 2.0,
-                -(bounds[4] + bounds[5]) / 2.0
-                );
+                        -(bounds[0] + bounds[1]) / 2.0,
+                        -(bounds[2] + bounds[3]) / 2.0,
+                        -(bounds[4] + bounds[5]) / 2.0
+                    );
             transformation = transformation.rightTimes(translateTransformation);
 
             return transformation;