Provide a better description of the type and provide the int type as tooltip 76/4376/3
Sylvestre Ledru [Fri, 1 Jul 2011 16:46:28 +0000 (18:46 +0200)]
Change-Id: Icc45b9f048294de1c77c227785b493167e4ffa17

scilab/modules/types/src/java/org/scilab/modules/types/ScilabTypeEnumDescription.java [new file with mode: 0644]
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/BrowseVar.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variablebrowser/SwingScilabVariableBrowser.java

diff --git a/scilab/modules/types/src/java/org/scilab/modules/types/ScilabTypeEnumDescription.java b/scilab/modules/types/src/java/org/scilab/modules/types/ScilabTypeEnumDescription.java
new file mode 100644 (file)
index 0000000..7de8279
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU
+ * 
+ *  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.types;
+import org.scilab.modules.localization.Messages;
+
+public class ScilabTypeEnumDescription {
+
+    public static String getTypeDescriptionFromId(int type) {
+        switch (ScilabTypeEnum.swigToEnum(type)) {
+            case sci_matrix:
+                return Messages.gettext("Double");
+            case sci_poly:
+                return Messages.gettext("Polynomial");
+            case sci_boolean:
+                return Messages.gettext("Boolean");
+            case sci_sparse:
+                return Messages.gettext("Sparse");
+            case sci_boolean_sparse:
+                return Messages.gettext("Boolean Sparse");
+            case sci_matlab_sparse:
+                return Messages.gettext("Matlab Sparse");
+            case sci_ints:
+                return Messages.gettext("Integer");
+            case sci_handles:
+                return Messages.gettext("Graphic handle");
+            case sci_strings:
+                return Messages.gettext("String");
+            case  sci_u_function:
+                return Messages.gettext("User function");
+            case sci_c_function:
+                return Messages.gettext("Compiled function");
+            case sci_lib:
+                return Messages.gettext("Function library");
+            case sci_list:
+                return Messages.gettext("List");
+            case sci_tlist:
+                return Messages.gettext("Tlist");                
+            case sci_mlist:
+                return Messages.gettext("Mlist");
+            case sci_pointer:
+                return Messages.gettext("Pointer");
+            case sci_implicit_poly:
+                return Messages.gettext("Implicit polynomial");
+            case sci_intrinsic_function:
+                return Messages.gettext("Intrinsic function");
+        }
+        return Messages.gettext("Unknown datatype");
+    }
+}
\ No newline at end of file
index 49ab3d5..5cffa23 100644 (file)
@@ -16,6 +16,7 @@ import javax.swing.ImageIcon;
 
 import org.scilab.modules.localization.Messages;
 import org.scilab.modules.ui_data.variablebrowser.ScilabVariableBrowser;
+import org.scilab.modules.types.ScilabTypeEnumDescription;
 
 /**
  *
@@ -27,10 +28,11 @@ public class BrowseVar {
     public static final int ICON_COLUMN_INDEX = 0;
     public static final int NAME_COLUMN_INDEX = 1;
     public static final int SIZE_COLUMN_INDEX = 2;
-    public static final int TYPE_COLUMN_INDEX = 3;
+    public static final int TYPE_DESC_COLUMN_INDEX = 3;
     public static final int VISIBILITY_COLUMN_INDEX = 4;
     public static final int BYTES_COLUMN_INDEX = 5;
     public static final int FROM_SCILAB_COLUMN_INDEX = 6;
+    public static final int TYPE_COLUMN_INDEX = 7;
 
     public static final String[] COLUMNNAMES = new String[]{"", /* Icon */
                                                             Messages.gettext("Name"),
@@ -38,7 +40,8 @@ public class BrowseVar {
                                                             Messages.gettext("Type"),
                                                             Messages.gettext("Visibility"),
                                                             Messages.gettext("Bytes"),
-                                                            Messages.gettext("User")
+                                                            Messages.gettext("User"),
+                                                            Messages.gettext("Type int value")
     };
 
     private static final String ICON_PATH = System.getenv("SCI") + "/modules/ui_data/images/icons/";
@@ -114,10 +117,11 @@ public class BrowseVar {
             data[i][ICON_COLUMN_INDEX] = getIconFromType(dataTypes[i]);
             data[i][NAME_COLUMN_INDEX] = dataNames[i];
             data[i][SIZE_COLUMN_INDEX] = dataSizes[i];
-            data[i][TYPE_COLUMN_INDEX] = dataTypes[i];
+            data[i][TYPE_DESC_COLUMN_INDEX] = ScilabTypeEnumDescription.getTypeDescriptionFromId(dataTypes[i]);
             data[i][VISIBILITY_COLUMN_INDEX] = dataVisibility[i];
             data[i][BYTES_COLUMN_INDEX] = dataBytes[i];
-            data[i][FROM_SCILAB_COLUMN_INDEX] = dataFromUser[i];
+            data[i][FROM_SCILAB_COLUMN_INDEX] = dataFromUser[i]; /* Tag if it is a variable from the user or from Scilab (%pi, %eps, etc) */
+            data[i][TYPE_COLUMN_INDEX] = dataTypes[i];
         }
         ScilabVariableBrowser.getVariableBrowser(update, data);
     }
index 726c17b..f0ebc79 100644 (file)
@@ -157,11 +157,9 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
                     if (rowIndex >= 0 && rowIndex < model.getRowCount()) {
                         
                         int colIndex = columnAtPoint(p);
-
-                        if (colIndex==BrowseVar.TYPE_COLUMN_INDEX) { /* Scilab type */
+                        if (colIndex==BrowseVar.TYPE_DESC_COLUMN_INDEX) { /* Scilab type */
                             try {
-                                int type = Integer.parseInt(getValueAt(rowIndex, colIndex).toString());
-                                tip = Messages.gettext("Scilab type:")+" "+ ScilabTypeEnum.swigToEnum(type);
+                                tip = Messages.gettext("Scilab type:")+" "+ model.getValueAt(rowIndex, BrowseVar.TYPE_COLUMN_INDEX).toString();
                             } catch (IllegalArgumentException exception) {
                                 /* If the type is not known/managed, don't crash */
                             }
@@ -189,7 +187,11 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
         table.getColumnModel().getColumn(0).setPreferredWidth(30);
 
         /* Hide the columns. But keep it in memory for the tooltip */
-        TableColumn column = table.getColumnModel().getColumn(BrowseVar.FROM_SCILAB_COLUMN_INDEX);
+        TableColumn column = table.getColumnModel().getColumn(BrowseVar.TYPE_COLUMN_INDEX);
+        /* The order to removing does matter since it changes the positions */
+        table.removeColumn(column);
+
+        column = table.getColumnModel().getColumn(BrowseVar.FROM_SCILAB_COLUMN_INDEX);
         table.removeColumn(column);
 
         column = table.getColumnModel().getColumn(BrowseVar.BYTES_COLUMN_INDEX);
@@ -259,14 +261,15 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
                 System.err.println(e);
             }
         }
-        VariableBrowserRowTypeFilter rowFilter = new VariableBrowserRowTypeFilter(getFilteredTypeValues());
+        VariableBrowserRowTypeFilter rowTypeFilter = new VariableBrowserRowTypeFilter(getFilteredTypeValues());
         VariableBrowserRowDataFilter rowDataFilter = new VariableBrowserRowDataFilter(getFilteredDataValues());
 
         List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>();
         RowFilter<Object, Object> compoundRowFilter = null;
-        filters.add(rowFilter);
+        filters.add(rowTypeFilter);
         filters.add(rowDataFilter);
         compoundRowFilter = RowFilter.andFilter(filters);
+
         rowSorter.setRowFilter(compoundRowFilter);
         table.setRowSorter(rowSorter);