1 /** 2 * Jin - a chess client for internet chess servers. 3 * More information is available at http://www.jinchess.com/. 4 * Copyright (C) 2005 Alexander Maryanovsky. 5 * All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 package free.jin; 23 24 import java.util.EventObject; 25 26 27 /** 28 * The event object fired when a session to the chess server is established or 29 * closed. 30 */ 31 32 public class SessionEvent extends EventObject{ 33 34 35 36 /** 37 * The code for when a session is established. 38 */ 39 40 public static final int SESSION_ESTABLISHED = 1; 41 42 43 44 /** 45 * The code for when a session is closed. 46 */ 47 48 public static final int SESSION_CLOSED = 0; 49 50 51 52 /** 53 * The id of the event. 54 */ 55 56 private final int id; 57 58 59 60 /** 61 * The session. 62 */ 63 64 private final Session session; 65 66 67 68 /** 69 * Creates a new <code>SessionEvent</code>. 70 */ 71 SessionEvent(ConnectionManager connManager, int id, Session session)72 public SessionEvent(ConnectionManager connManager, int id, Session session){ 73 super(connManager); 74 75 switch(id){ 76 case SESSION_ESTABLISHED: 77 case SESSION_CLOSED: 78 break; 79 default: 80 throw new IllegalArgumentException("Invalid id: " + id); 81 } 82 83 this.id = id; 84 this.session = session; 85 } 86 87 88 89 /** 90 * Returns the connection manager responsible for the session. 91 */ 92 getConnManager()93 public ConnectionManager getConnManager(){ 94 return (ConnectionManager)getSource(); 95 } 96 97 98 99 /** 100 * Returns the id of the session event - either {@link #SESSION_ESTABLISHED} 101 * or {@link #SESSION_CLOSED}. 102 */ 103 getId()104 public int getId(){ 105 return id; 106 } 107 108 109 110 /** 111 * Returns the session that was established or closed. 112 */ 113 getSession()114 public Session getSession(){ 115 return session; 116 } 117 118 119 } 120