01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //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;
21:
22: import javax.swing.JOptionPane;
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 arg0) {
61: // prompt for jabber id
62: String jabberId = JOptionPane.showInputDialog(FrameManager
63: .getInstance().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 normalizedFrom = Parser.normalizeFrom(jabberId);
72:
73: CommandProcessor.getInstance().addOp(
74: new AddContactCommand(
75: (IChatFrameMediator) getFrameMediator(),
76: new ChatCommandReference(normalizedFrom)));
77:
78: }
79: }
|