From 809d7378e29c4ae89601b11dd86a388d3ca28f3a Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Fri, 27 Jan 2017 16:26:02 +0800 Subject: [PATCH] Clean up --- .../core/launch/DefaultGameLauncher.java | 2 +- .../launcher/ui/GameDownloadPanel.java | 4 +- .../launcher/ui/GameSettingsPanel.java | 11 +-- .../launcher/ui/LauncherSettingsPanel.form | 22 ++--- .../launcher/ui/LauncherSettingsPanel.java | 22 ++--- .../hellominecraft/util/NetUtils.java | 2 +- .../util/lang/SupportedLocales.java | 2 +- .../util/tasks/ParallelTask.java | 8 +- .../hellominecraft/util/tasks/TaskInfo.java | 6 +- .../hellominecraft/util/tasks/TaskWindow.java | 10 +- .../tasks/comm/DefaultPreviousResult.java | 38 -------- .../tasks/comm/PreviousResultRegistrar.java | 2 +- .../util/tasks/download/DownloadListener.java | 31 ------- .../util/tasks/download/FileDownloadTask.java | 8 +- .../util/tasks/download/HTTPGetTask.java | 2 +- .../util/tasks/download/NetException.java | 38 -------- .../util/ui/LogWindowOutputStream.java | 9 +- .../hellominecraft/util/ui/SwingUtils.java | 91 ++++++++++--------- README.md | 43 ++++----- 19 files changed, 117 insertions(+), 234 deletions(-) delete mode 100755 HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/DefaultPreviousResult.java delete mode 100755 HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/DownloadListener.java delete mode 100755 HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/NetException.java diff --git a/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java b/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java index 7383fa2e8..e453982a3 100755 --- a/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java +++ b/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/launch/DefaultGameLauncher.java @@ -46,7 +46,7 @@ public class DefaultGameLauncher extends GameLauncher { if (names.contains(s.lib.name)) continue; names.add(s.lib.name); - parallelTask.addDependsTask(new LibraryDownloadTask(s)); + parallelTask.addTask(new LibraryDownloadTask(s)); } dw.append(parallelTask); boolean flag = true; diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameDownloadPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameDownloadPanel.java index 4c09bc584..e88f5efcb 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameDownloadPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameDownloadPanel.java @@ -111,10 +111,10 @@ public class GameDownloadPanel extends Page { MinecraftRemoteVersions.refreshRomoteVersions(Settings.getLastProfile().service().getDownloadType()) .reg((ver) -> model.addRow(new Object[] { ver.id, ver.time, StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type })) - .regDone(() -> { + .regDone(SwingUtils.invokeLater(() -> { lstDownloads.requestFocus(); model.removeRow(0); - }).execute(); + })).execute(); } void downloadMinecraft() { diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameSettingsPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameSettingsPanel.java index 988875a84..419135b6f 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameSettingsPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/GameSettingsPanel.java @@ -112,13 +112,6 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi Settings.profileChangedEvent.register(onSelectedProfilesChanged); dropTarget = new DropTarget(lstExternalMods, DnDConstants.ACTION_COPY_OR_MOVE, this); - - /*AeroPage pnlAero = new AeroPage(); - pnlAero.setBounds(0, 0, 800, 480); - pnlAero.setLayout(null); - pnlAero.addAeroObject(jPanel1); - pnlAero.setBackgroundImage(MainFrame.INSTANCE.background.getImage()); - add(jPanel1);*/ } void initExplorationMenu() { @@ -248,9 +241,11 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi } } }); + ((NewTabPane) tabVersionEdit).initializing = true; - tabVersionEdit.addTab(C.i18n("settings.tabs.game_download"), pnlGameDownloads); // NOI18N + tabVersionEdit.addTab(C.i18n("settings.tabs.game_download"), pnlGameDownloads); ((NewTabPane) tabVersionEdit).initializing = false; + ((NewTabPane) tabInstallers).initializing = true; for (int i = 0; i < InstallerType.values().length; i++) tabInstallers.addTab(InstallerType.values()[i].getLocalizedName(), installerPanels[i]); diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.form b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.form index 441e7dd3e..02e0dc17f 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.form +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.form @@ -67,16 +67,15 @@ + + + + + + - - - - - - - @@ -121,20 +120,21 @@ - - + + + - + - + diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.java index b09e42091..01b4c3e9a 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/ui/LauncherSettingsPanel.java @@ -293,14 +293,13 @@ public class LauncherSettingsPanel extends RepaintPage { .addComponent(btnMCBBS)) .addComponent(lblAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblModpack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblRestart)) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(chkEnableShadow) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(chkEnableBlur) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(chkDecorated))) + .addComponent(lblRestart) + .addGroup(layout.createSequentialGroup() + .addComponent(chkEnableShadow) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkEnableBlur)) + .addComponent(chkDecorated)) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( @@ -337,9 +336,10 @@ public class LauncherSettingsPanel extends RepaintPage { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(chkEnableShadow) - .addComponent(chkDecorated) .addComponent(chkEnableBlur)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(chkDecorated) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnMCBBS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) @@ -348,7 +348,7 @@ public class LauncherSettingsPanel extends RepaintPage { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblModpack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lblAbout, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); }// //GEN-END:initComponents diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/NetUtils.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/NetUtils.java index e458255d3..5b8fd4bed 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/NetUtils.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/NetUtils.java @@ -31,7 +31,7 @@ import org.jackhuang.hellominecraft.util.system.IOUtils; /** * - * @author huang + * @author huangyuhui */ public final class NetUtils { diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/lang/SupportedLocales.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/lang/SupportedLocales.java index 034e87516..bf1021f97 100644 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/lang/SupportedLocales.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/lang/SupportedLocales.java @@ -24,7 +24,7 @@ import java.util.Locale; * @author huangyuhui */ public enum SupportedLocales { - def(Locale.getDefault(), "lang.default"), en(Locale.ENGLISH, null), zh_TW(Locale.TRADITIONAL_CHINESE, null), zh_CN(Locale.SIMPLIFIED_CHINESE, null); + def(Locale.getDefault(), "lang.default"), en(Locale.ENGLISH, null), zh_TW(Locale.TRADITIONAL_CHINESE, null), zh_CN(Locale.SIMPLIFIED_CHINESE, null), vi(new Locale("vi"), null); public Locale self; private String showString, customized; diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/ParallelTask.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/ParallelTask.java index 7eeb4f80d..fce15c20e 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/ParallelTask.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/ParallelTask.java @@ -26,7 +26,7 @@ import java.util.HashSet; */ public class ParallelTask extends Task { - Collection dependsTask = new HashSet<>(); + Collection tasks = new HashSet<>(); public ParallelTask() { hidden = true; @@ -43,11 +43,11 @@ public class ParallelTask extends Task { @Override public Collection getDependTasks() { - return dependsTask; + return tasks; } - public void addDependsTask(Task t) { - dependsTask.add(t); + public void addTask(Task t) { + tasks.add(t); } } diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskInfo.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskInfo.java index 70a88be71..b2ab31c9f 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskInfo.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskInfo.java @@ -23,15 +23,13 @@ package org.jackhuang.hellominecraft.util.tasks; */ public abstract class TaskInfo extends Task { - String info; - public TaskInfo(String info) { - this.info = info; + this.tag = info; } @Override public String getInfo() { - return info; + return tag; } } diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskWindow.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskWindow.java index 4ebc7ca50..edaf8c498 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskWindow.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/TaskWindow.java @@ -70,12 +70,10 @@ public class TaskWindow extends javax.swing.JDialog return; taskList = new TaskList(); taskList.addTaskListener(this); - taskList.doneEvent.register(() -> { - SwingUtilities.invokeLater(() -> { - dispose(); - suc = true; - }); - }); + taskList.doneEvent.register(SwingUtils.invokeLater(() -> { + dispose(); + suc = true; + })); } public static String downloadSource = ""; diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/DefaultPreviousResult.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/DefaultPreviousResult.java deleted file mode 100755 index 0550769fb..000000000 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/DefaultPreviousResult.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Hello Minecraft!. - * Copyright (C) 2013 huangyuhui - * - * 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hellominecraft.util.tasks.comm; - -/** - * - * @author huangyuhui - * @param the type of result. - */ -public class DefaultPreviousResult implements PreviousResult { - - T a; - - public DefaultPreviousResult(T a) { - this.a = a; - } - - @Override - public T getResult() { - return a; - } - -} diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/PreviousResultRegistrar.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/PreviousResultRegistrar.java index e63f2918b..a637e76b8 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/PreviousResultRegistrar.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/comm/PreviousResultRegistrar.java @@ -30,7 +30,7 @@ public interface PreviousResultRegistrar { * * @param pr previous task handler * - * @return task self instance + * @return task self instance(factory mode!) */ Task registerPreviousResult(PreviousResult pr); } diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/DownloadListener.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/DownloadListener.java deleted file mode 100755 index 2d629a730..000000000 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/DownloadListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Hello Minecraft!. - * Copyright (C) 2013 huangyuhui - * - * 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hellominecraft.util.tasks.download; - -import org.jackhuang.hellominecraft.util.tasks.ProgressProviderListener; - -/** - * - * @author huangyuhui - */ -public interface DownloadListener extends ProgressProviderListener { - - boolean OnFailed(); - - void OnFailedMoreThan5Times(String url); -} diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/FileDownloadTask.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/FileDownloadTask.java index 7b1e71e56..f8ae04bbc 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/FileDownloadTask.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/FileDownloadTask.java @@ -130,12 +130,12 @@ public class FileDownloadTask extends Task implements PreviousResult, Prev // Make sure response code is in the 200 range. if (con.getResponseCode() / 100 != 2) - throw new NetException(C.i18n("download.not_200") + " " + con.getResponseCode()); + throw new IOException(C.i18n("download.not_200") + " " + con.getResponseCode()); // Check for valid content length. int contentLength = con.getContentLength(); if (contentLength < 1) - throw new NetException("The content length is invalid."); + throw new IOException("The content length is invalid."); if (!filePath.getParentFile().mkdirs() && !filePath.getParentFile().isDirectory()) throw new IOException("Could not make directory"); @@ -210,8 +210,8 @@ public class FileDownloadTask extends Task implements PreviousResult, Prev if (ppl != null) ppl.onProgressProviderDone(this); return; - } catch (IOException | IllegalStateException | NetException e) { - setFailReason(new NetException(C.i18n("download.failed") + " " + url, e)); + } catch (IOException | IllegalStateException e) { + setFailReason(new IOException(C.i18n("download.failed") + " " + url, e)); } finally { closeFiles(); } diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/HTTPGetTask.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/HTTPGetTask.java index 6e9125dfb..fe572a8a9 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/HTTPGetTask.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/HTTPGetTask.java @@ -85,7 +85,7 @@ public class HTTPGetTask extends Task implements PreviousResult { doneEvent.execute(result); return; } catch (IOException ex) { - t = new NetException("Failed to get " + url, ex); + t = new IOException("Failed to get " + url, ex); } } if (t != null) diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/NetException.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/NetException.java deleted file mode 100755 index 5bfb496dc..000000000 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/tasks/download/NetException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Hello Minecraft!. - * Copyright (C) 2013 huangyuhui - * - * 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hellominecraft.util.tasks.download; - -/** - * - * @author huangyuhui - */ -public class NetException extends RuntimeException { - - public NetException(Exception message) { - super(message); - } - - public NetException(String message) { - super(message); - } - - public NetException(String message, Exception e) { - super(message, e); - } - -} diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/LogWindowOutputStream.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/LogWindowOutputStream.java index b108254b8..4aef2404c 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/LogWindowOutputStream.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/LogWindowOutputStream.java @@ -51,12 +51,9 @@ public class LogWindowOutputStream extends OutputStream { } private void append(final String str) { - try { - SwingUtilities.invokeLater(() -> { - txt.log(str, Level.guessLevel(str, sas)); - }); - } catch (Throwable ignore) { - } + SwingUtilities.invokeLater(() -> { + txt.log(str, Level.guessLevel(str, sas)); + }); } @Override diff --git a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/SwingUtils.java b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/SwingUtils.java index 06b8578ca..5c7ed045b 100755 --- a/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/SwingUtils.java +++ b/HMCUtils/src/main/java/org/jackhuang/hellominecraft/util/ui/SwingUtils.java @@ -41,6 +41,7 @@ import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; +import javax.swing.SwingUtilities; import javax.swing.table.DefaultTableModel; import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.logging.HMCLog; @@ -55,58 +56,58 @@ import org.jackhuang.hellominecraft.util.system.OS; * @author huang */ public final class SwingUtils { - + private SwingUtils() { } - + /** * Make DefaultTableModel by overriding getColumnClass and isCellEditable of * DefaultTableModel. * - * @param titleA The title of each column. - * @param typesA The type of each column value. + * @param titleA The title of each column. + * @param typesA The type of each column value. * @param canEditA Is column editable? * * @return */ public static DefaultTableModel makeDefaultTableModel(String[] titleA, final Class[] typesA, final boolean[] canEditA) { return new DefaultTableModel( - new Object[][] {}, - titleA) { + new Object[][] {}, + titleA) { Class[] types = typesA; boolean[] canEdit = canEditA; - + @Override public Class getColumnClass(int columnIndex) { return types[columnIndex]; } - + @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }; } - + public static void openFolder(File f) { f.mkdirs(); String path = f.getAbsolutePath(); switch (OS.os()) { - case OSX: - try { - Runtime.getRuntime().exec(new String[] { "/usr/bin/open", path }); - } catch (IOException ex) { - HMCLog.err("Failed to open " + path + " through /usr/bin/open", ex); - } - break; - default: - try { - java.awt.Desktop.getDesktop().open(f); - } catch (Throwable ex) { - MessageBox.show(C.i18n("message.cannot_open_explorer") + ex.getMessage()); - HMCLog.warn("Failed to open " + path + " through java.awt.Desktop.getDesktop().open()", ex); - } - break; + case OSX: + try { + Runtime.getRuntime().exec(new String[] { "/usr/bin/open", path }); + } catch (IOException ex) { + HMCLog.err("Failed to open " + path + " through /usr/bin/open", ex); + } + break; + default: + try { + java.awt.Desktop.getDesktop().open(f); + } catch (Throwable ex) { + MessageBox.show(C.i18n("message.cannot_open_explorer") + ex.getMessage()); + HMCLog.warn("Failed to open " + path + " through java.awt.Desktop.getDesktop().open()", ex); + } + break; } } @@ -165,18 +166,18 @@ public final class SwingUtils { /** * Append new element to JList * - * @param list the JList + * @param list the JList * @param element the Element */ public static void appendLast(JList list, Object element) { getDefaultListModel(list).addElement(element); } - + public static void replaceLast(JList list, Object element) { DefaultListModel model = getDefaultListModel(list); model.set(model.getSize() - 1, element); } - + public static void clear(JList list) { list.setModel(new DefaultListModel()); } @@ -194,17 +195,17 @@ public final class SwingUtils { model.removeRow(0); return model; } - + public static void appendLast(JTable table, Object... elements) { DefaultTableModel model = (DefaultTableModel) table.getModel(); model.addRow(elements); } - + public static void setValueAt(JTable table, Object element, int row, int col) { DefaultTableModel model = (DefaultTableModel) table.getModel(); model.setValueAt(element, row, col); } - + public static Object[] getValueBySelectedRow(JTable table, int rows[], int col) { DefaultTableModel model = (DefaultTableModel) table.getModel(); Object[] ret = new Object[rows.length]; @@ -212,12 +213,12 @@ public final class SwingUtils { ret[i] = model.getValueAt(rows[i], col); return ret; } - + public static void removeRow(JTable table, int row) { DefaultTableModel model = (DefaultTableModel) table.getModel(); model.removeRow(row); } - + public static String getParsedJPanelText(JLabel jLabel1, String longString) { if (StrUtils.isBlank(longString)) return longString; @@ -239,11 +240,11 @@ public final class SwingUtils { } return builder.toString(); } - + private static final Map 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 invokeAndWait(NonFunction x) { int id; synchronized (INVOKE_AND_WAIT_LOCK) { @@ -254,7 +255,7 @@ public final class SwingUtils { invokeAndWait(r); return (T) INVOKE_AND_WAIT_MAP.remove(id); } - + public static void invokeAndWait(Runnable r) { if (EventQueue.isDispatchThread()) r.run(); @@ -266,7 +267,7 @@ public final class SwingUtils { r.run(); } } - + public static int select(String[] selList, String msg) { Object msgs[] = new Object[2]; msgs[0] = msg; @@ -276,7 +277,7 @@ public final class SwingUtils { return -1; return ((JComboBox) msgs[1]).getSelectedIndex(); } - + public static void setEnabled(JComponent component, boolean t) { synchronized (component.getTreeLock()) { for (Component c : component.getComponents()) @@ -285,11 +286,11 @@ public final class SwingUtils { } component.setEnabled(t); } - + public static void exitIfNoWindow(Window thisFrame) { exitIfNoWindow(thisFrame, false); } - + public static void exitIfNoWindow(Window thisFrame, boolean neededDispose) { boolean flag = false; for (Window f : Window.getWindows()) { @@ -308,11 +309,11 @@ public final class SwingUtils { else thisFrame.dispose(); } - + public static ImageIcon scaleImage(ImageIcon i, int x, int y) { return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH)); } - + public static ImageIcon searchBackgroundImage(ImageIcon init, String bgpath, int width, int height) { Random r = new Random(); boolean loaded = false; @@ -362,9 +363,15 @@ public final class SwingUtils { HMCLog.log("Prepared background image in background.jpg."); } } - + if (background == null) return init; return background; } + + public static Runnable invokeLater(Runnable r) { + return () -> { + SwingUtilities.invokeLater(r); + }; + } } diff --git a/README.md b/README.md index d636c0f41..49138745c 100755 --- a/README.md +++ b/README.md @@ -1,31 +1,26 @@ # Hello Minecraft! Launcher [![Build Status](https://travis-ci.org/huanghongxun/HMCL.svg?branch=master)](https://travis-ci.org/huanghongxun/HMCL) 开源协议为GPL v3, 详情参见http://www.gnu.org/licenses/gpl.html -## 介绍 +## Introduction -HMCL是一个Minecraft启动器,支持Mod管理,游戏定制,自动安装,整合包制作,界面主题定制等功能。 -并且一天的使用次数在工作日时有40万左右、节假日有150万左右的使用次数,也就是说日活跃用户在10万以上。 -但是本项目的代码不够完善,希望有更多的人能加入HMCL的开发。 +HMCL is a Minecraft launcher which supports Mod management, game customizing, auto installing(Forge, LiteLoader and OptiFine), modpack creating, UI customizing and so on. -## 贡献 -如果你很想为本项目贡献代码,这里有一些要求: -* 开发环境为Netbeans 8.1 -* 编译器为Java 1.8,通过retrolambda兼容Java 1.7,所以请不要使用Java 8的新API(如Stream) -* 请不要修改`gradle`文件 +## Contribution +If you want to submit a pull request, there're some requirements: +* IDE: Netbeans 8.1 +* Compiler: Java 1.8 and libraries only supports Java 1.7(because of retrolambda). +* Do NOT modify `gradle` files. -## 代码 -* 包 `org.jackhuang.hellominecraft.util` 为HMCL和HMCSM的共用工具代码 -* 包 `org.jackhuang.hellominecraft.launcher` 包含了HMCL的界面以及逻辑代码 -* 包 `org.jackhuang.hellominecraft.launcher.core` 为HMCL的启动核心 -* 包 `org.jackhuang.hellominecraft.launcher.api` 是HMCL为了便于定制提供的API,暂不支持加载插件 -* 包 `org.jackhuang.hellominecraft.svrmgr` 为HMCSM的所有代码 -* 文件夹 `HMCUtils/src/main/resources/org/jackhuang/hellominecraft/lang` 包含了HMCL和HMCSM使用的语言文件 +## Code +* package `org.jackhuang.hellominecraft.util`: HMCL development utilities. +* package `org.jackhuang.hellominecraft.launcher`: HMCL UI core. +* package `org.jackhuang.hellominecraft.launcher.core`: HMCL game launcher core. +* package `org.jackhuang.hellominecraft.launcher.api`: Nothing here! +* package `org.jackhuang.hellominecraft.svrmgr`: All HMCSM codes. +* Folder `HMCUtils/src/main/resources/org/jackhuang/hellominecraft/lang` contains language files. -由于包树已经相当清晰,因此不再赘述各包各类的用途。 - -## 注意事项 -* 包 `org.jackhuang.hellominecraft.util.logging` 包含了经过精简的Apache License 2.0的Log4j项目的代码 -* 包 `com.google.gson` 为Google Gson项目Apache License 2.0的代码 -* 包 `org.jackhuang.hellominecraft.lookandfeel.ui` 包含了Sun Microsystems的NimbusLookAndFeel项目的部分LGPL代码 -* 所有Pull Request提交的代码均会被重写 -* 本项目的开源协议是GPL v3,因此包含LGPL和Apache License 2.0的代码是没有法律问题的 +## Pay Attention +* When you do decide to modify this app, please and you MUST delete `org.jackhuang.hellominecraft.launcher.util.CrashReporter`, or errors your code cause will be sent to my server. +* package `org.jackhuang.hellominecraft.util.logging`: repackaged Apache Log4j, Apache License 2.0. +* package `com.google.gson`: Apache License 2.0 +* package `org.jackhuang.hellominecraft.lookandfeel.ui`: contains some NimbusLAF's code belonging to Sun Microsystems under LGPL. \ No newline at end of file