From 75770cc03d63cddb3731b7b745c25756020d2bb5 Mon Sep 17 00:00:00 2001 From: codistmonk Date: Sat, 3 Jul 2010 13:57:42 +0000 Subject: [PATCH] [SubtitlesAdjuster] Did modifications to put application information (name, version, copyright) in context. That way, SubtitlesAdjuster's code is easier to reuse. git-svn-id: https://aprog.svn.sourceforge.net/svnroot/aprog/trunk@86 7cbf5e2b-b55d-4b93-acdd-c0d7b961df51 --- .../aprog/subtitlesadjuster/Actions.java | 17 +++++++++------ .../aprog/subtitlesadjuster/Constants.java | 15 +++++++++++++ .../aprog/subtitlesadjuster/SubtitlesAdjuster.java | 25 ++++++++++++++++------ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Actions.java b/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Actions.java index de82726..f510c02 100644 --- a/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Actions.java +++ b/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Actions.java @@ -26,7 +26,6 @@ package net.sourceforge.aprog.subtitlesadjuster; import static net.sourceforge.aprog.i18n.Messages.*; import static net.sourceforge.aprog.subtitlesadjuster.Components.*; -import static net.sourceforge.aprog.subtitlesadjuster.Constants.*; import static net.sourceforge.aprog.subtitlesadjuster.Constants.Variables.*; import java.awt.Component; @@ -63,8 +62,10 @@ public final class Actions { public static final void showAboutDialog(final Context context) { JOptionPane.showMessageDialog( (Component) context.get(MAIN_FRAME), - APPLICATION_NAME + "\n" + APPLICATION_VERSION + "\n" + APPLICATION_COPYRIGHT, - translate("About $0", APPLICATION_NAME), + context.get(APPLICATION_NAME) + "\n" + + context.get(APPLICATION_VERSION) + "\n" + + context.get(APPLICATION_COPYRIGHT), + translate("About $0", context.get(APPLICATION_NAME)), JOptionPane.INFORMATION_MESSAGE); } @@ -145,21 +146,23 @@ public final class Actions { JOptionPane.showMessageDialog( (Component) context.get(MAIN_FRAME), translate("Not implemented"), - APPLICATION_NAME, + context.get(APPLICATION_NAME).toString(), JOptionPane.INFORMATION_MESSAGE); } /** * + * @param context + *
Not null * @param throwable *
Not null */ - public static final void showErrorMessage(final Throwable throwable) { + public static final void showErrorMessage(final Context context, final Throwable throwable) { if (SwingTools.canInvokeLaterThisMethodInAWT(null, throwable)) { JOptionPane.showMessageDialog( null, newErrorMessagePanel(throwable), - APPLICATION_NAME, + context.get(APPLICATION_NAME).toString(), JOptionPane.ERROR_MESSAGE); } } @@ -184,7 +187,7 @@ public final class Actions { final File file = context.get(FILE); final Boolean fileModified = context.get(FILE_MODIFIED); - return file == null ? APPLICATION_NAME : file.getName() + (fileModified ? "*" : ""); + return file == null ? context.get(APPLICATION_NAME).toString() : file.getName() + (fileModified ? "*" : ""); } } diff --git a/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Constants.java b/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Constants.java index 1cae059..138d7d6 100644 --- a/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Constants.java +++ b/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/Constants.java @@ -69,6 +69,21 @@ public final class Constants { /** * {@value}. */ + public static final String APPLICATION_NAME = "application.name"; + + /** + * {@value}. + */ + public static final String APPLICATION_VERSION = "application.version"; + + /** + * {@value}. + */ + public static final String APPLICATION_COPYRIGHT = "application.copyright"; + + /** + * {@value}. + */ public static final String MAIN_FRAME = "mainFrame"; /** diff --git a/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/SubtitlesAdjuster.java b/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/SubtitlesAdjuster.java index c856ff0..8970527 100644 --- a/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/SubtitlesAdjuster.java +++ b/SubtitlesAdjuster/src/net/sourceforge/aprog/subtitlesadjuster/SubtitlesAdjuster.java @@ -25,7 +25,6 @@ package net.sourceforge.aprog.subtitlesadjuster; import static net.sourceforge.aprog.i18n.Messages.*; -import static net.sourceforge.aprog.subtitlesadjuster.Constants.*; import static net.sourceforge.aprog.subtitlesadjuster.Constants.Variables.*; import static net.sourceforge.aprog.subtitlesadjuster.SubtitlesAdjusterTools.*; import static net.sourceforge.aprog.swing.SwingTools.*; @@ -51,7 +50,7 @@ public final class SubtitlesAdjuster { } static { - MacAdapterTools.setApplicationName(APPLICATION_NAME); + MacAdapterTools.setApplicationName(Constants.APPLICATION_NAME); useSystemLookAndFeel(); setMessagesBase(getCallerPackagePath() + "Messages"); } @@ -64,10 +63,12 @@ public final class SubtitlesAdjuster { */ public static final void main(final String[] arguments) { if (canInvokeLaterThisMethodInAWT(null, (Object) arguments)) { + final Context context = newContext(); + // FIXME The following doesn't seem to work well on Windows XP - Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler()); + Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler(context)); - Components.newMainFrame(newContext()).setVisible(true); + Components.newMainFrame(context).setVisible(true); } } @@ -80,6 +81,9 @@ public final class SubtitlesAdjuster { public static final Context newContext() { final Context result = new Context(); + result.set(APPLICATION_NAME, Constants.APPLICATION_NAME); + result.set(APPLICATION_VERSION, Constants.APPLICATION_VERSION); + result.set(APPLICATION_COPYRIGHT, Constants.APPLICATION_COPYRIGHT); result.set(FILE, null); result.set(FILE_MODIFIED, false); result.set(FIRST_TIME, new Date(0L)); @@ -112,9 +116,18 @@ public final class SubtitlesAdjuster { */ private static final class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { + private final Context context; + private final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler; - UncaughtExceptionHandler() { + /** + * + * @param context + *
Not null + *
Shared + */ + UncaughtExceptionHandler(final Context context) { + this.context = context; this.defaultUncaughtExceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); } @@ -122,7 +135,7 @@ public final class SubtitlesAdjuster { public final void uncaughtException(final Thread thread, final Throwable throwable) { this.defaultUncaughtExceptionHandler.uncaughtException(thread, throwable); - Actions.showErrorMessage(throwable); + Actions.showErrorMessage(context, throwable); } } -- 2.11.4.GIT