Fix syncing TaskWindow.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
@@ -30,7 +31,7 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
*/
|
||||
public class TaskList extends Thread {
|
||||
|
||||
List<Task> taskQueue = Collections.synchronizedList(new ArrayList());
|
||||
List<Task> taskQueue = Collections.synchronizedList(new LinkedList<>());
|
||||
ArrayList<Runnable> allDone = new ArrayList();
|
||||
ArrayList<DoingDoneListener<Task>> taskListener = new ArrayList();
|
||||
|
||||
@@ -143,8 +144,8 @@ public class TaskList extends Thread {
|
||||
|
||||
threadPool.clear();
|
||||
totTask = taskQueue.size();
|
||||
for (Task taskQueue1 : taskQueue)
|
||||
executeTask(taskQueue1);
|
||||
while(!taskQueue.isEmpty())
|
||||
executeTask(taskQueue.remove(0));
|
||||
if (shouldContinue)
|
||||
for (Runnable d : allDone)
|
||||
d.run();
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
</SyntheticProperties>
|
||||
<Events>
|
||||
<EventHandler event="windowClosed" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosed"/>
|
||||
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jackhuang.hellominecraft.tasks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
@@ -33,10 +34,14 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
|
||||
private static final TaskWindow instance = new TaskWindow();
|
||||
|
||||
public static TaskWindow getInstance() {
|
||||
private static TaskWindow inst() {
|
||||
instance.clean();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static TaskWindowFactory getInstance() {
|
||||
return new TaskWindowFactory();
|
||||
}
|
||||
|
||||
boolean suc = false;
|
||||
|
||||
@@ -75,7 +80,7 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
if (taskList.isAlive()) return false;
|
||||
if (isVisible() || taskList.isAlive()) return false;
|
||||
pgsTotal.setValue(0);
|
||||
suc = false;
|
||||
SwingUtils.clearDefaultTable(lstDownload);
|
||||
@@ -113,6 +118,9 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
public void windowClosed(java.awt.event.WindowEvent evt) {
|
||||
formWindowClosed(evt);
|
||||
}
|
||||
public void windowClosing(java.awt.event.WindowEvent evt) {
|
||||
formWindowClosing(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setText(bundle.getString("taskwindow.cancel")); // NOI18N
|
||||
@@ -174,8 +182,13 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
SwingUtilities.invokeLater(taskList::abort);
|
||||
HMCLog.log("Tasks have been canceled by user.");
|
||||
}
|
||||
taskList = null;
|
||||
}//GEN-LAST:event_formWindowClosed
|
||||
|
||||
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_formWindowClosing
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JTable lstDownload;
|
||||
@@ -262,4 +275,23 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
SwingUtils.setValueAt(lstDownload, task.getInfo() + ": " + sta, idx, 0);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TaskWindowFactory {
|
||||
public static final Object obj = new Object();
|
||||
|
||||
LinkedList<Task> ll = new LinkedList<>();
|
||||
|
||||
public TaskWindowFactory addTask(Task t) {
|
||||
ll.add(t);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean start() {
|
||||
synchronized(obj) {
|
||||
TaskWindow tw = inst();
|
||||
for(Task t : ll) tw.addTask(t);
|
||||
return tw.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user