1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.gift.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.FlowLayout;
24 import java.awt.GridBagLayout;
25
26 import javax.swing.Action;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.SwingUtilities;
30 import javax.swing.border.EmptyBorder;
31
32 import org.xnap.XNap;
33 import org.xnap.gui.ActionProvider;
34 import org.xnap.gui.component.XNapButton;
35 import org.xnap.gui.util.GUIHelper;
36 import org.xnap.gui.util.GridBagHelper;
37 import org.xnap.plugin.gift.GiFTPlugin;
38 import org.xnap.plugin.gift.net.GiFTDaemon;
39 import org.xnap.plugin.gift.net.GiFTDaemonListener;
40
41 public class GiFTDaemonPanel extends JPanel
42 implements ActionProvider, GiFTDaemonListener {
43
44
45
46
47
48 private JLabel jlStatus;
49
50
51
52 public GiFTDaemonPanel(GiFTDaemon daemon)
53 {
54 initialize();
55
56 statusChanged(daemon);
57 }
58
59
60
61 public void initialize()
62 {
63 setBorder(new EmptyBorder(5, 5, 5, 5));
64 setLayout(new GridBagLayout());
65
66 JPanel jpStatus = new JPanel(new BorderLayout());
67 GridBagHelper.add(this, jpStatus);
68 jpStatus.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Status")));
69 jlStatus = new JLabel(XNap.tr("Not connected."));
70 jpStatus.add(jlStatus, BorderLayout.CENTER);
71
72 GridBagHelper.addVerticalSpacer(this);
73
74 JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.LEFT));
75 GridBagHelper.add(this, jpButtons);
76 jpButtons.add
77 (new XNapButton(GiFTPlugin.getInstance().getConnectAction()));
78 jpButtons.add
79 (new XNapButton(GiFTPlugin.getInstance().getDisconnectAction()));
80 jpButtons.add
81 (new XNapButton(GiFTPlugin.getInstance().getUpdateAction()));
82
83 JPanel jpService = new JPanel(new FlowLayout(FlowLayout.LEFT));
84 GridBagHelper.add(this, jpService);
85 jpButtons.add
86 (new XNapButton(GiFTPlugin.getInstance().getStartAction()));
87 jpButtons.add
88 (new XNapButton(GiFTPlugin.getInstance().getShutdownAction()));
89 }
90
91 public Action[] getActions()
92 {
93 return new Action[] {
94 GiFTPlugin.getInstance().getConnectAction(),
95 GiFTPlugin.getInstance().getDisconnectAction(),
96 GiFTPlugin.getInstance().getUpdateAction()
97 };
98 }
99
100 /***
101 * @see org.xnap.plugin.gift.net.GiFTDaemonListener#statusChanged(org.xnap.plugin.gift.net.GiFTDaemon)
102 */
103 public void statusChanged(final GiFTDaemon daemon)
104 {
105 Runnable runner = new Runnable()
106 {
107 public void run()
108 {
109 String s = daemon.getVerboseMessage();
110 jlStatus.setText
111 (daemon.getStatus() + ((s != null) ? s : ""));
112 }
113 };
114 SwingUtilities.invokeLater(runner);
115 }
116
117 }