Unify gui/console logging

This commit is contained in:
Reinhard Pointner 2016-03-09 20:48:56 +00:00
parent 78c3b6917d
commit fd1f5b17f4
16 changed files with 30 additions and 74 deletions

View File

@ -1,7 +1,5 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -23,7 +21,6 @@ import javax.swing.text.JTextComponent;
import net.filebot.util.ui.AbstractFancyListCellRenderer; import net.filebot.util.ui.AbstractFancyListCellRenderer;
import net.filebot.util.ui.SwingUI; import net.filebot.util.ui.SwingUI;
class HighlightListCellRenderer extends AbstractFancyListCellRenderer { class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
protected final JTextComponent textComponent = new JTextField(); protected final JTextComponent textComponent = new JTextField();
@ -31,7 +28,6 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
protected final Pattern pattern; protected final Pattern pattern;
protected final Highlighter.HighlightPainter highlightPainter; protected final Highlighter.HighlightPainter highlightPainter;
public HighlightListCellRenderer(Pattern pattern, Highlighter.HighlightPainter highlightPainter, int padding) { public HighlightListCellRenderer(Pattern pattern, Highlighter.HighlightPainter highlightPainter, int padding) {
super(new Insets(0, 0, 0, 0)); super(new Insets(0, 0, 0, 0));
@ -50,7 +46,6 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
textComponent.getDocument().addDocumentListener(new HighlightUpdateListener()); textComponent.getDocument().addDocumentListener(new HighlightUpdateListener());
} }
@Override @Override
protected void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { protected void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus); super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
@ -58,7 +53,6 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
textComponent.setText(value.toString()); textComponent.setText(value.toString());
} }
protected void updateHighlighter() { protected void updateHighlighter() {
textComponent.getHighlighter().removeAllHighlights(); textComponent.getHighlighter().removeAllHighlights();
@ -68,13 +62,12 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
try { try {
textComponent.getHighlighter().addHighlight(matcher.start(0), matcher.end(0), highlightPainter); textComponent.getHighlighter().addHighlight(matcher.start(0), matcher.end(0), highlightPainter);
} catch (BadLocationException e) { } catch (BadLocationException e) {
//should not happen // should not happen
debug.log(Level.SEVERE, e.toString(), e); debug.log(Level.SEVERE, e.getMessage(), e);
} }
} }
} }
@Override @Override
public void setForeground(Color fg) { public void setForeground(Color fg) {
super.setForeground(fg); super.setForeground(fg);
@ -85,7 +78,6 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
} }
} }
private class HighlightUpdateListener implements DocumentListener { private class HighlightUpdateListener implements DocumentListener {
@Override @Override
@ -93,13 +85,11 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
updateHighlighter(); updateHighlighter();
} }
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
updateHighlighter(); updateHighlighter();
} }
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
updateHighlighter(); updateHighlighter();

View File

@ -65,7 +65,7 @@ class MatchAction extends AbstractAction {
// display progress dialog and stop blocking EDT // display progress dialog and stop blocking EDT
dialog.setVisible(true); dialog.setVisible(true);
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.SEVERE, e.toString(), e); debug.log(Level.SEVERE, e.getMessage(), e);
} finally { } finally {
window.setCursor(Cursor.getDefaultCursor()); window.setCursor(Cursor.getDefaultCursor());
} }
@ -121,7 +121,7 @@ class MatchAction extends AbstractAction {
// insert objects that could not be matched at the end of the model // insert objects that could not be matched at the end of the model
model.addAll(matcher.remainingValues(), matcher.remainingCandidates()); model.addAll(matcher.remainingValues(), matcher.remainingCandidates());
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.SEVERE, e.toString(), e); debug.log(Level.SEVERE, e.getMessage(), e);
} }
} }

View File

@ -272,7 +272,7 @@ public class RenamePanel extends JComponent {
UserFiles.revealFiles(list.getSelectedValuesList()); UserFiles.revealFiles(list.getSelectedValuesList());
} }
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.getMessage()); debug.log(Level.WARNING, e.getMessage(), e);
} finally { } finally {
getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor()); getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor());
} }
@ -368,7 +368,7 @@ public class RenamePanel extends JComponent {
} }
} }
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.getMessage()); debug.log(Level.WARNING, e.getMessage(), e);
} }
} }
}); });
@ -388,7 +388,7 @@ public class RenamePanel extends JComponent {
Preset p = (Preset) JsonReader.jsonToJava(it); Preset p = (Preset) JsonReader.jsonToJava(it);
actionPopup.add(new ApplyPresetAction(p)); actionPopup.add(new ApplyPresetAction(p));
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.toString()); debug.log(Level.SEVERE, e.getMessage(), e);
} }
} }
actionPopup.addSeparator(); actionPopup.addSeparator();
@ -590,7 +590,7 @@ public class RenamePanel extends JComponent {
try { try {
initMode = Mode.valueOf(persistentLastFormatState.getValue()); initMode = Mode.valueOf(persistentLastFormatState.getValue());
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.getMessage()); debug.log(Level.WARNING, e.getMessage(), e);
} }
} }

View File

@ -1,7 +1,5 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
@ -37,7 +35,6 @@ import javax.swing.text.BadLocationException;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
class ValidateDialog extends JDialog { class ValidateDialog extends JDialog {
private final JList list; private final JList list;
@ -46,7 +43,6 @@ class ValidateDialog extends JDialog {
private boolean cancelled = true; private boolean cancelled = true;
public ValidateDialog(Window owner, Collection<File> source) { public ValidateDialog(Window owner, Collection<File> source) {
super(owner, "Invalid Names", ModalityType.DOCUMENT_MODAL); super(owner, "Invalid Names", ModalityType.DOCUMENT_MODAL);
@ -73,8 +69,8 @@ class ValidateDialog extends JDialog {
try { try {
textComponent.getHighlighter().addHighlight(matcher.start(0), matcher.end(0), highlightPainter); textComponent.getHighlighter().addHighlight(matcher.start(0), matcher.end(0), highlightPainter);
} catch (BadLocationException e) { } catch (BadLocationException e) {
//should not happen // should not happen
debug.log(Level.SEVERE, e.toString(), e); debug.log(Level.SEVERE, e.getMessage(), e);
} }
} }
} }
@ -101,17 +97,14 @@ class ValidateDialog extends JDialog {
pack(); pack();
} }
public List<File> getModel() { public List<File> getModel() {
return unmodifiableList(Arrays.asList(model)); return unmodifiableList(Arrays.asList(model));
} }
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }
private void finish(boolean cancelled) { private void finish(boolean cancelled) {
this.cancelled = cancelled; this.cancelled = cancelled;
@ -156,7 +149,6 @@ class ValidateDialog extends JDialog {
} }
}; };
public static boolean validate(Component parent, List<File> source) { public static boolean validate(Component parent, List<File> source) {
IndexView<File> invalidFilePaths = new IndexView<File>(source); IndexView<File> invalidFilePaths = new IndexView<File>(source);
@ -193,24 +185,20 @@ class ValidateDialog extends JDialog {
return true; return true;
} }
private static class IndexView<E> extends AbstractList<E> { private static class IndexView<E> extends AbstractList<E> {
private final List<Integer> mapping = new ArrayList<Integer>(); private final List<Integer> mapping = new ArrayList<Integer>();
private final List<E> source; private final List<E> source;
public IndexView(List<E> source) { public IndexView(List<E> source) {
this.source = source; this.source = source;
} }
public boolean addIndex(int index) { public boolean addIndex(int index) {
return mapping.add(index); return mapping.add(index);
} }
@Override @Override
public E get(int index) { public E get(int index) {
int sourceIndex = mapping.get(index); int sourceIndex = mapping.get(index);
@ -221,13 +209,11 @@ class ValidateDialog extends JDialog {
return null; return null;
} }
@Override @Override
public E set(int index, E element) { public E set(int index, E element) {
return source.set(mapping.get(index), element); return source.set(mapping.get(index), element);
} }
@Override @Override
public int size() { public int size() {
return mapping.size(); return mapping.size();

View File

@ -785,7 +785,7 @@ class SubtitleAutoMatchDialog extends JDialog {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
// log and ignore // log and ignore
debug.log(Level.WARNING, e.getMessage()); debug.warning(e.getMessage());
} }
} }

View File

@ -376,7 +376,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
// logout from test session // logout from test session
osdb.logout(); osdb.logout();
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.toString()); debug.warning(e.getMessage());
} }
}); });
} else if (osdbUser.getText().isEmpty()) { } else if (osdbUser.getText().isEmpty()) {

View File

@ -9,7 +9,6 @@ import java.awt.Cursor;
import java.io.File; import java.io.File;
import java.util.EventObject; import java.util.EventObject;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.event.CellEditorListener; import javax.swing.event.CellEditorListener;
@ -86,7 +85,7 @@ class MovieEditor implements TableCellEditor {
// print error message // print error message
if (error != null) { if (error != null) {
debug.log(Level.WARNING, error.toString()); debug.warning(error.getMessage());
} }
} }

View File

@ -138,7 +138,7 @@ public class FileTransferable implements Transferable {
files.add(file); files.add(file);
} catch (Throwable e) { } catch (Throwable e) {
// URISyntaxException, IllegalArgumentException, FileNotFoundException, LinkageError, etc // URISyntaxException, IllegalArgumentException, FileNotFoundException, LinkageError, etc
debug.log(Level.WARNING, "Invalid file URI: " + line); debug.warning("Invalid file URI: " + line);
} }
} }

View File

@ -56,7 +56,7 @@ public class SaveAction extends AbstractAction {
} }
} }
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.SEVERE, e.toString(), e); debug.log(Level.SEVERE, e.getMessage(), e);
} }
} }
} }

View File

@ -1,7 +1,5 @@
package net.filebot.ui.transfer; package net.filebot.ui.transfer;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
@ -11,15 +9,12 @@ import java.util.logging.Level;
import javax.swing.TransferHandler; import javax.swing.TransferHandler;
import javax.swing.TransferHandler.TransferSupport; import javax.swing.TransferHandler.TransferSupport;
public abstract class TransferablePolicy { public abstract class TransferablePolicy {
public abstract boolean accept(Transferable tr) throws Exception; public abstract boolean accept(Transferable tr) throws Exception;
public abstract void handleTransferable(Transferable tr, TransferAction action) throws Exception; public abstract void handleTransferable(Transferable tr, TransferAction action) throws Exception;
public boolean canImport(TransferSupport support) { public boolean canImport(TransferSupport support) {
if (support.isDrop()) { if (support.isDrop()) {
support.setShowDropLocation(false); support.setShowDropLocation(false);
@ -34,12 +29,11 @@ public abstract class TransferablePolicy {
// just assume that the transferable will be accepted, accept will be called in importData again anyway // just assume that the transferable will be accepted, accept will be called in importData again anyway
return true; return true;
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.toString(), e); debug.log(Level.WARNING, e.getMessage(), e);
return false; return false;
} }
} }
public boolean importData(TransferSupport support) { public boolean importData(TransferSupport support) {
Transferable transferable = support.getTransferable(); Transferable transferable = support.getTransferable();
@ -49,14 +43,13 @@ public abstract class TransferablePolicy {
return true; return true;
} }
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.toString(), e); debug.log(Level.WARNING, e.getMessage(), e);
} }
// transferable was not accepted, or transfer failed // transferable was not accepted, or transfer failed
return false; return false;
} }
protected TransferAction getTransferAction(TransferSupport support) { protected TransferAction getTransferAction(TransferSupport support) {
if (support.isDrop()) { if (support.isDrop()) {
return TransferAction.fromDnDConstant(support.getDropAction()); return TransferAction.fromDnDConstant(support.getDropAction());
@ -66,25 +59,19 @@ public abstract class TransferablePolicy {
return TransferAction.PUT; return TransferAction.PUT;
} }
public static enum TransferAction { public static enum TransferAction {
PUT(TransferHandler.MOVE), PUT(TransferHandler.MOVE), ADD(TransferHandler.COPY), LINK(TransferHandler.LINK);
ADD(TransferHandler.COPY),
LINK(TransferHandler.LINK);
private final int dndConstant; private final int dndConstant;
private TransferAction(int dndConstant) { private TransferAction(int dndConstant) {
this.dndConstant = dndConstant; this.dndConstant = dndConstant;
} }
public int getDnDConstant() { public int getDnDConstant() {
return dndConstant; return dndConstant;
} }
public static TransferAction fromDnDConstant(int dndConstant) { public static TransferAction fromDnDConstant(int dndConstant) {
for (TransferAction action : values()) { for (TransferAction action : values()) {
if (dndConstant == action.dndConstant) if (dndConstant == action.dndConstant)

View File

@ -42,7 +42,6 @@ import java.util.Scanner;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.logging.Level;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -67,7 +66,7 @@ public final class FileUtilities {
try { try {
return Files.move(source.toPath(), destination.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile(); return Files.move(source.toPath(), destination.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile();
} catch (AtomicMoveNotSupportedException e) { } catch (AtomicMoveNotSupportedException e) {
debug.log(Level.WARNING, e.toString()); debug.warning(e.getMessage());
} }
} }

View File

@ -307,7 +307,7 @@ public class PreferencesMap<T> implements Map<String, T> {
try { try {
prefs.flush(); prefs.flush();
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.toString()); debug.log(Level.WARNING, e.getMessage(), e);
} }
} }

View File

@ -34,19 +34,15 @@ public abstract class Timer implements Runnable {
addShutdownHook(); addShutdownHook();
} catch (Exception e) { } catch (Exception e) {
// may fail if running with restricted permissions // may fail if running with restricted permissions
debug.log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage()); debug.log(Level.WARNING, e.getMessage(), e);
} }
// remove shutdown hook after execution // remove shutdown hook after execution
runnable = new Runnable() { runnable = () -> {
try {
@Override Timer.this.run();
public void run() { } finally {
try { cancel();
Timer.this.run();
} finally {
cancel();
}
} }
}; };
} else { } else {
@ -55,7 +51,7 @@ public abstract class Timer implements Runnable {
removeShutdownHook(); removeShutdownHook();
} catch (Exception e) { } catch (Exception e) {
// may fail if running with restricted permissions // may fail if running with restricted permissions
debug.log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage()); debug.log(Level.WARNING, e.getMessage(), e);
} }
} }

View File

@ -108,7 +108,7 @@ public class LinkButton extends JButton {
} }
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
debug.log(Level.SEVERE, e.toString(), e); debug.log(Level.SEVERE, e.getMessage(), e);
} }
} }
} }

View File

@ -241,7 +241,7 @@ public class AcoustIDClient implements MusicIdentificationService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.WARNING, e.toString(), e); debug.log(Level.WARNING, e.getMessage(), e);
} }
return n; return n;
} }

View File

@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@ -279,7 +278,7 @@ public final class WebRequest {
try { try {
return Charset.forName(matcher.group(1)); return Charset.forName(matcher.group(1));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
debug.log(Level.WARNING, "Illegal charset: " + contentType); debug.warning("Illegal charset: " + contentType);
} }
} }