Enable flat object view. Update LogView. Register debug view when starting MVC. 59/5559/2
Bruno JOFRET [Thu, 1 Dec 2011 14:38:57 +0000 (15:38 +0100)]
Change-Id: If54a92fe03426b8c8fe053d467b0b428c4152658

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/MVCDebugView.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicController/GraphicController.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicView/GuiLogView.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicView/TreeView.java [new file with mode: 0644]

index 743e04f..bafb575 100644 (file)
  */
 package org.scilab.modules.graphic_objects;
 
-import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.graphic_objects.graphicView.GuiLogView;
+import org.scilab.modules.graphic_objects.graphicView.TreeView;
 
 public class MVCDebugView {
 
     public static void showLogView() {
-        GraphicController.getController().register(GuiLogView.createGuiLogView());
+        GuiLogView.createGuiLogView().show();
     }
-    
+   
+    public static void showAllObjectsView() {
+        TreeView.createTreeView().show();
+    } 
 }
index ad521bb..e182fcb 100644 (file)
@@ -24,7 +24,8 @@ import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject.Type;
 import org.scilab.modules.graphic_objects.graphicView.GraphicView;
-
+import org.scilab.modules.graphic_objects.graphicView.GuiLogView;
+import org.scilab.modules.graphic_objects.graphicView.TreeView;
 
 /**
  * GraphicController class
@@ -51,6 +52,8 @@ public class GraphicController {
      * Default constructor
      */
     private GraphicController() {
+        register(GuiLogView.createGuiLogView());
+        register(TreeView.createTreeView());
     }
 
     /**
@@ -100,11 +103,20 @@ public class GraphicController {
      * @return true if the property has been set, false otherwise
      */
     public boolean setProperty(String id, String prop, Object value) {
-        if (GraphicModel.getModel().setProperty(id, prop, value)) {
-            objectUpdate(id, prop);
-            return true;
+        try {
+            if (GraphicModel.getModel().setProperty(id, prop, value)) {
+                objectUpdate(id, prop);
+                return true;
+            }
+            return false;
+        }
+        catch (Exception e) {
+            System.err.println("====== Exception caught ======");
+            DEBUG("setProperty : " + id + " " + prop);
+            e.printStackTrace();
+            System.err.println("====== Exception caught ======");
+            return false;
         }
-        return false;
     }
 
     /**
@@ -114,7 +126,16 @@ public class GraphicController {
      * @return the property value
      */
     public Object getProperty(String id, String prop) {
-        return GraphicModel.getModel().getProperty(id, prop);
+        try {
+            return GraphicModel.getModel().getProperty(id, prop);
+        }
+        catch (Exception e) {
+            System.err.println("====== Exception caught ======");
+            DEBUG("getProperty : [" + id + "] " + prop);
+            e.printStackTrace();
+            System.err.println("====== Exception caught ======");
+            return null;
+        }
     }
 
     /**
@@ -133,11 +154,20 @@ public class GraphicController {
      * @return the created object's id
      */
     public String askObject(Type type) {
-        UID id = createUID();
-        GraphicModel.getModel().createObject(id.toString(), type);
-        objectCreated(id.toString());
+        try {
+            UID id = createUID();
+            GraphicModel.getModel().createObject(id.toString(), type);
+            objectCreated(id.toString());
+
+            return id.toString();
+        }
+        catch (Exception e) {
+            System.err.println("====== Exception caught ======");
+            e.printStackTrace();
+            System.err.println("====== Exception caught ======");
+            return "";
+        }
 
-        return id.toString();
     }
 
     /**
@@ -146,11 +176,19 @@ public class GraphicController {
      * @return the id of the clone.
      */
     public String cloneObject(String id) {
-        UID newId = createUID();
-        GraphicModel.getModel().cloneObject(id, newId.toString());
-        objectCreated(newId.toString());
+        try {
+            UID newId = createUID();
+            GraphicModel.getModel().cloneObject(id, newId.toString());
+            objectCreated(newId.toString());
 
-        return newId.toString();
+            return newId.toString();
+        }
+        catch (Exception e) {
+            System.err.println("====== Exception caught ======");
+            e.printStackTrace();
+            System.err.println("====== Exception caught ======");
+            return "";
+        }
     }
 
     /**
@@ -158,8 +196,15 @@ public class GraphicController {
      * @param id the deleted object's id
      */
     public void deleteObject(String id) {
-        objectDeleted(id);
-        GraphicModel.getModel().deleteObject(id);
+        try {
+            objectDeleted(id);
+            GraphicModel.getModel().deleteObject(id);
+        }
+        catch (Exception e) {
+            System.err.println("====== Exception caught ======");
+            e.printStackTrace();
+            System.err.println("====== Exception caught ======");
+        }
     }
 
     /**
index 9b03506..4612e09 100644 (file)
@@ -23,6 +23,7 @@ import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 public class GuiLogView implements GraphicView {
     private static GuiLogView me;
     private JEditorPane htmlLogPane;
+    private JFrame frame;
 
     public static GuiLogView createGuiLogView() {
         if (me == null) {
@@ -32,16 +33,21 @@ public class GuiLogView implements GraphicView {
     }
 
     private GuiLogView() {
-        JFrame frame = new JFrame("GuiLogView");
+        frame = new JFrame("GuiLogView");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
         htmlLogPane = new JEditorPane();
         htmlLogPane.setEditable(false);
         JScrollPane logView = new JScrollPane(htmlLogPane);
         frame.setContentPane(logView);
-        frame.setVisible(true);
+        frame.setVisible(false);
         frame.setSize(800, 600);
     }
+    
+    public void show() {
+        frame.setVisible(true);
+    }
+    
     public void createObject(String id) {
         try {
             String objectType = (String) GraphicController.getController().getProperty(id, __GO_TYPE__);
diff --git a/scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicView/TreeView.java b/scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/graphicView/TreeView.java
new file mode 100644 (file)
index 0000000..22b612a
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - DIGITEO - 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
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+package org.scilab.modules.graphic_objects.graphicView;
+
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.util.HashMap;
+
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTree;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeSelectionModel;
+
+import org.scilab.modules.graphic_objects.contouredObject.ContouredObject;
+import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
+
+public class TreeView implements GraphicView, TreeSelectionListener{
+
+    private static TreeView me;
+    private HashMap<String, DefaultMutableTreeNode> fObjects = new HashMap<String, DefaultMutableTreeNode>();
+    private DefaultTreeModel topFModel = null;
+    private DefaultMutableTreeNode topF = new DefaultMutableTreeNode("Graphic Objects Flatten");
+    private JTree flatTree;
+    private JEditorPane htmlDetailPane;
+    private JFrame frame;
+    
+    public static TreeView createTreeView() {
+        if (me == null) {
+            me = new TreeView();
+        }
+        return me;
+    }
+
+    public void show() {
+        frame.setVisible(true);
+    }
+    
+    private TreeView() {
+        frame = new JFrame("TreeView");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        JPanel panel = new JPanel(new GridLayout(1,0));
+
+        //Create a tree that allows one selection at a time.
+        //topHModel = new DefaultTreeModel(topH);
+        //hierarchicalTree = new JTree(topHModel);
+        //hierarchicalTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+        //hierarchicalTree.addTreeSelectionListener(this);
+        //hierarchicalTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+        //Create a tree that allows one selection at a time.
+        topFModel = new DefaultTreeModel(topF);
+        flatTree = new JTree(topFModel);
+        flatTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+        flatTree.addTreeSelectionListener(this);
+        flatTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+
+        //Listen for when the selection changes.
+        //tree.addTreeSelectionListener(this);
+
+
+        Dimension minDims = new Dimension(400,300);
+        //Create the scroll pane and add the tree to it. 
+        //JScrollPane hTreeView = new JScrollPane(hierarchicalTree);
+        //hTreeView.setMinimumSize(minDims);
+        JScrollPane fTreeView = new JScrollPane(flatTree);
+        fTreeView.setMinimumSize(minDims);
+
+                //Create the HTML detail viewing pane.
+        htmlDetailPane = new JEditorPane();
+        htmlDetailPane.setEditable(false);
+        htmlDetailPane.setContentType("text/html");
+        JScrollPane htmlView = new JScrollPane(htmlDetailPane);
+
+        //Add the scroll panes to a split pane.
+        JSplitPane treeDetailPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+        treeDetailPane.setLeftComponent(fTreeView);
+        treeDetailPane.setRightComponent(htmlView);
+
+        treeDetailPane.setDividerLocation(100); 
+        treeDetailPane.setPreferredSize(new Dimension(1200, 600));
+
+        //Add the split pane to this panel.
+        panel.add(treeDetailPane);
+        frame.add(panel);
+        frame.setVisible(false);
+        frame.setSize(1200, 600);
+    }
+
+    public void createObject(String id) {
+        try {
+            DefaultMutableTreeNode node = new DefaultMutableTreeNode(new GraphicObjectNode(GraphicController.getController().getObjectFromId(id)));
+           
+            node = new DefaultMutableTreeNode(new GraphicObjectNode(GraphicController.getController().getObjectFromId(id)));
+            fObjects.put(id, node);
+            topF.add(node);
+            topFModel.nodeStructureChanged(topF);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void deleteObject(String id) {
+        try {
+            DefaultMutableTreeNode node = fObjects.get(id);
+            topF.remove(node);
+            fObjects.remove(id);
+            topFModel.nodeStructureChanged(topF);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void updateObject(String id, String property) {
+    }
+
+    /*
+     * Inner class to wrap GraphicObject in a Node.
+     */
+    private class GraphicObjectNode {
+        private GraphicObject graphicObject;
+
+        public GraphicObjectNode(GraphicObject object) {
+            this.graphicObject = object;
+        }
+
+        public String toString() {
+            return graphicObject.getType() + " : @" + graphicObject.getIdentifier();
+        }
+
+        public String toHTML() {
+            StringBuffer strBuff = new StringBuffer();
+            strBuff.append("<html><body>");
+            strBuff.append("<h1>Graphic Object of type: "+graphicObject.getType()+"</h1>");
+            strBuff.append("<h2> Id : "+graphicObject.getIdentifier()+"</h2>");
+            strBuff.append("<table border=\"1\">");
+            strBuff.append("<tr><th>Property Name</th><th>Value</th></tr>");
+            // Graphic Object
+            for (GraphicObject.GraphicObjectPropertyType goProperty : GraphicObject.GraphicObjectPropertyType.values()) {
+                strBuff.append("<tr><td>");
+                strBuff.append(goProperty);
+                strBuff.append("</td><td>");
+                Object values = graphicObject.getProperty(goProperty);
+                if (values instanceof String[]) {
+                    String[] strings = (String []) values;
+                    strBuff.append("{");
+                    for (int i = 0; i < strings.length ; ++i) {
+                        strBuff.append(strings[i]+",");
+                    }
+                    strBuff.append("}");
+                }
+                else {
+                    if (values != null) {
+                        strBuff.append(values.toString());
+                    }
+                    else
+                    {
+                        strBuff.append("??? NULL ???");
+                    }
+                }
+                strBuff.append("</td></tr>");
+            }
+
+            // ContouredObject
+            if (graphicObject instanceof ContouredObject) {
+                for (ContouredObject.ContouredObjectPropertyType goProperty : ContouredObject.ContouredObjectPropertyType.values()) {
+                    strBuff.append("<tr><td>");
+                    strBuff.append(goProperty);
+                    strBuff.append("</td><td>");
+                    strBuff.append(graphicObject.getProperty(goProperty));
+                    strBuff.append("</td></tr>");
+                }
+            }
+            strBuff.append("</table>");
+            strBuff.append("</body></html>");
+            return strBuff.toString();
+        }
+    }
+    /** Required by TreeSelectionListener interface. */
+    public void valueChanged(TreeSelectionEvent e) {
+        Object node = flatTree.getLastSelectedPathComponent();
+
+        if (node == null || !(node instanceof DefaultMutableTreeNode)) {
+            htmlDetailPane.setText("");
+            return;
+        }
+
+        Object nodeInfo = ((DefaultMutableTreeNode) node).getUserObject();
+        if (nodeInfo == null || !(nodeInfo instanceof GraphicObjectNode)) {
+            htmlDetailPane.setText("");
+            return;
+        }
+        GraphicObjectNode graphicObject = (GraphicObjectNode) nodeInfo;
+        htmlDetailPane.setText(graphicObject.toHTML());
+    }
+
+}