1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

+ fixed UI logging / user notifications

This commit is contained in:
Reinhard Pointner 2011-08-10 18:46:19 +00:00
parent 7c3b3a226f
commit 6f394dfadf
15 changed files with 72 additions and 64 deletions

View File

@ -13,7 +13,6 @@ import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -26,7 +25,6 @@ import org.kohsuke.args4j.CmdLineParser;
import net.sf.ehcache.CacheManager;
import net.sourceforge.filebot.format.ExpressionFormat;
import net.sourceforge.filebot.ui.MainFrame;
import net.sourceforge.filebot.ui.NotificationLoggingHandler;
import net.sourceforge.filebot.ui.SinglePanelFrame;
import net.sourceforge.filebot.ui.panel.sfv.SfvPanelBuilder;
@ -38,7 +36,6 @@ public class Main {
*/
public static void main(String... args) throws Exception {
// initialize this stuff before anything else
initializeLogging();
initializeCache();
initializeSecurityManager();
@ -121,23 +118,6 @@ public class Main {
}
private static void initializeLogging() {
Logger uiLogger = Logger.getLogger("ui");
// don't use parent handlers
uiLogger.setUseParentHandlers(false);
// ui handler
uiLogger.addHandler(new NotificationLoggingHandler());
// console handler (for warnings and errors only)
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.WARNING);
uiLogger.addHandler(consoleHandler);
}
/**
* Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk
*/

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui;
import static javax.swing.ScrollPaneConstants.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
import java.awt.Window;
@ -197,7 +198,7 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
switch (results.size()) {
case 0:
Logger.getLogger("ui").log(Level.WARNING, String.format("'%s' has not been found.", requestProcessor.request.getSearchText()));
UILogger.log(Level.WARNING, String.format("'%s' has not been found.", requestProcessor.request.getSearchText()));
break;
case 1:
selectedSearchResult = results.iterator().next();
@ -227,8 +228,7 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
new FetchTask(requestProcessor).execute();
} catch (Exception e) {
tab.close();
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
}
}
@ -278,13 +278,12 @@ public abstract class AbstractSearchPanel<S, E> extends JComponent {
// close tab if no elements were fetched
if (get().size() <= 0) {
Logger.getLogger("ui").warning(statusMessage);
UILogger.warning(statusMessage);
tab.close();
}
} catch (Exception e) {
tab.close();
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
} finally {
tab.setLoading(false);
}

View File

@ -5,9 +5,11 @@ package net.sourceforge.filebot.ui;
import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.tuned.ui.notification.Direction.*;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
@ -19,18 +21,39 @@ import net.sourceforge.tuned.ui.notification.NotificationManager;
import net.sourceforge.tuned.ui.notification.QueueNotificationLayout;
public class NotificationLoggingHandler extends Handler {
public class NotificationLogging extends Handler {
public static final Logger UILogger = createNotificationLogger("net.sourceforge.filebot.ui");
private static Logger createNotificationLogger(String name) {
Logger log = Logger.getLogger(name);
// don't use parent handlers
log.setUseParentHandlers(false);
// ui handler
log.addHandler(new NotificationLogging());
// console handler (for warnings and errors only)
ConsoleHandler console = new ConsoleHandler();
console.setLevel(Level.WARNING);
log.addHandler(console);
return log;
}
public final NotificationManager notificationManager;
public final int timeout = 2500;
public NotificationLoggingHandler() {
public NotificationLogging() {
this(new NotificationManager(new QueueNotificationLayout(NORTH, SOUTH)));
}
public NotificationLoggingHandler(NotificationManager notificationManager) {
public NotificationLogging(NotificationManager notificationManager) {
this.notificationManager = notificationManager;
}

View File

@ -2,6 +2,8 @@
package net.sourceforge.filebot.ui.panel.analyze;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.event.ActionEvent;
@ -18,7 +20,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -153,11 +154,12 @@ public class FileTree extends JTree {
Desktop.getDesktop().open((File) file);
}
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
}
}
}
private final Action expandAction = new AbstractAction("Expand all", ResourceManager.getIcon("tree.expand")) {
@Override

View File

@ -2,10 +2,11 @@
package net.sourceforge.filebot.ui.panel.analyze;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.filebot.ui.panel.analyze.FileTree.AbstractTreeNode;
import net.sourceforge.filebot.ui.panel.analyze.FileTree.FileNode;
@ -54,7 +55,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<Abstra
@Override
protected void process(Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
}

View File

@ -4,6 +4,7 @@ package net.sourceforge.filebot.ui.panel.list;
import static java.awt.Font.*;
import static java.lang.Math.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import java.awt.BorderLayout;
import java.awt.Font;
@ -14,7 +15,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Bindings;
import javax.script.SimpleBindings;
@ -137,7 +137,7 @@ public class ListPanel extends JComponent {
list.getModel().clear();
list.getModel().addAll(names);
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getMessage(e), e);
}
}
};

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.rename;
import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
import java.awt.Color;
@ -26,7 +27,6 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Compilable;
import javax.script.ScriptException;
@ -277,10 +277,10 @@ class EpisodeBindingDialog extends JDialog {
// check episode and media file
if (getEpisode() == null) {
// illegal episode string
Logger.getLogger("ui").warning(String.format("Failed to parse episode: '%s'", episodeTextField.getText()));
UILogger.warning(String.format("Failed to parse episode: '%s'", episodeTextField.getText()));
} else if (getMediaFile() == null && !mediaFileTextField.getText().isEmpty()) {
// illegal file path
Logger.getLogger("ui").warning(String.format("Invalid media file: '%s'", mediaFileTextField.getText()));
UILogger.warning(String.format("Invalid media file: '%s'", mediaFileTextField.getText()));
} else {
// everything seems to be in order
finish(Option.APPROVE);
@ -311,7 +311,7 @@ class EpisodeBindingDialog extends JDialog {
}
}
} catch (LinkageError e) {
Logger.getLogger("ui").log(Level.SEVERE, "Unable to load native library 'mediainfo'", e);
UILogger.log(Level.SEVERE, "Unable to load native library 'mediainfo'", e);
}
// could not retrieve media info

View File

@ -4,6 +4,7 @@ package net.sourceforge.filebot.ui.panel.rename;
import static java.awt.Font.*;
import static javax.swing.BorderFactory.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
import java.awt.Color;
@ -536,7 +537,7 @@ class EpisodeFormatDialog extends JDialog {
finish(Option.APPROVE);
} catch (ScriptException e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e));
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e));
}
}
};

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.rename;
import static java.util.Collections.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
import java.awt.Window;
@ -15,7 +16,6 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
@ -50,11 +50,11 @@ class RenameAction extends AbstractAction {
// renamed all matches successfully
if (renameLog.size() > 0) {
Logger.getLogger("ui").info(String.format("%d files renamed.", renameLog.size()));
UILogger.info(String.format("%d files renamed.", renameLog.size()));
}
} catch (Exception e) {
// could not rename one of the files, revert all changes
Logger.getLogger("ui").warning(e.getMessage());
UILogger.warning(e.getMessage());
// revert rename operations in reverse order
for (ListIterator<Entry<File, String>> iterator = renameLog.listIterator(renameLog.size()); iterator.hasPrevious();) {
@ -69,7 +69,7 @@ class RenameAction extends AbstractAction {
iterator.remove();
} else {
// failed to revert rename operation
Logger.getLogger("ui").severe("Failed to revert file: " + mapping.getValue());
UILogger.severe("Failed to revert file: " + mapping.getValue());
}
}
}

View File

@ -5,6 +5,7 @@ package net.sourceforge.filebot.ui.panel.rename;
import static javax.swing.JOptionPane.*;
import static javax.swing.SwingUtilities.*;
import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.tuned.ui.LoadingOverlayPane.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
@ -19,7 +20,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -368,7 +368,7 @@ public class RenamePanel extends JComponent {
// add remaining file entries
renameModel.files().addAll(remainingFiles);
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
} finally {
// auto-match finished
namesList.firePropertyChange(LOADING_PROPERTY, true, false);

View File

@ -4,6 +4,7 @@ package net.sourceforge.filebot.ui.panel.sfv;
import static java.util.Collections.*;
import static net.sourceforge.filebot.hash.VerificationUtilities.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import java.io.File;
import java.io.IOException;
@ -13,7 +14,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.filebot.MediaTypes;
import net.sourceforge.filebot.hash.HashType;
@ -65,7 +65,7 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
@Override
protected void process(Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
}

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.subtitle;
import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.filebot.ui.panel.subtitle.SubtitleUtilities.*;
import static net.sourceforge.tuned.FileUtilities.*;
@ -18,7 +19,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
@ -240,7 +240,7 @@ class SubtitleDownloadComponent extends JComponent {
} catch (CancellationException e) {
// ignore cancellation
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e);
// reset download
subtitle.reset();
@ -268,7 +268,7 @@ class SubtitleDownloadComponent extends JComponent {
}
}
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, e.getMessage(), e);
UILogger.log(Level.WARNING, e.getMessage(), e);
}
}
@ -310,7 +310,7 @@ class SubtitleDownloadComponent extends JComponent {
}
}
} catch (IOException e) {
Logger.getLogger("ui").log(Level.WARNING, e.getMessage(), e);
UILogger.log(Level.WARNING, e.getMessage(), e);
}
}

View File

@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.subtitle;
import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.filebot.ui.transfer.FileTransferable.*;
import static net.sourceforge.tuned.FileUtilities.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*;
@ -24,7 +25,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.JButton;
@ -219,7 +219,7 @@ abstract class SubtitleDropTarget extends JButton {
try {
dtde.dropComplete(handleDrop(getFilesFromTransferable(dtde.getTransferable())));
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, e.getMessage(), e);
UILogger.log(Level.WARNING, e.getMessage(), e);
}
// reset to default state

View File

@ -4,6 +4,7 @@ package net.sourceforge.filebot.ui.panel.subtitle;
import static javax.swing.BorderFactory.*;
import static javax.swing.JOptionPane.*;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import static net.sourceforge.filebot.ui.panel.subtitle.SubtitleUtilities.*;
import java.awt.Color;
@ -715,7 +716,7 @@ class VideoHashSubtitleDownloadDialog extends JDialog {
return destination;
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, e.getMessage(), e);
UILogger.log(Level.WARNING, e.getMessage(), e);
}
return null;

View File

@ -2,10 +2,11 @@
package net.sourceforge.filebot.ui.transfer;
import static net.sourceforge.filebot.ui.NotificationLogging.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Icon;
@ -73,7 +74,7 @@ public class LoadAction extends AbstractAction {
transferablePolicy.handleTransferable(transferable, getTransferAction(evt));
}
} catch (Exception e) {
Logger.getLogger("ui").log(Level.WARNING, e.getMessage(), e);
UILogger.log(Level.WARNING, e.getMessage(), e);
}
// remember last location