Changeset 5317
- Timestamp:
- 2003-08-28T12:36:27+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/WGet.java
r4675 r5317 38 38 import java.awt.*; 39 39 import java.io.*; 40 import java.net.*; 40 41 import java.util.*; 41 42 import javax.swing.*; … … 43 44 import org.greenstone.gatherer.Gatherer; 44 45 import org.greenstone.gatherer.collection.Job; 45 import org.greenstone.gatherer.util.GURL;46 46 /** This class provides access to the functionality of the WGet program, either by calling it via a shell script or by the JNI. It maintains a queue of pending jobs, and the component for showing these tasks to the user. 47 47 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 50 50 public class WGet 51 51 extends Thread { 52 52 53 /** <i>true</i> if there is a task currently being carried out, <i>false</i> otherwise. */ 53 54 private boolean busy = false; … … 56 57 /** <i>true</i> if successfully completed tasks should be automatically removed from the job queue. */ 57 58 private boolean remove_complete_jobs = true; 58 /** The panel that the task list will be shown it. */ 59 60 private JPanel filler_pane = null; 61 /** The panel that the task list will be shown in. */ 59 62 private JPanel list_pane; 60 63 /** The job currently underway. */ … … 77 80 job = null; 78 81 job_queue = new Vector(); 82 filler_pane = new JPanel(); 79 83 list_pane = new JPanel(); 80 84 list_pane.setLayout(new BoxLayout(list_pane, BoxLayout.Y_AXIS)); 81 //list_pane.setLayout(new GridLayout( 1,1));85 //list_pane.setLayout(new GridLayout(height_count,1)); 82 86 list_scroll = new JScrollPane(list_pane); 83 87 //list_scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); … … 173 177 if(delete_me.hasSignalledStop()) { 174 178 list_pane.remove(delete_me.getProgressBar()); 179 job_queue.remove(delete_me); 180 // Unfortunately removing a task gets a bit more complicated as we have to resize the filler 181 list_pane.remove(filler_pane); 182 if(job_queue.size() > 0) { 183 Dimension progress_bar_size = delete_me.getProgressBar().getPreferredSize(); 184 Dimension list_pane_size = list_pane.getSize(); 185 int height = list_pane_size.height - (job_queue.size() * progress_bar_size.height); 186 progress_bar_size = null; 187 if(height > 0) { 188 filler_pane.setPreferredSize(new Dimension(list_pane_size.width, height)); 189 list_pane.add(filler_pane); 190 } 191 list_pane_size = null; 192 } 175 193 list_pane.updateUI(); 176 job_queue.remove(delete_me);177 194 } 178 195 else { … … 227 244 228 245 /** Creates a new mirroring job on the queue given the target url and the destination (private, public). All other details are harvested from the config file, but these two must be captured from the GUI's current state. 229 * @param url A <strong>GURL</strong> which points to the root url for the mirroring.230 * @param model The <strong>GTreeModel</strong> that any new records should be added to.231 * @param destination The destination file as a <strong>String</strong>.246 * @param url a URL which points to the root url for the mirroring 247 * @param model the GTreeModel that any new records should be added to 248 * @param destination the destination file as a String 232 249 * @see org.greenstone.gatherer.Configuration 233 250 * @see org.greenstone.gatherer.Gatherer … … 236 253 * @see org.greenstone.gatherer.util.GURL 237 254 */ 238 public void newJob(GURL url, TreeModel model, String destination) { 239 if(url.valid()) { 240 // Create the job and fill in the details from gatherer.config. 241 Gatherer.println("About to create a new job"); 242 Job new_job = new Job(model, Gatherer.config.get("mirroring.overwrite", false), Gatherer.config.get("mirroring.debug", false), Gatherer.config.get("mirroring.no_parents", false), Gatherer.config.get("mirroring.other_hosts", false), Gatherer.config.get("mirroring.page_requisites", false), Gatherer.config.get("mirroring.quiet", false), url, Gatherer.config.getInt("mirroring.depth", false), destination, Gatherer.config.proxy_pass, Gatherer.config.proxy_user, this, simple); 243 // Add to job_queue job list. 244 job_queue.add(new_job); 245 // Now add it to the visual component, job list. 246 list_pane.add(new_job.getProgressBar()); 247 //list_pane.setAlignmentX(Component.LEFT_ALIGNMENT); 248 list_pane.updateUI(); 249 new_job = null; 250 synchronized(this) { 251 notify(); // Just incase its sleeping. 252 } 255 public void newJob(TreeModel model, boolean overwrite, boolean no_parents, boolean other_hosts, boolean page_requisites, URL url, int depth, String destination) { 256 // Create the job and fill in the details from gatherer.config. 257 Gatherer.println("About to create a new job"); 258 // If it was decided not to download page requisites, then create the destination by basing it on the given destination, but appending the url host. If page requisites is used then WGet will do this for us 259 if(!page_requisites) { 260 destination = destination + url.getHost(); 261 } 262 Job new_job = new Job(model, overwrite, Gatherer.config.get("mirroring.debug", false), no_parents, other_hosts, page_requisites, Gatherer.config.get("mirroring.quiet", false), url, depth, destination, Gatherer.config.proxy_pass, Gatherer.config.proxy_user, this, simple); 263 // Add to job_queue job list. 264 job_queue.add(new_job); 265 // Now add it to the visual component, job list. 266 list_pane.remove(filler_pane); 267 Dimension progress_bar_size = new_job.getProgressBar().getPreferredSize(); 268 Dimension list_pane_size = list_pane.getSize(); 269 int height = list_pane_size.height - (job_queue.size() * progress_bar_size.height); 270 progress_bar_size = null; 271 list_pane.add(new_job.getProgressBar()); 272 if(height > 0) { 273 filler_pane.setPreferredSize(new Dimension(list_pane_size.width, height)); 274 list_pane.add(filler_pane); 275 } 276 list_pane_size = null; 277 //list_pane.setAlignmentX(Component.LEFT_ALIGNMENT); 278 list_pane.updateUI(); 279 new_job = null; 280 synchronized(this) { 281 notify(); // Just incase its sleeping. 253 282 } 254 283 } … … 287 316 // If there are jobs job_queue and we have more room. 288 317 if(job_queue.size() > 0) { 289 // Get the first job that isn't stopped. 290 for(Enumeration e = job_queue.elements(); e.hasMoreElements();) { 291 job = (Job) e.nextElement(); 318 int index = 0; 319 while(index < job_queue.size()) { 320 // Get the first job that isn't stopped. 321 job = (Job) job_queue.get(index); 292 322 if(job.getState() == Job.RUNNING) { 293 323 Gatherer.println("Job " + job.toString() + " Begun."); … … 303 333 busy = false; 304 334 Gatherer.println("Job " + job.toString() + " complete."); 305 // And if the user has requested that complete jobs 306 // be removed, then remove it from the list. 307 if(remove_complete_jobs) { 308 deleteJob(job); 309 } 335 // And if the user has requested that complete jobs 336 // be removed, then remove it from the list. 337 deleteJob(job); 310 338 job = null; 311 339 } 340 index++; 312 341 } 313 342 }
Note:
See TracChangeset
for help on using the changeset viewer.