mirror of
https://github.com/correl/mage.git
synced 2025-04-10 17:00:08 -09:00
Finished connection tab.
This commit is contained in:
parent
e642a6aff6
commit
24e35b4a38
3 changed files with 74 additions and 42 deletions
Mage.Client/src/main/java
mage/client/dialog
org/mage/plugins/card/images
|
@ -37,6 +37,8 @@ package mage.client.dialog;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -267,18 +269,11 @@ public class ConnectDialog extends MageDialog {
|
||||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||||
connection.setUsername(this.txtUserName.getText().trim());
|
connection.setUsername(this.txtUserName.getText().trim());
|
||||||
|
|
||||||
String proxyType = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None");
|
ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
|
||||||
ProxyType configProxyType = null;
|
|
||||||
for (ProxyType pt : Connection.ProxyType.values()) {
|
|
||||||
if (pt.toString().equals(proxyType)) {
|
|
||||||
configProxyType = pt;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configProxyType != null) {
|
if (configProxyType != null) {
|
||||||
connection.setProxyType(configProxyType);
|
connection.setProxyType(configProxyType);
|
||||||
if (!proxyType.equals("None")) {
|
if (!configProxyType.equals(ProxyType.NONE)) {
|
||||||
String host = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
|
String host = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, "");
|
||||||
String port = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "");
|
String port = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "");
|
||||||
if (!host.isEmpty() && !port.isEmpty()) {
|
if (!host.isEmpty() && !port.isEmpty()) {
|
||||||
|
@ -361,7 +356,34 @@ public class ConnectDialog extends MageDialog {
|
||||||
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");
|
||||||
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>();
|
List<String> servers = new ArrayList<String>();
|
||||||
String inputLine;
|
String inputLine;
|
||||||
|
|
|
@ -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);
|
save(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true", "false", UPDATE_CACHE_POLICY);
|
||||||
|
|
||||||
// connection
|
// connection
|
||||||
//MageFrame.getPreferences().put("proxyAddress", txtProxyServer.getText().trim());
|
save(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS);
|
||||||
//MageFrame.getPreferences().put("proxyPort", txtProxyPort.getText().trim());
|
save(prefs, dialog.txtProxyPort, KEY_PROXY_PORT);
|
||||||
//MageFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
|
save(prefs, dialog.txtProxyUserName, KEY_PROXY_USERNAME);
|
||||||
//MageFrame.getPreferences().put("proxyUsername", txtProxyUserName.getText().trim());
|
save(prefs, dialog.rememberPswd, KEY_PROXY_REMEMBER, "true", "false", UPDATE_CACHE_POLICY);
|
||||||
//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");
|
|
||||||
if (dialog.rememberPswd.isSelected()) {
|
if (dialog.rememberPswd.isSelected()) {
|
||||||
load(prefs, dialog.txtPasswordField, KEY_PROXY_PSWD, "");
|
char[] input = txtPasswordField.getPassword();
|
||||||
}*/
|
prefs.put(KEY_PROXY_PSWD, new String(input));
|
||||||
|
}
|
||||||
|
|
||||||
// images
|
// images
|
||||||
saveImagesPath(prefs);
|
saveImagesPath(prefs);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prefs.flush();
|
prefs.flush();
|
||||||
} catch (BackingStoreException ex) {
|
} catch (BackingStoreException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
JOptionPane.showMessageDialog(null, "Error: couldn't save phase stops. Please try again.");
|
JOptionPane.showMessageDialog(null, "Error: couldn't save phase stops. Please try again.");
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.setVisible(false);
|
dialog.setVisible(false);
|
||||||
}//GEN-LAST:event_saveButtonActionPerformed
|
}//GEN-LAST:event_saveButtonActionPerformed
|
||||||
|
|
||||||
|
@ -679,11 +671,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
}//GEN-LAST:event_exitButtonActionPerformed
|
}//GEN-LAST:event_exitButtonActionPerformed
|
||||||
|
|
||||||
private void showToolTipsInHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showToolTipsInHandActionPerformed
|
private void showToolTipsInHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showToolTipsInHandActionPerformed
|
||||||
// TODO add your handling code here:
|
|
||||||
}//GEN-LAST:event_showToolTipsInHandActionPerformed
|
}//GEN-LAST:event_showToolTipsInHandActionPerformed
|
||||||
|
|
||||||
private void displayBigCardsInHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayBigCardsInHandActionPerformed
|
private void displayBigCardsInHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayBigCardsInHandActionPerformed
|
||||||
// TODO add your handling code here:
|
|
||||||
}//GEN-LAST:event_displayBigCardsInHandActionPerformed
|
}//GEN-LAST:event_displayBigCardsInHandActionPerformed
|
||||||
|
|
||||||
private void useDefaultImageFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useDefaultImageFolderActionPerformed
|
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() {
|
public void reset() {
|
||||||
jTabbedPane1.setSelectedIndex(0);
|
jTabbedPane1.setSelectedIndex(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
import javax.management.ImmutableDescriptor;
|
import javax.management.ImmutableDescriptor;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
|
@ -45,6 +46,9 @@ import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
|
||||||
|
import mage.client.MageFrame;
|
||||||
|
import mage.client.dialog.PreferencesDialog;
|
||||||
|
import mage.remote.Connection;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.mage.plugins.card.constants.Constants;
|
import org.mage.plugins.card.constants.Constants;
|
||||||
import org.mage.plugins.card.dl.sources.CardImageSource;
|
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 {
|
public class DownloadPictures extends DefaultBoundedRangeModel implements Runnable {
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
private JTextField addr, port;
|
//private JTextField addr, port;
|
||||||
private JProgressBar bar;
|
private JProgressBar bar;
|
||||||
private JOptionPane dlg;
|
private JOptionPane dlg;
|
||||||
private boolean cancel;
|
private boolean cancel;
|
||||||
|
@ -121,15 +125,15 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
this.cards = cards;
|
this.cards = cards;
|
||||||
this.imagesPath = imagesPath;
|
this.imagesPath = imagesPath;
|
||||||
|
|
||||||
addr = new JTextField("Proxy Address");
|
//addr = new JTextField("Proxy Address");
|
||||||
port = new JTextField("Proxy Port");
|
//port = new JTextField("Proxy Port");
|
||||||
bar = new JProgressBar(this);
|
bar = new JProgressBar(this);
|
||||||
|
|
||||||
JPanel p0 = new JPanel();
|
JPanel p0 = new JPanel();
|
||||||
p0.setLayout(new BoxLayout(p0, BoxLayout.Y_AXIS));
|
p0.setLayout(new BoxLayout(p0, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
// Proxy Choice
|
// Proxy Choice
|
||||||
ButtonGroup bg = new ButtonGroup();
|
/*ButtonGroup bg = new ButtonGroup();
|
||||||
String[] labels = { "No Proxy", "HTTP Proxy", "SOCKS Proxy" };
|
String[] labels = { "No Proxy", "HTTP Proxy", "SOCKS Proxy" };
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
JRadioButton rb = new JRadioButton(labels[i]);
|
JRadioButton rb = new JRadioButton(labels[i]);
|
||||||
|
@ -138,11 +142,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
p0.add(rb);
|
p0.add(rb);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
rb.setSelected(true);
|
rb.setSelected(true);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Proxy config
|
// Proxy config
|
||||||
p0.add(addr);
|
//p0.add(addr);
|
||||||
p0.add(port);
|
//p0.add(port);
|
||||||
|
|
||||||
p0.add(Box.createVerticalStrut(5));
|
p0.add(Box.createVerticalStrut(5));
|
||||||
jLabel1 = new JLabel();
|
jLabel1 = new JLabel();
|
||||||
|
@ -384,11 +388,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
if (((AbstractButton) e.getSource()).isSelected()) {
|
/*if (((AbstractButton) e.getSource()).isSelected()) {
|
||||||
DownloadPictures.this.type = type;
|
DownloadPictures.this.type = type;
|
||||||
addr.setEnabled(type != 0);
|
addr.setEnabled(type != 0);
|
||||||
port.setEnabled(type != 0);
|
port.setEnabled(type != 0);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,14 +404,25 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
base.mkdir();
|
base.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == 0)
|
Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
|
||||||
p = Proxy.NO_PROXY;
|
|
||||||
else
|
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 {
|
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) {
|
} 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) {
|
||||||
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
|
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
|
||||||
|
|
Loading…
Add table
Reference in a new issue