View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
45      
46      //--- Data field(s) ---
47  
48      private JLabel jlStatus;
49  
50      //--- Constructor(s) ---
51      
52      public GiFTDaemonPanel(GiFTDaemon daemon)
53      {
54  		initialize();
55  
56  		statusChanged(daemon);
57     	}
58      
59      //--- Method(s) ---
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 }