1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-10 01:01:05 -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:
magenoxx 2011-12-09 15:15:48 +04:00
parent e076c0b6ee
commit 13c5177d54

View file

@ -34,7 +34,16 @@
package mage.client.dialog; 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.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -45,51 +54,53 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; 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 * @author BetaSteward_at_googlemail.com
*/ */
public class ConnectDialog extends MageDialog { public class ConnectDialog extends MageDialog {
private final static Logger logger = Logger.getLogger(ConnectDialog.class); private final static Logger logger = Logger.getLogger(ConnectDialog.class);
private Connection connection; private Connection connection;
private ConnectTask task; 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() { public ConnectDialog() {
initComponents(); initComponents();
this.txtUserName.addActionListener(connectAction);
this.txtServer.addActionListener(connectAction);
this.txtPort.addActionListener(connectAction);
} }
public void showDialog() { public void showDialog() {
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName)); this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port))); this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
this.txtUserName.setText(MageFrame.getPreferences().get("userName", "")); this.txtUserName.setText(MageFrame.getPreferences().get("userName", ""));
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get("autoConnect", "false"))); this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get("autoConnect", "false")));
this.setModal(true); this.setModal(true);
this.setLocation(50, 50); this.setLocation(50, 50);
this.setVisible(true); this.setVisible(true);
} }
private void saveSettings() { private void saveSettings() {
MageFrame.getPreferences().put("serverAddress", txtServer.getText().trim()); MageFrame.getPreferences().put("serverAddress", txtServer.getText().trim());
MageFrame.getPreferences().put("serverPort", txtPort.getText().trim()); MageFrame.getPreferences().put("serverPort", txtPort.getText().trim());
MageFrame.getPreferences().put("userName", txtUserName.getText().trim()); MageFrame.getPreferences().put("userName", txtUserName.getText().trim());
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected())); 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. * initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor. * always regenerated by the Form Editor.
@ -169,266 +180,273 @@ public class ConnectDialog extends MageDialog {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblPort) .addComponent(lblPort)
.addComponent(lblServer) .addComponent(lblServer)
.addComponent(lblUserName)) .addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131)) .addGap(131, 131, 131))
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE) .addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE) .addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE) .addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)) .addComponent(jButton1))
.addComponent(jProxySettingsButton))) .addComponent(jProxySettingsButton)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnConnect) .addComponent(btnConnect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)) .addComponent(btnCancel))
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblServer) .addComponent(lblServer)
.addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)) .addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .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(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblPort)) .addComponent(lblPort))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtUserName, 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)) .addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkAutoConnect) .addComponent(chkAutoConnect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jProxySettingsButton) .addComponent(jProxySettingsButton)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel) .addComponent(btnCancel)
.addComponent(btnConnect)) .addComponent(btnConnect))
.addContainerGap()) .addContainerGap())
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8) .addGap(8, 8, 8)
.addComponent(lblStatus) .addComponent(lblStatus)
.addContainerGap()))) .addContainerGap())))
); );
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected())); MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
if (task != null && !task.isDone()) if (task != null && !task.isDone())
task.cancel(true); task.cancel(true);
else else
this.hideDialog(); this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed }//GEN-LAST:event_btnCancelActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
if (txtUserName.getText().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a user name");
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(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
return;
}
char[] input = new char[0]; if (txtUserName.getText().isEmpty()) {
try { JOptionPane.showMessageDialog(rootPane, "Please provide a user name");
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); return;
connection = new Connection(); }
connection.setHost(this.txtServer.getText().trim()); if (txtServer.getText().trim().isEmpty()) {
connection.setPort(Integer.valueOf(this.txtPort.getText().trim())); JOptionPane.showMessageDialog(rootPane, "Please provide a server address");
connection.setUsername(this.txtUserName.getText().trim()); 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(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
return;
}
ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None")); char[] input = new char[0];
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
connection = new Connection();
connection.setHost(this.txtServer.getText().trim());
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
connection.setUsername(this.txtUserName.getText().trim());
if (configProxyType != null) { ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
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);
}
}
}
// Avatar if (configProxyType != null) {
int avatarId = PreferencesDialog.getSelectedAvatar(); connection.setProxyType(configProxyType);
connection.setAvatarId(avatarId); 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);
}
}
}
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort()); // Avatar
task = new ConnectTask(); int avatarId = PreferencesDialog.getSelectedAvatar();
task.execute(); connection.setAvatarId(avatarId);
}
finally {
Arrays.fill(input, '0');
}
}//GEN-LAST:event_btnConnectActionPerformed logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
task = new ConnectTask();
task.execute();
} finally {
Arrays.fill(input, '0');
}
private class ConnectTask extends SwingWorker<Boolean, Void> { }//GEN-LAST:event_btnConnectActionPerformed
private boolean result = false; private class ConnectTask extends SwingWorker<Boolean, Void> {
@Override private boolean result = false;
protected Boolean doInBackground() throws Exception {
lblStatus.setText("Connecting...");
btnConnect.setEnabled(false);
result = MageFrame.connect(connection);
return result;
}
@Override @Override
protected void done() { protected Boolean doInBackground() throws Exception {
try { lblStatus.setText("Connecting...");
get(); btnConnect.setEnabled(false);
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); result = MageFrame.connect(connection);
if (result) { return 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) {
logger.info("Connect was canceled");
lblStatus.setText("Connect was canceled");
MageFrame.stopConnecting();
} finally {
btnConnect.setEnabled(true);
}
}
}
private void connected() { @Override
this.saveSettings(); protected void done() {
this.hideDialog(); try {
} get();
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
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) {
logger.info("Connect was canceled");
lblStatus.setText("Connect was canceled");
MageFrame.stopConnecting();
} finally {
btnConnect.setEnabled(true);
}
}
}
private void connected() {
this.saveSettings();
this.hideDialog();
}
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
char c = evt.getKeyChar(); char c = evt.getKeyChar();
if (!Character.isDigit(c)) if (!Character.isDigit(c))
evt.consume(); evt.consume();
}//GEN-LAST:event_keyTyped }//GEN-LAST:event_keyTyped
private void chkAutoConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAutoConnectActionPerformed private void chkAutoConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAutoConnectActionPerformed
// TODO add your handling code here: // TODO add your handling code here:
}//GEN-LAST:event_chkAutoConnectActionPerformed }//GEN-LAST:event_chkAutoConnectActionPerformed
private void findPublicServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed private void findPublicServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
BufferedReader in = null; BufferedReader in = null;
try { try {
URL serverListURL = new URL("http://mage.googlecode.com/files/server-list.txt"); URL serverListURL = new URL("http://mage.googlecode.com/files/server-list.txt");
Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None")); Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
Proxy p = null; Proxy p = null;
Proxy.Type type = Proxy.Type.DIRECT; Proxy.Type type = Proxy.Type.DIRECT;
switch (configProxyType) { switch (configProxyType) {
case HTTP: type = Proxy.Type.HTTP; break; case HTTP:
case SOCKS: type = Proxy.Type.SOCKS; break; type = Proxy.Type.HTTP;
case NONE: break;
default: p = Proxy.NO_PROXY; break; case SOCKS:
} type = Proxy.Type.SOCKS;
break;
case NONE:
default:
p = Proxy.NO_PROXY;
break;
}
if (p == null || !p.equals(Proxy.NO_PROXY)) { if (p == null || !p.equals(Proxy.NO_PROXY)) {
try { try {
String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, ""); String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80")); Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
p = new Proxy(type, new InetSocketAddress(address, port)); p = new Proxy(type, new InetSocketAddress(address, port));
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex); throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex);
} }
} }
if (p == null) { if (p == null) {
JOptionPane.showMessageDialog(null, "Couldn't configure Proxy object!", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "Couldn't configure Proxy object!", "Error", JOptionPane.ERROR_MESSAGE);
return; return;
} }
in = new BufferedReader(new InputStreamReader(serverListURL.openConnection(p).getInputStream())); in = new BufferedReader(new InputStreamReader(serverListURL.openConnection(p).getInputStream()));
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, List<String> servers = new ArrayList<String>();
"Choose MAGE Public Server:", "Input", String inputLine;
JOptionPane.INFORMATION_MESSAGE, null, servers.toArray(), while ((inputLine = in.readLine()) != null) {
servers.get(0)); System.out.println("Found server: " + inputLine);
if (selectedServer != null) { servers.add(inputLine);
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(); if (servers.size() == 0) {
} catch(Exception ex) { JOptionPane.showMessageDialog(null, "Couldn't find any server.");
logger.error(ex,ex); return;
} finally { }
if (in != null) try { in.close(); } catch (Exception e) {}
} 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 }//GEN-LAST:event_jButton1ActionPerformed
private void jProxySettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jProxySettingsButtonActionPerformed private void jProxySettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jProxySettingsButtonActionPerformed
PreferencesDialog.main(new String[]{PreferencesDialog.OPEN_CONNECTION_TAB}); PreferencesDialog.main(new String[]{PreferencesDialog.OPEN_CONNECTION_TAB});
}//GEN-LAST:event_jProxySettingsButtonActionPerformed }//GEN-LAST:event_jProxySettingsButtonActionPerformed