KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > whiteboard > net > BoardSlave


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.whiteboard.net;
20
21 import java.io.IOException JavaDoc;
22 import java.io.Serializable JavaDoc;
23 import java.net.Socket JavaDoc;
24
25 import org.lucane.applications.whiteboard.BoardAction;
26 import org.lucane.common.net.ObjectConnection;
27 import org.lucane.common.net.ObjectListener;
28
29 public class BoardSlave implements ObjectListener
30 {
31     private BoardServer server;
32     private ObjectConnection connection;
33     private String JavaDoc user;
34     
35     public BoardSlave(BoardServer server, Socket JavaDoc client)
36     {
37         this.server = server;
38         this.connection = new ObjectConnection(client);
39     }
40
41     public void start()
42     {
43         connection.addObjectListener(this);
44         connection.listen();
45     }
46     
47     public void stop()
48     {
49         this.user = null;
50         this.connection.close();
51     }
52     
53     public void objectRead(Object JavaDoc o)
54     {
55         BoardAction action = (BoardAction)o;
56     
57         //join & leave
58
if(action.getAction() == BoardAction.JOIN_BOARD)
59         {
60             this.user = action.getUser();
61             server.joinBoard(connection, action.getUser());
62         }
63         else if(action.getAction() == BoardAction.LEAVE_BOARD)
64         {
65             this.stop();
66             server.leaveBoard(action.getUser());
67         }
68         
69         //pen
70
else if(action.getAction() == BoardAction.TAKE_PEN)
71             server.takePen(action.getUser());
72         else if(action.getAction() == BoardAction.RELEASE_PEN)
73             server.releasePen(action.getUser());
74         
75         //graph operation
76
else if(action.getAction() == BoardAction.BROADCAST_OPERATION)
77             server.broadcast(action.getUser(), action);
78         else if(action.getAction() == BoardAction.BROADCAST_MODEL)
79             server.broadcast(action.getUser(), action);
80     }
81     
82     public void write(Serializable JavaDoc o)
83     throws IOException JavaDoc
84     {
85         this.connection.write(o);
86     }
87     
88     public String JavaDoc getUser()
89     {
90         return user;
91     }
92 }
Popular Tags