* Bug #11497 fixed - A lot of EDT violation was detected by the 50/10350/4
Clément DAVID [Thu, 31 Jan 2013 16:30:54 +0000 (17:30 +0100)]
                     ThreadCheckingRepaintManager tool.

Change-Id: I07895ab937e2aa3da6c2ecc00fe4e73e3391445e

scilab/CHANGES_5.4.X
scilab/modules/history_browser/src/java/org/scilab/modules/history_browser/CommandHistory.java

index 1315487..fc2d133 100644 (file)
@@ -220,6 +220,9 @@ Bug fixes
 
 * Bug #11477 fixed - There were memory leaks with textures.
 
+* Bug #11497 fixed - A lot of EDT violation was detected by the
+                     ThreadCheckingRepaintManager tool.
+
 * Bug #11711 fixed - xclick and xgetmouse did not work under Mac OS X.
 
 * Bug #11778 fixed - Bad color_map dims did not return an error.
index db34f0e..5c44985 100644 (file)
@@ -18,6 +18,10 @@ import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Collections;
 
 import javax.swing.BoundedRangeModel;
 import javax.swing.JPanel;
@@ -25,6 +29,7 @@ import javax.swing.JScrollBar;
 import javax.swing.JScrollPane;
 import javax.swing.JTree;
 import javax.swing.SwingUtilities;
+import javax.swing.Timer;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeCellRenderer;
 import javax.swing.tree.DefaultTreeModel;
@@ -86,8 +91,19 @@ public final class CommandHistory extends SwingScilabTab implements SimpleTab {
     private static boolean modelLoaded;
     private static boolean initialized;
 
+    private static java.util.List<String> linesToAppend;
+    private static javax.swing.Timer linesToAppendTimer;
+
     static {
         ScilabTabFactory.getInstance().addTabFactory(CommandHistoryTabFactory.getInstance());
+
+        linesToAppend = Collections.synchronizedList(new ArrayList<String>());
+        linesToAppendTimer = new Timer(0, new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                appendLinesOnEDT();
+            }
+        });
+        linesToAppendTimer.setRepeats(false);
     }
 
     /**
@@ -190,13 +206,19 @@ public final class CommandHistory extends SwingScilabTab implements SimpleTab {
      * Update the browser once an history file has been loaded
      */
     public static void loadFromFile() {
-        reset();
-        String historyLines[] = HistoryManagement.getAllLinesOfScilabHistory();
-        int nbEntries = historyLines.length;
-        for (int entryIndex = 0; entryIndex < nbEntries; entryIndex++) {
-            /* Do not expand at each insertion for performances reasons */
-            appendLineAndExpand(historyLines[entryIndex], false);
-        }
+        final String historyLines[] = HistoryManagement.getAllLinesOfScilabHistory();
+
+        SwingUtilities.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                reset();
+                int nbEntries = historyLines.length;
+                for (int entryIndex = 0; entryIndex < nbEntries; entryIndex++) {
+                    /* Do not expand at each insertion for performances reasons */
+                    appendLineAndExpand(historyLines[entryIndex], false);
+                }
+            }
+        });
 
         /* Expand all sessions tree */
         expandAll();
@@ -238,7 +260,19 @@ public final class CommandHistory extends SwingScilabTab implements SimpleTab {
      * @param lineToAppend the line to append
      */
     public static void appendLine(String lineToAppend) {
-        appendLineAndExpand(lineToAppend, true);
+        synchronized (linesToAppend) {
+            linesToAppend.add(lineToAppend);
+            linesToAppendTimer.start();
+        }
+    }
+
+    public static void appendLinesOnEDT() {
+        synchronized (linesToAppend) {
+            for (String lineToAppend : linesToAppend) {
+                appendLineAndExpand(lineToAppend, true);
+            }
+            linesToAppend.clear();
+        }
     }
 
     /**