Add mod modification.
This commit is contained in:
@@ -18,7 +18,7 @@ package org.jackhuang.hellominecraft.tasks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
|
||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrator;
|
||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrar;
|
||||
import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
||||
* @author huangyuhui
|
||||
* @param <T> Runnable<T>
|
||||
*/
|
||||
public class TaskRunnableArg1<T> extends TaskInfo implements PreviousResultRegistrator<T> {
|
||||
public class TaskRunnableArg1<T> extends TaskInfo implements PreviousResultRegistrar<T> {
|
||||
private final Consumer<T> r;
|
||||
public TaskRunnableArg1(String info, Consumer<T> r) {
|
||||
super(info);
|
||||
|
||||
@@ -31,40 +31,26 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblSingleProgress" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="349" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="pgsSingle" alignment="0" pref="434" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="lblTotalProgress" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="pgsTotal" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="lblTotalProgress" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="pgsTotal" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="srlDownload" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="srlDownload" alignment="0" pref="517" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="srlDownload" pref="232" max="32767" attributes="0"/>
|
||||
<Component id="srlDownload" pref="289" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="btnCancel" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="lblSingleProgress" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="pgsSingle" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="lblTotalProgress" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="pgsTotal" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" alignment="1" min="-2" pref="22" max="-2" attributes="0"/>
|
||||
<Group type="103" alignment="1" groupAlignment="3" attributes="0">
|
||||
<Component id="pgsTotal" alignment="3" min="-2" pref="22" max="-2" attributes="0"/>
|
||||
<Component id="lblTotalProgress" alignment="3" min="-2" pref="22" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@@ -83,18 +69,6 @@
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JProgressBar" name="pgsSingle">
|
||||
<Properties>
|
||||
<Property name="stringPainted" type="boolean" value="true"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblSingleProgress">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="taskwindow.single_progress" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblTotalProgress">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
|
||||
@@ -70,7 +70,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
|
||||
public boolean start() {
|
||||
if (taskList.isAlive()) return false;
|
||||
pgsSingle.setValue(0);
|
||||
pgsTotal.setValue(0);
|
||||
suc = false;
|
||||
SwingUtils.clearDefaultTable(lstDownload);
|
||||
@@ -97,8 +96,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
private void initComponents() {
|
||||
|
||||
btnCancel = new javax.swing.JButton();
|
||||
pgsSingle = new javax.swing.JProgressBar();
|
||||
lblSingleProgress = new javax.swing.JLabel();
|
||||
lblTotalProgress = new javax.swing.JLabel();
|
||||
pgsTotal = new javax.swing.JProgressBar();
|
||||
srlDownload = new javax.swing.JScrollPane();
|
||||
@@ -120,10 +117,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}
|
||||
});
|
||||
|
||||
pgsSingle.setStringPainted(true);
|
||||
|
||||
lblSingleProgress.setText(bundle.getString("taskwindow.single_progress")); // NOI18N
|
||||
|
||||
lblTotalProgress.setText(bundle.getString("taskwindow.total_progress")); // NOI18N
|
||||
|
||||
pgsTotal.setStringPainted(true);
|
||||
@@ -140,35 +133,24 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(lblSingleProgress)
|
||||
.addGap(349, 349, 349))
|
||||
.addComponent(pgsSingle, javax.swing.GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(lblTotalProgress)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addComponent(pgsTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(lblTotalProgress)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pgsTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel)
|
||||
.addContainerGap())
|
||||
.addComponent(srlDownload)
|
||||
.addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
|
||||
.addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(lblSingleProgress)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pgsSingle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(lblTotalProgress)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(pgsTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addComponent(btnCancel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(pgsTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblTotalProgress, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@@ -196,10 +178,8 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JLabel lblSingleProgress;
|
||||
private javax.swing.JLabel lblTotalProgress;
|
||||
private javax.swing.JTable lstDownload;
|
||||
private javax.swing.JProgressBar pgsSingle;
|
||||
private javax.swing.JProgressBar pgsTotal;
|
||||
private javax.swing.JScrollPane srlDownload;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
@@ -218,8 +198,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
progresses.set(idx, pgs);
|
||||
}
|
||||
if (task.isParallelExecuting()) return;
|
||||
pgsSingle.setMaximum(max);
|
||||
pgsSingle.setValue(progress);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jackhuang.hellominecraft.tasks.Task;
|
||||
* @author huangyuhui
|
||||
* @param <T> Previous task result type
|
||||
*/
|
||||
public interface PreviousResultRegistrator<T> {
|
||||
public interface PreviousResultRegistrar<T> {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -33,7 +33,7 @@ import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.tasks.Task;
|
||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResult;
|
||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrator;
|
||||
import org.jackhuang.hellominecraft.tasks.communication.PreviousResultRegistrar;
|
||||
import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ import org.jackhuang.hellominecraft.utils.system.IOUtils;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
// This class downloads a file from a URL.
|
||||
public class FileDownloadTask extends Task implements PreviousResult<File>, PreviousResultRegistrator<String> {
|
||||
public class FileDownloadTask extends Task implements PreviousResult<File>, PreviousResultRegistrar<String> {
|
||||
|
||||
private static final X509TrustManager xtm = new X509TrustManager() {
|
||||
@Override
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.net.URI;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JScrollPane;
|
||||
@@ -33,12 +35,13 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Make DefaultTableModel by overriding getColumnClass and isCellEditable of DefaultTableModel.
|
||||
*
|
||||
* 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 canEditA Is column editable?
|
||||
* @return
|
||||
* @return
|
||||
*/
|
||||
public static DefaultTableModel makeDefaultTableModel(String[] titleA, final Class[] typesA, final boolean[] canEditA) {
|
||||
return new javax.swing.table.DefaultTableModel(
|
||||
@@ -61,7 +64,8 @@ public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Open URL by java.awt.Desktop
|
||||
* @param link
|
||||
*
|
||||
* @param link
|
||||
*/
|
||||
public static void openLink(URI link) {
|
||||
try {
|
||||
@@ -73,7 +77,8 @@ public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Move the cursor to the end of TextArea.
|
||||
* @param tf the TextArea
|
||||
*
|
||||
* @param tf the TextArea
|
||||
*/
|
||||
public static void moveEnd(JTextArea tf) {
|
||||
int position = tf.getText().length();
|
||||
@@ -82,6 +87,7 @@ public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Move the cursor to the end of ScrollPane.
|
||||
*
|
||||
* @param pane the ScrollPane
|
||||
*/
|
||||
public static void moveEnd(JScrollPane pane) {
|
||||
@@ -91,6 +97,7 @@ public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Get the DefaultListModel from JList.
|
||||
*
|
||||
* @param list
|
||||
* @return Forcely Type casted to DefaultListModel
|
||||
*/
|
||||
@@ -100,6 +107,7 @@ public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Append new element to JList
|
||||
*
|
||||
* @param list the JList
|
||||
* @param element the Element
|
||||
*/
|
||||
@@ -118,6 +126,7 @@ public class SwingUtils {
|
||||
|
||||
/**
|
||||
* Clear the JTable
|
||||
*
|
||||
* @param table JTable with DefaultTableModel.
|
||||
*/
|
||||
public static void clearDefaultTable(JTable table) {
|
||||
@@ -126,20 +135,39 @@ public class SwingUtils {
|
||||
model.removeRow(0);
|
||||
table.updateUI();
|
||||
}
|
||||
|
||||
|
||||
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 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;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = longString.toCharArray();
|
||||
FontMetrics fontMetrics = jLabel1.getFontMetrics(jLabel1.getFont());
|
||||
for (int beginIndex = 0, limit = 1;; limit++) {
|
||||
if (fontMetrics.charsWidth(chars, beginIndex, limit) < jLabel1.getWidth()) {
|
||||
if (beginIndex + limit < chars.length)
|
||||
continue;
|
||||
builder.append(chars, beginIndex, limit);
|
||||
break;
|
||||
}
|
||||
builder.append(chars, beginIndex, limit - 1).append("<br/>");
|
||||
beginIndex += limit - 1;
|
||||
limit = 1;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
@@ -26,7 +25,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.utils.NetUtils;
|
||||
@@ -230,6 +228,14 @@ public class FileUtils {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFileQuietly(File srcFile, File destFile) {
|
||||
try {
|
||||
copyFile(srcFile, destFile);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to copy file", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFile(File srcFile, File destFile)
|
||||
throws IOException {
|
||||
|
||||
@@ -72,6 +72,16 @@ public class Java {
|
||||
if (javahome != null)
|
||||
ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\".length()), javahome));
|
||||
}
|
||||
javas = queryRegSubFolders("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit");
|
||||
for (String java : javas) {
|
||||
int s = 0;
|
||||
for (char c : java.toCharArray())
|
||||
if (c == '.') s++;
|
||||
if (s <= 1) continue;
|
||||
String javahome = queryRegValue(java, "JavaHome");
|
||||
if (javahome != null)
|
||||
ans.add(new Java(java.substring("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\".length()), javahome));
|
||||
}
|
||||
return ans;
|
||||
} catch (IOException | InterruptedException ex) {
|
||||
HMCLog.err("Faield to query java", ex);
|
||||
|
||||
Reference in New Issue
Block a user