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
.SubtitlesAdjusterComponents
.*;
29 import static net
.sourceforge
.aprog
.subtitlesadjuster
.SubtitlesAdjusterConstants
.Variables
.*;
31 import java
.awt
.Component
;
34 import javax
.swing
.JFileChooser
;
35 import javax
.swing
.JFrame
;
36 import javax
.swing
.JOptionPane
;
37 import javax
.swing
.filechooser
.FileFilter
;
39 import net
.sourceforge
.aprog
.context
.Context
;
40 import net
.sourceforge
.aprog
.swing
.SwingTools
;
41 import net
.sourceforge
.aprog
.tools
.Tools
;
44 * This class defines all the operations that can be executed on the application context object.
46 * @author codistmonk (creation 2010-06-27)
48 public final class SubtitlesAdjusterActions
{
51 * Private default constructor to prevent instantiation.
53 private SubtitlesAdjusterActions() {
62 public static final void showAboutDialog(final Context context
) {
63 JOptionPane
.showMessageDialog(
64 (Component
) context
.get(MAIN_FRAME
),
65 context
.get(APPLICATION_NAME
) + "\n" +
66 context
.get(APPLICATION_VERSION
) + "\n" +
67 context
.get(APPLICATION_COPYRIGHT
),
68 translate("About $0", context
.get(APPLICATION_NAME
)),
69 JOptionPane
.INFORMATION_MESSAGE
);
77 public static final void showPreferencesDialog(final Context context
) {
78 newPreferencesDialog(context
).setVisible(true);
86 public static final void quit(final Context context
) {
96 public static final void open(final Context context
) {
97 final JFileChooser fileChooser
= new JFileChooser();
99 fileChooser
.setMultiSelectionEnabled(false);
100 fileChooser
.setFileFilter(new FileFilter() {
103 public final boolean accept(final File file
) {
104 return file
.isDirectory() || file
.getName().endsWith(".srt");
108 public final String
getDescription() {
109 return translate("Subtitles file $0", "(*.srt)");
114 if (JFileChooser
.APPROVE_OPTION
== fileChooser
.showOpenDialog((Component
) context
.get(MAIN_FRAME
)) &&
115 fileChooser
.getSelectedFile() != null) {
116 ((Subtitles
) context
.get(SUBTITLES
)).load(fileChooser
.getSelectedFile());
126 public static final void save(final Context context
) {
127 ((Subtitles
) context
.get(SUBTITLES
)).save();
135 public static final void showManual(final Context context
) {
136 showTODOMessage(context
);
144 public static final void showTODOMessage(final Context context
) {
145 System
.out
.println(Tools
.debug(3, "TODO"));
146 JOptionPane
.showMessageDialog(
147 (Component
) context
.get(MAIN_FRAME
),
148 translate("Not implemented"),
149 context
.get(APPLICATION_NAME
).toString(),
150 JOptionPane
.INFORMATION_MESSAGE
);
160 public static final void showErrorMessage(final Context context
, final Throwable throwable
) {
161 if (SwingTools
.canInvokeLaterThisMethodInAWT(null, throwable
)) {
162 JOptionPane
.showMessageDialog(
164 newErrorMessagePanel(throwable
),
165 context
.get(APPLICATION_NAME
).toString(),
166 JOptionPane
.ERROR_MESSAGE
);
175 public static final void updateMainFrameTitle(final Context context
) {
176 ((JFrame
) context
.get(MAIN_FRAME
)).setTitle(makeMainFrameTitle(context
));
186 private static final String
makeMainFrameTitle(final Context context
) {
187 final File file
= context
.get(FILE
);
188 final Boolean fileModified
= context
.get(FILE_MODIFIED
);
190 return file
== null ? context
.get(APPLICATION_NAME
).toString() : file
.getName() + (fileModified ?
"*" : "");