001: /*
002: * LoadProcess.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: LoadProcess.java,v 1.1.1.1 2002/09/24 16:09:06 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: public abstract class LoadProcess implements BackgroundProcess,
025: Runnable, Cancellable {
026: protected Buffer buffer;
027: protected File file;
028: protected Runnable successRunnable;
029: protected ErrorRunnable errorRunnable;
030: protected ProgressNotifier progressNotifier;
031: protected File cache;
032: protected boolean cancelled;
033:
034: private String errorText;
035: private Thread thread;
036:
037: protected LoadProcess(Buffer buffer, File file) {
038: this .buffer = buffer;
039: this .file = file;
040: }
041:
042: public final File getFile() {
043: return file;
044: }
045:
046: public final void setSuccessRunnable(Runnable r) {
047: successRunnable = r;
048: }
049:
050: public final void setCancelRunnable(Runnable r) {
051: cancelRunnable = r;
052: }
053:
054: public final void setErrorRunnable(ErrorRunnable r) {
055: errorRunnable = r;
056: }
057:
058: public void setProgressNotifier(ProgressNotifier progressNotifier) {
059: this .progressNotifier = progressNotifier;
060: }
061:
062: public final File getCache() {
063: return cache;
064: }
065:
066: public final boolean cancelled() {
067: return cancelled;
068: }
069:
070: public final String getErrorText() {
071: return errorText;
072: }
073:
074: protected final void setErrorText(String s) {
075: errorText = s;
076: }
077:
078: public void start() {
079: buffer.setBusy(true);
080: for (EditorIterator it = new EditorIterator(); it.hasNext();) {
081: Editor ed = it.nextEditor();
082: if (ed.getBuffer() == buffer)
083: ed.setWaitCursor();
084: }
085: thread = new Thread(this );
086: thread.start();
087: }
088:
089: public void cancel() {
090: if (thread != null)
091: thread.interrupt();
092: cancelled = true;
093: if (progressNotifier != null) {
094: progressNotifier.cancel();
095: progressNotifier.progressStop();
096: progressNotifier.setText("Transfer cancelled");
097: }
098: }
099:
100: // Can be overridden.
101: protected Runnable cancelRunnable = new Runnable() {
102: public void run() {
103: buffer.setBusy(false);
104: for (EditorIterator it = new EditorIterator(); it.hasNext();) {
105: Editor ed = it.nextEditor();
106: if (ed.getBuffer() == buffer) {
107: ed.status("Transfer cancelled");
108: ed.setDefaultCursor();
109: }
110: }
111: MessageDialog.showMessageDialog("Transfer cancelled", file
112: .netPath());
113: }
114: };
115: }
|