2
0
mirror of https://github.com/HMCL-dev/HMCL.git synced 2025-04-12 18:30:26 +08:00

Fix NullPointerException in SwingUtils.invokeAndWait

This commit is contained in:
huangyuhui 2016-01-01 10:51:44 +08:00
parent 6968809499
commit 1f7eb04215
6 changed files with 51 additions and 18 deletions
HMCL/src/main/java/org/jackhuang/hellominecraft/launcher
HMCLAPI/src/main/java/org/jackhuang/hellominecraft
MetroLookAndFeel/src/main/java/org/jackhuang/hellominecraft/lookandfeel/painters

@ -1,7 +1,7 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@ -30,6 +30,7 @@ import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.system.OS;
import org.jackhuang.hellominecraft.views.LogWindow;
/**
@ -96,7 +97,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
text += "\n Content: \n ";
text += s + "\n\n";
text += "-- System Details --\n";
text += " Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version") + "\n";
text += " Operating System: " + OS.getSystemVersion() + "\n";
text += " Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + "\n";
text += " Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor") + "\n";
if (enableLogger)

@ -43,7 +43,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
/**
* Creates new form InstallerPanel
*
* @param gsp To get the minecraft version
* @param gsp To get the minecraft version
* @param installerType load which installer
*/
public InstallerPanel(GameSettingsPanel gsp, InstallerType installerType) {
@ -56,10 +56,9 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
}
/**
* 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.
* 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
@ -125,7 +124,7 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
void refreshVersions() {
if (TaskWindow.getInstance().addTask(new TaskRunnableArg1<>(C.i18n("install." + id.id + ".get_list"), list)
.registerPreviousResult(new DefaultPreviousResult<>(new String[] {gsp.getMinecraftVersionFormatted()})))
.registerPreviousResult(new DefaultPreviousResult<>(new String[]{gsp.getMinecraftVersionFormatted()})))
.start())
loadVersions();
}
@ -152,7 +151,8 @@ public class InstallerPanel extends AnimatedPanel implements Selectable {
SwingUtils.clearDefaultTable(lstInstallers);
if (versions != null)
for (InstallerVersionList.InstallerVersion v : versions)
model.addRow(new Object[] {v.selfVersion == null ? "null" : v.selfVersion, v.mcVersion == null ? "null" : v.mcVersion});
if (v != null)
model.addRow(new Object[]{v.selfVersion == null ? "null" : v.selfVersion, v.mcVersion == null ? "null" : v.mcVersion});
}
});
}

@ -1,7 +1,7 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@ -87,6 +87,13 @@ public final class StrUtils {
return false;
}
public static boolean containsOne(String base, String... match) {
for (String s : match)
if (base.contains(s))
return true;
return false;
}
public static boolean containsOne(List<String> base, List<String> match) {
for (String a : base)
for (String b : match)

@ -26,6 +26,7 @@ import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.util.StringTokenizer;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.StrUtils;
/**
* @author huangyuhui
@ -108,4 +109,18 @@ public enum OS {
return result;
}
public static String getLinuxReleaseVersion() throws IOException {
return FileUtils.readFileToString(new File("/etc/issue"));
}
public static String getSystemVersion() {
if (os() == LINUX)
try {
return getLinuxReleaseVersion();
} catch (IOException e) {
HMCLog.warn("Failed to catch /etc/issue");
}
return System.getProperty("os.name") + " (" + System.getProperty("os.arch") + "), " + System.getProperty("os.version");
}
}

@ -22,6 +22,9 @@ import java.awt.FontMetrics;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
@ -222,12 +225,19 @@ public class SwingUtils {
return builder.toString();
}
private static final ThreadLocal<Object> THREAD_LOCAL = new ThreadLocal<>();
private static final Map<Integer, Object> INVOKE_AND_WAIT_MAP = Collections.synchronizedMap(new HashMap<>());
private static int INVOKE_AND_WAIT_ID = 0;
private static final Object INVOKE_AND_WAIT_LOCK = new Object();
public static <T> T invokeAndWait(NonFunction<T> x) {
Runnable r = () -> THREAD_LOCAL.set(x.apply());
int id;
synchronized (INVOKE_AND_WAIT_LOCK) {
id = ++INVOKE_AND_WAIT_ID;
}
int fuck = id;
Runnable r = () -> INVOKE_AND_WAIT_MAP.put(fuck, x.apply());
invokeAndWait(r);
return (T) THREAD_LOCAL.get();
return (T) INVOKE_AND_WAIT_MAP.remove(id);
}
public static void invokeAndWait(Runnable r) {

@ -37,13 +37,13 @@ import java.awt.LinearGradientPaint;
*/
public class ProgressPainter extends SynthPainter {
private static final float[] NORMAL_BG_PTS = new float[] {0, 1};
private static final Color[] NORMAL_BG = new Color[] {
private static final float[] NORMAL_BG_PTS = new float[]{0, 1};
private static final Color[] NORMAL_BG = new Color[]{
GraphicsUtils.getWebColor("c6c6c6"),
GraphicsUtils.getWebColor("c6c6c6")
};
private static final float[] BAR_FG_PTS = new float[] {0, 1};
private static final Color[] BAR_FG = new Color[] {
private static final float[] BAR_FG_PTS = new float[]{0, 1};
private static final Color[] BAR_FG = new Color[]{
GraphicsUtils.getWebColor("41B1E1"),
GraphicsUtils.getWebColor("41B1E1")
};
@ -69,7 +69,7 @@ public class ProgressPainter extends SynthPainter {
Graphics2D g2 = (Graphics2D) g.create();
g2.setPaint(new LinearGradientPaint(x, y + 2, x, y + h - 2, BAR_FG_PTS, BAR_FG));
if (x + 2 < w - 5 && y + 2 < h - 5)
g2.drawRect(x + 2, y + 2, w - 5, h - 5);
g2.fillRect(x + 2, y + 2, w - 5, h - 5);
}
/**