001/* 
002   Copyright (C) 2005 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.sound.sampled;
040
041import java.io.IOException;
042import java.io.NotSerializableException;
043import java.io.ObjectInputStream;
044import java.io.ObjectOutputStream;
045import java.util.EventObject;
046
047/**
048 * This class holds information about a state change of a Line.
049 * @specnote This class is not really serializable, and attempts to
050 * serialize it will throw {@link NotSerializableException}.
051 * @since 1.3
052 */
053public class LineEvent extends EventObject
054{
055  // We define this even though this class can't be serialized, in
056  // order to placate the compiler.
057  private static final long serialVersionUID = -1274246333383880410L;
058
059  /**
060   * This class represents the kinds of state changes that can occur
061   * to a Line.  The standard states are availabe as static instances.
062   * @since 1.3
063   */
064  public static class Type
065  {
066    /** An event of this type is posted when a Line closes.  */
067    public static final Type CLOSE = new Type("close");
068
069    /** An event of this type is posted when a Line opens.  */
070    public static final Type OPEN = new Type("open");
071
072    /** An event of this type is posted when a Line starts.  */
073    public static final Type START = new Type("start");
074
075    /** An event of this type is posted when a Line stops.  */
076    public static final Type STOP = new Type("stop");
077
078    private String name;
079
080    /**
081     * Create a new type with the indicated name.
082     * @param name the name
083     */
084    protected Type(String name)
085    {
086      this.name = name;
087    }
088
089    public final boolean equals(Object o)
090    {
091      return super.equals(o);
092    }
093
094    public final int hashCode()
095    {
096      return super.hashCode();
097    }
098
099    /**
100     * Return the name of this Type.
101     */
102    public String toString()
103    {
104      return name;
105    }
106  }
107
108  private Type type;
109  private long framePosition;
110  private Line line;
111
112  /**
113   * Create a new LineEvent with the indicated line, type, and frame position.
114   * @param line the line
115   * @param type the type of the event
116   * @param pos the frame position
117   */
118  public LineEvent(Line line, Type type, long pos)
119  {
120    super(line);
121    this.line = line;
122    this.type = type;
123    this.framePosition = pos;
124  }
125
126  /**
127   * Return the frame position associated with this event.
128   */
129  public final long getFramePosition()
130  {
131    return framePosition;
132  }
133
134  /**
135   * Return the Line associated with this event.
136   */
137  public final Line getLine()
138  {
139    return line;
140  }
141
142  /**
143   * Return the Type associated with this event.
144   */
145  public final Type getType()
146  {
147    return type;
148  }
149
150  /**
151   * Return a description of this event.
152   */
153  public String toString()
154  {
155    return ("type=" + type + "; framePosition=" + framePosition
156            + "line=" + line);
157  }
158  
159  private void readObject(ObjectInputStream ois)
160    throws IOException
161  {
162    throw new NotSerializableException("LineEvent is not serializable");
163  }
164  
165  private void writeObject(ObjectOutputStream oos)
166    throws IOException
167  {
168    throw new NotSerializableException("LineEvent is not serializable");
169  }
170}