fix bugs with Swing.
This commit is contained in:
@@ -31,5 +31,5 @@ buildscript {
|
||||
}
|
||||
|
||||
retrolambda {
|
||||
javaVersion = JavaVersion.VERSION_1_7
|
||||
javaVersion = JavaVersion.VERSION_1_6
|
||||
}
|
||||
@@ -30,8 +30,6 @@
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<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"/>
|
||||
@@ -44,14 +42,11 @@
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="srlDownload" pref="289" max="32767" attributes="0"/>
|
||||
<Component id="srlDownload" pref="291" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" 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>
|
||||
<Component id="pgsTotal" alignment="1" min="-2" pref="22" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@@ -69,13 +64,6 @@
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lblTotalProgress">
|
||||
<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.total_progress" replaceFormat="java.util.ResourceBundle.getBundle("{bundleNameSlashes}").getString("{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JProgressBar" name="pgsTotal">
|
||||
<Properties>
|
||||
<Property name="stringPainted" type="boolean" value="true"/>
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.tasks;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
@@ -52,6 +51,13 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
initComponents();
|
||||
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
if (lstDownload.getColumnModel().getColumnCount() > 1) {
|
||||
int i = 35;
|
||||
lstDownload.getColumnModel().getColumn(1).setMinWidth(i);
|
||||
lstDownload.getColumnModel().getColumn(1).setMaxWidth(i);
|
||||
lstDownload.getColumnModel().getColumn(1).setPreferredWidth(i);
|
||||
}
|
||||
|
||||
setModal(true);
|
||||
}
|
||||
@@ -96,7 +102,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
private void initComponents() {
|
||||
|
||||
btnCancel = new javax.swing.JButton();
|
||||
lblTotalProgress = new javax.swing.JLabel();
|
||||
pgsTotal = new javax.swing.JProgressBar();
|
||||
srlDownload = new javax.swing.JScrollPane();
|
||||
lstDownload = new javax.swing.JTable();
|
||||
@@ -117,8 +122,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
}
|
||||
});
|
||||
|
||||
lblTotalProgress.setText(bundle.getString("taskwindow.total_progress")); // NOI18N
|
||||
|
||||
pgsTotal.setStringPainted(true);
|
||||
|
||||
lstDownload.setModel(SwingUtils.makeDefaultTableModel(new String[]{C.i18n("taskwindow.file_name"), C.i18n("taskwindow.download_progress")}, new Class[]{String.class, String.class}, new boolean[]{false,false})
|
||||
@@ -133,8 +136,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.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)
|
||||
@@ -144,13 +145,11 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
|
||||
.addComponent(srlDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.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)))
|
||||
.addComponent(pgsTotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@@ -166,19 +165,18 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
tasks.clear();
|
||||
|
||||
if (!this.failReasons.isEmpty()) {
|
||||
MessageBox.Show(StrUtils.parseParams("", failReasons.toArray(), "\n"), C.i18n("message.error"), MessageBox.ERROR_MESSAGE);
|
||||
SwingUtilities.invokeLater(() -> MessageBox.Show(StrUtils.parseParams("", failReasons.toArray(), "\n"), C.i18n("message.error"), MessageBox.ERROR_MESSAGE));
|
||||
failReasons.clear();
|
||||
}
|
||||
|
||||
if (!suc) {
|
||||
EventQueue.invokeLater(taskList::abort);
|
||||
SwingUtilities.invokeLater(taskList::abort);
|
||||
HMCLog.log("Tasks have been canceled by user.");
|
||||
}
|
||||
}//GEN-LAST:event_formWindowClosed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JLabel lblTotalProgress;
|
||||
private javax.swing.JTable lstDownload;
|
||||
private javax.swing.JProgressBar pgsTotal;
|
||||
private javax.swing.JScrollPane srlDownload;
|
||||
@@ -197,7 +195,6 @@ public class TaskWindow extends javax.swing.JDialog
|
||||
SwingUtils.setValueAt(lstDownload, pgs + "%", idx, 1);
|
||||
progresses.set(idx, pgs);
|
||||
}
|
||||
if (task.isParallelExecuting()) return;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
|
||||
|
||||
@Override
|
||||
public String getInfo() {
|
||||
return C.i18n("download") + ": " + url + " " + filePath;
|
||||
return C.i18n("download") + ": " + url;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jackhuang.hellominecraft.utils.system.MessageBox;
|
||||
import org.jackhuang.hellominecraft.C;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.utils.system.OS;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -186,4 +186,8 @@ public final class Utils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void requireNonNull(Object o) {
|
||||
if (o == null) throw new NullPointerException("Oh dear, there is a problem...");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.system;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -59,9 +60,30 @@ public class Java {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------
|
||||
MAC OS X
|
||||
-----------------------------------
|
||||
*/
|
||||
public static List<Java> queryAllJDKInMac() {
|
||||
List<Java> ans = new ArrayList<>();
|
||||
if (new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home").exists())
|
||||
ans.add(new Java("JRE", "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"));
|
||||
File f = new File("/Library/Java/JavaVirtualMachines/");
|
||||
if (f.exists())
|
||||
for (File a : f.listFiles())
|
||||
ans.add(new Java(a.getName(), new File(a, "Contents/Home").getAbsolutePath()));
|
||||
return ans;
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------
|
||||
WINDOWS
|
||||
-----------------------------------
|
||||
*/
|
||||
public static List<Java> queryAllJavaHomeInWindowsByReg() {
|
||||
List<Java> ans = new ArrayList<>();
|
||||
try {
|
||||
List<Java> ans = new ArrayList<>();
|
||||
List<String> javas = queryRegSubFolders("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment");
|
||||
for (String java : javas) {
|
||||
int s = 0;
|
||||
@@ -82,21 +104,19 @@ public class Java {
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
private static List<String> queryRegSubFolders(String location) throws IOException, InterruptedException {
|
||||
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location};
|
||||
List<String> l = IOUtils.readProcessByInputStream(cmd);
|
||||
List<String> ans = new ArrayList<>();
|
||||
for (String line : l) {
|
||||
for (String line : l)
|
||||
if (line.startsWith(location) && !line.equals(location))
|
||||
ans.add(line);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
@@ -104,20 +124,20 @@ public class Java {
|
||||
String[] cmd = new String[]{"cmd", "/c", "reg", "query", location, "/v", name};
|
||||
List<String> l = IOUtils.readProcessByInputStream(cmd);
|
||||
boolean last = false;
|
||||
for(String s : l) {
|
||||
if(s.trim().isEmpty()) continue;
|
||||
for (String s : l) {
|
||||
if (s.trim().isEmpty()) continue;
|
||||
if (last == true && s.trim().startsWith(name)) {
|
||||
int begins = s.indexOf(name);
|
||||
if(begins > 0) {
|
||||
if (begins > 0) {
|
||||
s = s.substring(begins + name.length());
|
||||
begins = s.indexOf("REG_SZ");
|
||||
if(begins > 0) {
|
||||
if (begins > 0) {
|
||||
s = s.substring(begins + "REG_SZ".length());
|
||||
return s.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(s.trim().equals(location)) last = true;
|
||||
if (s.trim().equals(location)) last = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user