mirror of
https://github.com/correl/mage.git
synced 2025-04-13 01:01:11 -09:00
[ui] Now pressing "Enter" on any text field in Connect dialog will force connecting - No need to press "Connect" button anymore.
This commit is contained in:
parent
e076c0b6ee
commit
13c5177d54
1 changed files with 278 additions and 260 deletions
|
@ -34,7 +34,16 @@
|
|||
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.Config;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -45,20 +54,8 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.util.Config;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Connection.ProxyType;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ConnectDialog extends MageDialog {
|
||||
|
@ -67,9 +64,22 @@ public class ConnectDialog extends MageDialog {
|
|||
private Connection connection;
|
||||
private ConnectTask task;
|
||||
|
||||
/** Creates new form ConnectDialog */
|
||||
private final ActionListener connectAction = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
btnConnectActionPerformed(evt);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates new form ConnectDialog
|
||||
*/
|
||||
public ConnectDialog() {
|
||||
initComponents();
|
||||
|
||||
this.txtUserName.addActionListener(connectAction);
|
||||
this.txtServer.addActionListener(connectAction);
|
||||
this.txtPort.addActionListener(connectAction);
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
|
@ -89,7 +99,8 @@ public class ConnectDialog extends MageDialog {
|
|||
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
/**
|
||||
* 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.
|
||||
|
@ -255,7 +266,7 @@ public class ConnectDialog extends MageDialog {
|
|||
JOptionPane.showMessageDialog(rootPane, "Please provide a port number");
|
||||
return;
|
||||
}
|
||||
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
|
||||
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
|
||||
txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
||||
return;
|
||||
|
@ -298,8 +309,7 @@ public class ConnectDialog extends MageDialog {
|
|||
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
|
||||
task = new ConnectTask();
|
||||
task.execute();
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
Arrays.fill(input, '0');
|
||||
}
|
||||
|
||||
|
@ -325,8 +335,7 @@ public class ConnectDialog extends MageDialog {
|
|||
if (result) {
|
||||
lblStatus.setText("");
|
||||
connected();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lblStatus.setText("Could not connect");
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
|
@ -370,10 +379,16 @@ public class ConnectDialog extends MageDialog {
|
|||
Proxy p = null;
|
||||
Proxy.Type type = Proxy.Type.DIRECT;
|
||||
switch (configProxyType) {
|
||||
case HTTP: type = Proxy.Type.HTTP; break;
|
||||
case SOCKS: type = Proxy.Type.SOCKS; break;
|
||||
case HTTP:
|
||||
type = Proxy.Type.HTTP;
|
||||
break;
|
||||
case SOCKS:
|
||||
type = Proxy.Type.SOCKS;
|
||||
break;
|
||||
case NONE:
|
||||
default: p = Proxy.NO_PROXY; break;
|
||||
default:
|
||||
p = Proxy.NO_PROXY;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p == null || !p.equals(Proxy.NO_PROXY)) {
|
||||
|
@ -396,7 +411,7 @@ public class ConnectDialog extends MageDialog {
|
|||
List<String> servers = new ArrayList<String>();
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
System.out.println("Found server: "+inputLine);
|
||||
System.out.println("Found server: " + inputLine);
|
||||
servers.add(inputLine);
|
||||
}
|
||||
|
||||
|
@ -420,10 +435,13 @@ public class ConnectDialog extends MageDialog {
|
|||
}
|
||||
|
||||
in.close();
|
||||
} catch(Exception ex) {
|
||||
logger.error(ex,ex);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex, ex);
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (Exception e) {}
|
||||
if (in != null) try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue