CoverityFix-CID:1351066 Inner class could be made static
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / graphicView / TreeView.java
index e3bfb44..1acf3ed 100644 (file)
@@ -2,11 +2,14 @@
  * 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
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
  *
  */
 package org.scilab.modules.graphic_objects.graphicView;
@@ -30,10 +33,12 @@ import javax.swing.tree.TreeSelectionModel;
 
 import org.scilab.modules.graphic_objects.contouredObject.ContouredObject;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
+import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
+import org.scilab.modules.graphic_objects.uicontrol.frame.border.FrameBorder;
 
-public abstract class TreeView implements GraphicView, TreeSelectionListener{
+public abstract class TreeView implements GraphicView, TreeSelectionListener {
 
-    protected Map<String, DefaultMutableTreeNode> allObjects = new ConcurrentHashMap<String, DefaultMutableTreeNode>();
+    protected Map<Integer, DefaultMutableTreeNode> allObjects = new ConcurrentHashMap<Integer, DefaultMutableTreeNode>();
     protected DefaultTreeModel topModel = null;
     protected DefaultMutableTreeNode top = new DefaultMutableTreeNode("Graphic Objects");
     private JTree tree;
@@ -44,11 +49,15 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
         frame.setVisible(true);
     }
 
+    public void hide() {
+        frame.setVisible(false);
+    }
+
     protected TreeView() {
         frame = new JFrame("TreeView");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
-        JPanel panel = new JPanel(new GridLayout(1,0));
+        JPanel panel = new JPanel(new GridLayout(1, 0));
 
         topModel = new DefaultTreeModel(top);
         tree = new JTree(topModel);
@@ -61,8 +70,8 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
         tree.addTreeSelectionListener(this);
 
 
-        Dimension minDims = new Dimension(400,300);
-        //Create the scroll pane and add the tree to it. 
+        Dimension minDims = new Dimension(400, 300);
+        //Create the scroll pane and add the tree to it.
         JScrollPane treeView = new JScrollPane(tree);
         treeView.setMinimumSize(minDims);
 
@@ -78,7 +87,7 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
         treeDetailPane.setLeftComponent(treeView);
         treeDetailPane.setRightComponent(htmlView);
 
-        treeDetailPane.setDividerLocation(100); 
+        treeDetailPane.setDividerLocation(100);
         treeDetailPane.setPreferredSize(new Dimension(1200, 600));
 
         //Add the split pane to this panel.
@@ -88,14 +97,14 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
         frame.setSize(1200, 600);
     }
 
-    public abstract void createObject(String id);
-    public abstract void deleteObject(String id) ;
-    public abstract void updateObject(String id, String property);
-    
+    public abstract void createObject(Integer id);
+    public abstract void deleteObject(Integer id) ;
+    public abstract void updateObject(Integer id, int property);
+
     /*
      * Inner class to wrap GraphicObject in a Node.
      */
-    protected class GraphicObjectNode {
+    protected static class GraphicObjectNode {
         private GraphicObject graphicObject;
 
         public GraphicObjectNode(GraphicObject object) {
@@ -103,14 +112,14 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
         }
 
         public String toString() {
-            return graphicObject.getType() + " : @" + graphicObject.getIdentifier();
+            return typeToString(graphicObject.getType()) + " : @" + graphicObject.getIdentifier().toString();
         }
 
         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("<h1>Graphic Object of type: " + typeToString(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
@@ -123,16 +132,31 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
                     String[] strings = (String []) values;
                     strBuff.append("{");
                     for (int i = 0; i < strings.length ; ++i) {
-                        strBuff.append(strings[i]+",");
+                        strBuff.append(strings[i] + ",");
                     }
                     strBuff.append("}");
-                }
-                else {
-                    if (values != null) {
-                        strBuff.append(values.toString());
+                } else if (values instanceof Integer[]) {
+                    Integer[] ints = (Integer []) values;
+                    strBuff.append("{");
+                    for (int i = 0; i < ints.length ; ++i) {
+                        strBuff.append(ints[i] + ",");
+                    }
+                    strBuff.append("}");
+                } else if (values instanceof Double[]) {
+                    Double[] vals = (Double []) values;
+                    strBuff.append("{");
+                    for (int i = 0; i < vals.length ; ++i) {
+                        strBuff.append(vals[i] + ",");
                     }
-                    else
-                    {
+                    strBuff.append("}");
+                } else {
+                    if (values != null) {
+                        if (values.getClass().getPackage().getName().contains("scilab")) {
+                            strBuff.append(values.getClass().getCanonicalName());
+                        } else {
+                            strBuff.append(values.toString());
+                        }
+                    } else {
                         strBuff.append("??? NULL ???");
                     }
                 }
@@ -149,11 +173,33 @@ public abstract class TreeView implements GraphicView, TreeSelectionListener{
                     strBuff.append("</td></tr>");
                 }
             }
+
+            // UiControl
+            if (graphicObject instanceof Uicontrol) {
+                Uicontrol uiControl = (Uicontrol) graphicObject;
+                strBuff.append("<tr><td>STYLE</td><td>" + typeToString(uiControl.getStyle()) + "</td>");
+                strBuff.append("<tr><td>LAYOUT</td><td>" + uiControl.getLayoutAsEnum() + "</td>");
+                strBuff.append("<tr><td>GROUP NAME</td><td>" + uiControl.getGroupName() + "</td>");
+                strBuff.append("<tr><td>FRAME_BORDER</td><td>" + uiControl.getFrameBorder() + "</td>");
+            }
+
+            if (graphicObject instanceof FrameBorder) {
+                FrameBorder frameBorder = (FrameBorder) graphicObject;
+                strBuff.append("<tr><td>STYLE</td><td>" + frameBorder.getStyleAsEnum().toString() + "</td>");
+            }
+
             strBuff.append("</table>");
             strBuff.append("</body></html>");
             return strBuff.toString();
         }
+
+        private String typeToString(Integer key) {
+            return LogView.pierreDeRosette.get(key);
+        }
     }
+
+
+
     /** Required by TreeSelectionListener interface. */
     public void valueChanged(TreeSelectionEvent e) {
         Object node = tree.getLastSelectedPathComponent();