1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui;
21
22 import java.awt.Color;
23 import java.awt.Graphics;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.MouseAdapter;
26 import java.awt.event.MouseEvent;
27 import java.beans.PropertyChangeEvent;
28 import java.beans.PropertyChangeListener;
29
30 import javax.swing.AbstractAction;
31 import javax.swing.Action;
32 import javax.swing.Icon;
33 import javax.swing.JPopupMenu;
34
35 import org.xnap.XNap;
36 import org.xnap.gui.component.XNapMenuItem;
37 import org.xnap.gui.util.IconHelper;
38 import org.xnap.util.Preferences;
39
40 /***
41 *
42 */
43 public class PresenceStatusPanel extends StatusPanel
44 implements PropertyChangeListener {
45
46
47
48 private static final Icon ICON_ONLINE
49 = IconHelper.getIcon("noatunplay.png", 16);
50
51 private static final Icon ICON_AWAY
52 = IconHelper.getIcon("player_pause.png", 16);
53
54
55
56 private JPopupMenu jpPresence;
57
58
59
60 public PresenceStatusPanel()
61 {
62 jpPresence = new JPopupMenu();
63 jpPresence.add(new XNapMenuItem(new OnlineAction()));
64 jpPresence.add(new XNapMenuItem(new AwayAction()));
65
66 propertyChange(null);
67
68 addMouseListener(new PopupListener());
69 Preferences.getInstance().addPropertyChangeListener
70 ("sendChatAwayMessage", this);
71 }
72
73
74
75 protected void paintComponent(Graphics g)
76 {
77 super.paintComponent(g);
78
79 int w = 16 + getHorizontalTextPosition();
80 int h = getHeight();
81
82 g.setColor(Color.black);
83
84
85 for (int i = 0; i < 4; i++) {
86 g.drawLine(w - 8 - i, h - 3 - i, w - 8 + i, h - 3 - i);
87 }
88 g.drawLine(w - 8 - 4, h - 3 - 4, w - 8 + 4, h - 3 - 4);
89 }
90
91 public void propertyChange(PropertyChangeEvent e)
92 {
93 if (Preferences.getInstance().getSendChatAwayMessage()) {
94 setIcon(ICON_AWAY);
95 setText(XNap.tr("Away"));
96 }
97 else {
98 setIcon(ICON_ONLINE);
99 setText(XNap.tr("Online"));
100 }
101 }
102
103
104
105 public class PopupListener extends MouseAdapter {
106
107 public void mousePressed(MouseEvent e)
108 {
109 if (!jpPresence.isVisible()) {
110 jpPresence.show(PresenceStatusPanel.this, 0,
111 -jpPresence.getHeight());
112 }
113 else {
114 jpPresence.setVisible(false);
115 }
116 }
117 }
118
119 public class OnlineAction extends AbstractAction {
120
121
122
123 public OnlineAction()
124 {
125 putValue(Action.NAME, XNap.tr("Online"));
126 putValue(IconHelper.XNAP_ICON, "noatunplay.png");
127 }
128
129
130
131 public void actionPerformed(ActionEvent event)
132 {
133 Preferences.getInstance().setSendChatAwayMessage(false);
134 }
135
136 }
137
138 public class AwayAction extends AbstractAction {
139
140
141
142 public AwayAction()
143 {
144 putValue(Action.NAME, XNap.tr("Away"));
145 putValue(IconHelper.XNAP_ICON, "player_pause.png");
146 }
147
148
149
150 public void actionPerformed(ActionEvent event)
151 {
152 Preferences.getInstance().setSendChatAwayMessage(true);
153 }
154
155 }
156
157 }