Finished connection tab.

This commit is contained in:
magenoxx 2011-09-03 01:25:39 +04:00
parent e642a6aff6
commit 24e35b4a38
3 changed files with 74 additions and 42 deletions

View file

@ -37,6 +37,8 @@ package mage.client.dialog;
import java.awt.Cursor;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@ -267,18 +269,11 @@ public class ConnectDialog extends MageDialog {
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
connection.setUsername(this.txtUserName.getText().trim());
String proxyType = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None");
ProxyType configProxyType = null;
for (ProxyType pt : Connection.ProxyType.values()) {
if (pt.toString().equals(proxyType)) {
configProxyType = pt;
break;
}
}
ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
if (configProxyType != null) {
connection.setProxyType(configProxyType);
if (!proxyType.equals("None")) {
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()) {
@ -361,7 +356,34 @@ public class ConnectDialog extends MageDialog {
BufferedReader in = null;
try {
URL serverListURL = new URL("http://mage.googlecode.com/files/server-list.txt");
in = new BufferedReader(new InputStreamReader(serverListURL.openStream()));
Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
Proxy p = null;
Proxy.Type type = Proxy.Type.DIRECT;
switch (configProxyType) {
case HTTP: type = Proxy.Type.HTTP; break;
case SOCKS: type = Proxy.Type.SOCKS; break;
case NONE:
default: p = Proxy.NO_PROXY; break;
}
if (!p.equals(Proxy.NO_PROXY)) {
try {
String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
p = new Proxy(type, new InetSocketAddress(address, port));
} catch (Exception ex) {
throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex);
}
}
if (p == null) {
JOptionPane.showMessageDialog(null, "Couldn't configure Proxy object!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
in = new BufferedReader(new InputStreamReader(serverListURL.openConnection(p).getInputStream()));
List<String> servers = new ArrayList<String>();
String inputLine;

View file

@ -644,33 +644,25 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true", "false", UPDATE_CACHE_POLICY);
// connection
//MageFrame.getPreferences().put("proxyAddress", txtProxyServer.getText().trim());
//MageFrame.getPreferences().put("proxyPort", txtProxyPort.getText().trim());
//MageFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
//MageFrame.getPreferences().put("proxyUsername", txtProxyUserName.getText().trim());
//char[] input = txtPasswordField.getPassword();
//MageFrame.getPreferences().put("proxyPassword", new String(input));
//Arrays.fill(input, '0');
//TODO: !!!!!!!!!!!!!
// connection
/*dialog.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(MageFrame.getPreferences().get(KEY_PROXY_TYPE, "NONE").toUpperCase()));
load(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS, Config.serverName);
load(prefs, dialog.txtProxyPort, KEY_PROXY_PORT, Integer.toString(Config.port));
load(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME, "");
load(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false");
save(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS);
save(prefs, dialog.txtProxyPort, KEY_PROXY_PORT);
save(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME);
save(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false", UPDATE_CACHE_POLICY);
if (dialog.rememberPswd.isSelected()) {
load(prefs, dialog.txtPasswordField, KEY_PROXY_PSWD, "");
}*/
char[] input = txtPasswordField.getPassword();
prefs.put(KEY_PROXY_PSWD, new String(input));
}
// images
saveImagesPath(prefs);
try {
prefs.flush();
} catch (BackingStoreException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Error: couldn't save phase stops. Please try again.");
}
dialog.setVisible(false);
}//GEN-LAST:event_saveButtonActionPerformed
@ -679,11 +671,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
}//GEN-LAST:event_exitButtonActionPerformed
private void showToolTipsInHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showToolTipsInHandActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_showToolTipsInHandActionPerformed
private void displayBigCardsInHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayBigCardsInHandActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_displayBigCardsInHandActionPerformed
private void useDefaultImageFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useDefaultImageFolderActionPerformed
@ -877,6 +867,11 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
}
private static void save(Preferences prefs, JTextField textField, String propName) {
prefs.put(propName, textField.getText().trim());
updateCache(propName, textField.getText().trim());
}
public void reset() {
jTabbedPane1.setSelectedIndex(0);
}

View file

@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.prefs.Preferences;
import javax.management.ImmutableDescriptor;
import javax.swing.AbstractButton;
@ -45,6 +46,9 @@ import javax.swing.event.ChangeListener;
import mage.cards.Card;
import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
import mage.remote.Connection;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.dl.sources.CardImageSource;
@ -57,7 +61,7 @@ import org.mage.plugins.card.utils.CardImageUtils;
public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable {
private int type;
private JTextField addr, port;
//private JTextField addr, port;
private JProgressBar bar;
private JOptionPane dlg;
private boolean cancel;
@ -121,15 +125,15 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
this.cards = cards;
this.imagesPath = imagesPath;
addr = new JTextField("Proxy Address");
port = new JTextField("Proxy Port");
//addr = new JTextField("Proxy Address");
//port = new JTextField("Proxy Port");
bar = new JProgressBar(this);
JPanel p0 = new JPanel();
p0.setLayout(new BoxLayout(p0, BoxLayout.Y_AXIS));
// Proxy Choice
ButtonGroup bg = new ButtonGroup();
/*ButtonGroup bg = new ButtonGroup();
String[] labels = { "No Proxy", "HTTP Proxy", "SOCKS Proxy" };
for (int i = 0; i < types.length; i++) {
JRadioButton rb = new JRadioButton(labels[i]);
@ -138,11 +142,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
p0.add(rb);
if (i == 0)
rb.setSelected(true);
}
}*/
// Proxy config
p0.add(addr);
p0.add(port);
//p0.add(addr);
//p0.add(port);
p0.add(Box.createVerticalStrut(5));
jLabel1 = new JLabel();
@ -384,11 +388,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
@Override
public void stateChanged(ChangeEvent e) {
if (((AbstractButton) e.getSource()).isSelected()) {
/*if (((AbstractButton) e.getSource()).isSelected()) {
DownloadPictures.this.type = type;
addr.setEnabled(type != 0);
port.setEnabled(type != 0);
}
}*/
}
}
@ -400,14 +404,25 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
base.mkdir();
}
if (type == 0)
p = Proxy.NO_PROXY;
else
Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
Proxy.Type type = Proxy.Type.DIRECT;
switch (configProxyType) {
case HTTP: type = Proxy.Type.HTTP; break;
case SOCKS: type = Proxy.Type.SOCKS; break;
case NONE:
default: p = Proxy.NO_PROXY; break;
}
if (!p.equals(Proxy.NO_PROXY)) {
try {
p = new Proxy(types[type], new InetSocketAddress(addr.getText(), Integer.parseInt(port.getText())));
String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
Integer port = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80"));
p = new Proxy(type, new InetSocketAddress(address, port));
} catch (Exception ex) {
throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex);
}
}
if (p != null) {
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();