mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-16 08:31:54 +00:00
gui - error log
This commit is contained in:
177
trunk/src/com/jpexs/decompiler/flash/gui/ErrorLogFrame.java
Normal file
177
trunk/src/com/jpexs/decompiler/flash/gui/ErrorLogFrame.java
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2013 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ErrorLogFrame extends AppFrame {
|
||||
|
||||
private JPanel logView = new JPanel();
|
||||
|
||||
|
||||
private Handler handler;
|
||||
|
||||
public Handler getHandler(){
|
||||
return handler;
|
||||
}
|
||||
|
||||
public ErrorLogFrame() {
|
||||
setTitle("Log");
|
||||
setSize(500, 400);
|
||||
View.centerScreen(this);
|
||||
View.setWindowIcon(this);
|
||||
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
Container cnt = getContentPane();
|
||||
cnt.setLayout(new BorderLayout());
|
||||
|
||||
logView.setLayout(new ListLayout());
|
||||
|
||||
cnt.add(new JScrollPane(logView));
|
||||
handler = new Handler() {
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
log(record.getLevel(),record.getMessage(),record.getThrown());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
|
||||
}
|
||||
};
|
||||
//setAlwaysOnTop(true);
|
||||
}
|
||||
|
||||
|
||||
public void log(Level level, String msg, String detail) {
|
||||
if (detail == null) {
|
||||
log(level, msg, (JComponent) null);
|
||||
return;
|
||||
}
|
||||
final JTextArea detailTextArea = new JTextArea(detail);
|
||||
detailTextArea.setEditable(false);
|
||||
detailTextArea.setOpaque(false);
|
||||
log(level, msg, detailTextArea);
|
||||
}
|
||||
|
||||
private void log(Level level, String msg, final JComponent detail) {
|
||||
JPanel pan = new JPanel();
|
||||
pan.setLayout(new ListLayout());
|
||||
|
||||
JPanel header = new JPanel();
|
||||
header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
|
||||
final JToggleButton expandButton = new JToggleButton(View.getIcon("expand16"));
|
||||
expandButton.setFocusPainted(false);
|
||||
expandButton.setBorderPainted(false);
|
||||
expandButton.setFocusable(false);
|
||||
expandButton.setContentAreaFilled(false);
|
||||
final JScrollPane scrollPane;
|
||||
if (detail != null) {
|
||||
scrollPane=new JScrollPane(detail);
|
||||
scrollPane.setAlignmentX(0f);
|
||||
scrollPane.setMinimumSize(new Dimension(getWidth(),500));
|
||||
}else{
|
||||
scrollPane =null;
|
||||
}
|
||||
|
||||
expandButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
if (detail != null) {
|
||||
expandButton.setMargin(new Insets(2, 2, 2, 2));
|
||||
expandButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
scrollPane.setVisible(expandButton.isSelected());
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/YYYY HH:mm:ss");
|
||||
|
||||
JLabel dateLabel = new JLabel(format.format(new Date()));
|
||||
dateLabel.setPreferredSize(new Dimension(100, 25));
|
||||
dateLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
header.add(dateLabel);
|
||||
|
||||
|
||||
|
||||
JLabel levelLabel = new JLabel(level.getName());
|
||||
levelLabel.setPreferredSize(new Dimension(300, 25));
|
||||
levelLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
header.add(levelLabel);
|
||||
JLabel msgLabel = new JLabel(msg);
|
||||
msgLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
header.add(msgLabel);
|
||||
header.setAlignmentX(0f);
|
||||
if (detail != null) {
|
||||
header.add(expandButton);
|
||||
}
|
||||
pan.add(header);
|
||||
if (detail != null) {
|
||||
pan.add(scrollPane);
|
||||
scrollPane.setVisible(false);
|
||||
}
|
||||
//pan.setPreferredSize(new Dimension(getWidth(), 30));
|
||||
pan.setAlignmentX(0f);
|
||||
//curGBConstraints.weighty = 1;
|
||||
logView.add(pan);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void log(Level level, String msg) {
|
||||
log(level, msg, (String) null);
|
||||
}
|
||||
|
||||
public void log(Level level, String msg, Throwable ex) {
|
||||
StringWriter sw = new StringWriter();
|
||||
ex.printStackTrace(new PrintWriter(sw));
|
||||
log(level, msg, sw.toString());
|
||||
}
|
||||
}
|
||||
100
trunk/src/com/jpexs/decompiler/flash/gui/ListLayout.java
Normal file
100
trunk/src/com/jpexs/decompiler/flash/gui/ListLayout.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2013 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ListLayout implements LayoutManager {
|
||||
|
||||
private int border;
|
||||
|
||||
public ListLayout() {
|
||||
this(5);
|
||||
}
|
||||
|
||||
public ListLayout(int border) {
|
||||
this.border = border;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
int h = 0;
|
||||
int maxw = 0;
|
||||
boolean first = true;
|
||||
for (Component c : parent.getComponents()) {
|
||||
if(!c.isVisible()){
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
h += border;
|
||||
}
|
||||
Dimension pref=c.getPreferredSize();
|
||||
if(pref.width > maxw){
|
||||
maxw = pref.width;
|
||||
}
|
||||
h += pref.height;
|
||||
first = false;
|
||||
}
|
||||
Insets ins = parent.getInsets();
|
||||
return new Dimension(maxw, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return preferredLayoutSize(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
Dimension dim=preferredLayoutSize(parent);
|
||||
int top = 0;
|
||||
Insets ins = parent.getInsets();
|
||||
boolean first = true;
|
||||
for (Component c : parent.getComponents()) {
|
||||
if(!c.isVisible()){
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
top += border;
|
||||
}
|
||||
Dimension pref=c.getPreferredSize();
|
||||
c.setBounds(0, top, dim.width, pref.height);
|
||||
top += pref.height;
|
||||
first = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,7 @@ import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Insets;
|
||||
@@ -136,7 +137,9 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
@@ -235,6 +238,8 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
|
||||
private JLabel fontLeadingLabel;
|
||||
private JLabel fontCharactersLabel;
|
||||
private JTextField fontAddCharactersField;
|
||||
private JButton errorNotificationButton;
|
||||
private ErrorLogFrame errorLogFrame;
|
||||
|
||||
public void setPercent(int percent) {
|
||||
progressBar.setValue(percent);
|
||||
@@ -751,6 +756,21 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
|
||||
statusPanel.setLayout(new BorderLayout());
|
||||
statusPanel.add(loadingPanel, BorderLayout.WEST);
|
||||
statusPanel.add(statusLabel, BorderLayout.CENTER);
|
||||
|
||||
errorLogFrame = new ErrorLogFrame();
|
||||
errorNotificationButton = new JButton("");
|
||||
errorNotificationButton.setIcon(View.getIcon("okay16"));
|
||||
errorNotificationButton.setBorderPainted(false);
|
||||
errorNotificationButton.setFocusPainted(false);
|
||||
errorNotificationButton.setContentAreaFilled(false);
|
||||
errorNotificationButton.setMargin(new Insets(2, 2, 2, 2));
|
||||
errorNotificationButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
errorNotificationButton.setActionCommand("SHOWERRORLOG");
|
||||
errorNotificationButton.addActionListener(this);
|
||||
errorNotificationButton.setToolTipText("There are no errors in the log");
|
||||
statusPanel.add(errorNotificationButton, BorderLayout.EAST);
|
||||
|
||||
|
||||
loadingPanel.setVisible(false);
|
||||
cnt.add(statusPanel, BorderLayout.SOUTH);
|
||||
|
||||
@@ -1027,6 +1047,26 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
|
||||
|
||||
//Opening files with drag&drop to main window
|
||||
enableDrop(true);
|
||||
|
||||
Logger logger = Logger.getLogger("");
|
||||
logger.addHandler(errorLogFrame.getHandler());
|
||||
logger.addHandler(new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (record.getLevel() == Level.SEVERE) {
|
||||
errorNotificationButton.setIcon(View.getIcon("error16"));
|
||||
errorNotificationButton.setToolTipText("There are ERRORS in the log");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void enableDrop(boolean value) {
|
||||
@@ -1662,6 +1702,9 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
switch (e.getActionCommand()) {
|
||||
case "SHOWERRORLOG":
|
||||
errorLogFrame.setVisible(true);
|
||||
break;
|
||||
case "FONTADDCHARS":
|
||||
String newchars = fontAddCharactersField.getText();
|
||||
if (oldValue instanceof FontTag) {
|
||||
|
||||
Reference in New Issue
Block a user