Improves writing speed when not using a GUI
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good

Uses buffered writers instead of System.out
Uses a GUI for writing JarBuilder messages
Adds some missing comments to the jar builder
This commit is contained in:
2021-08-02 16:49:35 +02:00
parent 52eacb9980
commit 32c17c6005
4 changed files with 50 additions and 12 deletions

View File

@ -1,6 +1,9 @@
package net.knarcraft.minecraftserverlauncher.userinterface;
import javax.swing.*;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
/**
* This class handles displaying messages to the user
@ -8,6 +11,7 @@ import javax.swing.*;
public abstract class MessageHandler implements GUI {
private final boolean silent;
private final BufferedWriter writer;
/***
* Initializes a new message handler
@ -16,12 +20,18 @@ public abstract class MessageHandler implements GUI {
*/
public MessageHandler(boolean silent) {
this.silent = silent;
this.writer = new BufferedWriter(new OutputStreamWriter(System.out));
}
@Override
public void showError(String title, String message) {
if (silent) {
System.out.println(message);
try {
writer.write(message);
writer.flush();
} catch (IOException e) {
System.out.println(message);
}
} else {
showJOptionPane(title, message, JOptionPane.ERROR_MESSAGE);
}
@ -35,7 +45,12 @@ public abstract class MessageHandler implements GUI {
@Override
public void showMessage(String title, String message) {
if (silent) {
System.out.println(message);
try {
writer.write(message);
writer.flush();
} catch (IOException e) {
System.out.println(message);
}
} else {
showJOptionPane(title, message, JOptionPane.INFORMATION_MESSAGE);
}