📄 serversetup.java
字号:
JPanel netPanel = new JPanel(new BorderLayout());
netPanel.setBackground(Color.white);
netPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
JPanel netPanel1 = new JPanel(new BorderLayout());
netPanel1.setBackground(Color.white);
netPanel1.add(r_automatic,BorderLayout.NORTH);
netPanel1.add(autoPanel,BorderLayout.SOUTH);
JPanel netPanel2 = new JPanel(new GridLayout(2,1,0,0));
netPanel2.setBackground(Color.white);
netPanel2.add(r_fixed);
netPanel2.add(fixedPanel);
netPanel2.setBorder(BorderFactory.createEmptyBorder(0,0,1,0));
netPanel.add( netPanel1, BorderLayout.NORTH);
netPanel.add( netPanel2, BorderLayout.SOUTH);
mainPanel.add( netPanel, BorderLayout.NORTH );
// Creation of the publish panel
r_publishSelect = new ARadioButton("Publish the IP of the interface that was selected above.");
r_publishSelect.setActionCommand("publishItf");
r_publishSelect.addActionListener(this);
r_publishFixed = new ARadioButton("Publish another IP/DNS name:");
r_publishFixed.setActionCommand("publishOther");
r_publishFixed.addActionListener(this);
btGroupPublish = new ButtonGroup();
btGroupPublish.add(r_publishSelect);
btGroupPublish.add(r_publishFixed);
t_itfPublish = new ATextField("");
t_itfPublish.setBackground(Color.white);
JPanel otherPanel = new JPanel(new GridLayout(1,2,0,0));
otherPanel.setBackground(Color.white);
otherPanel.add(r_publishFixed);
otherPanel.add(t_itfPublish);
otherPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
JPanel publishPanel = new JPanel(new GridLayout(3,1,5,5));
publishPanel.setBackground(Color.white);
ALabel l5 = new ALabel("IP Address to Publish on the Internet");
l5.setBackground(Color.white);
publishPanel.add(l5);
publishPanel.add(r_publishSelect);
publishPanel.add(otherPanel);
publishPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
mainPanel.add( publishPanel, BorderLayout.CENTER );
// Third Radio section
r_automaticUpdate = new ARadioButton("Automatically when the IP changes (via the transfer script).");
r_manualUpdate = new ARadioButton("Never. I will do it manually via the Server Address Wizard.");
btGroupItf = new ButtonGroup();
btGroupItf.add(r_automaticUpdate);
btGroupItf.add(r_manualUpdate);
JPanel updatePanel = new JPanel(new GridLayout(3,1,5,5));
updatePanel.setBackground(Color.white);
updatePanel.setBorder(BorderFactory.createLineBorder(Color.gray));
ALabel l6 = new ALabel("When do we have to do the IP File Transfer ?");
l6.setBackground(Color.white);
updatePanel.add(l6);
updatePanel.add(r_automaticUpdate);
updatePanel.add(r_manualUpdate);
mainPanel.add( updatePanel, BorderLayout.SOUTH );
// Selection init
r_automatic.setSelected(true);
t_itfName.setEnabled(false);
l4.setEnabled(false);
r_publishSelect.setSelected(true);
t_itfPublish.setEnabled(false);
r_automaticUpdate.setSelected(true);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Action Performed when the user clicks a button.
*/
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
if( name.equals("automaticItf") ) {
c_itfName.setEnabled(true);
c_ipName.setEnabled(true);
l_itfDesc.setEnabled(true);
t_itfName.setEnabled(false);
l1.setEnabled(true);
l2.setEnabled(true);
l3.setEnabled(true);
l4.setEnabled(false);
}
else if( name.equals("fixedItf") ) {
c_itfName.setEnabled(false);
c_ipName.setEnabled(false);
l_itfDesc.setEnabled(false);
t_itfName.setEnabled(true);
l1.setEnabled(false);
l2.setEnabled(false);
l3.setEnabled(false);
l4.setEnabled(true);
}
else if( name.equals("publishItf") ) {
t_itfPublish.setEnabled(false);
r_automaticUpdate.setEnabled(true);
}
else if( name.equals("publishOther") ) {
t_itfPublish.setEnabled(true);
r_automaticUpdate.setSelected(false);
r_manualUpdate.setSelected(true);
r_automaticUpdate.setEnabled(false);
}
else if( name.equals("itf") ) {
if( c_itfName.getItemCount()==0 || l_itfDesc==null || c_ipName==null)
return;
String itfName = (String) c_itfName.getSelectedItem();
if(itfName==null) return;
l_itfDesc.setText( NetInterface.getInterfaceDescription(itfName) );
String ip[] = NetInterface.getInterfaceAddresses( itfName );
c_ipName.removeAllItems();
for( int i=0; i<ip.length; i++ )
c_ipName.addItem(ip[i]);
if(ip.length!=0)
c_ipName.setSelectedIndex(0);
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Called each time the step is shown on screen.
*/
protected void onShow(Object context, JWizard wizard) {
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Called when the "Next" button is clicked.
* Use the wizard's setNextStep() method to set the next step to be displayed.
* @return return true to validate the "Next" button action, false to cancel it...
*/
protected boolean onNext(Object context, JWizard wizard) {
// we retrieve the setup data
String itf = "";
String publish = "";
if( r_automatic.isSelected() ) {
itf = (String) c_itfName.getSelectedItem();
if(itf==null || itf.length()==0) {
JOptionPane.showMessageDialog( null, "No network interface selected.",
"Error", JOptionPane.ERROR_MESSAGE);
return false;
}
int ind = c_ipName.getSelectedIndex();
if( ind<0 ) {
JOptionPane.showMessageDialog( null, "No IP address index selected.",
"Error", JOptionPane.ERROR_MESSAGE);
return false;
}
itf = itf+","+ind;
}
else {
if( t_itfName.getText().length()==0 ) {
JOptionPane.showMessageDialog( null, "No IP/DNS name entered.",
"Error", JOptionPane.ERROR_MESSAGE);
return false;
}
itf = t_itfName.getText();
}
if( r_publishFixed.isSelected() ) {
if( t_itfPublish.getText().length()==0 ) {
JOptionPane.showMessageDialog( null, "No IP/DNS name entered (publish section).",
"Error", JOptionPane.ERROR_MESSAGE);
return false;
}
publish = t_itfPublish.getText();
}
// set this config as default ?
int value = JOptionPane.showConfirmDialog( null, "Set this config as default ?\n Server Interface : "+itf
+"\n Published Interface: "+(publish.length()==0?itf:publish),
"Server Interface Update", JOptionPane.YES_NO_OPTION);
if( value == JOptionPane.YES_OPTION ) {
ServerDirector.getServerProperties().setProperty( "init.serverItf", itf );
ServerDirector.getServerProperties().setProperty( "init.publishAddress", publish );
ServerDirector.getServerProperties().setProperty( "init.automaticUpdate",
""+r_automaticUpdate.isSelected() );
}
else
return false;
wizard.setNextStep( ServerConfigWizardStep.getStaticParameters() );
return true;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Called when Previous button is clicked.
* Use the wizard's setNextStep() method to set the next step to be displayed.
* @return return true to validate the "Previous" button action, false to cancel it...
*/
protected boolean onPrevious(Object context, JWizard wizard) {
wizard.setNextStep( RegisterChoicesWizardStep.getStaticParameters() );
return true;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
}
/*------------------------------------------------------------------------------------*/
/**
* Third Step of our JWizard. Server config.
*/
public static class ServerConfigWizardStep extends JWizardStep {
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** This is a static JWizardStep, to build it more simply this method
* returns the JWizardStepParameters needed for the JWizard.
*/
public static JWizardStepParameters getStaticParameters() {
JWizardStepParameters param = new JWizardStepParameters(
"wotlas.server.setup.ServerSetup$ServerConfigWizardStep",
"Edit your Server's Config" );
param.setIsPrevButtonEnabled(true);
param.setIsDynamic(true);
return param;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Swing Components
*/
private ATextField t_serverSymbolicName, t_serverName, t_serverID, t_accountServerPort,
t_gameServerPort, t_gatewayServerPort, t_maxNumberOfGameConnections,
t_maxNumberOfAccountConnections, t_maxNumberOfGatewayConnections,
t_description, t_location, t_adminEmail;
private JComboBox c_worldStartLocation;
/** The server config we build.
*/
private ServerConfig config;
/** Server config Manager to save/load configs
*/
private ServerConfigManager serverConfigManager;
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Constructor.
*/
public ServerConfigWizardStep() {
super();
// II - we load the default server config.
serverConfigManager = new ServerConfigManager( ServerDirector.getResourceManager() );
config = serverConfigManager.loadServerConfig( serverID );
if( config == null )
config = new ServerConfig(); // none ? ok, we build one...
config.setServerID(serverID);
// III - Swing components
JPanel sconfPanel = new JPanel(new GridLayout(24,1,10,10));
sconfPanel.setBackground(Color.white);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -