From e3b42f2698189b07cb448704f7db4776c3935456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Tue, 24 Sep 2013 22:56:11 +0200 Subject: [PATCH] Issue #301 Reseting icon on clearing error log Logging errors to GUI on application startup / file load --- .../decompiler/flash/gui/ErrorLogFrame.java | 1 - .../com/jpexs/decompiler/flash/gui/Main.java | 67 ++++++++++- .../jpexs/decompiler/flash/gui/MainFrame.java | 109 +++++++----------- 3 files changed, 107 insertions(+), 70 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ErrorLogFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/ErrorLogFrame.java index 62765aaea..d798bcfda 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ErrorLogFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ErrorLogFrame.java @@ -200,7 +200,6 @@ public class ErrorLogFrame extends AppFrame { JLabel levelLabel = new JLabel(level.getName()); - levelLabel.setPreferredSize(new Dimension(75, 25)); levelLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); header.add(levelLabel); JTextArea msgLabel = new JTextArea(msg); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index 6c4ceee84..c8cd23049 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -57,7 +57,9 @@ import java.util.Locale; import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.FileHandler; +import java.util.logging.Handler; import java.util.logging.Level; +import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; import java.util.regex.Matcher; @@ -102,6 +104,7 @@ public class Main { public static LoadFromMemoryFrame loadFromMemoryFrame; public static LoadFromCacheFrame loadFromCacheFrame; public static boolean readOnly = false; + private static ErrorLogFrame errorLogFrame; public static void loadFromCache() { if (loadFromCacheFrame == null) { @@ -291,6 +294,9 @@ public class Main { @Override public void run() { mainFrame = new MainFrame(swf); + if (errorState) { + mainFrame.setErrorState(); + } } }); @@ -470,12 +476,62 @@ public class Main { } } + public static void displayErrorFrame() { + if (errorLogFrame != null) { + errorLogFrame.setVisible(true); + } + } + private static boolean errorState = false; + + private static void initGui() { + View.execInEventDispatch(new Runnable() { + @Override + public void run() { + if (errorLogFrame == null) { + errorLogFrame = new ErrorLogFrame(); + } + Logger logger = Logger.getLogger(""); + logger.addHandler(errorLogFrame.getHandler()); + logger.addHandler(new Handler() { + @Override + public void publish(final LogRecord record) { + View.execInEventDispatch(new Runnable() { + @Override + public void run() { + if (record.getLevel() == Level.SEVERE) { + errorState = true; + if (mainFrame != null) { + mainFrame.setErrorState(); + } + } + } + }); + + } + + @Override + public void flush() { + } + + @Override + public void close() throws SecurityException { + } + }); + } + }); + autoCheckForUpdates(); + offerAssociation(); + } + public static void showModeFrame() { View.execInEventDispatch(new Runnable() { @Override public void run() { if (mainFrame == null) { mainFrame = new MainFrame(null); + if (errorState) { + mainFrame.setErrorState(); + } } mainFrame.setVisible(true); } @@ -783,8 +839,7 @@ public class Main { int retryCount = 0; if (args.length < pos + 1) { - autoCheckForUpdates(); - offerAssociation(); + initGui(); showModeFrame(); } else { boolean parameterProcessed = true; @@ -1050,8 +1105,8 @@ public class Main { printCmdLineUsage(); System.exit(0); } else if (args.length == pos + 1) { - autoCheckForUpdates(); - offerAssociation(); + + initGui(); openFile(args[pos]); } else { badArguments(); @@ -1347,6 +1402,10 @@ public class Main { fileTxt.setFormatter(formatterTxt); logger.addHandler(fileTxt); + errorState = false; + if (mainFrame != null) { + mainFrame.clearErrorState(); + } } public static void initLogging(boolean debug) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 7c7b0ba83..f2c3ff451 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -158,9 +158,7 @@ import java.util.Stack; import java.util.Timer; import java.util.TimerTask; import java.util.TreeSet; -import java.util.logging.Handler; import java.util.logging.Level; -import java.util.logging.LogRecord; import java.util.logging.Logger; import javax.swing.Box; import javax.swing.BoxLayout; @@ -288,7 +286,6 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel private JTextArea fontCharactersTextArea; private JTextField fontAddCharactersField; private JButton errorNotificationButton; - private ErrorLogFrame errorLogFrame; private ComponentListener fontChangeList; private JComboBox fontSelection; private JCommandButton saveCommandButton; @@ -1054,7 +1051,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel statusPanel.add(loadingPanel, BorderLayout.WEST); statusPanel.add(statusLabel, BorderLayout.CENTER); - errorLogFrame = new ErrorLogFrame(); + errorNotificationButton = new JButton(""); errorNotificationButton.setIcon(View.getIcon("okay16")); errorNotificationButton.setBorderPainted(false); @@ -1490,66 +1487,6 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel //Opening files with drag&drop to main window enableDrop(true); - - Logger logger = Logger.getLogger(""); - logger.addHandler(errorLogFrame.getHandler()); - logger.addHandler(new Handler() { - private Timer timer = null; - private int pos = 0; - - @Override - public void publish(final LogRecord record) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (record.getLevel() == Level.SEVERE) { - if (errorNotificationButton == null) { - // todo: honfika - // why null? - return; - } - - errorNotificationButton.setIcon(View.getIcon("error16")); - errorNotificationButton.setToolTipText(translate("errors.present")); - if (timer != null) { - timer.cancel(); - } - timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - pos++; - if ((pos % 2) == 0 || (pos >= 4)) { - errorNotificationButton.setIcon(View.getIcon("error16")); - } else { - errorNotificationButton.setIcon(null); - errorNotificationButton.setSize(16, 16); - } - } - }); - - if (pos >= 4) { - cancel(); - } - } - }, 500, 500); - } - } - }); - - } - - @Override - public void flush() { - } - - @Override - public void close() throws SecurityException { - } - }); } public void enableDrop(boolean value) { @@ -2370,7 +2307,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel Main.loadFromCache(); break; case "SHOWERRORLOG": - errorLogFrame.setVisible(true); + Main.displayErrorFrame(); break; case "FONTADDCHARS": String newchars = fontAddCharactersField.getText(); @@ -3638,4 +3575,46 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel public void free() { Helper.emptyObject(this); } + + public void clearErrorState() { + errorNotificationButton.setIcon(View.getIcon("okay16")); + errorNotificationButton.setToolTipText(translate("errors.none")); + } + private Timer blinkTimer; + private int blinkPos; + + public void setErrorState() { + if (errorNotificationButton == null) { + // todo: honfika + // why null? + return; + } + errorNotificationButton.setIcon(View.getIcon("error16")); + errorNotificationButton.setToolTipText(translate("errors.present")); + if (blinkTimer != null) { + blinkTimer.cancel(); + } + blinkTimer = new Timer(); + blinkTimer.schedule(new TimerTask() { + @Override + public void run() { + View.execInEventDispatch(new Runnable() { + @Override + public void run() { + blinkPos++; + if ((blinkPos % 2) == 0 || (blinkPos >= 4)) { + errorNotificationButton.setIcon(View.getIcon("error16")); + } else { + errorNotificationButton.setIcon(null); + errorNotificationButton.setSize(16, 16); + } + } + }); + + if (blinkPos >= 4) { + cancel(); + } + } + }, 500, 500); + } }