| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2008 Thomas Aglassinger |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.ui; |
| 17 | |
| 18 | import java.awt.Component; |
| 19 | import java.awt.event.ActionEvent; |
| 20 | import java.awt.event.ActionListener; |
| 21 | import java.awt.event.WindowEvent; |
| 22 | import java.awt.event.WindowListener; |
| 23 | import java.io.File; |
| 24 | import java.io.IOException; |
| 25 | import java.util.LinkedList; |
| 26 | import java.util.List; |
| 27 | |
| 28 | import javax.help.HelpBroker; |
| 29 | import javax.swing.AbstractAction; |
| 30 | import javax.swing.Action; |
| 31 | import javax.swing.JFileChooser; |
| 32 | import javax.swing.JOptionPane; |
| 33 | import javax.swing.SwingUtilities; |
| 34 | import javax.swing.WindowConstants; |
| 35 | |
| 36 | import net.roydesign.event.ApplicationEvent; |
| 37 | import net.roydesign.mac.MRJAdapter; |
| 38 | import net.sf.jomic.comic.ComicCache; |
| 39 | import net.sf.jomic.comic.ComicChooserFileFilter; |
| 40 | import net.sf.jomic.comic.ComicFileFilter; |
| 41 | import net.sf.jomic.common.JomicHelpTools; |
| 42 | import net.sf.jomic.common.JomicStartup; |
| 43 | import net.sf.jomic.common.JomicTools; |
| 44 | import net.sf.jomic.common.PropertyConstants; |
| 45 | import net.sf.jomic.common.Settings; |
| 46 | import net.sf.jomic.tools.ConsoleTools; |
| 47 | import net.sf.jomic.tools.LocaleTools; |
| 48 | import net.sf.jomic.tools.StringTools; |
| 49 | import net.sf.jomic.tools.SystemTools; |
| 50 | import net.sf.jomic.tools.UiTools; |
| 51 | import net.sf.wraplog.Logger; |
| 52 | |
| 53 | /** |
| 54 | * Jomic application that manages all open comics and processes comic independant commands like |
| 55 | * "about", "help", or "quit". |
| 56 | * |
| 57 | * @author Thomas Aglassinger |
| 58 | */ |
| 59 | public final class JomicApplication implements ActionListener, WindowListener |
| 60 | { |
| 61 | private static final float MINIMUM_UNRAR_VERSION = 3.5f; |
| 62 | |
| 63 | private static JomicApplication instance; |
| 64 | |
| 65 | private AboutFrame aboutFrame; |
| 66 | private ChangeBlurSettingsDialog changeBlurSettingsDialog; |
| 67 | private ComicFileFilter comicFileFilter; |
| 68 | private ComicChooserFileFilter comicFilter; |
| 69 | private ConsoleTools consoleTools; |
| 70 | private ConvertDialog convertDialog; |
| 71 | private CreateComicDialog createComicDialog; |
| 72 | private FramelessJomicMenuBar framelessMenuBar; |
| 73 | private Runnable fullScreenViewerRunner; |
| 74 | private boolean hasFramelessMenuBar; |
| 75 | private JomicStartup jomicStartup; |
| 76 | private JomicTools jomicTools; |
| 77 | private LocaleTools localeTools; |
| 78 | private Logger logger; |
| 79 | private JFileChooser openComicChooser; |
| 80 | private List openComicWindows; |
| 81 | private Settings settings; |
| 82 | private StringTools stringTools; |
| 83 | private SystemInfoFrame systemInfoFrame; |
| 84 | private SystemTools systemTools; |
| 85 | private UiTools uiTools; |
| 86 | |
| 87 | private JomicApplication() { |
| 88 | logger = Logger.getLogger(JomicApplication.class); |
| 89 | consoleTools = ConsoleTools.instance(); |
| 90 | jomicTools = JomicTools.instance(); |
| 91 | localeTools = LocaleTools.instance(); |
| 92 | stringTools = StringTools.instance(); |
| 93 | systemTools = SystemTools.instance(); |
| 94 | uiTools = UiTools.instance(); |
| 95 | jomicStartup = JomicStartup.instance(); |
| 96 | settings = Settings.instance(); |
| 97 | openComicWindows = new LinkedList(); |
| 98 | comicFileFilter = new ComicFileFilter(); |
| 99 | comicFilter = new ComicChooserFileFilter(); |
| 100 | |
| 101 | jomicTools.setFullScreenCancelabel(FullScreenViewer.instance()); |
| 102 | |
| 103 | checkForUnrar(); |
| 104 | } |
| 105 | |
| 106 | public void setUpFramelessMenuBar() { |
| 107 | // Under Mac OS X, the following lines create a hidden frame with a |
| 108 | // menu bar where most items are disabled. This keeps Jomic running |
| 109 | // even when no comic is open. (Don't ask. This is a Mac OS UI |
| 110 | // convention.) |
| 111 | if (MRJAdapter.isSwingUsingScreenMenuBar()) { |
| 112 | String showMenuBarName = |
| 113 | PropertyConstants.SYSTEM_PROPERTY_PREFIX + PropertyConstants.SHOW_FRAMELESS_MENU_BAR; |
| 114 | |
| 115 | hasFramelessMenuBar = Boolean.getBoolean(showMenuBarName); |
| 116 | if (hasFramelessMenuBar) { |
| 117 | framelessMenuBar = new FramelessJomicMenuBar(); |
| 118 | framelessMenuBar.addActionListener(this); |
| 119 | MRJAdapter.setFramelessJMenuBar(framelessMenuBar); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | public Action getChangeBlurSettingsAction() { |
| 125 | return new ChangeBlurSettingsAction(); |
| 126 | } |
| 127 | |
| 128 | private JomicFrame getLastActiveWindow() { |
| 129 | JomicFrame result; |
| 130 | |
| 131 | synchronized (openComicWindows) { |
| 132 | int lastActiveWindowIndex = openComicWindows.size() - 1; |
| 133 | |
| 134 | assert lastActiveWindowIndex >= 0; |
| 135 | result = (JomicFrame) openComicWindows.get(lastActiveWindowIndex); |
| 136 | } |
| 137 | return result; |
| 138 | } |
| 139 | |
| 140 | public static synchronized JomicApplication instance() { |
| 141 | if (instance == null) { |
| 142 | instance = new JomicApplication(); |
| 143 | } |
| 144 | return instance; |
| 145 | } |
| 146 | |
| 147 | public void actionPerformed(ActionEvent event) { |
| 148 | ApplicationEvent appEvent = null; |
| 149 | String command = null; |
| 150 | |
| 151 | // Find out if we received an Mac OS ApplicationEvent or just a |
| 152 | // "normal" command. |
| 153 | if (event instanceof ApplicationEvent) { |
| 154 | appEvent = (ApplicationEvent) event; |
| 155 | logger.info("handle application event: {}", appEvent); |
| 156 | } else { |
| 157 | command = event.getActionCommand(); |
| 158 | logger.info("handle command: {}", command); |
| 159 | } |
| 160 | |
| 161 | try { |
| 162 | if (appEvent != null) { |
| 163 | performApplicationEvent(appEvent); |
| 164 | } else if (command.equals(Commands.ABOUT)) { |
| 165 | performAbout(); |
| 166 | } else if (command.equals(Commands.CLEAR_RECENT)) { |
| 167 | settings.clearRecentFiles(); |
| 168 | } else if (command.equals(Commands.CONVERT)) { |
| 169 | performConvert(); |
| 170 | } else if (command.equals(Commands.NEW_COMIC)) { |
| 171 | performCreate(); |
| 172 | } else if (command.equals(Commands.FULL_SCREEN)) { |
| 173 | performToggleFullScreen(); |
| 174 | } else if (command.equals(Commands.HELP)) { |
| 175 | performHelp(); |
| 176 | } else if (command.equals(Commands.OPEN)) { |
| 177 | synchronized (openComicWindows) { |
| 178 | int lastWindowIndex = openComicWindows.size(); |
| 179 | JomicFrame mostRecentlyActivatedWindow; |
| 180 | |
| 181 | if (lastWindowIndex == 0) { |
| 182 | mostRecentlyActivatedWindow = null; |
| 183 | } else { |
| 184 | mostRecentlyActivatedWindow = (JomicFrame) openComicWindows.get(lastWindowIndex - 1); |
| 185 | } |
| 186 | open(mostRecentlyActivatedWindow, null); |
| 187 | } |
| 188 | } else if (command.equals(Commands.OPEN_IN_NEW_WINDOW)) { |
| 189 | openInNewWindow(); |
| 190 | } else if (command.equals(Commands.OPEN_RECENT)) { |
| 191 | performOpenRecent(event); |
| 192 | } else if (command.equals(Commands.QUIT)) { |
| 193 | quit(); |
| 194 | } else if (command.equals(Commands.SYSTEM_INFO)) { |
| 195 | performSystemInfo(); |
| 196 | } else if (command.equals(Commands.TOGGLE_ADJUST_ARCHIVE_SUFFIX)) { |
| 197 | performToggleAdjustArchiveSuffix(); |
| 198 | } else if (command.equals(Commands.TOGGLE_OPEN_IN_FULL_SCREEN)) { |
| 199 | performToggleOpenInFullScreen(); |
| 200 | } else { |
| 201 | String message = localeTools.getMessage("errors.cannotProcessUnknownCommand", command); |
| 202 | |
| 203 | throw new IllegalArgumentException(message); |
| 204 | } |
| 205 | } catch (Throwable error) { |
| 206 | showInternalCommandErrorMessage(command, error); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Open in window <code>jomicFrameToOpenIn</code> the comic <code>comicToOpen</code>. If <code>jomicFrameToOpenIn</code> |
| 212 | * is <code>null</code>, open a new window first. If <code>comicToOpen</code> is <code>null</code> |
| 213 | * , let the user choose one. |
| 214 | */ |
| 215 | public void open(JomicFrame jomicFrameToOpenIn, File comicToOpen) { |
| 216 | JomicFrame jomicFrame; |
| 217 | boolean useNewFrame = jomicFrameToOpenIn == null; |
| 218 | |
| 219 | if (useNewFrame) { |
| 220 | jomicFrame = createJomicFrame(); |
| 221 | } else { |
| 222 | jomicFrame = jomicFrameToOpenIn; |
| 223 | } |
| 224 | |
| 225 | File comicFile = comicToOpen; |
| 226 | |
| 227 | if (comicFile == null) { |
| 228 | prepareOpenDialog(); |
| 229 | |
| 230 | // Let the user select the file, and open it. |
| 231 | int selection = openComicChooser.showOpenDialog(jomicFrame); |
| 232 | |
| 233 | if (selection == JFileChooser.APPROVE_OPTION) { |
| 234 | comicFile = openComicChooser.getSelectedFile(); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (comicFile != null) { |
| 239 | jomicFrame.open(comicFile); |
| 240 | } else if (useNewFrame) { |
| 241 | boolean frameWasVisible = jomicFrame.isVisible(); |
| 242 | |
| 243 | // We just created a new window for this comic, but now do not need |
| 244 | // it because the user cancelled the "Open comic" dialog. |
| 245 | if (!frameWasVisible) { |
| 246 | removeOpenWindow(jomicFrame); |
| 247 | } |
| 248 | jomicFrame.performClose(); |
| 249 | if (!frameWasVisible) { |
| 250 | ifAllWindowsClosedThenQuit(); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Open dialog to select comic, then open it in new window. |
| 257 | */ |
| 258 | public void openInNewWindow() { |
| 259 | open(null, null); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Open comic in new window. |
| 264 | */ |
| 265 | public void openInNewWindow(File comicFile) { |
| 266 | assert comicFile != null; |
| 267 | createJomicFrame().open(comicFile); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Change view of current comic to full screen. |
| 272 | */ |
| 273 | public void performToggleFullScreen() { |
| 274 | FullScreenViewer fullScreen = FullScreenViewer.instance(); |
| 275 | JomicFrame controller = getLastActiveWindow(); |
| 276 | |
| 277 | if (fullScreen.isVisible()) { |
| 278 | fullScreen.performCancel(); |
| 279 | } else { |
| 280 | fullScreenViewerRunner = new FullScreenViewerRunner(controller); |
| 281 | |
| 282 | SwingUtilities.invokeLater(fullScreenViewerRunner); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Cleanup, write settings and exit application. |
| 288 | * |
| 289 | * @see JomicStartup#exit(int) |
| 290 | */ |
| 291 | public void quit() { |
| 292 | ComicCache.instance().dispose(); |
| 293 | |
| 294 | if (logger.isInfoEnabled()) { |
| 295 | logger.info("write settings"); |
| 296 | } |
| 297 | |
| 298 | File settingsFile = settings.getSettingsFile(); |
| 299 | |
| 300 | try { |
| 301 | settings.write(settingsFile); |
| 302 | } catch (IOException error) { |
| 303 | logger.warn("cannot write settings to \"" + settingsFile + "\"", error); |
| 304 | } |
| 305 | if (framelessMenuBar != null) { |
| 306 | framelessMenuBar.removeActionListener(this); |
| 307 | } |
| 308 | jomicStartup.exit(0); |
| 309 | } |
| 310 | |
| 311 | public void windowActivated(WindowEvent event) { |
| 312 | assert event != null; |
| 313 | |
| 314 | synchronized (openComicWindows) { |
| 315 | // Move window to end of list |
| 316 | JomicFrame jomicFrame = (JomicFrame) event.getWindow(); |
| 317 | |
| 318 | removeOpenWindow(jomicFrame); |
| 319 | addOpenWindow(jomicFrame); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | public void windowClosed(WindowEvent event) { |
| 324 | // Do nothing. |
| 325 | } |
| 326 | |
| 327 | public void windowClosing(WindowEvent event) { |
| 328 | assert event != null; |
| 329 | |
| 330 | synchronized (openComicWindows) { |
| 331 | JomicFrame jomicFrame = (JomicFrame) event.getWindow(); |
| 332 | |
| 333 | if (logger.isInfoEnabled()) { |
| 334 | logger.info("closing comic frame: {}", stringTools.sourced(jomicFrame.getTitle())); |
| 335 | } |
| 336 | removeOpenWindow(jomicFrame); |
| 337 | jomicFrame.removeWindowListener(this); |
| 338 | jomicFrame.dispose(); |
| 339 | settings.setComicWindow(jomicFrame); |
| 340 | |
| 341 | ifAllWindowsClosedThenQuit(); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | public void windowDeactivated(WindowEvent event) { |
| 346 | // Do nothing. |
| 347 | } |
| 348 | |
| 349 | public void windowDeiconified(WindowEvent event) { |
| 350 | // Do nothing. |
| 351 | } |
| 352 | |
| 353 | public void windowIconified(WindowEvent event) { |
| 354 | // Do nothing. |
| 355 | } |
| 356 | |
| 357 | public void windowOpened(WindowEvent event) { |
| 358 | // Do nothing. |
| 359 | } |
| 360 | |
| 361 | synchronized void prepareChangeBlurSettings() { |
| 362 | if (changeBlurSettingsDialog == null) { |
| 363 | changeBlurSettingsDialog = new ChangeBlurSettingsDialog(null); |
| 364 | changeBlurSettingsDialog.pack(); |
| 365 | settings.applyComponentAreaProperty(PropertyConstants.SET_BLUR_DIALOG_WINDOW, changeBlurSettingsDialog); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | synchronized void prepareConvertDialog() { |
| 370 | if (convertDialog == null) { |
| 371 | convertDialog = new ConvertDialog(); |
| 372 | convertDialog.pack(); |
| 373 | settings.applyComponentAreaProperty(PropertyConstants.CONVERT_DIALOG_WINDOW, convertDialog); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | synchronized void prepareCreateComicDialog() { |
| 378 | if (createComicDialog == null) { |
| 379 | createComicDialog = new CreateComicDialog(); |
| 380 | createComicDialog.pack(); |
| 381 | settings.applyComponentAreaProperty(PropertyConstants.NEW_COMIC_DIALOG_WINDOW, createComicDialog); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Prepare <code>openComicChooser</code> by possibly creating it first, and setting the |
| 387 | * selected file name to the most recently opened file. |
| 388 | */ |
| 389 | void prepareOpenDialog() { |
| 390 | // Create the dialog if necessary. |
| 391 | if (openComicChooser == null) { |
| 392 | String title = localeTools.getMessage("dialogs.open.title"); |
| 393 | OpenComicFileChooserAccessory accessory = new OpenComicFileChooserAccessory(); |
| 394 | |
| 395 | openComicChooser = new SnapableJFileChooser(settings, PropertyConstants.OPEN_DIALOG_WINDOW); |
| 396 | openComicChooser.setDialogTitle(title); |
| 397 | openComicChooser.setFileFilter(comicFilter); |
| 398 | openComicChooser.setAccessory(accessory); |
| 399 | openComicChooser.addPropertyChangeListener(accessory); |
| 400 | } |
| 401 | |
| 402 | // Set the selected file to the most recent one. |
| 403 | File mostRecentFile = settings.getMostRecentFile(); |
| 404 | |
| 405 | if (mostRecentFile != null) { |
| 406 | String mostRecentName = mostRecentFile.getName(); |
| 407 | |
| 408 | if (comicFileFilter.accept(null, mostRecentName)) { |
| 409 | openComicChooser.setSelectedFile(mostRecentFile); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | private void addOpenWindow(JomicFrame openWindow) { |
| 415 | synchronized (openComicWindows) { |
| 416 | assert openWindow != null; |
| 417 | assert !openComicWindows.contains(openWindow); |
| 418 | openComicWindows.add(openWindow); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Check for proper unrar version to be installed within system search path. If not, show a |
| 424 | * warning dialog offering to go to the download page or continue dispite being unable open |
| 425 | * CBR/RAR comics. |
| 426 | */ |
| 427 | private void checkForUnrar() { |
| 428 | String warningMessage; |
| 429 | |
| 430 | // Set warning message depending on unrar version. |
| 431 | try { |
| 432 | float unrarVersion = consoleTools.getVersion(settings.getUnrarCommand()); |
| 433 | |
| 434 | if (unrarVersion < 0) { |
| 435 | warningMessage = localeTools.getMessage("warnings.unrarVersionXShouldBeInstalled", |
| 436 | consoleTools.asVersionNumber(MINIMUM_UNRAR_VERSION)); |
| 437 | } else if (unrarVersion < MINIMUM_UNRAR_VERSION) { |
| 438 | Object[] options = new Object[]{ |
| 439 | consoleTools.asVersionNumber(MINIMUM_UNRAR_VERSION), |
| 440 | consoleTools.asVersionNumber(unrarVersion)}; |
| 441 | |
| 442 | warningMessage = localeTools.getMessage("warnings.unrarVersionMustBeXButIsY", options); |
| 443 | } else { |
| 444 | warningMessage = null; |
| 445 | } |
| 446 | } catch (Exception error) { |
| 447 | warningMessage = localeTools.getMessage("warnings.cannotObtainUnrarVersion"); |
| 448 | } |
| 449 | |
| 450 | if (warningMessage != null) { |
| 451 | Object[] options = {localeTools.getMessage("buttons.goToDownloadPage"), |
| 452 | localeTools.getMessage("buttons.continue")}; |
| 453 | String dialogTitle = localeTools.getMessage("dialogs.warning.title"); |
| 454 | String warningAndImplicationsMessage = localeTools.getMessage( |
| 455 | "warnings.openingRarComicWillNotWork", stringTools.titled(warningMessage)); |
| 456 | int chosenOption = JOptionPane.showOptionDialog( |
| 457 | null, warningAndImplicationsMessage, |
| 458 | dialogTitle, JOptionPane.YES_NO_OPTION, |
| 459 | JOptionPane.WARNING_MESSAGE, null, options, |
| 460 | options[1]); |
| 461 | |
| 462 | if (chosenOption == JOptionPane.YES_OPTION) { |
| 463 | systemTools.openURL("http://www.rarlab.com/"); |
| 464 | try { |
| 465 | Thread.sleep(PropertyConstants.BROWSER_STARTUP_DELAY); |
| 466 | } catch (InterruptedException interruption) { |
| 467 | logger.warn("sleep interruped", interruption); |
| 468 | } |
| 469 | quit(); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | private JomicFrame createJomicFrame() { |
| 475 | JomicFrame result; |
| 476 | |
| 477 | synchronized (openComicWindows) { |
| 478 | if (openComicWindows.size() > 0) { |
| 479 | result = (JomicFrame) openComicWindows.get(0); |
| 480 | } else { |
| 481 | result = new JomicFrame(); |
| 482 | result.addWindowListener(this); |
| 483 | result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 484 | result.pack(); |
| 485 | settings.applyComicWindow(result); |
| 486 | if (logger.isInfoEnabled()) { |
| 487 | logger.info("create new comic window"); |
| 488 | } |
| 489 | addOpenWindow(result); |
| 490 | } |
| 491 | } |
| 492 | return result; |
| 493 | } |
| 494 | |
| 495 | private void ifAllWindowsClosedThenQuit() { |
| 496 | // If this was the last window, then quit (unless we are running |
| 497 | // under Mac OS and using a frameless menu). |
| 498 | boolean allWindowsClosed = (openComicWindows.size() == 0); |
| 499 | |
| 500 | if (allWindowsClosed && !hasFramelessMenuBar) { |
| 501 | SwingUtilities.invokeLater(new QuitRunner()); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | private synchronized void performAbout() { |
| 506 | if (aboutFrame == null) { |
| 507 | aboutFrame = new AboutFrame(); |
| 508 | aboutFrame.pack(); |
| 509 | } |
| 510 | aboutFrame.setVisible(true); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Process Mac OS application event. |
| 515 | */ |
| 516 | private void performApplicationEvent(ApplicationEvent appEvent) { |
| 517 | int type = appEvent.getType(); |
| 518 | |
| 519 | if (type == ApplicationEvent.ABOUT) { |
| 520 | performAbout(); |
| 521 | } else if (type == ApplicationEvent.QUIT_APPLICATION) { |
| 522 | quit(); |
| 523 | } else { |
| 524 | logger.warn("ignoring unknown application event: " + appEvent); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | private void performConvert() { |
| 529 | prepareConvertDialog(); |
| 530 | convertDialog.setVisible(true); |
| 531 | settings.setComponentAreaProperty(PropertyConstants.CONVERT_DIALOG_WINDOW, convertDialog); |
| 532 | |
| 533 | int selection = convertDialog.getSelection(); |
| 534 | |
| 535 | if (selection == JFileChooser.APPROVE_OPTION) { |
| 536 | ConvertWorker convertWorker = new ConvertWorker( |
| 537 | convertDialog.getTargetDir(), |
| 538 | convertDialog.getSelectedFiles(), |
| 539 | convertDialog.getConversion()); |
| 540 | |
| 541 | convertWorker.start(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | private void performCreate() { |
| 546 | prepareCreateComicDialog(); |
| 547 | createComicDialog.setVisible(true); |
| 548 | settings.setComponentAreaProperty(PropertyConstants.NEW_COMIC_DIALOG_WINDOW, createComicDialog); |
| 549 | |
| 550 | int selection = createComicDialog.getSelection(); |
| 551 | |
| 552 | if (selection == JFileChooser.APPROVE_OPTION) { |
| 553 | File targetDir = createComicDialog.getTargetDir(); |
| 554 | File sourceDir = createComicDialog.getSourceDir(); |
| 555 | boolean isCreateComicForEachFolder = createComicDialog.isCreateComicForEachFolder(); |
| 556 | boolean isOpenAfterwards = createComicDialog.isOpenAfterwards(); |
| 557 | CreateComicWorker createComicWorker = new CreateComicWorker(sourceDir, targetDir, |
| 558 | createComicDialog.getConversion(), isCreateComicForEachFolder, isOpenAfterwards); |
| 559 | |
| 560 | createComicWorker.start(); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | private void performHelp() { |
| 565 | JomicHelpTools helpTools = JomicHelpTools.instance(); |
| 566 | HelpBroker helpBroker = helpTools.getHelpBroker(); |
| 567 | |
| 568 | helpBroker.setDisplayed(true); |
| 569 | } |
| 570 | |
| 571 | private void performOpenRecent(ActionEvent event) { |
| 572 | OpenRecentFileEvent orfEvent = (OpenRecentFileEvent) event; |
| 573 | |
| 574 | openInNewWindow(orfEvent.getFile()); |
| 575 | } |
| 576 | |
| 577 | private synchronized void performSystemInfo() { |
| 578 | if (systemInfoFrame == null) { |
| 579 | systemInfoFrame = new SystemInfoFrame(); |
| 580 | systemInfoFrame.pack(); |
| 581 | uiTools.centerUp(systemInfoFrame); |
| 582 | } |
| 583 | systemInfoFrame.setVisible(true); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | private void performToggleAdjustArchiveSuffix() { |
| 588 | boolean newValue = !settings.getAdjustArchiveSuffix(); |
| 589 | |
| 590 | settings.setAdjustArchiveSuffix(newValue); |
| 591 | } |
| 592 | |
| 593 | private void performToggleOpenInFullScreen() { |
| 594 | boolean newValue = !settings.getOpenInFullScreen(); |
| 595 | |
| 596 | settings.setOpenInFullScreen(newValue); |
| 597 | } |
| 598 | |
| 599 | private void removeOpenWindow(Component frame) { |
| 600 | synchronized (openComicWindows) { |
| 601 | assert frame != null : "frame to remove must not be null"; |
| 602 | assert openComicWindows.contains(frame) || MRJAdapter.isSwingUsingScreenMenuBar() : |
| 603 | "frame must be open: " + frame; |
| 604 | openComicWindows.remove(frame); |
| 605 | if (hasFramelessMenuBar) { |
| 606 | framelessMenuBar.updateFileOpenRecent(); |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | private void showError(String key, Object option, Throwable error) { |
| 612 | jomicTools.showError(null, key, option, error); |
| 613 | } |
| 614 | |
| 615 | private void showInternalCommandErrorMessage(String command, Throwable error) { |
| 616 | showError("errors.cannotProcessInternalCommand", command, error); |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Action to open ChangeBlurSettingsDialog. |
| 621 | * |
| 622 | * @see ChangeBlurSettingsDialog |
| 623 | * @author Thomas Aglassinger |
| 624 | */ |
| 625 | private final class ChangeBlurSettingsAction extends AbstractAction |
| 626 | { |
| 627 | private ChangeBlurSettingsAction() { |
| 628 | super(localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "changeBlurSettings")); |
| 629 | } |
| 630 | |
| 631 | public void actionPerformed(ActionEvent event) { |
| 632 | prepareChangeBlurSettings(); |
| 633 | changeBlurSettingsDialog.setVisible(true); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Runnable to quit application. |
| 639 | */ |
| 640 | private final class QuitRunner implements Runnable |
| 641 | { |
| 642 | private QuitRunner() { |
| 643 | super(); |
| 644 | } |
| 645 | |
| 646 | public void run() { |
| 647 | quit(); |
| 648 | } |
| 649 | } |
| 650 | } |