KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > administrator > gui > PluginButton


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 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.administrator.gui;
20
21 import javax.swing.*;
22 import java.awt.event.*;
23
24 import org.lucane.client.*;
25 import org.lucane.client.widgets.ListBox;
26 import org.lucane.common.ConnectInfo;
27
28
29 public class PluginButton extends JButton
30 implements ActionListener
31 {
32     private Plugin plugin;
33
34     public PluginButton(Plugin plugin)
35     {
36         this.plugin = plugin;
37         this.setIcon(plugin.getImageIcon(plugin.getIcon()));
38         
39         this.addActionListener(this);
40         this.setHorizontalAlignment(SwingConstants.LEFT);
41         this.setText(plugin.getTitle());
42     }
43     
44     public void actionPerformed(ActionEvent ae)
45     {
46         ConnectInfo[] friends = null;
47         
48         // get users
49
if(plugin.isStandalone())
50             friends = new ConnectInfo[0];
51         else
52         {
53             ListBox userList = new ListBox(null, plugin.getTitle(), plugin.tr("msg.selectUsers"),
54                     Client.getInstance().getUserList());
55             Object JavaDoc[] users = userList.selectItems();
56             if(users != null)
57             {
58                 friends = new ConnectInfo[users.length];
59                 for(int i=0;i<friends.length;i++)
60                     friends[i] = Communicator.getInstance().getConnectInfo((String JavaDoc)users[i]);
61             }
62         }
63         
64         // run the plugin if the user didn't click on cancel
65
if(friends != null)
66             PluginManager.getInstance().run(plugin.getName(), friends);
67     }
68 }
Popular Tags