1 /* 2 * jDTAUS Core SPI 3 * Copyright (C) 2005 Christian Schulte 4 * <cs@schulte.it> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 package org.jdtaus.core.monitor.spi; 22 23 import org.jdtaus.core.text.Message; 24 25 /** 26 * Extends {@code Task} providing write access to the state of a {@code Task} 27 * to be used by implementations. 28 * 29 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 30 * @version $JDTAUS: Task.java 8743 2012-10-07 03:06:20Z schulte $ 31 */ 32 public final class Task extends org.jdtaus.core.monitor.Task 33 { 34 //--Constants--------------------------------------------------------------- 35 36 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 37 private static final long serialVersionUID = 7910325638688854657L; 38 39 //---------------------------------------------------------------Constants-- 40 //--Task-------------------------------------------------------------------- 41 42 /** Creates a new {@code Task} instance. */ 43 public Task() 44 { 45 super(); 46 } 47 48 /** 49 * Setter for property {@code description}. 50 * 51 * @param description the description for the task. 52 * 53 * @throws NullPointerException if {@code description} is {@code null}. 54 */ 55 public synchronized void setDescription( final Message description ) 56 { 57 if ( description == null ) 58 { 59 throw new NullPointerException( "description" ); 60 } 61 62 this.description = description; 63 } 64 65 /** 66 * Setter for property {@code progressDescription}. 67 * 68 * @param progressDescription the description for the progress of the task. 69 * 70 * @throws NullPointerException if {@code progressDescription} is 71 * {@code null}. 72 */ 73 public synchronized void setProgressDescription( 74 final Message progressDescription ) 75 { 76 if ( progressDescription == null ) 77 { 78 throw new NullPointerException( "progressDescription" ); 79 } 80 81 this.progressDescription = progressDescription; 82 } 83 84 /** 85 * Sets the lower end of the progress value. 86 * 87 * @param minimum an int specifying the minimum value. 88 * 89 * @throws IllegalStateException if the task is indeterminate. 90 */ 91 public synchronized void setMinimum( final int minimum ) 92 { 93 if ( this.isIndeterminate() ) 94 { 95 throw new IllegalStateException(); 96 } 97 98 this.minimum = minimum; 99 } 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 }