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 8641 2012-09-27 06:45:17Z 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 /** 043 * Setter for property {@code description}. 044 * 045 * @param description the description for the task. 046 * 047 * @throws NullPointerException if {@code description} is {@code null}. 048 */ 049 synchronized public void setDescription( final Message description ) 050 { 051 if ( description == null ) 052 { 053 throw new NullPointerException( "description" ); 054 } 055 056 this.description = description; 057 } 058 059 /** 060 * Setter for property {@code progressDescription}. 061 * 062 * @param progressDescription the description for the progress of the task. 063 * 064 * @throws NullPointerException if {@code progressDescription} is 065 * {@code null}. 066 */ 067 synchronized public void setProgressDescription( 068 final Message progressDescription ) 069 { 070 if ( progressDescription == null ) 071 { 072 throw new NullPointerException( "progressDescription" ); 073 } 074 075 this.progressDescription = progressDescription; 076 } 077 078 /** 079 * Sets the lower end of the progress value. 080 * 081 * @param minimum an int specifying the minimum value. 082 * 083 * @throws IllegalStateException if the task is indeterminate. 084 */ 085 synchronized public void setMinimum( int minimum ) 086 { 087 if ( this.isIndeterminate() ) 088 { 089 throw new IllegalStateException(); 090 } 091 092 this.minimum = minimum; 093 } 094 095 /** 096 * Sets the higher end of the progress value. 097 * 098 * @param maximum an int specifying the maximum value. 099 * 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}