PageRenderTime 29ms CodeModel.GetById 24ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/util/WorkRequest.java

#
Java | 131 lines | 61 code | 8 blank | 62 comment | 8 complexity | 3c7182159a1e717a6faf3a2be72b4295 MD5 | raw file
  1/*
  2 * WorkRequest.java - Runnable subclass
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2000 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.util;
 24
 25/**
 26 * A subclass of the Runnable interface.
 27 * @since jEdit 2.6pre1
 28 * @version $Id: WorkRequest.java 5234 2005-07-27 21:44:10Z kpouer $
 29 */
 30public abstract class WorkRequest implements Runnable, ProgressObserver
 31{
 32	/**
 33	 * If the max value is greater that <code>Integer.MAX_VALUE</code> this 
 34	 * will be true and all values will be divided by 1024.
 35	 * @since jEdit 4.3pre3
 36	 */
 37	private boolean largeValues;
 38
 39	/**
 40	 * Sets if the request can be aborted.
 41	 */
 42	public void setAbortable(boolean abortable)
 43	{
 44		Thread thread = Thread.currentThread();
 45		if(thread instanceof WorkThread)
 46			((WorkThread)thread).setAbortable(abortable);
 47	}
 48
 49	/**
 50	 * Sets the status text.
 51	 * @param status The status text
 52	 */
 53	public void setStatus(String status)
 54	{
 55		Thread thread = Thread.currentThread();
 56		if(thread instanceof WorkThread)
 57			((WorkThread)thread).setStatus(status);
 58	}
 59
 60	/**
 61	 * Sets the progress value.
 62	 * @param value The progress value.
 63	 * @deprecated use {@link #setValue(long)}
 64	 */
 65	public void setProgressValue(int value)
 66	{
 67		Thread thread = Thread.currentThread();
 68		if(thread instanceof WorkThread)
 69			((WorkThread)thread).setProgressValue(value);
 70	}
 71
 72	/**
 73	 * Sets the maximum progress value.
 74	 * @param value The progress value.
 75	 * @deprecated use {@link #setMaximum(long)}
 76	 */
 77	public void setProgressMaximum(int value)
 78	{
 79		Thread thread = Thread.currentThread();
 80		if(thread instanceof WorkThread)
 81			((WorkThread)thread).setProgressMaximum(value);
 82	}
 83
 84	//{{{ setValue() method
 85	/**
 86	 * Update the progress value.
 87	 *
 88	 * @param value the new value
 89	 * @since jEdit 4.3pre3
 90	 */
 91	public void setValue(long value)
 92	{
 93		Thread thread = Thread.currentThread();
 94		if(thread instanceof WorkThread)
 95		{
 96			if (largeValues)
 97			{
 98				((WorkThread)thread).setProgressValue((int) (value >> 10));
 99			}
100			else
101			{
102				((WorkThread)thread).setProgressValue((int) value);
103			}
104		}
105	} //}}}
106
107	//{{{ setValue() method
108	/**
109	 * Update the maximum value.
110	 *
111	 * @param value the new maximum value
112	 * @since jEdit 4.3pre3
113	 */
114	public void setMaximum(long value)
115	{
116		Thread thread = Thread.currentThread();
117		if(thread instanceof WorkThread)
118		{
119			if (value > Integer.MAX_VALUE)
120			{
121				largeValues = true;
122				((WorkThread)thread).setProgressMaximum((int) (value >> 10));
123			}
124			else
125			{
126				largeValues = false;
127				((WorkThread)thread).setProgressMaximum((int) value);
128			}
129		}
130	} //}}}
131}