* Bug 16633: now Listbox callback can be triggered by item click 81/21681/4
mottelet [Thu, 21 Jan 2021 07:48:37 +0000 (08:48 +0100)]
https://bugzilla.scilab.org/show_bug.cgi?id=16633

Movie: https://bugzilla.scilab.org/attachment.cgi?id=5219

Change-Id: Ia54de8cb31f21628b47d6e6a5514b13dafccb325

scilab/CHANGES.md
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/listbox/SwingScilabListBox.java

index f367c66..9f4248d 100644 (file)
@@ -224,6 +224,7 @@ Feature changes and additions on 6.1.1
 * `gamma` is extended to incomplete gamma integrals.
 * `close` is extended to close the help browser, xcos, or the variables browser or editor GUIs.
 * `polyint` is introduced to compute polynomial antiderivatives.
+* Listbox uicontrol callback is now triggered by item click in single selection mode. For example, it allows successive execution of a demo in the demonstrations gui.
 
 
 Help pages:
index e62cc01..4de22e7 100644 (file)
@@ -31,6 +31,8 @@ import java.awt.Font;
 import java.awt.event.AdjustmentEvent;
 import java.awt.event.AdjustmentListener;
 import java.io.IOException;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 
 import javax.swing.DefaultListModel;
 import javax.swing.Icon;
@@ -140,13 +142,21 @@ public class SwingScilabListBox extends JScrollPane implements SwingViewObject,
                 }
 
                 GraphicController.getController().setProperty(uid, __GO_UI_VALUE__, scilabIndices);
-                if (callback != null) {
+                if (callback != null && getList().getSelectionMode() == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) {
                     callback.actionPerformed(null);
                 }
             }
         };
         getList().addListSelectionListener(listListener);
 
+         getList().addMouseListener(new MouseAdapter() {
+            public void mouseReleased(MouseEvent evt) {
+                if (callback != null && getList().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) {
+                    callback.actionPerformed(null);
+                }
+            }
+        });
+
         adjustmentListener = new AdjustmentListener() {
             public void adjustmentValueChanged(AdjustmentEvent arg0) {
                 int listboxtopValue = getList().getUI().locationToIndex(getList(), getViewport().getViewPosition()) + 1;