* Bug #13942 fixed - tree is not resized when expanded/collapsed 60/17160/2
Marcos CARDINOT [Wed, 29 Jul 2015 18:22:00 +0000 (15:22 -0300)]
- implements a tree expand listener

Change-Id: I4e89374eefbe0f0cc15007a6886d001b2f57f5e1

scilab/CHANGES_6.0.X
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteManagerTreeWillExpandListener.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteManagerPanel.java

index 432ce71..a67bf8d 100644 (file)
@@ -284,6 +284,9 @@ Scilab Bug Fixes
 * Bug #13941 fixed - Internal timestamps of HDF5 files prevented having a fixed
                      hash for an unvarying set of saved objects.
 
+* Bug #13942 fixed - Now the palette browser tree is always resized when
+                     expanded/collapsed.
+
 * Bug #13971 fixed - A space has been added between Scilab prompt and cursor.
 
 * Bug #13972 fixed - Wildcard ('*') was not managed in printf expressions.
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteManagerTreeWillExpandListener.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteManagerTreeWillExpandListener.java
new file mode 100644 (file)
index 0000000..3a24b6d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Marcos CARDINOT
+ *
+ * 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.1-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.palette.listener;
+
+import javax.swing.JSplitPane;
+import javax.swing.JTree;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeWillExpandListener;
+import javax.swing.tree.ExpandVetoException;
+
+/**
+ * Implement the tree expand listener
+ */
+public class PaletteManagerTreeWillExpandListener implements TreeWillExpandListener {
+
+    /**
+     * Default constructor
+     */
+    public PaletteManagerTreeWillExpandListener() {
+    }
+
+    @Override
+    public void treeWillCollapse(TreeExpansionEvent e)
+            throws ExpandVetoException {
+        JTree tree = (JTree) e.getSource();
+        JSplitPane splitPanel = (JSplitPane) tree.getParent().getParent().getParent();
+        splitPanel.resetToPreferredSizes();
+    }
+
+    @Override
+    public void treeWillExpand(TreeExpansionEvent e)
+            throws ExpandVetoException {
+        JTree tree = (JTree) e.getSource();
+        JSplitPane splitPanel = (JSplitPane) tree.getParent().getParent().getParent();
+        splitPanel.resetToPreferredSizes();
+    }
+
+}
index 68b748c..992e915 100644 (file)
@@ -26,6 +26,7 @@ import javax.swing.tree.TreeSelectionModel;
 import org.scilab.modules.xcos.palette.PaletteManager;
 import org.scilab.modules.xcos.palette.listener.PaletteManagerMouseListener;
 import org.scilab.modules.xcos.palette.listener.PaletteManagerTreeSelectionListener;
+import org.scilab.modules.xcos.palette.listener.PaletteManagerTreeWillExpandListener;
 import org.scilab.modules.xcos.palette.listener.PaletteTreeTransferHandler;
 import org.scilab.modules.xcos.utils.XcosConstants;
 
@@ -68,6 +69,7 @@ public class PaletteManagerPanel extends JSplitPane {
         tree.getSelectionModel().setSelectionMode(
             TreeSelectionModel.SINGLE_TREE_SELECTION);
         tree.addMouseListener(new PaletteManagerMouseListener());
+        tree.addTreeWillExpandListener(new PaletteManagerTreeWillExpandListener());
         tree.addTreeSelectionListener(new PaletteManagerTreeSelectionListener(
                                           panel));