1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.FlowLayout;
24 import java.awt.event.ActionEvent;
25
26 import javax.swing.AbstractAction;
27 import javax.swing.Action;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTable;
31
32 import org.xnap.XNap;
33 import org.xnap.gui.ActionProvider;
34 import org.xnap.gui.PeerProvider;
35 import org.xnap.gui.component.XNapButton;
36 import org.xnap.gui.event.PopupListener;
37 import org.xnap.gui.menu.PeerMenu;
38 import org.xnap.gui.util.IconHelper;
39 import org.xnap.peer.Peer;
40 import org.xnap.plugin.opennap.OpenNapPlugin;
41
42 public class OpenNapWhoisPanel extends JPanel
43 implements ActionProvider, PeerProvider {
44
45
46
47 protected JTable jtaWhois;
48 protected OpenNapWhoisTableModel tmWhois;
49
50 protected ClearAction acClear = new ClearAction();
51 protected UpdateAction acUpdate = new UpdateAction();
52
53
54
55 public OpenNapWhoisPanel()
56 {
57 initialize();
58 }
59
60
61
62 private void initialize()
63 {
64 setLayout(new BorderLayout(5, 5));
65
66 JPanel jpUsers = new JPanel(new BorderLayout());
67
68
69 PeerMenu jm = new PeerMenu(this);
70
71
72 tmWhois = new OpenNapWhoisTableModel();
73 jtaWhois = tmWhois.createTable(OpenNapPlugin.getPreferences(), "whois");
74 jtaWhois.addMouseListener(new PopupListener(jm));
75 jtaWhois.setShowGrid(false);
76
77 jpUsers.add(new JScrollPane(jtaWhois), BorderLayout.CENTER);
78
79
80 JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.LEFT));
81 jpButtons.add(new XNapButton(acUpdate));
82 jpButtons.add(new XNapButton(acClear));
83 jpUsers.add(jpButtons, BorderLayout.SOUTH);
84
85 add(jpUsers, BorderLayout.CENTER);
86 }
87
88 public Action[] getActions()
89 {
90 return new AbstractAction[] { acUpdate, acClear };
91 }
92
93 public Peer[] getPeers()
94 {
95 int[] rows = jtaWhois.getSelectedRows();
96 Peer[] users = new Peer[rows.length];
97 for (int i = 0; i < rows.length; i++) {
98 users[i] = tmWhois.get(rows[i]);
99 }
100 return users;
101 }
102
103 /***
104 * Clears whois table.
105 */
106 private class ClearAction extends AbstractAction {
107
108 public ClearAction()
109 {
110 putValue(Action.NAME, XNap.tr("Clear"));
111 putValue(Action.SHORT_DESCRIPTION, XNap.tr("Clear table."));
112 putValue(IconHelper.XNAP_ICON, "edittrash.png");
113 }
114
115 public void actionPerformed(ActionEvent event)
116 {
117 tmWhois.clear();
118 }
119
120 }
121
122 /***
123 * Updates user table.
124 */
125 private class UpdateAction extends AbstractAction {
126
127 public UpdateAction()
128 {
129 putValue(Action.NAME,XNap.tr("Update"));
130 putValue(Action.SHORT_DESCRIPTION,XNap.tr("Update table."));
131 putValue(IconHelper.XNAP_ICON, "reload.png");
132 }
133
134 public void actionPerformed(ActionEvent event)
135 {
136 tmWhois.reload();
137 }
138
139 }
140
141 }
142
143