1 21 22 package org.armedbear.j; 23 24 public abstract class LoadProcess implements BackgroundProcess, Runnable , Cancellable 25 { 26 protected Buffer buffer; 27 protected File file; 28 protected Runnable successRunnable; 29 protected ErrorRunnable errorRunnable; 30 protected ProgressNotifier progressNotifier; 31 protected File cache; 32 protected boolean cancelled; 33 34 private String errorText; 35 private Thread thread; 36 37 protected LoadProcess(Buffer buffer, File file) 38 { 39 this.buffer = buffer; 40 this.file = file; 41 } 42 43 public final File getFile() 44 { 45 return file; 46 } 47 48 public final void setSuccessRunnable(Runnable r) 49 { 50 successRunnable = r; 51 } 52 53 public final void setCancelRunnable(Runnable r) 54 { 55 cancelRunnable = r; 56 } 57 58 public final void setErrorRunnable(ErrorRunnable r) 59 { 60 errorRunnable = r; 61 } 62 63 public void setProgressNotifier(ProgressNotifier progressNotifier) 64 { 65 this.progressNotifier = progressNotifier; 66 } 67 68 public final File getCache() 69 { 70 return cache; 71 } 72 73 public final boolean cancelled() 74 { 75 return cancelled; 76 } 77 78 public final String getErrorText() 79 { 80 return errorText; 81 } 82 83 protected final void setErrorText(String s) 84 { 85 errorText = s; 86 } 87 88 public void start() 89 { 90 buffer.setBusy(true); 91 for (EditorIterator it = new EditorIterator(); it.hasNext();) { 92 Editor ed = it.nextEditor(); 93 if (ed.getBuffer() == buffer) 94 ed.setWaitCursor(); 95 } 96 thread = new Thread (this); 97 thread.start(); 98 } 99 100 public void cancel() 101 { 102 if (thread != null) 103 thread.interrupt(); 104 cancelled = true; 105 if (progressNotifier != null) { 106 progressNotifier.cancel(); 107 progressNotifier.progressStop(); 108 progressNotifier.setText("Transfer cancelled"); 109 } 110 } 111 112 protected Runnable cancelRunnable = new Runnable () { 114 public void run() 115 { 116 buffer.setBusy(false); 117 for (EditorIterator it = new EditorIterator(); it.hasNext();) { 118 Editor ed = it.nextEditor(); 119 if (ed.getBuffer() == buffer) { 120 ed.status("Transfer cancelled"); 121 ed.setDefaultCursor(); 122 } 123 } 124 MessageDialog.showMessageDialog("Transfer cancelled", file.netPath()); 125 } 126 }; 127 } 128 | Popular Tags |