1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.joscar;
21
22 import java.awt.event.ActionEvent;
23
24 import javax.swing.AbstractAction;
25 import javax.swing.Action;
26 import javax.swing.Icon;
27 import javax.swing.JOptionPane;
28
29 import org.apache.log4j.Logger;
30 import org.xnap.XNap;
31 import org.xnap.event.StateEvent;
32 import org.xnap.event.StateListener;
33 import org.xnap.event.StateSupport;
34 import org.xnap.gui.XNapFrame;
35 import org.xnap.gui.util.FocusManager;
36 import org.xnap.peer.AbstractPeer;
37 import org.xnap.peer.HotlistItem;
38 import org.xnap.peer.action.AbstractChatAction;
39 import org.xnap.peer.action.AbstractRemoveFromHotlistAction;
40 import org.xnap.util.State;
41
42 public class JOscarPeer extends AbstractPeer
43 implements HotlistItem, StateListener
44 {
45
46
47
48
49 private StateSupport listeners = new StateSupport(this);
50
51 private String status;
52
53 private static Logger logger = Logger.getLogger(JOscarPeer.class);
54 /***
55 * Keeps track if actions are enabled or not.
56 */
57 private boolean enabled = false;
58
59
60
61 public JOscarPeer(String uin)
62 {
63 super(uin);
64 setStatus(XNap.tr("Offline"));
65 stateChanged(null);
66 }
67
68
69
70 public void stateChanged(StateEvent e)
71 {
72 State s = JOscarPlugin.getInstance().getConnection().getState();
73 if (s == State.DISCONNECTED) {
74 setStatus(XNap.tr("Offline"));
75 enabled = false;
76 }
77 else if (s == State.CONNECTED) {
78 enabled = true;
79 }
80 }
81
82 public void addStateListener(StateListener listener)
83 {
84 listeners.addStateListener(listener);
85 }
86
87 public Action[] getActions()
88 {
89 return new Action[] {
90 new ChatAction(), new SendSMSAction(), new RemoveAction(),
91 };
92 }
93
94 public String getCategory()
95 {
96 return null;
97 }
98
99
100
101
102 public String getComment() {
103
104 return null;
105 }
106
107 public Icon getIcon()
108 {
109 return JOscarPlugin.ICON_16;
110 }
111
112 /***
113 * @see xnap.peer.HotlistItem#getStatus()
114 */
115 public String getStatus()
116 {
117 return status;
118 }
119
120 public void setStatus(String newStatus)
121 {
122 status = newStatus;
123 listeners.fireStateChanged();
124 }
125
126 public void removeStateListener(StateListener listener)
127 {
128 listeners.removeStateListener(listener);
129 }
130
131 public String getHost()
132 {
133
134 return null;
135 }
136
137
138
139
140 public int getLocalDownloadCount() {
141
142 return 0;
143 }
144
145
146
147
148 public int getLocalUploadCount() {
149
150 return 0;
151 }
152
153
154
155 private class ChatAction extends AbstractChatAction
156 {
157 public ChatAction()
158 {
159 setEnabled(JOscarPeer.this.enabled);
160 }
161
162 public void actionPerformed(ActionEvent event)
163 {
164 JOscarPlugin.getInstance().addChannel
165 (new JOscarChannel(JOscarPeer.this));
166 FocusManager.setFocusTo("chat", event);
167 }
168 }
169
170 private class RemoveAction extends AbstractRemoveFromHotlistAction
171 {
172 public void actionPerformed(ActionEvent event)
173 {
174 JOscarPlugin.getInstance().removeBuddy(JOscarPeer.this);
175 }
176 }
177
178 private class SendSMSAction extends AbstractAction
179 {
180 public SendSMSAction()
181 {
182 putValue(Action.NAME, XNap.tr("Send SMS"));
183 setEnabled(JOscarPeer.this.enabled);
184 }
185
186 public void actionPerformed(ActionEvent event)
187 {
188 String message = JOptionPane.showInputDialog
189 (XNapFrame.getInstance(), XNap.tr("Enter SMS:"),
190 XNap.tr("Send SMS"), JOptionPane.QUESTION_MESSAGE);
191
192 if (message != null) {
193 JOscarPlugin.getInstance().sendSMS(JOscarPeer.this.getName(),
194 message);
195 }
196 }
197 }
198 }