forked from External/mage
Add a user registration dialog.
This commit is contained in:
parent
9ca716bf76
commit
835f08c18f
14 changed files with 801 additions and 268 deletions
|
|
@ -28,12 +28,6 @@
|
|||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Component id="btnConnect" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
|
|
@ -60,9 +54,21 @@
|
|||
<Component id="btnFind" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="chkForceUpdateDB" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="chkAutoConnect" alignment="0" pref="358" max="32767" attributes="0"/>
|
||||
<Component id="chkAutoConnect" alignment="0" pref="375" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="btnRegister" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="btnConnect" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
|
|
@ -103,7 +109,7 @@
|
|||
<Component id="chkForceUpdateDB" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jProxySettingsButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="50" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="38" max="32767" attributes="0"/>
|
||||
<Component id="lblStatus" min="-2" pref="24" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
|
|
@ -111,6 +117,8 @@
|
|||
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnRegister" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
|
@ -226,5 +234,13 @@
|
|||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblStatus">
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnRegister">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Register new user"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnRegisterActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ import java.util.concurrent.CancellationException;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingWorker;
|
||||
import mage.client.MageFrame;
|
||||
|
|
@ -65,7 +66,6 @@ import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_FLAG;
|
|||
import mage.client.util.Config;
|
||||
import mage.client.util.gui.countryBox.CountryItemEditor;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -76,6 +76,7 @@ public class ConnectDialog extends MageDialog {
|
|||
private static final Logger logger = Logger.getLogger(ConnectDialog.class);
|
||||
private Connection connection;
|
||||
private ConnectTask task;
|
||||
private RegisterUserDialog registerUserDialog;
|
||||
|
||||
private final ActionListener connectAction = new ActionListener() {
|
||||
@Override
|
||||
|
|
@ -94,6 +95,9 @@ public class ConnectDialog extends MageDialog {
|
|||
this.txtPort.addActionListener(connectAction);
|
||||
this.txtUserName.addActionListener(connectAction);
|
||||
this.txtPassword.addActionListener(connectAction);
|
||||
|
||||
registerUserDialog = new RegisterUserDialog();
|
||||
MageFrame.getDesktop().add(registerUserDialog, JLayeredPane.POPUP_LAYER);
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
|
|
@ -152,6 +156,7 @@ public class ConnectDialog extends MageDialog {
|
|||
btnConnect = new javax.swing.JButton();
|
||||
btnCancel = new javax.swing.JButton();
|
||||
lblStatus = new javax.swing.JLabel();
|
||||
btnRegister = new javax.swing.JButton();
|
||||
|
||||
setTitle("Connect to server");
|
||||
setNormalBounds(new java.awt.Rectangle(100, 100, 410, 307));
|
||||
|
|
@ -180,21 +185,9 @@ public class ConnectDialog extends MageDialog {
|
|||
lblUserName.setLabelFor(txtUserName);
|
||||
lblUserName.setText("User name:");
|
||||
|
||||
txtUserName.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
txtUserNameActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblPassword.setLabelFor(txtPassword);
|
||||
lblPassword.setText("Password:");
|
||||
|
||||
txtPassword.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
txtPasswordActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblFlag.setLabelFor(txtUserName);
|
||||
lblFlag.setText("User flag:");
|
||||
|
||||
|
|
@ -237,6 +230,13 @@ public class ConnectDialog extends MageDialog {
|
|||
}
|
||||
});
|
||||
|
||||
btnRegister.setText("Register new user");
|
||||
btnRegister.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnRegisterActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
|
|
@ -244,11 +244,6 @@ public class ConnectDialog extends MageDialog {
|
|||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(btnConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
|
|
@ -271,7 +266,16 @@ public class ConnectDialog extends MageDialog {
|
|||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnFind))
|
||||
.addComponent(chkForceUpdateDB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE))))
|
||||
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(btnRegister)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel)))
|
||||
.addGap(26, 26, 26)))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
|
|
@ -304,13 +308,15 @@ public class ConnectDialog extends MageDialog {
|
|||
.addComponent(chkForceUpdateDB)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jProxySettingsButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
|
||||
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnConnect)
|
||||
.addComponent(btnCancel))
|
||||
.addContainerGap())
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnRegister)
|
||||
.addGap(3, 3, 3))
|
||||
);
|
||||
|
||||
pack();
|
||||
|
|
@ -360,28 +366,7 @@ public class ConnectDialog extends MageDialog {
|
|||
connection.setPassword(this.txtPassword.getText().trim());
|
||||
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected());
|
||||
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, ((CountryItemEditor) cbFlag.getEditor()).getImageItem());
|
||||
|
||||
ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
|
||||
|
||||
if (configProxyType != null) {
|
||||
connection.setProxyType(configProxyType);
|
||||
if (!configProxyType.equals(ProxyType.NONE)) {
|
||||
String host = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
|
||||
String port = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "");
|
||||
if (!host.isEmpty() && !port.isEmpty()) {
|
||||
connection.setProxyHost(host);
|
||||
connection.setProxyPort(Integer.valueOf(port));
|
||||
String username = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_USERNAME, "");
|
||||
connection.setProxyUsername(username);
|
||||
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_REMEMBER, "false").equals("true")) {
|
||||
String password = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PSWD, "");
|
||||
connection.setProxyPassword(password);
|
||||
}
|
||||
} else {
|
||||
logger.warn("host or\\and port are empty: host=" + host + ", port=" + port);
|
||||
}
|
||||
}
|
||||
}
|
||||
PreferencesDialog.setProxyInformation(connection);
|
||||
|
||||
// pref settings
|
||||
MageFrame.getInstance().setUserPrefsToConnection(connection);
|
||||
|
|
@ -580,10 +565,15 @@ public class ConnectDialog extends MageDialog {
|
|||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_txtPasswordActionPerformed
|
||||
|
||||
private void btnRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegisterActionPerformed
|
||||
registerUserDialog.showDialog();
|
||||
}//GEN-LAST:event_btnRegisterActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnConnect;
|
||||
private javax.swing.JButton btnFind;
|
||||
private javax.swing.JButton btnRegister;
|
||||
private mage.client.util.gui.countryBox.CountryComboBox cbFlag;
|
||||
private javax.swing.JCheckBox chkAutoConnect;
|
||||
private javax.swing.JCheckBox chkForceUpdateDB;
|
||||
|
|
|
|||
|
|
@ -2298,6 +2298,30 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
this.repaint();
|
||||
}
|
||||
|
||||
public static void setProxyInformation(Connection connection) {
|
||||
ProxyType configProxyType = Connection.ProxyType.valueByText(getCachedValue(KEY_PROXY_TYPE, "None"));
|
||||
if (configProxyType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
connection.setProxyType(configProxyType);
|
||||
if (!configProxyType.equals(ProxyType.NONE)) {
|
||||
String host = getCachedValue(KEY_PROXY_ADDRESS, "");
|
||||
String port = getCachedValue(KEY_PROXY_PORT, "");
|
||||
if (!host.isEmpty() && !port.isEmpty()) {
|
||||
connection.setProxyHost(host);
|
||||
connection.setProxyPort(Integer.valueOf(port));
|
||||
String username = getCachedValue(KEY_PROXY_USERNAME, "");
|
||||
connection.setProxyUsername(username);
|
||||
if (getCachedValue(KEY_PROXY_REMEMBER, "false").equals("true")) {
|
||||
String password = getCachedValue(KEY_PROXY_PSWD, "");
|
||||
connection.setProxyPassword(password);
|
||||
}
|
||||
} else {
|
||||
log.warn("host or\\and port are empty: host=" + host + ", port=" + port);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,161 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Register"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
|
||||
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblPassword" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblServer" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblStatus" min="-2" pref="292" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" max="-2" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="btnRegister" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="txtUserName" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="txtPassword" alignment="0" pref="292" max="32767" attributes="0"/>
|
||||
<Component id="txtServer" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="txtPort" min="-2" pref="292" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="16" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtServer" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtPort" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblUserName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtUserName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="separate" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblStatus" min="-2" pref="28" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btnRegister" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="14" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="lblServer">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtServer"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Server:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblPort">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtPort"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Port:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblUserName">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtUserName"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="User name:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblPassword">
|
||||
<Properties>
|
||||
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||
<ComponentRef name="txtPassword"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Password:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtUserName">
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtUserNameActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JPasswordField" name="txtPassword">
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnRegister">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Register"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnRegisterActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnCancel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Cancel"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblStatus">
|
||||
<Properties>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtServer">
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtPort">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
package mage.client.dialog;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import javax.swing.SwingWorker;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.Config;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Session;
|
||||
import mage.remote.SessionImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class RegisterUserDialog extends MageDialog {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ConnectDialog.class);
|
||||
private Connection connection;
|
||||
private ConnectTask task;
|
||||
private Session session;
|
||||
|
||||
/**
|
||||
* Creates new form RegisterUserDialog
|
||||
*/
|
||||
public RegisterUserDialog() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
|
||||
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
||||
this.lblStatus.setText("");
|
||||
|
||||
this.setModal(true);
|
||||
this.setLocation(50, 50);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
lblServer = new javax.swing.JLabel();
|
||||
lblPort = new javax.swing.JLabel();
|
||||
lblUserName = new javax.swing.JLabel();
|
||||
lblPassword = new javax.swing.JLabel();
|
||||
txtUserName = new javax.swing.JTextField();
|
||||
txtPassword = new javax.swing.JPasswordField();
|
||||
btnRegister = new javax.swing.JButton();
|
||||
btnCancel = new javax.swing.JButton();
|
||||
lblStatus = new javax.swing.JLabel();
|
||||
txtServer = new javax.swing.JTextField();
|
||||
txtPort = new javax.swing.JTextField();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle("Register");
|
||||
|
||||
lblServer.setLabelFor(txtServer);
|
||||
lblServer.setText("Server:");
|
||||
|
||||
lblPort.setLabelFor(txtPort);
|
||||
lblPort.setText("Port:");
|
||||
|
||||
lblUserName.setLabelFor(txtUserName);
|
||||
lblUserName.setText("User name:");
|
||||
|
||||
lblPassword.setLabelFor(txtPassword);
|
||||
lblPassword.setText("Password:");
|
||||
|
||||
txtUserName.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
txtUserNameActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnRegister.setText("Register");
|
||||
btnRegister.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnRegisterActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnCancelActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblStatus.setToolTipText("");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(14, 14, 14)
|
||||
.addComponent(lblUserName))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblPassword, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblPort, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblServer, javax.swing.GroupLayout.Alignment.TRAILING))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnRegister)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
|
||||
.addComponent(txtServer, javax.swing.GroupLayout.Alignment.LEADING))
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap(16, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(9, 9, 9)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblServer)
|
||||
.addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblPort)
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblUserName)
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblPassword)
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnRegister)
|
||||
.addComponent(btnCancel))
|
||||
.addContainerGap(14, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void txtUserNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUserNameActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_txtUserNameActionPerformed
|
||||
|
||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||
this.hideDialog();
|
||||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
private void btnRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegisterActionPerformed
|
||||
connection = new Connection();
|
||||
connection.setHost(this.txtServer.getText().trim());
|
||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||
connection.setUsername(this.txtUserName.getText().trim());
|
||||
connection.setPassword(this.txtPassword.getText().trim());
|
||||
PreferencesDialog.setProxyInformation(connection);
|
||||
task = new ConnectTask();
|
||||
task.execute();
|
||||
}//GEN-LAST:event_btnRegisterActionPerformed
|
||||
|
||||
private class ConnectTask extends SwingWorker<Boolean, Void> {
|
||||
|
||||
private boolean result = false;
|
||||
|
||||
private static final int CONNECTION_TIMEOUT_MS = 2100;
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground() throws Exception {
|
||||
lblStatus.setText("Connecting...");
|
||||
btnRegister.setEnabled(false);
|
||||
session = new SessionImpl(MageFrame.getInstance());
|
||||
result = session.register(connection);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
if (result) {
|
||||
lblStatus.setText("Registration succeeded");
|
||||
MageFrame.getInstance().showMessage("Registration succeeded");
|
||||
hideDialog();
|
||||
} else {
|
||||
lblStatus.setText("Could not register");
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (ExecutionException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (CancellationException ex) {
|
||||
logger.info("Registration was canceled");
|
||||
lblStatus.setText("Registration was canceled (but an account might have been actually created)");
|
||||
} catch (TimeoutException ex) {
|
||||
logger.fatal("Registration timeout: ", ex);
|
||||
} finally {
|
||||
MageFrame.stopConnecting();
|
||||
btnRegister.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnRegister;
|
||||
private javax.swing.JLabel lblPassword;
|
||||
private javax.swing.JLabel lblPort;
|
||||
private javax.swing.JLabel lblServer;
|
||||
private javax.swing.JLabel lblStatus;
|
||||
private javax.swing.JLabel lblUserName;
|
||||
private javax.swing.JPasswordField txtPassword;
|
||||
private javax.swing.JTextField txtPort;
|
||||
private javax.swing.JTextField txtServer;
|
||||
private javax.swing.JTextField txtUserName;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue