1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-24 12:16:28 +01:00

Added console log button to ProgressDialog.

This commit is contained in:
sk89q 2014-01-09 09:21:51 -08:00
parent 8f922b4edb
commit 152538e2b8
5 changed files with 57 additions and 8 deletions

View File

@ -28,12 +28,16 @@ import static com.skcraft.launcher.util.SharedLocale._;
*/
public class ConsoleFrame extends JFrame {
private static ConsoleFrame globalFrame;
@Getter private final Image trayRunningIcon;
@Getter private final Image trayClosedIcon;
@Getter private final MessageLog messageLog;
@Getter private LinedBoxPanel buttonsPanel;
private boolean registeredGlobalLog = false;
/**
* Construct the frame.
*
@ -92,11 +96,23 @@ public class ConsoleFrame extends JFrame {
});
}
/**
* Register the global logger if it hasn't been registered.
*/
private void registerLoggerHandler() {
if (!registeredGlobalLog) {
getMessageLog().registerLoggerHandler();
registeredGlobalLog = true;
}
}
/**
* Attempt to perform window close.
*/
protected void performClose() {
messageLog.detachGlobalHandler();
messageLog.clear();
registeredGlobalLog = false;
dispose();
}
@ -122,4 +138,19 @@ public class ConsoleFrame extends JFrame {
});
}
public static void showMessages() {
ConsoleFrame frame = globalFrame;
if (frame == null) {
frame = new ConsoleFrame(10000, false);
globalFrame = frame;
frame.setTitle(_("console.launcherConsoleTitle"));
frame.registerLoggerHandler();
frame.setVisible(true);
} else {
frame.setVisible(true);
frame.registerLoggerHandler();
frame.requestFocus();
}
}
}

View File

@ -39,6 +39,7 @@ public class ProgressDialog extends JDialog {
private final JTextArea logText = new JTextArea();
private final JScrollPane logScroll = new JScrollPane(logText);
private final JButton detailsButton = new JButton();
private final JButton logButton = new JButton(_("progress.viewLog"));
private final JButton cancelButton = new JButton(_("button.cancel"));
public ProgressDialog(Window owner, String title, String message) {
@ -65,13 +66,15 @@ public class ProgressDialog extends JDialog {
}
private void setCompactSize() {
detailsButton.setText("Details...");
detailsButton.setText(_("progress.details"));
logButton.setVisible(false);
setMinimumSize(new Dimension(400, 100));
pack();
}
private void setDetailsSize() {
detailsButton.setText("Less...");
detailsButton.setText(_("progress.less"));
logButton.setVisible(true);
setSize(400, 350);
}
@ -82,6 +85,7 @@ public class ProgressDialog extends JDialog {
progressBar.setPreferredSize(new Dimension(0, 18));
buttonsPanel.addElement(detailsButton);
buttonsPanel.addElement(logButton);
buttonsPanel.addGlue();
buttonsPanel.addElement(cancelButton);
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(30, 13, 13, 13));
@ -113,16 +117,24 @@ public class ProgressDialog extends JDialog {
}
}
});
detailsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleDetails();
}
});
logButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ConsoleFrame.showMessages();
}
});
}
private boolean confirmCancel() {
return SwingHelper.confirmDialog(this, "Are you sure that you wish to cancel?", "Cancel");
return SwingHelper.confirmDialog(this, _("progress.confirmCancel"), _("progress.confirmCancelTitle"));
}
protected void cancel() {

View File

@ -218,7 +218,7 @@ public class HttpDownloader implements Downloader {
}
private void download() throws IOException, InterruptedException {
log.log(Level.INFO, "Downloading {0} from {1}...", new Object[] { destFile, urls });
log.log(Level.INFO, "Downloading " + destFile + " from " + urls);
File destDir = destFile.getParentFile();
File tempFile = new File(destDir, destFile.getName() + ".tmp");

View File

@ -8,6 +8,7 @@ package com.skcraft.launcher.swing;
import com.skcraft.launcher.LauncherUtils;
import com.skcraft.launcher.util.LimitLinesDocumentListener;
import com.skcraft.launcher.util.SimpleLogFormatter;
import javax.swing.*;
import javax.swing.text.*;
@ -264,6 +265,8 @@ public class MessageLog extends JPanel {
* Used to send logger messages to the console.
*/
private class ConsoleLoggerHandler extends Handler {
private final SimpleLogFormatter formatter = new SimpleLogFormatter();
@Override
public void publish(LogRecord record) {
Level level = record.getLevel();
@ -276,10 +279,7 @@ public class MessageLog extends JPanel {
attributes = debugAttributes;
}
log(record.getMessage() + "\n", attributes);
if (t != null) {
log(LauncherUtils.getStackTrace(t) + "\n", attributes);
}
log(formatter.format(record), attributes);
}
@Override

View File

@ -104,6 +104,7 @@ login.noLoginTitle=Missing Account
login.minecraftNotOwnedError=Sorry, Minecraft is not owned on that account.
console.title=Messages and Errors
console.launcherConsoleTitle=Launcher Messages
console.uploadLog=Upload Log
console.pasteUploading=Uploading {0} bytes...\n
console.pasteUploaded=Paste uploaded\: {0}\n
@ -127,6 +128,11 @@ downloader.jobPending=...\t{0}
downloader.noDownloads=No pending downloads.
downloader.failedCount=({0} have failed)
progress.details=Details...
progress.less=Less...
progress.viewLog=View log
progress.confirmCancel=Are you sure that you wish to cancel?
progress.confirmCancelTitle=Cancel
progress.defaultStatus=Working...
progress.percentTitle=({0}%) {1}