001/*
002 *  jDTAUS Core SPI
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.monitor.spi;
022
023import org.jdtaus.core.text.Message;
024
025/**
026 * Extends {@code Task} providing write access to the state of a {@code Task}
027 * to be used by implementations.
028 *
029 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
030 * @version $JDTAUS: Task.java 8743 2012-10-07 03:06:20Z schulte $
031 */
032public final class Task extends org.jdtaus.core.monitor.Task
033{
034    //--Constants---------------------------------------------------------------
035
036    /** Serial version UID for backwards compatibility with 1.0.x classes. */
037    private static final long serialVersionUID = 7910325638688854657L;
038
039    //---------------------------------------------------------------Constants--
040    //--Task--------------------------------------------------------------------
041
042    /** Creates a new {@code Task} instance. */
043    public Task()
044    {
045        super();
046    }
047
048    /**
049     * Setter for property {@code description}.
050     *
051     * @param description the description for the task.
052     *
053     * @throws NullPointerException if {@code description} is {@code null}.
054     */
055    public synchronized void setDescription( final Message description )
056    {
057        if ( description == null )
058        {
059            throw new NullPointerException( "description" );
060        }
061
062        this.description = description;
063    }
064
065    /**
066     * Setter for property {@code progressDescription}.
067     *
068     * @param progressDescription the description for the progress of the task.
069     *
070     * @throws NullPointerException if {@code progressDescription} is
071     * {@code null}.
072     */
073    public synchronized void setProgressDescription(
074        final Message progressDescription )
075    {
076        if ( progressDescription == null )
077        {
078            throw new NullPointerException( "progressDescription" );
079        }
080
081        this.progressDescription = progressDescription;
082    }
083
084    /**
085     * Sets the lower end of the progress value.
086     *
087     * @param minimum an int specifying the minimum value.
088     *
089     * @throws IllegalStateException if the task is indeterminate.
090     */
091    public synchronized void setMinimum( final int minimum )
092    {
093        if ( this.isIndeterminate() )
094        {
095            throw new IllegalStateException();
096        }
097
098        this.minimum = minimum;
099    }
100
101    /**
102     * Sets the higher end of the progress value.
103     *
104     * @param maximum an int specifying the maximum value.
105     *
106     * @throws IllegalStateException if the task is indeterminate.
107     */
108    public synchronized void setMaximum( final int maximum )
109    {
110        if ( this.isIndeterminate() )
111        {
112            throw new IllegalStateException();
113        }
114
115        this.maximum = maximum;
116    }
117
118    /**
119     * Sets the progress of the task.
120     *
121     * @param progress an int specifying the current value, between the
122     * maximum and minimum specified for this task.
123     *
124     * @throws IllegalStateException if the task is indeterminate.
125     * @throws IllegalArgumentException if {@code progress} is lower than
126     * the minimum of the range or greater than the maximum of the range.
127     */
128    public synchronized void setProgress( final int progress )
129    {
130        if ( this.isIndeterminate() )
131        {
132            throw new IllegalStateException();
133        }
134        if ( progress < this.minimum || progress > this.maximum )
135        {
136            throw new IllegalArgumentException( Integer.toString( progress ) );
137        }
138
139        this.progress = progress;
140    }
141
142    /**
143     * Setter for property {@code indeterminate}.
144     *
145     * @param indeterminate {@code true} if the operations performed by the task
146     * are of unknown length; {@code false} to support properties
147     * {@code minimum}, {@code maximum} and {@code progress}.
148     */
149    public synchronized void setIndeterminate( final boolean indeterminate )
150    {
151        this.indeterminate = indeterminate;
152    }
153
154    /**
155     * Setter for property {@code cancelable}.
156     *
157     * @param cancelable {@code true} to indicate support for property
158     * {@code cancelled}; {@code false} to indicate that property
159     * {@code cancelled} is not supported.
160     */
161    public synchronized void setCancelable( final boolean cancelable )
162    {
163        this.cancelable = cancelable;
164    }
165
166    //--------------------------------------------------------------------Task--
167}