KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > chat > ui > action > AddContactAction


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.chat.ui.action;
19
20 import java.awt.event.ActionEvent JavaDoc;
21
22 import javax.swing.JOptionPane JavaDoc;
23
24 import org.columba.api.gui.frame.IFrameMediator;
25 import org.columba.chat.base.Parser;
26 import org.columba.chat.command.AddContactCommand;
27 import org.columba.chat.command.ChatCommandReference;
28 import org.columba.chat.resourceloader.ResourceLoader;
29 import org.columba.chat.ui.frame.api.IChatFrameMediator;
30 import org.columba.core.command.CommandProcessor;
31 import org.columba.core.gui.action.AbstractColumbaAction;
32 import org.columba.core.gui.frame.FrameManager;
33
34 /**
35  * @author fdietz
36  *
37  */

38
39 public class AddContactAction extends AbstractConnectionAwareAction {
40
41     /**
42      * @param mediator
43      * @param name
44      */

45     public AddContactAction(IFrameMediator mediator) {
46         super(mediator, "Add Contact...");
47
48         putValue(AbstractColumbaAction.TOOLBAR_NAME, "Add Contact");
49
50         putValue(AbstractColumbaAction.LARGE_ICON, ResourceLoader
51                 .getIcon("system-users.png"));
52         putValue(AbstractColumbaAction.SMALL_ICON, ResourceLoader
53                 .getSmallIcon("system-users.png"));
54
55     }
56
57     /**
58      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
59      */

60     public void actionPerformed(ActionEvent JavaDoc arg0) {
61         // prompt for jabber id
62
String JavaDoc jabberId = JOptionPane.showInputDialog(FrameManager.getInstance()
63                 .getActiveFrame(), "Enter jabber ID");
64
65         // if user cancelled action
66
if (jabberId == null)
67             return;
68
69         // example: fdietz@jabber.org/Jabber-client
70
// -> remove "/Jabber-client"
71
String JavaDoc normalizedFrom = Parser.normalizeFrom(jabberId);
72
73         CommandProcessor.getInstance()
74                 .addOp(
75                         new AddContactCommand((IChatFrameMediator) getFrameMediator(), new ChatCommandReference(
76                                 normalizedFrom)));
77
78     }
79 }
80
Popular Tags