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.gui.component;
21  
22  import java.awt.Component;
23  import java.awt.Insets;
24  import java.awt.event.ActionEvent;
25  
26  import javax.swing.AbstractAction;
27  import javax.swing.Action;
28  import javax.swing.Box;
29  import javax.swing.BoxLayout;
30  import javax.swing.JButton;
31  import javax.swing.JCheckBox;
32  import javax.swing.JPanel;
33  import javax.swing.JTextField;
34  
35  import org.xnap.XNap;
36  import org.xnap.gui.action.EnableAction;
37  import org.xnap.gui.util.IconHelper;
38  
39  /***
40   * Provides a panel with a <code>JTextField</code> and a button for file
41   * selection.
42   */
43  public class PortPanel extends JPanel {
44      
45      //--- Data field(s) ---
46  
47  	private JCheckBox jcbEnable;
48      private JTextField jtfPort;
49  
50      //--- Constructor(s) ---
51  
52      public PortPanel(boolean selected, String text, int size) 
53      {
54  		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
55  
56  		jtfPort = new ValidatedTextField
57  			(text, size, ValidatedTextField.NUMBERS_INT + ";-");
58  
59  		EnableAction ac = new EnableAction
60  			(XNap.tr("Enable"), new Component[] { jtfPort }, selected);
61  
62  		jcbEnable = new XNapCheckBox(ac);
63  		add(jcbEnable);
64  
65  		add(Box.createHorizontalStrut(5));
66  
67  		add(jtfPort);
68  
69  		add(Box.createHorizontalStrut(1));
70  
71  		JButton jbCheck = new XNapButton(new PortCheckAction());
72  		jbCheck.setMargin(new Insets(1, 1, 1, 1));
73  		add(jbCheck);
74      }
75  
76  	//--- Method(s) ---
77  
78      public String getPort()
79      {
80  		return jtfPort.getText();
81      }
82  
83  	public boolean isSelected()
84  	{
85  		return jcbEnable.isSelected();
86  	}
87  
88      // --- Inner Class(es) ---
89  
90      private class PortCheckAction extends AbstractAction 
91  	{
92          public PortCheckAction() 
93  		{
94  			putValue(IconHelper.XNAP_ICON, "help.png");
95              putValue(Action.SHORT_DESCRIPTION, 
96  					 XNap.tr("Verifies if the selected port can be reached from outside."));
97  
98  			// FIX: Implement this
99  			setEnabled(false);
100 		}
101 
102         public void actionPerformed(ActionEvent event) 
103 		{
104 		}
105     } 
106 
107 }