KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > LoadProcess


1 /*
2  * LoadProcess.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: LoadProcess.java,v 1.1.1.1 2002/09/24 16:09:06 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 public abstract class LoadProcess implements BackgroundProcess, Runnable JavaDoc, Cancellable
25 {
26     protected Buffer buffer;
27     protected File file;
28     protected Runnable JavaDoc successRunnable;
29     protected ErrorRunnable errorRunnable;
30     protected ProgressNotifier progressNotifier;
31     protected File cache;
32     protected boolean cancelled;
33
34     private String JavaDoc errorText;
35     private Thread JavaDoc 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 JavaDoc r)
49     {
50         successRunnable = r;
51     }
52
53     public final void setCancelRunnable(Runnable JavaDoc 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 JavaDoc getErrorText()
79     {
80         return errorText;
81     }
82
83     protected final void setErrorText(String JavaDoc 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 JavaDoc(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     // Can be overridden.
113
protected Runnable JavaDoc cancelRunnable = new Runnable JavaDoc() {
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