forked from External/mage
retrying without jars
This commit is contained in:
parent
a4c3deb7ac
commit
0e66c5e030
23 changed files with 2646 additions and 57 deletions
|
|
@ -0,0 +1,410 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ConnectDialog.java
|
||||
*
|
||||
* Created on 20-Jan-2010, 9:37:07 PM
|
||||
*/
|
||||
|
||||
package mage.server.console;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ConnectDialog extends JDialog {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(ConnectDialog.class);
|
||||
|
||||
private ConsoleFrame console;
|
||||
|
||||
/** Creates new form ConnectDialog */
|
||||
public ConnectDialog() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void showDialog(ConsoleFrame console) {
|
||||
this.console = console;
|
||||
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", ""));
|
||||
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", ""));
|
||||
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.showProxySettings();
|
||||
this.setModal(true);
|
||||
this.setLocation(50, 50);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
private void showProxySettings() {
|
||||
if (chkUseProxy.isSelected()) {
|
||||
this.pnlProxy.setVisible(true);
|
||||
}
|
||||
else {
|
||||
this.pnlProxy.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("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()));
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
|
||||
txtServer = new javax.swing.JTextField();
|
||||
lblServer = new javax.swing.JLabel();
|
||||
lblPort = new javax.swing.JLabel();
|
||||
txtPort = new javax.swing.JTextField();
|
||||
txtPassword = 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();
|
||||
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();
|
||||
|
||||
setTitle("Connect");
|
||||
|
||||
lblServer.setLabelFor(txtServer);
|
||||
lblServer.setText("Server:");
|
||||
|
||||
lblPort.setLabelFor(txtPort);
|
||||
lblPort.setText("Port:");
|
||||
|
||||
txtPort.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyTyped(java.awt.event.KeyEvent evt) {
|
||||
ConnectDialog.this.keyTyped(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblUserName.setLabelFor(txtPassword);
|
||||
lblUserName.setText("Password:");
|
||||
|
||||
btnConnect.setText("Connect");
|
||||
btnConnect.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnConnectActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnCancelActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
chkAutoConnect.setText("Automatically connect to this server next time");
|
||||
chkAutoConnect.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
chkAutoConnectActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
chkUseProxy.setText("Use Proxy");
|
||||
chkUseProxy.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
chkUseProxyActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblProxyServer.setLabelFor(txtServer);
|
||||
lblProxyServer.setText("Server:");
|
||||
|
||||
lblProxyPort.setLabelFor(txtPort);
|
||||
lblProxyPort.setText("Port:");
|
||||
|
||||
txtProxyPort.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyTyped(java.awt.event.KeyEvent evt) {
|
||||
txtProxyPortkeyTyped(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout pnlProxyLayout = new javax.swing.GroupLayout(pnlProxy);
|
||||
pnlProxy.setLayout(pnlProxyLayout);
|
||||
pnlProxyLayout.setHorizontalGroup(
|
||||
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(pnlProxyLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.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))
|
||||
);
|
||||
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))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblProxyPort)
|
||||
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.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() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnConnect)
|
||||
.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)))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.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)
|
||||
.addComponent(jButton1))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.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(lblUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(chkAutoConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(chkUseProxy)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pnlProxy, 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))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
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");
|
||||
return;
|
||||
}
|
||||
if (txtServer.getText().trim().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a server address");
|
||||
return;
|
||||
}
|
||||
if (txtPort.getText().trim().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a port number");
|
||||
return;
|
||||
}
|
||||
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
|
||||
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", ""));
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_btnConnectActionPerformed
|
||||
|
||||
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
|
||||
char c = evt.getKeyChar();
|
||||
if (!Character.isDigit(c))
|
||||
evt.consume();
|
||||
}//GEN-LAST:event_keyTyped
|
||||
|
||||
private void chkAutoConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAutoConnectActionPerformed
|
||||
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_chkAutoConnectActionPerformed
|
||||
|
||||
private void txtProxyPortkeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProxyPortkeyTyped
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
|
||||
String selectedServer = (String) JOptionPane.showInputDialog(null,
|
||||
"Choose MAGE Public Server:", "Input",
|
||||
JOptionPane.INFORMATION_MESSAGE, null, servers.toArray(),
|
||||
servers.get(0));
|
||||
if (selectedServer != null) {
|
||||
String[] params = selectedServer.split(":");
|
||||
if (params.length == 3) {
|
||||
this.txtServer.setText(params[1]);
|
||||
this.txtPort.setText(params[2]);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Wrong server data format.");
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
} catch(Exception ex) {
|
||||
logger.error(ex,ex);
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (Exception e) {}
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnConnect;
|
||||
private javax.swing.JCheckBox chkAutoConnect;
|
||||
private javax.swing.JCheckBox chkUseProxy;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JLabel lblPort;
|
||||
private javax.swing.JLabel lblProxyPort;
|
||||
private javax.swing.JLabel lblProxyServer;
|
||||
private javax.swing.JLabel lblServer;
|
||||
private javax.swing.JLabel lblUserName;
|
||||
private javax.swing.JPanel pnlProxy;
|
||||
private javax.swing.JTextField txtPassword;
|
||||
private javax.swing.JTextField txtPort;
|
||||
private javax.swing.JTextField txtProxyPort;
|
||||
private javax.swing.JTextField txtProxyServer;
|
||||
private javax.swing.JTextField txtServer;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue