Xcos GUI: fix some graphic artefact 39/17539/2
Clément DAVID [Thu, 3 Dec 2015 16:47:35 +0000 (17:47 +0100)]
 * Handle ANNOTATION value on loading
 * Implement a convertion for custom exprs (used in block labels)

Change-Id: If7e15b326a61740b032d2c438b9cf417408af3b4

scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/TextBlock.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCell.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCellFactory.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/BlockHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/JGraphXHandler.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/sax/PortHandler.java

index c6cdfc3..07555c5 100644 (file)
@@ -20,7 +20,6 @@ import org.scilab.modules.gui.menu.Menu;
 import org.scilab.modules.xcos.Kind;
 import org.scilab.modules.xcos.block.actions.BlockParametersAction;
 import org.scilab.modules.xcos.block.actions.RegionToSuperblockAction;
-import org.scilab.modules.xcos.utils.XcosMessages;
 
 /**
  * A textblock is used to annotate diagrams.
@@ -32,8 +31,6 @@ public final class TextBlock extends BasicBlock {
      */
     public TextBlock(long uid) {
         super(uid, Kind.ANNOTATION);
-
-        setValue(XcosMessages.DOTS);
     }
 
     /**
index ea8aba1..4050c75 100644 (file)
@@ -90,6 +90,10 @@ public class XcosCell extends ScilabGraphUniqueObject {
     }
 
     private void setValue(JavaController controller, Object value) {
+        if (value == null) {
+            return;
+        }
+
         switch (getKind()) {
             case ANNOTATION:
                 controller.setObjectProperty(getUID(), getKind(), ObjectProperties.DESCRIPTION, String.valueOf(value));
index 6c26ee2..a8729c0 100644 (file)
@@ -364,6 +364,18 @@ public final class XcosCellFactory {
             block.setStyle(style[0]);
         }
 
+        String value;
+        if (block.getKind() == Kind.ANNOTATION) {
+            String[] description = new String[1];
+            controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.DESCRIPTION, description);
+            value = description[0];
+        } else { // BLOCK
+            String[] label = new String[1];
+            controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.LABEL, label);
+            value = label[0];
+        }
+        block.setValue(value);
+
         VectorOfDouble geom = new VectorOfDouble(4);
         controller.getObjectProperty(block.getUID(), block.getKind(), ObjectProperties.GEOMETRY, geom);
 
index 7e2cc62..477ccdb 100644 (file)
@@ -171,7 +171,11 @@ class BlockHandler implements ScilabHandler {
 
         v = atts.getValue("value");
         if (v != null) {
-            saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.DESCRIPTION, v);
+            if (kind == Kind.BLOCK) {
+                saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.LABEL, v);
+            } else { // ANNOTATION
+                saxHandler.controller.setObjectProperty(uid, kind, ObjectProperties.DESCRIPTION, v);
+            }
         }
 
         saxHandler.insertChild(block);
index 06e58e6..974ee15 100644 (file)
@@ -21,7 +21,6 @@ import org.xml.sax.Attributes;
 import com.mxgraph.model.mxGeometry;
 import com.mxgraph.util.mxPoint;
 import java.util.ArrayList;
-import org.scilab.modules.types.ScilabList;
 
 class JGraphXHandler implements ScilabHandler {
 
index 4f282e6..96cfdc8 100644 (file)
@@ -117,6 +117,11 @@ class PortHandler implements ScilabHandler {
             shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.STYLE, v);
         }
 
+        v = atts.getValue("value");
+        if (v != null) {
+            shared.controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.LABEL, v);
+        }
+
         VectorOfInt datatype = new VectorOfInt();
         shared.controller.getObjectProperty(uid, Kind.PORT, ObjectProperties.DATATYPE, datatype);