1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 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.BorderLayout; |
19 | import java.awt.GridLayout; |
20 | import java.beans.PropertyChangeEvent; |
21 | import java.beans.PropertyChangeListener; |
22 | import java.io.File; |
23 | |
24 | import javax.swing.JCheckBox; |
25 | import javax.swing.JFileChooser; |
26 | import javax.swing.JPanel; |
27 | |
28 | import net.sf.jomic.common.PropertyConstants; |
29 | import net.sf.jomic.tools.LocaleTools; |
30 | |
31 | /** |
32 | * JPanel to be used as accessory in the "open comic" dialog containing additional options. |
33 | * |
34 | * @author Thomas Aglassinger |
35 | */ |
36 | public class OpenComicFileChooserAccessory extends JPanel implements PropertyChangeListener |
37 | { |
38 | private JCheckBox adjustArchiveSuffixCheckBox; |
39 | private LocaleTools localeTools; |
40 | private JCheckBox openInFullScreenCheckBox; |
41 | private TitleImageView titleImageView; |
42 | |
43 | public OpenComicFileChooserAccessory() { |
44 | super(new BorderLayout()); |
45 | localeTools = LocaleTools.instance(); |
46 | |
47 | String adjustArchiveSuffixLabel = localeTools.getMessage("dialogs.open.adjustArchiveSuffix"); |
48 | String openInFullScreenLabel = localeTools.getMessage("dialogs.open.openInFullScreen"); |
49 | JPanel optionPane = new JPanel(new GridLayout(0, 1)); |
50 | |
51 | adjustArchiveSuffixCheckBox = new BooleanSettingCheckBox( |
52 | adjustArchiveSuffixLabel, PropertyConstants.ADJUST_ARCHIVE_SUFFIX, |
53 | Commands.TOGGLE_ADJUST_ARCHIVE_SUFFIX); |
54 | openInFullScreenCheckBox = new BooleanSettingCheckBox( |
55 | openInFullScreenLabel, PropertyConstants.OPEN_IN_FULL_SCREEN, |
56 | Commands.TOGGLE_OPEN_IN_FULL_SCREEN); |
57 | titleImageView = new TitleImageView(); |
58 | optionPane.add(openInFullScreenCheckBox); |
59 | optionPane.add(adjustArchiveSuffixCheckBox); |
60 | add(optionPane, BorderLayout.PAGE_END); |
61 | add(titleImageView, BorderLayout.CENTER); |
62 | } |
63 | |
64 | public synchronized void propertyChange(PropertyChangeEvent changeEvent) { |
65 | String nameOfChangedProperty = changeEvent.getPropertyName(); |
66 | |
67 | if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(nameOfChangedProperty)) { |
68 | titleImageView.setComicFile(null); |
69 | } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(nameOfChangedProperty)) { |
70 | File newComicFile = (File) changeEvent.getNewValue(); |
71 | |
72 | // HACK: Some platforms seem to fire a "file changed" event even for directories. |
73 | if ((newComicFile != null) && !newComicFile.isFile()) { |
74 | newComicFile = null; |
75 | } |
76 | |
77 | titleImageView.setComicFile(newComicFile); |
78 | } |
79 | } |
80 | } |