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
.*;
30 import static net
.sourceforge
.aprog
.tools
.Tools
.ignore
;
32 import java
.awt
.Component
;
35 import javax
.swing
.JFileChooser
;
36 import javax
.swing
.JFrame
;
37 import javax
.swing
.JOptionPane
;
38 import javax
.swing
.filechooser
.FileFilter
;
40 import net
.sourceforge
.aprog
.context
.Context
;
41 import net
.sourceforge
.aprog
.swing
.SwingTools
;
42 import net
.sourceforge
.aprog
.tools
.Tools
;
45 * This class defines all the operations that can be executed on the application context object.
47 * @author codistmonk (creation 2010-06-27)
49 public final class SubtitlesAdjusterActions
{
52 * Private default constructor to prevent instantiation.
54 private SubtitlesAdjusterActions() {
63 public static final void showAboutDialog(final Context context
) {
64 JOptionPane
.showMessageDialog(
65 (Component
) context
.get(MAIN_FRAME
),
66 context
.get(APPLICATION_NAME
) + "\n" +
67 context
.get(APPLICATION_VERSION
) + "\n" +
68 context
.get(APPLICATION_COPYRIGHT
),
69 translate("About $0", context
.get(APPLICATION_NAME
)),
70 JOptionPane
.INFORMATION_MESSAGE
);
78 public static final void showPreferencesDialog(final Context context
) {
79 newPreferencesDialog(context
).setVisible(true);
87 public static final void quit(final Context context
) {
101 public static final void open(final Context context
) {
102 final JFileChooser fileChooser
= new JFileChooser();
104 fileChooser
.setMultiSelectionEnabled(false);
105 fileChooser
.setFileFilter(new FileFilter() {
108 public final boolean accept(final File file
) {
109 return file
.isDirectory() || file
.getName().endsWith(".srt");
113 public final String
getDescription() {
114 return translate("Subtitles file $0", "(*.srt)");
119 if (JFileChooser
.APPROVE_OPTION
== fileChooser
.showOpenDialog((Component
) context
.get(MAIN_FRAME
)) &&
120 fileChooser
.getSelectedFile() != null) {
121 ((Subtitles
) context
.get(SUBTITLES
)).load(fileChooser
.getSelectedFile());
131 public static final void save(final Context context
) {
132 ((Subtitles
) context
.get(SUBTITLES
)).save();
140 public static final void showManual(final Context context
) {
141 showTODOMessage(context
);
149 public static final void showTODOMessage(final Context context
) {
150 System
.out
.println(Tools
.debug(3, "TODO"));
151 JOptionPane
.showMessageDialog(
152 (Component
) context
.get(MAIN_FRAME
),
153 translate("Not implemented"),
154 context
.get(APPLICATION_NAME
).toString(),
155 JOptionPane
.INFORMATION_MESSAGE
);
165 public static final void showErrorMessage(final Context context
, final Throwable throwable
) {
166 if (SwingTools
.canInvokeLaterThisMethodInAWT(null, throwable
)) {
167 JOptionPane
.showMessageDialog(
169 newErrorMessagePanel(throwable
),
170 context
.get(APPLICATION_NAME
).toString(),
171 JOptionPane
.ERROR_MESSAGE
);
180 public static final void updateMainFrameTitle(final Context context
) {
181 ((JFrame
) context
.get(MAIN_FRAME
)).setTitle(makeMainFrameTitle(context
));
191 private static final String
makeMainFrameTitle(final Context context
) {
192 final File file
= context
.get(FILE
);
193 final Boolean fileModified
= context
.get(FILE_MODIFIED
);
195 return file
== null ? context
.get(APPLICATION_NAME
).toString() : file
.getName() + (fileModified ?
"*" : "");