001/* 002 * jDTAUS Core API 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; 022 023import java.util.EventObject; 024 025/** 026 * Event produced by a {@code Task}. 027 * 028 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 029 * @version $JDTAUS: TaskEvent.java 8641 2012-09-27 06:45:17Z schulte $ 030 * 031 * @see TaskEventSource 032 */ 033public class TaskEvent extends EventObject 034{ 035 //--Constants--------------------------------------------------------------- 036 037 /** Event constant indicating the start of a {@code Task}. */ 038 public static final int STARTED = 1001; 039 040 /** Event constant indicating that state of a {@code Task} changed. */ 041 public static final int CHANGED_STATE = 1002; 042 043 /** Event constant indicating the end of a {@code Task}. */ 044 public static final int ENDED = 1003; 045 046 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 047 private static final long serialVersionUID = 4764885368541939098L; 048 049 //---------------------------------------------------------------Constants-- 050 //--Constructors------------------------------------------------------------ 051 052 /** 053 * Creates a new instance of {@code TaskEvent}. 054 * 055 * @param source the task producing the new event. 056 * @param type constant indicating the type of the event. 057 * 058 * @throws IllegalArgumentException if {@code type} is not equal to one of 059 * the constants {@code STARTED}, {@code CHANGED_STATE} or {@code ENDED}. 060 */ 061 public TaskEvent( final Task source, final int type ) 062 { 063 super( source ); 064 065 if ( type != STARTED && type != CHANGED_STATE && type != ENDED ) 066 { 067 throw new IllegalArgumentException( Integer.toString( type ) ); 068 } 069 070 this.type = type; 071 } 072 073 //------------------------------------------------------------Constructors-- 074 //--TaskEvent--------------------------------------------------------------- 075 076 /** 077 * Event type. 078 * @serial 079 */ 080 private final int type; 081 082 /** 083 * Getter for property {@code type}. 084 * 085 * @return the type of the event. 086 */ 087 public final int getType() 088 { 089 return this.type; 090 } 091 092 /** 093 * Gets the {@code Task} producing the event. 094 * 095 * @return the source of the event. 096 */ 097 public final Task getTask() 098 { 099 return (Task) this.getSource(); 100 } 101 102 /** 103 * Creates a string representing the properties of the instance. 104 * 105 * @return a string representing the properties of the instance. 106 */ 107 private String internalString() 108 { 109 return new StringBuffer( 500 ).append( '{' ). 110 append( "source=" ).append( this.source ). 111 append( ", type=" ).append( this.type ). 112 append( '}' ).toString(); 113 114 } 115 116 //---------------------------------------------------------------TaskEvent-- 117 //--Object------------------------------------------------------------------ 118 119 /** 120 * Returns a string representation of the object. 121 * 122 * @return a string representation of the object. 123 */ 124 public String toString() 125 { 126 return super.toString() + this.internalString(); 127 } 128 129 //------------------------------------------------------------------Object-- 130}