integrated jboss remoting

This commit is contained in:
BetaSteward 2011-06-22 22:37:50 -04:00
parent 34cd3bbcdc
commit 05be0a14ed
36 changed files with 1356 additions and 2061 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="Connect"/>
</Properties>
@ -27,38 +27,48 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" 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="1" attributes="0">
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="txtPort" min="-2" pref="71" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
</Group>
<Component id="txtPassword" alignment="0" pref="276" max="32767" attributes="0"/>
<Component id="chkAutoConnect" alignment="0" pref="276" max="32767" attributes="0"/>
<Component id="chkUseProxy" alignment="0" pref="276" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="txtServer" pref="205" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="txtPort" min="-2" pref="71" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
</Group>
<Component id="txtUserName" alignment="0" pref="382" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="txtServer" pref="311" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblProxyType" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="chkAutoConnect" alignment="0" pref="406" max="32767" attributes="0"/>
<Component id="cbProxyType" alignment="0" min="-2" pref="126" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="lblStatus" pref="294" max="32767" attributes="0"/>
<EmptySpace max="-2" 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>
<Component id="pnlProxySettings" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
<Component id="lblPassword" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPassword" pref="382" max="32767" attributes="0"/>
</Group>
<Component id="pnlProxy" alignment="1" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -78,21 +88,30 @@
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtPassword" min="-2" max="-2" attributes="0"/>
<Component id="txtUserName" min="-2" max="-2" attributes="0"/>
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtPassword" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="chkAutoConnect" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="chkUseProxy" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cbProxyType" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyType" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="pnlProxy" max="32767" attributes="0"/>
<Component id="pnlProxySettings" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnConnect" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblStatus" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -121,14 +140,14 @@
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="keyTyped"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtPassword">
<Component class="javax.swing.JTextField" name="txtUserName">
</Component>
<Component class="javax.swing.JLabel" name="lblUserName">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtPassword"/>
<ComponentRef name="txtUserName"/>
</Property>
<Property name="text" type="java.lang.String" value="Password:"/>
<Property name="text" type="java.lang.String" value="User Name:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnConnect">
@ -155,77 +174,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAutoConnectActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="chkUseProxy">
<Properties>
<Property name="text" type="java.lang.String" value="Use Proxy"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkUseProxyActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="pnlProxy">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblProxyPort" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyServer" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtProxyPort" min="-2" pref="71" max="-2" attributes="0"/>
<Component id="txtProxyServer" alignment="0" pref="260" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblProxyServer">
<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.JTextField" name="txtProxyServer">
</Component>
<Component class="javax.swing.JLabel" name="lblProxyPort">
<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.JTextField" name="txtProxyPort">
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtProxyPortkeyTyped"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="Find..."/>
@ -233,8 +181,189 @@
<Property name="name" type="java.lang.String" value="findServerBtn" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="findPublicServerActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="cbProxyType">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbProxyTypeActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblProxyType">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="cbProxyType"/>
</Property>
<Property name="text" type="java.lang.String" value="Proxy:"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlProxySettings">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/>
</Border>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 0]"/>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlProxy" alignment="0" max="32767" attributes="0"/>
<Component id="pnlProxyAuth" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="pnlProxy" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="pnlProxyAuth" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="pnlProxy">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="28" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblProxyPort" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyServer" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtProxyPort" min="-2" pref="71" max="-2" attributes="0"/>
<Component id="txtProxyServer" pref="360" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblProxyServer">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyServer"/>
</Property>
<Property name="text" type="java.lang.String" value="Server:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyServer">
</Component>
<Component class="javax.swing.JLabel" name="lblProxyPort">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyPort"/>
</Property>
<Property name="text" type="java.lang.String" value="Port:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyPort">
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtProxyPortkeyTyped"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="pnlProxyAuth">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblProxyPassword" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyUserName" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="txtPasswordField" max="32767" attributes="1"/>
<Component id="txtProxyUserName" alignment="1" pref="358" max="32767" attributes="1"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtProxyUserName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyUserName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="8" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtPasswordField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyPassword" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblProxyUserName">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyUserName"/>
</Property>
<Property name="text" type="java.lang.String" value="User Name:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyUserName">
</Component>
<Component class="javax.swing.JLabel" name="lblProxyPassword">
<Properties>
<Property name="text" type="java.lang.String" value="Password:"/>
</Properties>
</Component>
<Component class="javax.swing.JPasswordField" name="txtPasswordField">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtPasswordFieldActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
<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.JPasswordField" name="txtPassword">
</Component>
<Component class="javax.swing.JLabel" name="lblStatus">
</Component>
</SubComponents>
</Form>

View file

@ -39,10 +39,18 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
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.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import org.apache.log4j.Logger;
@ -53,22 +61,27 @@ import org.apache.log4j.Logger;
public class ConnectDialog extends JDialog {
private final static Logger logger = Logger.getLogger(ConnectDialog.class);
private ConsoleFrame console;
private Connection connection;
private ConnectTask task;
/** Creates new form ConnectDialog */
public ConnectDialog() {
initComponents();
cbProxyType.setModel(new DefaultComboBoxModel(Connection.ProxyType.values()));
}
public void showDialog(ConsoleFrame console) {
this.console = console;
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", ""));
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", ""));
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", "localhost"));
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
this.txtUserName.setText(ConsoleFrame.getPreferences().get("userName", ""));
this.chkAutoConnect.setSelected(Boolean.parseBoolean(ConsoleFrame.getPreferences().get("autoConnect", "false")));
this.txtProxyServer.setText(ConsoleFrame.getPreferences().get("proxyAddress", ""));
this.txtProxyPort.setText(ConsoleFrame.getPreferences().get("proxyPort", ""));
this.chkUseProxy.setSelected(Boolean.parseBoolean(ConsoleFrame.getPreferences().get("useProxy", "false")));
this.txtProxyServer.setText(ConsoleFrame.getPreferences().get("proxyAddress", "localhost"));
this.txtProxyPort.setText(ConsoleFrame.getPreferences().get("proxyPort", Integer.toString(17171)));
this.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(ConsoleFrame.getPreferences().get("proxyType", "NONE").toUpperCase()));
this.txtProxyUserName.setText(ConsoleFrame.getPreferences().get("proxyUsername", ""));
this.txtPasswordField.setText(ConsoleFrame.getPreferences().get("proxyPassword", ""));
this.showProxySettings();
this.setModal(true);
this.setLocation(50, 50);
@ -76,24 +89,37 @@ public class ConnectDialog extends JDialog {
}
private void showProxySettings() {
if (chkUseProxy.isSelected()) {
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(true);
}
else {
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(true);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
this.pnlProxy.setVisible(false);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(false);
}
this.pack();
// this.revalidate();
this.repaint();
}
private void saveSettings() {
ConsoleFrame.getPreferences().put("serverAddress", txtServer.getText());
ConsoleFrame.getPreferences().put("serverPort", txtPort.getText());
ConsoleFrame.getPreferences().put("userName", txtUserName.getText());
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
ConsoleFrame.getPreferences().put("proxyAddress", txtProxyServer.getText());
ConsoleFrame.getPreferences().put("proxyPort", txtProxyPort.getText());
ConsoleFrame.getPreferences().put("useProxy", Boolean.toString(chkUseProxy.isSelected()));
ConsoleFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
ConsoleFrame.getPreferences().put("proxyUsername", txtProxyUserName.getText());
char[] input = txtPasswordField.getPassword();
ConsoleFrame.getPreferences().put("proxyPassword", new String(input));
Arrays.fill(input, '0');
}
/** This method is called from within the constructor to
@ -109,18 +135,28 @@ public class ConnectDialog extends JDialog {
lblServer = new javax.swing.JLabel();
lblPort = new javax.swing.JLabel();
txtPort = new javax.swing.JTextField();
txtPassword = new javax.swing.JTextField();
txtUserName = new javax.swing.JTextField();
lblUserName = new javax.swing.JLabel();
btnConnect = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
chkAutoConnect = new javax.swing.JCheckBox();
chkUseProxy = new javax.swing.JCheckBox();
jButton1 = new javax.swing.JButton();
cbProxyType = new javax.swing.JComboBox();
lblProxyType = new javax.swing.JLabel();
pnlProxySettings = new javax.swing.JPanel();
pnlProxy = new javax.swing.JPanel();
lblProxyServer = new javax.swing.JLabel();
txtProxyServer = new javax.swing.JTextField();
lblProxyPort = new javax.swing.JLabel();
txtProxyPort = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
pnlProxyAuth = new javax.swing.JPanel();
lblProxyUserName = new javax.swing.JLabel();
txtProxyUserName = new javax.swing.JTextField();
lblProxyPassword = new javax.swing.JLabel();
txtPasswordField = new javax.swing.JPasswordField();
lblPassword = new javax.swing.JLabel();
txtPassword = new javax.swing.JPasswordField();
lblStatus = new javax.swing.JLabel();
setTitle("Connect");
@ -136,8 +172,8 @@ public class ConnectDialog extends JDialog {
}
});
lblUserName.setLabelFor(txtPassword);
lblUserName.setText("Password:");
lblUserName.setLabelFor(txtUserName);
lblUserName.setText("User Name:");
btnConnect.setText("Connect");
btnConnect.addActionListener(new java.awt.event.ActionListener() {
@ -160,17 +196,31 @@ public class ConnectDialog extends JDialog {
}
});
chkUseProxy.setText("Use Proxy");
chkUseProxy.addActionListener(new java.awt.event.ActionListener() {
jButton1.setText("Find...");
jButton1.setToolTipText("Find public server");
jButton1.setName("findServerBtn"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkUseProxyActionPerformed(evt);
findPublicServerActionPerformed(evt);
}
});
lblProxyServer.setLabelFor(txtServer);
cbProxyType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbProxyTypeActionPerformed(evt);
}
});
lblProxyType.setLabelFor(cbProxyType);
lblProxyType.setText("Proxy:");
pnlProxySettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
pnlProxySettings.setMinimumSize(new java.awt.Dimension(0, 0));
lblProxyServer.setLabelFor(txtProxyServer);
lblProxyServer.setText("Server:");
lblProxyPort.setLabelFor(txtPort);
lblProxyPort.setLabelFor(txtProxyPort);
lblProxyPort.setText("Port:");
txtProxyPort.addKeyListener(new java.awt.event.KeyAdapter() {
@ -184,22 +234,22 @@ public class ConnectDialog extends JDialog {
pnlProxyLayout.setHorizontalGroup(
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxyLayout.createSequentialGroup()
.addContainerGap()
.addContainerGap(28, Short.MAX_VALUE)
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblProxyPort)
.addComponent(lblProxyServer))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
.addGap(30, 30, 30))
.addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
.addContainerGap())
);
pnlProxyLayout.setVerticalGroup(
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxyLayout.createSequentialGroup()
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProxyServer)
.addComponent(txtProxyServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtProxyServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyServer))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProxyPort)
@ -207,15 +257,64 @@ public class ConnectDialog extends JDialog {
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jButton1.setText("Find...");
jButton1.setToolTipText("Find public server");
jButton1.setName("findServerBtn"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
lblProxyUserName.setLabelFor(txtProxyUserName);
lblProxyUserName.setText("User Name:");
lblProxyPassword.setText("Password:");
txtPasswordField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
txtPasswordFieldActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlProxyAuthLayout = new javax.swing.GroupLayout(pnlProxyAuth);
pnlProxyAuth.setLayout(pnlProxyAuthLayout);
pnlProxyAuthLayout.setHorizontalGroup(
pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProxyAuthLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblProxyPassword)
.addComponent(lblProxyUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txtPasswordField)
.addComponent(txtProxyUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE))
.addContainerGap())
);
pnlProxyAuthLayout.setVerticalGroup(
pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProxyAuthLayout.createSequentialGroup()
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtProxyUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyPassword))
.addContainerGap())
);
javax.swing.GroupLayout pnlProxySettingsLayout = new javax.swing.GroupLayout(pnlProxySettings);
pnlProxySettings.setLayout(pnlProxySettingsLayout);
pnlProxySettingsLayout.setHorizontalGroup(
pnlProxySettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlProxy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlProxyAuth, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pnlProxySettingsLayout.setVerticalGroup(
pnlProxySettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxySettingsLayout.createSequentialGroup()
.addComponent(pnlProxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlProxyAuth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
lblPassword.setLabelFor(txtPassword);
lblPassword.setText("Password:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@ -225,29 +324,38 @@ public class ConnectDialog extends JDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblPort)
.addComponent(lblServer)
.addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnConnect)
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131))
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblPort)
.addComponent(lblServer)
.addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131))
.addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addComponent(chkUseProxy, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))))
.addContainerGap())
.addComponent(pnlProxy, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jButton1))))
.addGroup(layout.createSequentialGroup()
.addComponent(lblProxyType)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE)
.addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnConnect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addComponent(pnlProxySettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(lblPassword)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -263,18 +371,25 @@ public class ConnectDialog extends JDialog {
.addComponent(lblPort))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblPassword))
.addGap(18, 18, 18)
.addComponent(chkAutoConnect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkUseProxy)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlProxy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlProxySettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnConnect))
.addComponent(btnConnect)
.addComponent(lblStatus))
.addContainerGap())
);
@ -283,13 +398,16 @@ public class ConnectDialog extends JDialog {
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
this.setVisible(false);
if (task != null && !task.isDone())
task.cancel(true);
else
this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
if (txtPassword.getText().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a password");
if (txtUserName.getText().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a user name");
return;
}
if (txtServer.getText().trim().isEmpty()) {
@ -302,31 +420,72 @@ public class ConnectDialog extends JDialog {
}
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", ""));
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
return;
}
char[] input = new char[0];
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
if (chkUseProxy.isSelected()) {
if (console.connect(txtPassword.getText(), txtServer.getText().trim(), Integer.valueOf(txtPort.getText()), txtProxyServer.getText().trim(), Integer.valueOf(txtProxyPort.getText()))) {
this.saveSettings();
this.setVisible(false);
}
}
else {
if (console.connect(txtPassword.getText(), txtServer.getText().trim(), Integer.valueOf(txtPort.getText()))) {
this.saveSettings();
this.setVisible(false);
}
}
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
connection = new Connection();
connection.setHost(this.txtServer.getText());
connection.setPort(Integer.valueOf(this.txtPort.getText()));
connection.setUsername(this.txtUserName.getText());
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
connection.setProxyHost(this.txtProxyServer.getText());
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
connection.setProxyUsername(this.txtProxyUserName.getText());
input = txtPasswordField.getPassword();
connection.setProxyPassword(new String(input));
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
task = new ConnectTask();
task.execute();
}
finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
Arrays.fill(input, '0');
}
}//GEN-LAST:event_btnConnectActionPerformed
private class ConnectTask extends SwingWorker<Boolean, Void> {
private boolean result = false;
@Override
protected Boolean doInBackground() throws Exception {
lblStatus.setText("Connecting...");
btnConnect.setEnabled(false);
result = console.connect(connection);
return result;
}
@Override
protected void done() {
try {
get();
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
btnConnect.setEnabled(true);
if (result) {
lblStatus.setText("");
connected();
}
else {
lblStatus.setText("Could not connect");
}
} catch (InterruptedException ex) {
logger.fatal("Update Players Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Players Task error", ex);
} catch (CancellationException ex) {}
}
}
private void connected() {
this.saveSettings();
this.setVisible(false);
}
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
char c = evt.getKeyChar();
if (!Character.isDigit(c))
@ -342,23 +501,19 @@ public class ConnectDialog extends JDialog {
// TODO add your handling code here:
}//GEN-LAST:event_txtProxyPortkeyTyped
private void chkUseProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkUseProxyActionPerformed
this.showProxySettings();
}//GEN-LAST:event_chkUseProxyActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
private void findPublicServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
BufferedReader in = null;
try {
URL serverListURL = new URL("http://mage.googlecode.com/files/server-list.txt");
in = new BufferedReader(new InputStreamReader(serverListURL.openStream()));
List<String> servers = new ArrayList<String>();
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Found server: "+inputLine);
servers.add(inputLine);
}
if (servers.size() == 0) {
JOptionPane.showMessageDialog(null, "Couldn't find any server.");
return;
@ -384,27 +539,44 @@ public class ConnectDialog extends JDialog {
} finally {
if (in != null) try { in.close(); } catch (Exception e) {}
}
}//GEN-LAST:event_jButton1ActionPerformed
}//GEN-LAST:event_jButton1ActionPerformed
private void cbProxyTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProxyTypeActionPerformed
this.showProxySettings();
}//GEN-LAST:event_cbProxyTypeActionPerformed
private void txtPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtPasswordFieldActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnConnect;
private javax.swing.JComboBox cbProxyType;
private javax.swing.JCheckBox chkAutoConnect;
private javax.swing.JCheckBox chkUseProxy;
private javax.swing.JButton jButton1;
private javax.swing.JLabel lblPassword;
private javax.swing.JLabel lblPort;
private javax.swing.JLabel lblProxyPassword;
private javax.swing.JLabel lblProxyPort;
private javax.swing.JLabel lblProxyServer;
private javax.swing.JLabel lblProxyType;
private javax.swing.JLabel lblProxyUserName;
private javax.swing.JLabel lblServer;
private javax.swing.JLabel lblStatus;
private javax.swing.JLabel lblUserName;
private javax.swing.JPanel pnlProxy;
private javax.swing.JTextField txtPassword;
private javax.swing.JPanel pnlProxyAuth;
private javax.swing.JPanel pnlProxySettings;
private javax.swing.JPasswordField txtPassword;
private javax.swing.JPasswordField txtPasswordField;
private javax.swing.JTextField txtPort;
private javax.swing.JTextField txtProxyPort;
private javax.swing.JTextField txtProxyServer;
private javax.swing.JTextField txtProxyUserName;
private javax.swing.JTextField txtServer;
private javax.swing.JTextField txtUserName;
// End of variables declaration//GEN-END:variables
}

View file

@ -34,11 +34,16 @@
package mage.server.console;
import java.util.UUID;
import java.util.prefs.Preferences;
import javax.swing.Box;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import mage.server.console.remote.Session;
import mage.interfaces.MageClient;
import mage.interfaces.callback.ClientCallback;
import mage.remote.Connection;
import mage.remote.Session;
import mage.utils.MageVersion;
import org.apache.log4j.Logger;
@ -46,7 +51,7 @@ import org.apache.log4j.Logger;
*
* @author BetaSteward_at_googlemail.com
*/
public class ConsoleFrame extends javax.swing.JFrame {
public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
private final static Logger logger = Logger.getLogger(ConsoleFrame.class);
@ -66,7 +71,8 @@ public class ConsoleFrame extends javax.swing.JFrame {
return prefs;
}
public static MageVersion getVersion() {
@Override
public MageVersion getVersion() {
return version;
}
@ -82,16 +88,9 @@ public class ConsoleFrame extends javax.swing.JFrame {
}
}
public boolean connect(String password, String serverName, int port) {
if (session.connect(password, serverName, port)) {
this.consolePanel1.start();
return true;
}
return false;
}
public boolean connect(String password, String serverName, int port, String proxyServer, int proxyPort) {
if (session.connect(password, serverName, port, proxyServer, proxyPort)) {
public boolean connect(Connection connection) {
if (session.connect(connection)) {
this.consolePanel1.start();
return true;
}
@ -168,7 +167,7 @@ public class ConsoleFrame extends javax.swing.JFrame {
if (session.isConnected()) {
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
this.consolePanel1.stop();
session.disconnect();
session.disconnect(false);
}
} else {
connectDialog.showDialog(this);
@ -185,6 +184,10 @@ public class ConsoleFrame extends javax.swing.JFrame {
}
});
}
private ConsoleFrame getFrame() {
return this;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnConnect;
@ -193,4 +196,77 @@ public class ConsoleFrame extends javax.swing.JFrame {
private javax.swing.JLabel lblStatus;
// End of variables declaration//GEN-END:variables
@Override
public UUID getId() {
return null;
}
@Override
public void connected(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
setStatusText(message);
enableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setStatusText(message);
enableButtons();
}
});
}
}
@Override
public void disconnected() {
if (SwingUtilities.isEventDispatchThread()) {
setStatusText("Not connected");
disableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setStatusText("Not connected");
disableButtons();
}
});
}
}
@Override
public void showMessage(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(getFrame(), message);
}
});
}
}
@Override
public void showError(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE);
}
});
}
}
@Override
public void processCallback(ClientCallback callback) {
}
}

View file

@ -38,7 +38,7 @@ import java.util.List;
import java.util.UUID;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import mage.server.console.remote.Session;
import mage.remote.Session;
import mage.view.TableView;
import mage.view.UserView;
@ -239,7 +239,7 @@ public class ConsolePanel extends javax.swing.JPanel {
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
int row = this.tblUsers.getSelectedRow();
ConsoleFrame.getSession().disconnectUser((UUID)tableUserModel.getValueAt(row, 3));
ConsoleFrame.getSession().disconnectUser((String)tableUserModel.getValueAt(row, 3));
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed

View file

@ -1,732 +0,0 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.console.remote;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import javax.swing.JOptionPane;
import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
import mage.MageException;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.interfaces.Server;
import mage.interfaces.ServerState;
import mage.server.console.ConsoleFrame;
import mage.view.DraftPickView;
import mage.view.GameTypeView;
import mage.view.TableView;
import mage.view.TournamentTypeView;
import mage.view.TournamentView;
import mage.view.UserView;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Session {
private final static Logger logger = Logger.getLogger(Session.class);
private static ScheduledExecutorService sessionExecutor = Executors.newScheduledThreadPool(1);
private UUID sessionId;
private Server server;
private ConsoleFrame frame;
private ServerState serverState;
private ScheduledFuture<?> future;
public Session(ConsoleFrame frame) {
this.frame = frame;
}
public synchronized boolean connect(String password, String serverName, int port) {
return connect(password, serverName, port, "", 0);
}
public synchronized boolean connect(String password, String serverName, int port, String proxyServer, int proxyPort) {
if (isConnected()) {
disconnect();
}
try {
System.setSecurityManager(null);
if (proxyServer.length() > 0) {
System.setProperty("socksProxyHost", proxyServer);
System.setProperty("socksProxyPort", Integer.toString(proxyPort));
}
else {
System.clearProperty("socksProxyHost");
System.clearProperty("socksProxyPort");
}
Registry reg = LocateRegistry.getRegistry(serverName, port);
this.server = (Server) reg.lookup("mage-server");
sessionId = server.registerAdmin(password, frame.getVersion());
serverState = server.getServerState();
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
logger.info("Connected to RMI server at " + serverName + ":" + port);
frame.setStatusText("Connected to " + serverName + ":" + port + " ");
frame.enableButtons();
return true;
} catch (RemoteException ex) {
logger.fatal("Unable to connect to server - ", ex);
disconnect();
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
} catch (NotBoundException ex) {
logger.fatal("Unable to connect to server - ", ex);
} catch (Exception ex) {
logger.fatal("Unable to connect to server - ", ex);
}
return false;
}
public synchronized void disconnect() {
if (isConnected()) {
try {
server.deregisterClient(sessionId);
} catch (RemoteException ex) {
logger.fatal("Error disconnecting ...", ex);
} catch (MageException ex) {
logger.fatal("Error disconnecting ...", ex);
}
removeServer();
}
}
public void removeServer() {
if (future != null && !future.isDone())
future.cancel(true);
server = null;
frame.setStatusText("Not connected");
frame.disableButtons();
logger.info("Disconnected ... ");
JOptionPane.showMessageDialog(frame, "Disconnected.", "Disconnected", JOptionPane.INFORMATION_MESSAGE);
}
// public void ack(int messageId) {
// try {
// server.ack(messageId, sessionId);
// } catch (RemoteException ex) {
// handleRemoteException(ex);
// } catch (MageException ex) {
// handleMageException(ex);
// }
// }
public boolean ping() {
try {
return server.ping(sessionId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean isConnected() {
return server != null;
}
public String[] getPlayerTypes() {
return serverState.getPlayerTypes();
}
public List<GameTypeView> getGameTypes() {
return serverState.getGameTypes();
}
public String[] getDeckTypes() {
return serverState.getDeckTypes();
}
public List<TournamentTypeView> getTournamentTypes() {
return serverState.getTournamentTypes();
}
public boolean isTestMode() {
if (serverState != null)
return serverState.isTestMode();
return false;
}
public UUID getMainRoomId() {
try {
return server.getMainRoomId();
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public UUID getRoomChatId(UUID roomId) {
try {
return server.getRoomChatId(roomId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public UUID getTableChatId(UUID tableId) {
try {
return server.getTableChatId(tableId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public UUID getGameChatId(UUID gameId) {
try {
return server.getGameChatId(gameId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public TableView getTable(UUID roomId, UUID tableId) {
try {
return server.getTable(roomId, tableId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean watchTable(UUID roomId, UUID tableId) {
try {
server.watchTable(sessionId, roomId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) {
try {
return server.joinTable(sessionId, roomId, tableId, playerName, playerType, skill, deckList);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (GameException ex) {
handleGameException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill) {
try {
return server.joinTournamentTable(sessionId, roomId, tableId, playerName, playerType, skill);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (GameException ex) {
handleGameException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public Collection<TableView> getTables(UUID roomId) throws Exception {
try {
return server.getTables(roomId);
} catch (RemoteException ex) {
handleRemoteException(ex);
throw new Exception();
} catch (MageException ex) {
handleMageException(ex);
throw new Exception();
}
}
public TournamentView getTournament(UUID tournamentId) throws Exception {
try {
return server.getTournament(tournamentId);
} catch (RemoteException ex) {
handleRemoteException(ex);
throw new Exception();
} catch (MageException ex) {
handleMageException(ex);
throw new Exception();
}
}
public UUID getTournamentChatId(UUID tournamentId) {
try {
return server.getTournamentChatId(tournamentId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean sendPlayerUUID(UUID gameId, UUID data) {
try {
server.sendPlayerUUID(gameId, sessionId, data);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean sendPlayerBoolean(UUID gameId, boolean data) {
try {
server.sendPlayerBoolean(gameId, sessionId, data);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean sendPlayerInteger(UUID gameId, int data) {
try {
server.sendPlayerInteger(gameId, sessionId, data);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean sendPlayerString(UUID gameId, String data) {
try {
server.sendPlayerString(gameId, sessionId, data);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public DraftPickView sendCardPick(UUID draftId, UUID cardId) {
try {
return server.sendCardPick(draftId, sessionId, cardId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean leaveChat(UUID chatId) {
try {
server.leaveChat(chatId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean sendChatMessage(UUID chatId, String message) {
try {
server.sendChatMessage(chatId, "", message);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean joinGame(UUID gameId) {
try {
server.joinGame(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean joinDraft(UUID draftId) {
try {
server.joinDraft(draftId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean joinTournament(UUID tournamentId) {
try {
server.joinTournament(tournamentId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean watchGame(UUID gameId) {
try {
server.watchGame(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean replayGame(UUID gameId) {
try {
server.replayGame(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public TableView createTable(UUID roomId, MatchOptions matchOptions) {
try {
return server.createTable(sessionId, roomId, matchOptions);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
try {
return server.createTournamentTable(sessionId, roomId, tournamentOptions);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean isTableOwner(UUID roomId, UUID tableId) {
try {
return server.isTableOwner(sessionId, roomId, tableId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean removeTable(UUID tableId) {
try {
server.removeTable(sessionId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean swapSeats(UUID roomId, UUID tableId, int seatNum1, int seatNum2) {
try {
server.swapSeats(sessionId, roomId, tableId, seatNum1, seatNum2);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean leaveTable(UUID roomId, UUID tableId) {
try {
server.leaveTable(sessionId, roomId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean startGame(UUID roomId, UUID tableId) {
try {
server.startMatch(sessionId, roomId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean startTournament(UUID roomId, UUID tableId) {
try {
server.startTournament(sessionId, roomId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) {
try {
server.startChallenge(sessionId, roomId, tableId, challengeId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean submitDeck(UUID tableId, DeckCardLists deck) {
try {
return server.submitDeck(sessionId, tableId, deck);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (GameException ex) {
handleGameException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean concedeGame(UUID gameId) {
try {
server.concedeGame(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean stopWatching(UUID gameId) {
try {
server.stopWatching(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean startReplay(UUID gameId) {
try {
server.startReplay(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean stopReplay(UUID gameId) {
try {
server.stopReplay(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean nextPlay(UUID gameId) {
try {
server.nextPlay(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean previousPlay(UUID gameId) {
try {
server.previousPlay(gameId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean cheat(UUID gameId, UUID playerId, DeckCardLists deckList) {
try {
server.cheat(gameId, sessionId, playerId, deckList);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public List<UserView> getUsers() {
try {
return server.getUsers(sessionId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean disconnectUser(UUID userSessionId) {
try {
server.disconnectUser(sessionId, userSessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
private void handleRemoteException(RemoteException ex) {
logger.fatal("Communication error", ex);
if (ex instanceof java.rmi.ConnectException) {
server = null;
frame.setStatusText("Not connected");
frame.disableButtons();
JOptionPane.showMessageDialog(frame, "Communication error - disconnecting.", "Error", JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(frame, "Communication error.", "Error", JOptionPane.ERROR_MESSAGE);
}
private void handleMageException(MageException ex) {
logger.fatal("Server error", ex);
JOptionPane.showMessageDialog(frame, "Critical server error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
disconnect();
frame.disableButtons();
}
private void handleGameException(GameException ex) {
logger.fatal("Game error", ex);
JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
public Server getServerRef() {
return server;
}
class ServerPinger implements Runnable {
private int missed = 0;
@Override
public void run() {
if (!ping()) {
missed++;
if (missed > 10) {
logger.info("Connection to server timed out");
removeServer();
}
}
else {
missed = 0;
}
}
}
}