Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleaned code a bit

  • Loading branch information...
commit 300f54d8aacdb9b65d09119add51c2a657644aec 1 parent a3a724f
Acerbic authored
View
1  src/dloader/GUI.java
@@ -205,7 +205,6 @@ public void actionPerformed(ActionEvent e) {
sl_panel.putConstraint(SpringLayout.EAST, lblStatus, -6, SpringLayout.WEST, btnStop);
sl_panel.putConstraint(SpringLayout.WEST, btnStop, -100, SpringLayout.EAST, panel);
btnStop.setFont(new Font("Courier New", Font.BOLD, 14));
- btnStop.setForeground(Color.RED);
sl_panel.putConstraint(SpringLayout.NORTH, btnStop, 8, SpringLayout.SOUTH, chckbxUseCache);
sl_panel.putConstraint(SpringLayout.EAST, btnStop, -10, SpringLayout.EAST, panel);
btnStop.addActionListener(new ActionListener() {
View
10 src/dloader/JobMaster.java
@@ -1,6 +1,5 @@
package dloader;
-import java.util.HashMap;
import java.util.concurrent.*;
@@ -77,7 +76,6 @@
*/
public
void goGoGo() {
- HashMap<AbstractPage, Boolean> checkSavingRequirementResult;
synchronized (this) {
// can be ran only once;
if (rootPage == null) return;
@@ -86,9 +84,7 @@ void goGoGo() {
case READCACHEPAGES: submit(new ReadCacheJob(rootPage, this)); break;
case UPDATEPAGES: submit(new UpdatePageJob(rootPage, this, !Main.allowFromCache)); break;
case SAVEDATA: submit(new SaveDataJob(rootPage, this)); break;
- case CHECKSAVINGREQUIREMENT:
- checkSavingRequirementResult = new HashMap<>(200);
- submit(new CheckSavingJob(rootPage, this, checkSavingRequirementResult)); break;
+ case CHECKSAVINGREQUIREMENT: submit(new CheckSavingJob(rootPage, this, true)); break;
}
}
@@ -97,8 +93,8 @@ void goGoGo() {
try {
results.poll().get();
} catch (InterruptedException | ExecutionException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // TODO Stop all jobs
+ break;
}
executor.shutdown();
View
23 src/dloader/gui/MyWorker.java
@@ -51,13 +51,14 @@ public void report(AbstractPage page, String type, long i) {
if (whatToDo.equals(JobType.CHECKSAVINGREQUIREMENT))
savingReqJobResults = new HashMap<>(200);
+
}
// called in worker thread
@Override
protected Object doInBackground() throws Exception {
if (jm != null)
- jm.goGoGo(); // -> several calls to jm.report() -> publish() -> process() -> gui.updateTree()
+ jm.goGoGo(); // -> several calls to PageJob.report() -> jm.report() -> SwingWorker.publish() -> this.process() -> gui.updateTree()
return null; // call to done() -> gui.myWorkerDone()
}
@@ -65,21 +66,29 @@ protected Object doInBackground() throws Exception {
@Override
protected void process(List<ProgressReportStruct> chunks) {
for (ProgressReportStruct element : chunks) {
- if (jm.whatToDo.equals(JobType.CHECKSAVINGREQUIREMENT))
- savingReqJobResults.put(element.page, element.value);
- else
- // kind of stupid.
+ switch (jm.whatToDo) {
+ case CHECKSAVINGREQUIREMENT:
+ savingReqJobResults.put(element.page, element.value); // 1st combine all, then update all after jobs are done
+ break;
+ default:
+ // pass individual messages
Main.gui.updateTree(element.page, element.type, element.value);
+
+ }
+
}
}
// called in ED thread
@Override
protected void done() {
- if (jm.whatToDo.equals(JobType.CHECKSAVINGREQUIREMENT))
+ switch (jm.whatToDo) {
+ case CHECKSAVINGREQUIREMENT:
Main.gui.myWorkerDoneCheckSavingReq(jm.rootPage, savingReqJobResults);
- else
+ break;
+ default:
Main.gui.myWorkerDone(jm.rootPage, jm.whatToDo);
+ }
}
/**
View
28 src/dloader/pagejob/CheckSavingJob.java
@@ -1,21 +1,19 @@
package dloader.pagejob;
-import java.util.HashMap;
-
import dloader.JobMaster;
import dloader.page.AbstractPage;
public class CheckSavingJob extends PageJob {
- private HashMap<AbstractPage, Boolean> results;
+ private boolean recurse;
public CheckSavingJob(AbstractPage page, JobMaster owner) {
- this(page, owner, null);
+ this(page, owner, false);
}
- public CheckSavingJob(AbstractPage page, JobMaster owner, HashMap<AbstractPage, Boolean> results) {
+ public CheckSavingJob(AbstractPage page, JobMaster owner, boolean recurse) {
super(page, owner);
- this.results = results;
+ this.recurse = recurse;
}
/**
@@ -25,18 +23,14 @@ public CheckSavingJob(AbstractPage page, JobMaster owner, HashMap<AbstractPage,
*/
@Override
public void run() {
- if (results == null) {
- if (page.isSavingNotRequired())
- report("saving not required", 1);
- else
- report("saving required", 1);
- } else {
- report ("", page.isSavingNotRequired()? 1: 0); // special kind of report that will not propagate to updateTree() directly
+ if (page.isSavingNotRequired())
+ report("saving not required", 1);
+ else
+ report("saving required", 1);
+ if (recurse)
//note: this iterator does not require locking because of CopyOnWriteArrayList implementation
- if (results != null)
- for (AbstractPage child: page.childPages)
- jobMaster.submit(new CheckSavingJob(child, jobMaster, results));
- }
+ for (AbstractPage child: page.childPages)
+ jobMaster.submit(new CheckSavingJob(child, jobMaster, true));
}
}
View
2  src/dloader/pagejob/UpdatePageJob.java
@@ -66,7 +66,7 @@ public void run() {
}
//saving pre-check for faster visual;
- CheckSavingJob checkJob = new CheckSavingJob(page, jobMaster, null);
+ CheckSavingJob checkJob = new CheckSavingJob(page, jobMaster, false);
checkJob.run();
} catch (ProblemsReadingDocumentException e) {
report("download failed", 1);
Please sign in to comment.
Something went wrong with that request. Please try again.