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 8641 2012-09-27 06:45:17Z 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 /** 43 * Setter for property {@code description}. 44 * 45 * @param description the description for the task. 46 * 47 * @throws NullPointerException if {@code description} is {@code null}. 48 */ 49 synchronized public void setDescription( final Message description ) 50 { 51 if ( description == null ) 52 { 53 throw new NullPointerException( "description" ); 54 } 55 56 this.description = description; 57 } 58 59 /** 60 * Setter for property {@code progressDescription}. 61 * 62 * @param progressDescription the description for the progress of the task. 63 * 64 * @throws NullPointerException if {@code progressDescription} is 65 * {@code null}. 66 */ 67 synchronized public void setProgressDescription( 68 final Message progressDescription ) 69 { 70 if ( progressDescription == null ) 71 { 72 throw new NullPointerException( "progressDescription" ); 73 } 74 75 this.progressDescription = progressDescription; 76 } 77 78 /** 79 * Sets the lower end of the progress value. 80 * 81 * @param minimum an int specifying the minimum value. 82 * 83 * @throws IllegalStateException if the task is indeterminate. 84 */ 85 synchronized public void setMinimum( int minimum ) 86 { 87 if ( this.isIndeterminate() ) 88 { 89 throw new IllegalStateException(); 90 } 91 92 this.minimum = minimum; 93 } 94 95 /** 96 * Sets the higher end of the progress value. 97 * 98 * @param maximum an int specifying the maximum value. 99 * 100 * @throws IllegalStateException if the task is indeterminate. 101 */ 102 synchronized public void setMaximum( int maximum ) 103 { 104 if ( this.isIndeterminate() ) 105 { 106 throw new IllegalStateException(); 107 } 108 109 this.maximum = maximum; 110 } 111 112 /** 113 * Sets the progress of the task. 114 * 115 * @param progress an int specifying the current value, between the 116 * maximum and minimum specified for this task. 117 * 118 * @throws IllegalStateException if the task is indeterminate. 119 * @throws IllegalArgumentException if {@code progress} is lower than 120 * the minimum of the range or greater than the maximum of the range. 121 */ 122 synchronized public void setProgress( final int progress ) 123 { 124 if ( this.isIndeterminate() ) 125 { 126 throw new IllegalStateException(); 127 } 128 if ( progress < this.minimum || progress > this.maximum ) 129 { 130 throw new IllegalArgumentException( Integer.toString( progress ) ); 131 } 132 133 this.progress = progress; 134 } 135 136 /** 137 * Setter for property {@code indeterminate}. 138 * 139 * @param indeterminate {@code true} if the operations performed by the task 140 * are of unknown length; {@code false} to support properties 141 * {@code minimum}, {@code maximum} and {@code progress}. 142 */ 143 synchronized public void setIndeterminate( final boolean indeterminate ) 144 { 145 this.indeterminate = indeterminate; 146 } 147 148 /** 149 * Setter for property {@code cancelable}. 150 * 151 * @param cancelable {@code true} to indicate support for property 152 * {@code cancelled}; {@code false} to indicate that property 153 * {@code cancelled} is not supported. 154 */ 155 synchronized public void setCancelable( final boolean cancelable ) 156 { 157 this.cancelable = cancelable; 158 } 159 160 //--------------------------------------------------------------------Task-- 161 }