Menu

[01c4ec]: / NetConfigWindow.java  Maximize  Restore  History

Download this file

165 lines (156 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Copyright (C) 2006-2010 Joan Queralt Molina
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package biogenesis;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
public class NetConfigWindow extends JDialog {
private static final long serialVersionUID = Utils.FILE_VERSION;
protected JCheckBox acceptConnectionsCheck;
protected boolean acceptConnections;
//protected JCheckBox connectToServerCheck;
//protected boolean connectToServer = Utils.CONNECT_TO_SERVER;
//protected JTextField serverAddressText;
//protected JTextField serverPortText;
protected JTextField localPortText;
protected JTextField remotePortText;
protected JTextField remoteAddressText;
protected JTextField maxConnectionsText;
protected JButton cancelButton;
protected JButton okButton;
protected MainWindow mainWindow;
public NetConfigWindow(MainWindow parent) {
super(parent,Messages.getString("T_NETWORK_CONFIGURATION"),true); //$NON-NLS-1$
mainWindow = parent;
acceptConnections = mainWindow.isAcceptingConnections();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setComponents();
pack();
setResizable(false);
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
dispose();
}
});
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int oldPort = Utils.LOCAL_PORT;
checkParams();
Utils.savePreferences();
if (oldPort != Utils.LOCAL_PORT) {
mainWindow.stopServer();
if (mainWindow.isAcceptingConnections())
mainWindow.startServer();
}
dispose();
}
});
setVisible(true);
}
protected void setComponents() {
getContentPane().setLayout(new BorderLayout());
// Set up buttons
JPanel buttonsPanel = new JPanel();
okButton = new JButton(Messages.getString("T_OK")); //$NON-NLS-1$
cancelButton = new JButton(Messages.getString("T_CANCEL")); //$NON-NLS-1$
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
// Accept connections + use server
JPanel generalPanel = new JPanel();
generalPanel.setLayout(new BoxLayout(generalPanel,BoxLayout.Y_AXIS));
JPanel panel = new JPanel();
acceptConnectionsCheck = new JCheckBox(Messages.getString("T_ALLOW_CONNECTIONS_FROM_OTHER_USERS"), //$NON-NLS-1$
acceptConnections);
acceptConnectionsCheck.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent arg0) {
acceptConnections = (arg0.getStateChange() == ItemEvent.SELECTED);
}
});
panel.add(acceptConnectionsCheck);
generalPanel.add(panel);
/*panel = new JPanel();
connectToServerCheck = new JCheckBox("Utilitza el servidor per trobar altres usuaris",
connectToServer);
connectToServerCheck.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent arg0) {
connectToServer = (arg0.getStateChange() == ItemEvent.SELECTED);
}
});
panel.add(connectToServerCheck);
generalPanel.add(panel);*/
/*panel = new JPanel();
JLabel label = new JLabel("Adre�a del servidor: ");
panel.add(label);
serverAddressText = new JTextField(Utils.SERVER_ADDRESS,25);
panel.add(serverAddressText);
label = new JLabel("Port del servidor: ");
panel.add(label);
serverPortText = new JTextField(String.valueOf(Utils.SERVER_PORT),5);
panel.add(serverPortText);
generalPanel.add(panel);*/
panel = new JPanel();
JLabel label = new JLabel(Messages.getString("T_MAXIMUM_NUMBER_OF_ALLOWED_CONNECTIONS")); //$NON-NLS-1$
panel.add(label);
maxConnectionsText = new JTextField(String.valueOf(Utils.MAX_CONNECTIONS),4);
panel.add(maxConnectionsText);
generalPanel.add(panel);
panel = new JPanel();
label = new JLabel(Messages.getString("T_LOCAL_PORT_TO_RECEIVE_CONNECTIONS")); //$NON-NLS-1$
panel.add(label);
localPortText = new JTextField(String.valueOf(Utils.LOCAL_PORT),6);
panel.add(localPortText);
generalPanel.add(panel);
getContentPane().add(generalPanel, BorderLayout.CENTER);
}
void checkParams() {
int i;
mainWindow.setAcceptConnections(acceptConnections);
/*Utils.CONNECT_TO_SERVER = connectToServer;
Utils.SERVER_ADDRESS = serverAddressText.getText();
try {
i = Integer.parseInt(serverPortText.getText());
if (i>=0) Utils.SERVER_PORT = i;
} catch (NumberFormatException e) {
// Keep old value if there is a problem
}*/
try {
i = Integer.parseInt(localPortText.getText());
if (i>=0) Utils.LOCAL_PORT = i;
} catch (NumberFormatException e) {
// Keep old value if there is a problem
}
try {
i = Integer.parseInt(maxConnectionsText.getText());
if (i>=0) Utils.MAX_CONNECTIONS = i;
} catch (NumberFormatException e) {
// Keep old value if there is a problem
}
}
/*
protected void defaultPreferences() {
acceptConnectionsCheck.setSelected(Utils.ACCEPT_CONNECTIONS);
connectToServerCheck.setSelected(Utils.CONNECT_TO_SERVER);
serverAddressText.setText(Utils.SERVER_ADDRESS);
serverPortText.setText(String.valueOf(Utils.SERVER_PORT));
localPortText.setText(String.valueOf(Utils.LOCAL_PORT));
remotePortText.setText("");
remoteAddressText.setText("");
maxConnectionsText.setText(String.valueOf(Utils.MAX_CONNECTIONS));
}*/
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.