Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleaned code a bit

  • Loading branch information...
commit 300f54d8aacdb9b65d09119add51c2a657644aec 1 parent a3a724f
authored October 10, 2012
1  src/dloader/GUI.java
@@ -205,7 +205,6 @@ public void actionPerformed(ActionEvent e) {
205 205
 		sl_panel.putConstraint(SpringLayout.EAST, lblStatus, -6, SpringLayout.WEST, btnStop);
206 206
 		sl_panel.putConstraint(SpringLayout.WEST, btnStop, -100, SpringLayout.EAST, panel);
207 207
 		btnStop.setFont(new Font("Courier New", Font.BOLD, 14));
208  
-		btnStop.setForeground(Color.RED);
209 208
 		sl_panel.putConstraint(SpringLayout.NORTH, btnStop, 8, SpringLayout.SOUTH, chckbxUseCache);
210 209
 		sl_panel.putConstraint(SpringLayout.EAST, btnStop, -10, SpringLayout.EAST, panel);
211 210
 		btnStop.addActionListener(new ActionListener() {
10  src/dloader/JobMaster.java
... ...
@@ -1,6 +1,5 @@
1 1
 package dloader;
2 2
 
3  
-import java.util.HashMap;
4 3
 import java.util.concurrent.*;
5 4
 
6 5
 
@@ -77,7 +76,6 @@
77 76
 	 */
78 77
 	public
79 78
 	void goGoGo() {
80  
-		HashMap<AbstractPage, Boolean> checkSavingRequirementResult;
81 79
 		synchronized (this) {
82 80
 			// can be ran only once;
83 81
 			if (rootPage == null) return;
@@ -86,9 +84,7 @@ void goGoGo() {
86 84
 			case READCACHEPAGES: submit(new ReadCacheJob(rootPage, this)); break;
87 85
 			case UPDATEPAGES: submit(new UpdatePageJob(rootPage, this, !Main.allowFromCache)); break;
88 86
 			case SAVEDATA: submit(new SaveDataJob(rootPage, this)); break;
89  
-			case CHECKSAVINGREQUIREMENT:
90  
-				checkSavingRequirementResult = new HashMap<>(200);
91  
-				submit(new CheckSavingJob(rootPage, this, checkSavingRequirementResult)); break;
  87
+			case CHECKSAVINGREQUIREMENT: submit(new CheckSavingJob(rootPage, this, true)); break;
92 88
 			}
93 89
 		}
94 90
 		
@@ -97,8 +93,8 @@ void goGoGo() {
97 93
 			try {
98 94
 				results.poll().get();
99 95
 			} catch (InterruptedException | ExecutionException e) {
100  
-				// TODO Auto-generated catch block
101  
-				e.printStackTrace();
  96
+				// TODO Stop all jobs
  97
+				break;
102 98
 			}
103 99
 		
104 100
 		executor.shutdown();
23  src/dloader/gui/MyWorker.java
@@ -51,13 +51,14 @@ public void report(AbstractPage page, String type, long i) {
51 51
 		
52 52
 		if (whatToDo.equals(JobType.CHECKSAVINGREQUIREMENT))
53 53
 			savingReqJobResults = new HashMap<>(200);
  54
+			
54 55
 	}
55 56
 
56 57
 	// called in worker thread
57 58
 	@Override
58 59
 	protected Object doInBackground() throws Exception {
59 60
 		if (jm != null)
60  
-			jm.goGoGo(); // -> several calls to jm.report() -> publish() -> process() -> gui.updateTree()
  61
+			jm.goGoGo(); // -> several calls to PageJob.report() -> jm.report() -> SwingWorker.publish() -> this.process() -> gui.updateTree()
61 62
 		return null; // call to done() -> gui.myWorkerDone()
62 63
 	}
63 64
 
@@ -65,21 +66,29 @@ protected Object doInBackground() throws Exception {
65 66
 	@Override
66 67
 	protected void process(List<ProgressReportStruct> chunks) {
67 68
 		for (ProgressReportStruct element : chunks) {
68  
-			if (jm.whatToDo.equals(JobType.CHECKSAVINGREQUIREMENT))
69  
-				savingReqJobResults.put(element.page, element.value);
70  
-			else
71  
-				// kind of stupid.
  69
+			switch (jm.whatToDo) {
  70
+			case CHECKSAVINGREQUIREMENT:
  71
+				savingReqJobResults.put(element.page, element.value); // 1st combine all, then update all after jobs are done
  72
+				break;
  73
+			default:
  74
+				// pass individual messages
72 75
 				Main.gui.updateTree(element.page, element.type, element.value);
  76
+			
  77
+			}
  78
+				
73 79
 		}
74 80
 	}
75 81
 	
76 82
 	// called in ED thread
77 83
 	@Override
78 84
 	protected void done() {
79  
-		if (jm.whatToDo.equals(JobType.CHECKSAVINGREQUIREMENT))
  85
+		switch (jm.whatToDo) {
  86
+		case CHECKSAVINGREQUIREMENT:
80 87
 			Main.gui.myWorkerDoneCheckSavingReq(jm.rootPage, savingReqJobResults);
81  
-		else
  88
+			break;
  89
+		default:
82 90
 			Main.gui.myWorkerDone(jm.rootPage, jm.whatToDo);
  91
+		}
83 92
 	}
84 93
 
85 94
 	/**
28  src/dloader/pagejob/CheckSavingJob.java
... ...
@@ -1,21 +1,19 @@
1 1
 package dloader.pagejob;
2 2
 
3  
-import java.util.HashMap;
4  
-
5 3
 import dloader.JobMaster;
6 4
 import dloader.page.AbstractPage;
7 5
 
8 6
 public class CheckSavingJob extends PageJob {
9 7
 
10  
-	private HashMap<AbstractPage, Boolean> results;
  8
+	private boolean recurse;
11 9
 	
12 10
 	public CheckSavingJob(AbstractPage page, JobMaster owner) {
13  
-		this(page, owner, null);
  11
+		this(page, owner, false);
14 12
 	}	
15 13
 	
16  
-	public CheckSavingJob(AbstractPage page, JobMaster owner, HashMap<AbstractPage, Boolean> results) {
  14
+	public CheckSavingJob(AbstractPage page, JobMaster owner, boolean recurse) {
17 15
 		super(page, owner);
18  
-		this.results = results;
  16
+		this.recurse = recurse;
19 17
 	}
20 18
 
21 19
 	/**
@@ -25,18 +23,14 @@ public CheckSavingJob(AbstractPage page, JobMaster owner, HashMap<AbstractPage,
25 23
 	 */	
26 24
 	@Override
27 25
 	public void run() {
28  
-		if (results == null) {		
29  
-			if (page.isSavingNotRequired()) 
30  
-				report("saving not required", 1); 
31  
-			else
32  
-				report("saving required", 1);
33  
-		} else {
34  
-			report ("",  page.isSavingNotRequired()? 1: 0); // special kind of report that will not propagate to updateTree() directly
  26
+		if (page.isSavingNotRequired()) 
  27
+			report("saving not required", 1); 
  28
+		else
  29
+			report("saving required", 1);
35 30
 			
  31
+		if (recurse)
36 32
 			//note: this iterator does not require locking because of CopyOnWriteArrayList implementation
37  
-			if (results != null)
38  
-				for (AbstractPage child: page.childPages)
39  
-					jobMaster.submit(new CheckSavingJob(child, jobMaster, results));
40  
-		}
  33
+			for (AbstractPage child: page.childPages)
  34
+				jobMaster.submit(new CheckSavingJob(child, jobMaster, true));
41 35
 	}
42 36
 }
2  src/dloader/pagejob/UpdatePageJob.java
@@ -66,7 +66,7 @@ public void run() {
66 66
 			}
67 67
 			
68 68
 			//saving pre-check for faster visual;
69  
-			CheckSavingJob checkJob = new CheckSavingJob(page, jobMaster, null);
  69
+			CheckSavingJob checkJob = new CheckSavingJob(page, jobMaster, false);
70 70
 			checkJob.run();
71 71
 		} catch (ProblemsReadingDocumentException e) {
72 72
 			report("download failed", 1);

0 notes on commit 300f54d

Please sign in to comment.
Something went wrong with that request. Please try again.