001: /*
002: * WorkRequest.java - Runnable subclass
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2000 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.util;
024:
025: /**
026: * A subclass of the Runnable interface.
027: * @since jEdit 2.6pre1
028: * @version $Id: WorkRequest.java 5234 2005-07-27 21:44:10Z kpouer $
029: */
030: public abstract class WorkRequest implements Runnable, ProgressObserver {
031: /**
032: * If the max value is greater that <code>Integer.MAX_VALUE</code> this
033: * will be true and all values will be divided by 1024.
034: * @since jEdit 4.3pre3
035: */
036: private boolean largeValues;
037:
038: /**
039: * Sets if the request can be aborted.
040: */
041: public void setAbortable(boolean abortable) {
042: Thread thread = Thread.currentThread();
043: if (thread instanceof WorkThread)
044: ((WorkThread) thread).setAbortable(abortable);
045: }
046:
047: /**
048: * Sets the status text.
049: * @param status The status text
050: */
051: public void setStatus(String status) {
052: Thread thread = Thread.currentThread();
053: if (thread instanceof WorkThread)
054: ((WorkThread) thread).setStatus(status);
055: }
056:
057: /**
058: * Sets the progress value.
059: * @param value The progress value.
060: * @deprecated use {@link #setValue(long)}
061: */
062: public void setProgressValue(int value) {
063: Thread thread = Thread.currentThread();
064: if (thread instanceof WorkThread)
065: ((WorkThread) thread).setProgressValue(value);
066: }
067:
068: /**
069: * Sets the maximum progress value.
070: * @param value The progress value.
071: * @deprecated use {@link #setMaximum(long)}
072: */
073: public void setProgressMaximum(int value) {
074: Thread thread = Thread.currentThread();
075: if (thread instanceof WorkThread)
076: ((WorkThread) thread).setProgressMaximum(value);
077: }
078:
079: //{{{ setValue() method
080: /**
081: * Update the progress value.
082: *
083: * @param value the new value
084: * @since jEdit 4.3pre3
085: */
086: public void setValue(long value) {
087: Thread thread = Thread.currentThread();
088: if (thread instanceof WorkThread) {
089: if (largeValues) {
090: ((WorkThread) thread)
091: .setProgressValue((int) (value >> 10));
092: } else {
093: ((WorkThread) thread).setProgressValue((int) value);
094: }
095: }
096: } //}}}
097:
098: //{{{ setValue() method
099: /**
100: * Update the maximum value.
101: *
102: * @param value the new maximum value
103: * @since jEdit 4.3pre3
104: */
105: public void setMaximum(long value) {
106: Thread thread = Thread.currentThread();
107: if (thread instanceof WorkThread) {
108: if (value > Integer.MAX_VALUE) {
109: largeValues = true;
110: ((WorkThread) thread)
111: .setProgressMaximum((int) (value >> 10));
112: } else {
113: largeValues = false;
114: ((WorkThread) thread).setProgressMaximum((int) value);
115: }
116: }
117: } //}}}
118: }
|