May fixed: length must be positive when logging

This commit is contained in:
huangyuhui
2017-02-18 18:29:46 +08:00
parent 9df351a2f0
commit f4c5fbf9dd
4 changed files with 205 additions and 33 deletions

View File

@@ -27,7 +27,7 @@ buildscript {
}
plugins {
id "edu.sc.seis.macAppBundle" version "2.1.6"
//id "edu.sc.seis.macAppBundle" version "2.1.6"
//id "me.tatarka.retrolambda" version "3.5.0"
id 'edu.sc.seis.launch4j' version '2.3.0'
}
@@ -71,7 +71,7 @@ task generateSources(type: Copy) {
compileJava.setSource "$buildDir/generated-src"
compileJava.dependsOn generateSources
task macAppCompressed(type: Zip, dependsOn: createApp) {
/*task macAppCompressed(type: Zip, dependsOn: createApp) {
archiveName "HMCL-$mavenVersion-MacOSApp.zip"
include '**'
destinationDir file("$buildDir/libs/")
@@ -82,7 +82,7 @@ macAppBundle {
mainClassName = mainClass
icon = "src/main/icon.icns"
javaProperties.put("apple.laf.useScreenMenuBar", "true")
}
}*/
configurations {
coreCompile.extendsFrom compile
@@ -139,4 +139,4 @@ processResources {
build.dependsOn makeExecutable
build.dependsOn makePackGZ
build.dependsOn macAppCompressed
//build.dependsOn macAppCompressed

View File

@@ -35,7 +35,7 @@ import org.jackhuang.hmcl.util.ui.SwingUtils;
* @author huangyuhui
*/
public class LogWindow extends javax.swing.JFrame {
boolean movingEnd;
NonFunction<Boolean> listener;
Runnable terminateGameListener;
@@ -45,20 +45,20 @@ public class LogWindow extends javax.swing.JFrame {
*/
public LogWindow() {
initComponents();
movingEnd = true;
DoubleOutputStream out = new DoubleOutputStream(new LogWindowOutputStream(this, Level.INFO), System.out);
System.setOut(new PrintStream(out));
DoubleOutputStream err = new DoubleOutputStream(new LogWindowOutputStream(this, Level.ERROR), System.err);
System.setErr(new PrintStream(err));
SwingUtilities.invokeLater(() -> {
setLocationRelativeTo(null);
txtLog.setEditable(false);
});
}
public static final LogWindow INSTANCE = new LogWindow();
/**
@@ -240,44 +240,46 @@ public class LogWindow extends javax.swing.JFrame {
terminateGameListener.run();
SwingUtils.exitIfNoWindow(this);
}//GEN-LAST:event_formWindowClosing
public synchronized void log(String status, Level c) {
status = status.replace("\t", " ");
Document d = txtLog.getStyledDocument();
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setForeground(sas, c.COLOR);
try {
d.insertString(d.getLength(), status, sas);
} catch (Exception ex) {
HMCLog.err("Failed to insert \"" + status + "\" to " + d.getLength(), ex);
}
if (movingEnd) {
int position = d.getLength();
txtLog.setCaretPosition(position);
}
public void log(final String status, final Level c) {
SwingUtilities.invokeLater(() -> {
String newStatus = status.replace("\t", " ");
Document d = txtLog.getStyledDocument();
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setForeground(sas, c.COLOR);
try {
d.insertString(d.getLength(), newStatus, sas);
} catch (Exception ex) {
HMCLog.err("Failed to insert \"" + newStatus + "\" to " + d.getLength(), ex);
}
if (movingEnd) {
int position = d.getLength();
txtLog.setCaretPosition(position);
}
});
}
public void setExit(NonFunction<Boolean> exit) {
this.listener = exit;
}
public void setTerminateGame(Runnable l) {
this.terminateGameListener = l;
}
public void clean() {
txtLog.setText("");
}
public boolean getMovingEnd() {
return movingEnd;
}
public void setMovingEnd(boolean b) {
movingEnd = b;
}
@Override
public void setVisible(boolean b) {
lblCrash.setVisible(false);
@@ -286,7 +288,7 @@ public class LogWindow extends javax.swing.JFrame {
btnMCF.setVisible(false);
super.setVisible(b);
}
public void showAsCrashWindow(boolean out_date) {
if (out_date) {
lblCrash.setVisible(false);
@@ -301,7 +303,7 @@ public class LogWindow extends javax.swing.JFrame {
btnMCF.setVisible(true);
lblCrash.setText(C.i18n("ui.label.crashing"));
}
super.setVisible(true);
}