This commit is contained in:
huanghongxun
2015-08-16 17:29:09 +08:00
parent a77275cfc0
commit 9ae9b5b912
16 changed files with 92 additions and 75 deletions

View File

@@ -117,7 +117,13 @@ public class TaskList extends Thread {
for (DoingDoneListener<Task> d : t.getTaskListeners())
d.onDoing(t);
if (t.executeTask()) {
boolean returns = false;
try {
returns = t.executeTask();
} catch(Throwable e) {
t.setFailReason(e);
}
if (returns) {
HMCLog.log((t.isAborted() ? "Task aborted: " : "Task finished: ") + t.getInfo());
for (DoingDoneListener<Task> d : taskListener)
d.onDone(t);

View File

@@ -51,7 +51,7 @@ public class TaskWindow extends javax.swing.JDialog
initComponents();
setLocationRelativeTo(null);
if (lstDownload.getColumnModel().getColumnCount() > 1) {
int i = 35;
lstDownload.getColumnModel().getColumn(1).setMinWidth(i);
@@ -68,6 +68,8 @@ public class TaskWindow extends javax.swing.JDialog
}
public void clean() {
if (isVisible())
throw new RuntimeException("This error should not appear, please contact the author.");
taskList = null;
taskList = new TaskList();
taskList.addTaskListener(this);
@@ -170,7 +172,8 @@ public class TaskWindow extends javax.swing.JDialog
}
if (!suc) {
SwingUtilities.invokeLater(taskList::abort);
if (taskList != null)
SwingUtilities.invokeLater(taskList::abort);
HMCLog.log("Tasks have been canceled by user.");
}
}//GEN-LAST:event_formWindowClosed

View File

@@ -22,13 +22,7 @@ import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.tasks.Task;
@@ -43,37 +37,6 @@ import org.jackhuang.hellominecraft.utils.system.IOUtils;
// This class downloads a file from a URL.
public class FileDownloadTask extends Task implements PreviousResult<File>, PreviousResultRegistrar<String> {
private static final X509TrustManager xtm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
private static final HostnameVerifier hnv = (hostname, session) -> true;
static {
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
X509TrustManager[] xtmArray = new X509TrustManager[]{xtm};
sslContext.init(null, xtmArray, new java.security.SecureRandom());
} catch (GeneralSecurityException gse) {
}
if (sslContext != null)
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
}
// Max size of download buffer.
private static final int MAX_BUFFER_SIZE = 2048;

View File

@@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.utils;
import java.awt.FontMetrics;
import java.net.URI;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollBar;
@@ -153,11 +152,12 @@ public class SwingUtils {
}
public static String getParsedJPanelText(JLabel jLabel1, String longString) {
if(StrUtils.isBlank(longString)) return longString;
if (StrUtils.isBlank(longString)) return longString;
StringBuilder builder = new StringBuilder();
char[] chars = longString.toCharArray();
FontMetrics fontMetrics = jLabel1.getFontMetrics(jLabel1.getFont());
for (int beginIndex = 0, limit = 1;; limit++) {
if (beginIndex + limit >= chars.length) break;
if (fontMetrics.charsWidth(chars, beginIndex, limit) < jLabel1.getWidth()) {
if (beginIndex + limit < chars.length)
continue;

View File

@@ -4,7 +4,7 @@
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="logwindow.title" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="logwindow.title" replaceFormat="C.I18N.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<SyntheticProperties>
@@ -99,7 +99,7 @@
<Component class="javax.swing.JButton" name="btnClear">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="ui.button.clear" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="ui.button.clear" replaceFormat="C.I18N.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
@@ -109,7 +109,7 @@
<Component class="javax.swing.JButton" name="btnClose">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="ui.button.close" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="ui.button.close" replaceFormat="C.I18N.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
@@ -119,7 +119,7 @@
<Component class="javax.swing.JButton" name="btnCopy">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="ui.button.copy" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="ui.button.copy" replaceFormat="C.I18N.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
@@ -144,7 +144,7 @@
<Component class="javax.swing.JButton" name="btnTieBa">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="logwindow.tieba" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="logwindow.tieba" replaceFormat="C.I18N.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
@@ -162,7 +162,7 @@
<Component class="javax.swing.JButton" name="btnTerminateGame">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="logwindow.terminate_game" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="logwindow.terminate_game" replaceFormat="C.I18N.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>

View File

@@ -76,8 +76,7 @@ public class LogWindow extends javax.swing.JFrame {
btnGitHub = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jackhuang/hellominecraft/launcher/I18N"); // NOI18N
setTitle(bundle.getString("logwindow.title")); // NOI18N
setTitle(C.I18N.getString("logwindow.title")); // NOI18N
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
@@ -89,21 +88,21 @@ public class LogWindow extends javax.swing.JFrame {
txtLog.setRows(5);
jScrollPane1.setViewportView(txtLog);
btnClear.setText(bundle.getString("ui.button.clear")); // NOI18N
btnClear.setText(C.I18N.getString("ui.button.clear")); // NOI18N
btnClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClearActionPerformed(evt);
}
});
btnClose.setText(bundle.getString("ui.button.close")); // NOI18N
btnClose.setText(C.I18N.getString("ui.button.close")); // NOI18N
btnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCloseActionPerformed(evt);
}
});
btnCopy.setText(bundle.getString("ui.button.copy")); // NOI18N
btnCopy.setText(C.I18N.getString("ui.button.copy")); // NOI18N
btnCopy.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCopyActionPerformed(evt);
@@ -119,7 +118,7 @@ public class LogWindow extends javax.swing.JFrame {
}
});
btnTieBa.setText(bundle.getString("logwindow.tieba")); // NOI18N
btnTieBa.setText(C.I18N.getString("logwindow.tieba")); // NOI18N
btnTieBa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTieBaActionPerformed(evt);
@@ -133,7 +132,7 @@ public class LogWindow extends javax.swing.JFrame {
}
});
btnTerminateGame.setText(bundle.getString("logwindow.terminate_game")); // NOI18N
btnTerminateGame.setText(C.I18N.getString("logwindow.terminate_game")); // NOI18N
btnTerminateGame.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnTerminateGameActionPerformed(evt);