4 * Copyright 2010 Codist Monk.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package net
.sourceforge
.aprog
.subtitlesadjuster
;
27 import static net
.sourceforge
.aprog
.i18n
.Messages
.*;
28 import static net
.sourceforge
.aprog
.subtitlesadjuster
.Constants
.Variables
.*;
29 import static net
.sourceforge
.aprog
.subtitlesadjuster
.SubtitlesAdjusterTools
.*;
30 import static net
.sourceforge
.aprog
.swing
.SwingTools
.*;
31 import static net
.sourceforge
.aprog
.tools
.Tools
.*;
33 import java
.util
.Date
;
35 import net
.sourceforge
.aprog
.context
.Context
;
36 import net
.sourceforge
.jmacadapter
.MacAdapterTools
;
41 * @author codistmonk (creation 2010-06-26)
43 public final class SubtitlesAdjuster
{
46 * Private default constructor to prevent instantiation.
48 private SubtitlesAdjuster() {
53 MacAdapterTools
.setApplicationName(Constants
.APPLICATION_NAME
);
54 useSystemLookAndFeel();
55 setMessagesBase(getThisPackagePath() + "Messages");
59 * @param arguments the command line arguments
64 public static final void main(final String
[] arguments
) {
65 if (canInvokeLaterThisMethodInAWT(null, (Object
) arguments
)) {
66 final Context context
= newContext();
68 // FIXME The following doesn't seem to work well on Windows XP
69 Thread
.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler(context
));
71 Components
.newMainFrame(context
).setVisible(true);
81 public static final Context
newContext() {
82 final Context result
= new Context();
84 result
.set(APPLICATION_NAME
, Constants
.APPLICATION_NAME
);
85 result
.set(APPLICATION_VERSION
, Constants
.APPLICATION_VERSION
);
86 result
.set(APPLICATION_COPYRIGHT
, Constants
.APPLICATION_COPYRIGHT
);
87 result
.set(FILE
, null);
88 result
.set(FILE_MODIFIED
, false);
89 result
.set(FIRST_TIME
, new Date(0L));
90 result
.set(LAST_TIME
, new Date(0L));
92 new Subtitles(result
);
94 setFileModifiedOnVariableChanged(result
, FIRST_TIME
, true);
95 setFileModifiedOnVariableChanged(result
, LAST_TIME
, true);
104 * @param variableName
106 * @param value The value to which the {@link Constants.Variables#FILE_MODIFIED} variable will be set
108 private static final void setFileModifiedOnVariableChanged(
109 final Context context
, final String variableName
, final boolean value
) {
110 invokeOnVariableChanged(context
, variableName
, context
.getVariable(FILE_MODIFIED
), "setValue", value
);
115 * @author codistmonk (creation 2010-06-28)
117 private static final class UncaughtExceptionHandler
implements Thread
.UncaughtExceptionHandler
{
119 private final Context context
;
121 private final Thread
.UncaughtExceptionHandler defaultUncaughtExceptionHandler
;
129 UncaughtExceptionHandler(final Context context
) {
130 this.context
= context
;
131 this.defaultUncaughtExceptionHandler
= Thread
.currentThread().getUncaughtExceptionHandler();
135 public final void uncaughtException(final Thread thread
, final Throwable throwable
) {
136 this.defaultUncaughtExceptionHandler
.uncaughtException(thread
, throwable
);
138 Actions
.showErrorMessage(context
, throwable
);