KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > slideshow > net > SlideClient


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.slideshow.net;
20
21 import java.awt.Image JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 import javax.swing.ImageIcon JavaDoc;
25
26 import org.lucane.applications.slideshow.SlideShow;
27 import org.lucane.client.Client;
28 import org.lucane.client.widgets.DialogBox;
29 import org.lucane.common.net.ObjectConnection;
30 import org.lucane.common.net.ObjectListener;
31
32 /**
33  * Server side implementation for slideshow
34  */

35 public class SlideClient
36 implements ObjectListener
37 {
38     //-- attributes
39
private SlideShow plugin;
40     private ObjectConnection server;
41     private String JavaDoc userName;
42
43     /**
44      * Constructor
45      */

46     public SlideClient(SlideShow plugin, ObjectConnection server)
47     {
48         this.plugin = plugin;
49         this.server = server;
50         this.userName = Client.getInstance().getMyInfos().getName();
51         
52         server.addObjectListener(this);
53     }
54     
55     public void acceptSlideShow()
56     {
57         server.listen();
58         SlideAction action = new SlideAction(SlideAction.ACCEPT_SHOW, userName);
59         try {
60             server.write(action);
61         } catch (IOException JavaDoc e) {
62             DialogBox.error(plugin.tr("err.unableToAccept") + " " + e);
63             e.printStackTrace();
64         }
65     }
66     
67     public void rejectSlideShow()
68     {
69         SlideAction action = new SlideAction(SlideAction.REJECT_SHOW, userName);
70         try {
71             server.write(action);
72         } catch (IOException JavaDoc e) {
73             e.printStackTrace();
74         }
75         
76         server.close();
77     }
78     
79     public void disconnect()
80     {
81         SlideAction action = new SlideAction(SlideAction.DISCONNECT, userName);
82         try {
83             server.write(action);
84         } catch (IOException JavaDoc e) {
85             e.printStackTrace();
86         }
87         
88         server.close();
89     }
90     
91     private void setUserList(Object JavaDoc[] users)
92     {
93         plugin.getFollowerWindow().setUsers(users);
94     }
95     
96     private void setImage(Image JavaDoc image)
97     {
98         plugin.getFollowerWindow().setImage(image);
99     }
100     
101     private void handleDisconnection()
102     {
103         server.close();
104         DialogBox.info(plugin.tr("msg.slideServerDisconnected"));
105         plugin.getFollowerWindow().dispose();
106         plugin.exit();
107     }
108     
109     //-- ObjectListener interface
110

111     public void objectRead(Object JavaDoc o)
112     {
113         SlideAction action = (SlideAction)o;
114         
115         switch(action.getAction())
116         {
117             case SlideAction.SEND_USER_LIST:
118                 setUserList((Object JavaDoc[])action.getParam());
119                 break;
120             
121             case SlideAction.SEND_IMAGE:
122                 setImage(((ImageIcon JavaDoc)action.getParam()).getImage());
123                 break;
124
125             case SlideAction.DISCONNECT:
126                 handleDisconnection();
127                 break;
128         }
129     }
130 }
Popular Tags