mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-30 13:13:58 +01:00
Added console log button to ProgressDialog.
This commit is contained in:
parent
8f922b4edb
commit
152538e2b8
@ -28,12 +28,16 @@ import static com.skcraft.launcher.util.SharedLocale._;
|
|||||||
*/
|
*/
|
||||||
public class ConsoleFrame extends JFrame {
|
public class ConsoleFrame extends JFrame {
|
||||||
|
|
||||||
|
private static ConsoleFrame globalFrame;
|
||||||
|
|
||||||
@Getter private final Image trayRunningIcon;
|
@Getter private final Image trayRunningIcon;
|
||||||
@Getter private final Image trayClosedIcon;
|
@Getter private final Image trayClosedIcon;
|
||||||
|
|
||||||
@Getter private final MessageLog messageLog;
|
@Getter private final MessageLog messageLog;
|
||||||
@Getter private LinedBoxPanel buttonsPanel;
|
@Getter private LinedBoxPanel buttonsPanel;
|
||||||
|
|
||||||
|
private boolean registeredGlobalLog = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the frame.
|
* 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.
|
* Attempt to perform window close.
|
||||||
*/
|
*/
|
||||||
protected void performClose() {
|
protected void performClose() {
|
||||||
messageLog.detachGlobalHandler();
|
messageLog.detachGlobalHandler();
|
||||||
|
messageLog.clear();
|
||||||
|
registeredGlobalLog = false;
|
||||||
dispose();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ public class ProgressDialog extends JDialog {
|
|||||||
private final JTextArea logText = new JTextArea();
|
private final JTextArea logText = new JTextArea();
|
||||||
private final JScrollPane logScroll = new JScrollPane(logText);
|
private final JScrollPane logScroll = new JScrollPane(logText);
|
||||||
private final JButton detailsButton = new JButton();
|
private final JButton detailsButton = new JButton();
|
||||||
|
private final JButton logButton = new JButton(_("progress.viewLog"));
|
||||||
private final JButton cancelButton = new JButton(_("button.cancel"));
|
private final JButton cancelButton = new JButton(_("button.cancel"));
|
||||||
|
|
||||||
public ProgressDialog(Window owner, String title, String message) {
|
public ProgressDialog(Window owner, String title, String message) {
|
||||||
@ -65,13 +66,15 @@ public class ProgressDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setCompactSize() {
|
private void setCompactSize() {
|
||||||
detailsButton.setText("Details...");
|
detailsButton.setText(_("progress.details"));
|
||||||
|
logButton.setVisible(false);
|
||||||
setMinimumSize(new Dimension(400, 100));
|
setMinimumSize(new Dimension(400, 100));
|
||||||
pack();
|
pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDetailsSize() {
|
private void setDetailsSize() {
|
||||||
detailsButton.setText("Less...");
|
detailsButton.setText(_("progress.less"));
|
||||||
|
logButton.setVisible(true);
|
||||||
setSize(400, 350);
|
setSize(400, 350);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +85,7 @@ public class ProgressDialog extends JDialog {
|
|||||||
progressBar.setPreferredSize(new Dimension(0, 18));
|
progressBar.setPreferredSize(new Dimension(0, 18));
|
||||||
|
|
||||||
buttonsPanel.addElement(detailsButton);
|
buttonsPanel.addElement(detailsButton);
|
||||||
|
buttonsPanel.addElement(logButton);
|
||||||
buttonsPanel.addGlue();
|
buttonsPanel.addGlue();
|
||||||
buttonsPanel.addElement(cancelButton);
|
buttonsPanel.addElement(cancelButton);
|
||||||
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(30, 13, 13, 13));
|
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(30, 13, 13, 13));
|
||||||
@ -113,16 +117,24 @@ public class ProgressDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
detailsButton.addActionListener(new ActionListener() {
|
detailsButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
toggleDetails();
|
toggleDetails();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ConsoleFrame.showMessages();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean confirmCancel() {
|
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() {
|
protected void cancel() {
|
||||||
|
@ -218,7 +218,7 @@ public class HttpDownloader implements Downloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void download() throws IOException, InterruptedException {
|
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 destDir = destFile.getParentFile();
|
||||||
File tempFile = new File(destDir, destFile.getName() + ".tmp");
|
File tempFile = new File(destDir, destFile.getName() + ".tmp");
|
||||||
|
@ -8,6 +8,7 @@ package com.skcraft.launcher.swing;
|
|||||||
|
|
||||||
import com.skcraft.launcher.LauncherUtils;
|
import com.skcraft.launcher.LauncherUtils;
|
||||||
import com.skcraft.launcher.util.LimitLinesDocumentListener;
|
import com.skcraft.launcher.util.LimitLinesDocumentListener;
|
||||||
|
import com.skcraft.launcher.util.SimpleLogFormatter;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.text.*;
|
import javax.swing.text.*;
|
||||||
@ -264,6 +265,8 @@ public class MessageLog extends JPanel {
|
|||||||
* Used to send logger messages to the console.
|
* Used to send logger messages to the console.
|
||||||
*/
|
*/
|
||||||
private class ConsoleLoggerHandler extends Handler {
|
private class ConsoleLoggerHandler extends Handler {
|
||||||
|
private final SimpleLogFormatter formatter = new SimpleLogFormatter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publish(LogRecord record) {
|
public void publish(LogRecord record) {
|
||||||
Level level = record.getLevel();
|
Level level = record.getLevel();
|
||||||
@ -276,10 +279,7 @@ public class MessageLog extends JPanel {
|
|||||||
attributes = debugAttributes;
|
attributes = debugAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(record.getMessage() + "\n", attributes);
|
log(formatter.format(record), attributes);
|
||||||
if (t != null) {
|
|
||||||
log(LauncherUtils.getStackTrace(t) + "\n", attributes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,6 +104,7 @@ login.noLoginTitle=Missing Account
|
|||||||
login.minecraftNotOwnedError=Sorry, Minecraft is not owned on that account.
|
login.minecraftNotOwnedError=Sorry, Minecraft is not owned on that account.
|
||||||
|
|
||||||
console.title=Messages and Errors
|
console.title=Messages and Errors
|
||||||
|
console.launcherConsoleTitle=Launcher Messages
|
||||||
console.uploadLog=Upload Log
|
console.uploadLog=Upload Log
|
||||||
console.pasteUploading=Uploading {0} bytes...\n
|
console.pasteUploading=Uploading {0} bytes...\n
|
||||||
console.pasteUploaded=Paste uploaded\: {0}\n
|
console.pasteUploaded=Paste uploaded\: {0}\n
|
||||||
@ -127,6 +128,11 @@ downloader.jobPending=...\t{0}
|
|||||||
downloader.noDownloads=No pending downloads.
|
downloader.noDownloads=No pending downloads.
|
||||||
downloader.failedCount=({0} have failed)
|
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.defaultStatus=Working...
|
||||||
progress.percentTitle=({0}%) {1}
|
progress.percentTitle=({0}%) {1}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user