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 org.columba.api.gui.frame.IFrameMediator;
23: import org.columba.chat.MainInterface;
24: import org.columba.chat.command.ChatCommandReference;
25: import org.columba.chat.command.ConnectCommand;
26: import org.columba.chat.config.api.IAccount;
27: import org.columba.chat.conn.api.ConnectionChangedEvent;
28: import org.columba.chat.conn.api.IConnectionChangedListener;
29: import org.columba.chat.conn.api.IConnection.STATUS;
30: import org.columba.chat.resourceloader.ResourceLoader;
31: import org.columba.chat.ui.dialog.AccountDialog;
32: import org.columba.chat.ui.frame.api.IChatFrameMediator;
33: import org.columba.core.command.CommandProcessor;
34: import org.columba.core.gui.action.AbstractColumbaAction;
35:
36: /**
37: * @author fdietz
38: *
39: */
40:
41: public class ConnectAction extends AbstractColumbaAction implements
42: IConnectionChangedListener {
43:
44: /**
45: * @param mediator
46: * @param name
47: */
48: public ConnectAction(IFrameMediator mediator) {
49: super (mediator, "Connect...");
50:
51: putValue(AbstractColumbaAction.TOOLBAR_NAME, "Connect");
52: putValue(AbstractColumbaAction.LARGE_ICON, ResourceLoader
53: .getIcon("network-receive.png"));
54: putValue(AbstractColumbaAction.SMALL_ICON, ResourceLoader
55: .getSmallIcon("network-receive.png"));
56: MainInterface.connection.addConnectionChangedListener(this );
57: }
58:
59: /**
60: * @see org.columba.chat.conn.api.IConnectionChangedListener#connectionChanged(org.columba.chat.conn.api.ConnectionChangedEvent)
61: */
62: public void connectionChanged(ConnectionChangedEvent object) {
63: STATUS status = object.getStatus();
64:
65: if (status == STATUS.ONLINE)
66: setEnabled(false);
67: else if (status == STATUS.OFFLINE)
68: setEnabled(true);
69: }
70:
71: /**
72: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
73: */
74: public void actionPerformed(ActionEvent arg0) {
75: IAccount account = MainInterface.config.getAccount();
76:
77: if ((account.getHost() == null) || (account.getId() == null))
78: new AccountDialog(account);
79:
80: CommandProcessor.getInstance().addOp(
81: new ConnectCommand(
82: (IChatFrameMediator) getFrameMediator(),
83: new ChatCommandReference()));
84: }
85: }
|