KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > kick > Kick


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.kick;
20
21 import org.lucane.client.*;
22 import org.lucane.client.widgets.DialogBox;
23 import org.lucane.common.*;
24 import org.lucane.common.net.ObjectConnection;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 public class Kick
30   extends Plugin
31 {
32     private ConnectInfo[] friends;
33
34   public Kick()
35   {
36   }
37
38
39   public Plugin newInstance(ConnectInfo[] friends)
40   {
41     if(friends.length > 0)
42       return new Kick(friends);
43     else
44       return new Kick(null);
45   }
46
47   public Kick(ConnectInfo[] friends)
48   {
49     this.friends = friends;
50   }
51
52   public void start()
53   {
54     // selection check
55
if(this.friends == null)
56     {
57       DialogBox.info(tr("msg.selectUsers"));
58       exit();
59       return;
60     }
61     
62     //ask for confirmation
63
String JavaDoc msg = tr("msg.reallyKickUsers");
64     msg = msg.replaceFirst("\\%1", String.valueOf(friends.length));
65     if(!DialogBox.question(getTitle(), msg))
66     {
67         exit();
68         return;
69     }
70     
71     //send deconnection
72
for(int i=0;i<friends.length;i++)
73     {
74         try {
75             Map JavaDoc action = new HashMap JavaDoc();
76             action.put("command", "DISCONNECT");
77             ObjectConnection oc = Communicator.getInstance().sendMessageTo(friends[i], "Client", action);
78             oc.close();
79         } catch (Exception JavaDoc e) {
80             Logging.getLogger().warning("Unable to kick : " + friends[i].getName());
81             e.printStackTrace();
82         }
83     }
84     
85     exit();
86   }
87 }
88
Popular Tags