EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.ui]

COVERAGE SUMMARY FOR SOURCE FILE [CreateComicDialog.java]

nameclass, %method, %block, %line, %
CreateComicDialog.java100% (1/1)36%  (9/25)76%  (433/573)71%  (91.5/128)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateComicDialog100% (1/1)36%  (9/25)76%  (433/573)71%  (91.5/128)
actionPerformed (ActionEvent): void 0%   (0/1)0%   (0/71)0%   (0/15)
changedUpdate (DocumentEvent): void 0%   (0/1)0%   (0/3)0%   (0/2)
getConversion (): Conversion 0%   (0/1)0%   (0/4)0%   (0/1)
getSelection (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getSourceDir (): File 0%   (0/1)0%   (0/7)0%   (0/1)
getTargetDir (): File 0%   (0/1)0%   (0/7)0%   (0/1)
insertUpdate (DocumentEvent): void 0%   (0/1)0%   (0/3)0%   (0/2)
isCreateComicForEachFolder (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
isOpenAfterwards (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
removeUpdate (DocumentEvent): void 0%   (0/1)0%   (0/3)0%   (0/2)
setSelectionAndClose (int): void 0%   (0/1)0%   (0/7)0%   (0/3)
windowClosed (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowClosing (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowDeactivated (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowDeiconified (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
windowIconified (WindowEvent): void 0%   (0/1)0%   (0/1)0%   (0/1)
createButton (String, String): JButton 100% (1/1)78%  (28/36)83%  (5/6)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
updateEnabledButtons (): void 100% (1/1)90%  (28/31)95%  (4.8/5)
CreateComicDialog (): void 100% (1/1)93%  (67/72)100% (16.9/17)
createButtonPanel (): JPanel 100% (1/1)100% (52/52)100% (11/11)
createFolderPanel (): JPanel 100% (1/1)100% (209/209)100% (42/42)
dispose (): void 100% (1/1)100% (30/30)100% (7/7)
windowActivated (WindowEvent): void 100% (1/1)100% (1/1)100% (1/1)
windowOpened (WindowEvent): void 100% (1/1)100% (6/6)100% (3/3)

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/>.
16package net.sf.jomic.ui;
17 
18import java.awt.BorderLayout;
19import java.awt.GridBagConstraints;
20import java.awt.GridBagLayout;
21import java.awt.Insets;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24import java.awt.event.WindowEvent;
25import java.awt.event.WindowListener;
26import java.io.File;
27 
28import javax.swing.Box;
29import javax.swing.BoxLayout;
30import javax.swing.JButton;
31import javax.swing.JDialog;
32import javax.swing.JFileChooser;
33import javax.swing.JOptionPane;
34import javax.swing.JPanel;
35import javax.swing.JTextField;
36import javax.swing.event.DocumentEvent;
37import javax.swing.event.DocumentListener;
38 
39import net.sf.jomic.comic.Conversion;
40import net.sf.jomic.comic.ConversionBean;
41import net.sf.jomic.common.JomicTools;
42import net.sf.jomic.common.PropertyConstants;
43import net.sf.jomic.common.Settings;
44import net.sf.jomic.tools.LocaleTools;
45import net.sf.jomic.tools.UiTools;
46import net.sf.wraplog.Logger;
47 
48/**
49 *  Dialog to specify how to create new comics.
50 *
51 * @author    Thomas Aglassinger
52 */
53public class CreateComicDialog extends JDialog implements ActionListener, DocumentListener, WindowListener
54{
55    private static final int INSET = 4;
56    private JButton cancelButton;
57    private ConversionBean conversionBean;
58    private JButton createButton;
59    private BooleanSettingCheckBox createComicForEachFolderCheckBox;
60    private JomicTools jomicTools;
61    private LocaleTools localeTools;
62    private Logger logger;
63    private BooleanSettingCheckBox openAfterwardsCheckBox;
64    private int selection;
65    private Settings settings;
66    private JTextField sourceDirField;
67    private JTextField targetDirField;
68    private UiTools uiTools;
69 
70    public CreateComicDialog() {
71        super();
72        logger = Logger.getLogger(CreateComicDialog.class);
73        settings = Settings.instance();
74        jomicTools = JomicTools.instance();
75        localeTools = LocaleTools.instance();
76        uiTools = UiTools.instance();
77 
78        setTitle(localeTools.getMessage("dialogs.createComic.title"));
79        setModal(true);
80 
81        JPanel mainPane = uiTools.createDialogMainPanel();
82 
83        conversionBean = new ConversionBean();
84        mainPane.add(conversionBean, BorderLayout.LINE_END);
85        mainPane.add(createFolderPanel(), BorderLayout.CENTER);
86        mainPane.add(createButtonPanel(), BorderLayout.PAGE_END);
87        getContentPane().add(mainPane);
88        getRootPane().setDefaultButton(createButton);
89        addWindowListener(this);
90    }
91 
92    private void setSelectionAndClose(int newSelection) {
93        selection = newSelection;
94        setVisible(false);
95    }
96 
97    public Conversion getConversion() {
98        return conversionBean.getConversion();
99    }
100 
101    /**
102     *  Get selected button.
103     *
104     * @see    JOptionPane#CANCEL_OPTION
105     * @see    JOptionPane#OK_OPTION
106     */
107    public int getSelection() {
108        return selection;
109    }
110 
111    public File getSourceDir() {
112        return new File(sourceDirField.getText());
113    }
114 
115    public File getTargetDir() {
116        return new File(targetDirField.getText());
117    }
118 
119    public boolean isCreateComicForEachFolder() {
120        return createComicForEachFolderCheckBox.isSelected();
121    }
122 
123    public boolean isOpenAfterwards() {
124        return openAfterwardsCheckBox.isSelected();
125    }
126 
127    public void actionPerformed(ActionEvent event) {
128        try {
129            assert event != null;
130 
131            String command = event.getActionCommand();
132 
133            assert command != null;
134            if (command.equals(Commands.CANCEL)) {
135                setSelectionAndClose(JOptionPane.CANCEL_OPTION);
136                logger.info("canceled");
137            } else if (command.equals(Commands.NEW_COMIC)) {
138                settings.setLastCreateComicSourceDir(getSourceDir());
139                settings.setLastCreateComicTargetDir(getTargetDir());
140                setSelectionAndClose(JOptionPane.OK_OPTION);
141            } else {
142                assert false : "command=" + command;
143            }
144        } catch (Throwable error) {
145            jomicTools.showError(event, error);
146        }
147    }
148 
149    public void changedUpdate(DocumentEvent event) {
150        updateEnabledButtons();
151    }
152 
153    public void dispose() {
154        removeWindowListener(this);
155        uiTools.attemptToRemoveDocumentListener(targetDirField, this);
156        uiTools.attemptToRemoveDocumentListener(sourceDirField, this);
157        uiTools.attemptToRemoveActionListener(cancelButton, this);
158        uiTools.attemptToRemoveActionListener(createButton, this);
159        super.dispose();
160    }
161 
162    public void insertUpdate(DocumentEvent event) {
163        updateEnabledButtons();
164    }
165 
166    public void removeUpdate(DocumentEvent event) {
167        updateEnabledButtons();
168    }
169 
170    public void windowActivated(WindowEvent event) {
171        // Do nothing.
172    }
173 
174    public void windowClosed(WindowEvent event) {
175        // Do nothing.
176    }
177 
178    public void windowClosing(WindowEvent event) {
179        // Do nothing.
180    }
181 
182    public void windowDeactivated(WindowEvent event) {
183        // Do nothing.
184    }
185 
186    public void windowDeiconified(WindowEvent event) {
187        // Do nothing.
188    }
189 
190    public void windowIconified(WindowEvent event) {
191        // Do nothing.
192    }
193 
194    public void windowOpened(WindowEvent event) {
195        // Set to cancel in case dialog is closed without clicking any buttons.
196        selection = JOptionPane.CANCEL_OPTION;
197        updateEnabledButtons();
198    }
199 
200    private JButton createButton(String localeKeySuffix, String command) {
201        assert localeKeySuffix != null;
202        assert command != null;
203        JButton result = localeTools.createButton("dialogs.createComic." + localeKeySuffix);
204 
205        result.setActionCommand(command);
206        result.addActionListener(this);
207        return result;
208    }
209 
210    private JPanel createButtonPanel() {
211        JPanel result = new JPanel();
212 
213        createButton = createButton("create", Commands.NEW_COMIC);
214        cancelButton = localeTools.createCancelButton();
215        cancelButton.setActionCommand(Commands.CANCEL);
216        cancelButton.addActionListener(this);
217        result.setLayout(new BoxLayout(result, BoxLayout.LINE_AXIS));
218        result.add(Box.createHorizontalGlue());
219        result.add(cancelButton);
220        result.add(uiTools.createRigidAreaBetweenButtons());
221        result.add(createButton);
222        return result;
223    }
224 
225    private JPanel createFolderPanel() {
226        JPanel result = new JPanel();
227        GridBagConstraints constraints = new GridBagConstraints();
228        JFileChooser sourceImageDirChooser = new SnapableJFileChooser(
229                settings, PropertyConstants.SET_CREATE_COMIC_SOURCE_DIR_DIALOG_WINDOW);
230        String setButtonText = localeTools.getMessage("buttons.set");
231        String sourceChooserTitle = localeTools.getMessage("dialogs.setCreateComicSourceDir.title");
232        String targetChooserTitle = localeTools.getMessage("dialogs.setCreateComicTargetDir.title");
233        JFileChooser targetDirChooser = new SnapableJFileChooser(
234                settings, PropertyConstants.SET_CREATE_COMIC_TARGET_DIR_DIALOG_WINDOW);
235        FileFieldAdder sourceDirPane;
236        FileFieldAdder targetDirPane;
237 
238        result.setLayout(new GridBagLayout());
239        constraints.insets = new Insets(INSET, INSET, INSET / 2, INSET / 2);
240        constraints.gridx = 0;
241        constraints.gridy = 0;
242        sourceDirPane = new FileFieldAdder(result, constraints, sourceImageDirChooser);
243        constraints.gridx = 0;
244        constraints.gridy += 1;
245        targetDirPane = new FileFieldAdder(result, constraints, targetDirChooser);
246 
247        sourceImageDirChooser.setApproveButtonText(setButtonText);
248        sourceImageDirChooser.setDialogTitle(sourceChooserTitle);
249        sourceImageDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
250        targetDirChooser.setApproveButtonText(setButtonText);
251        targetDirChooser.setDialogTitle(targetChooserTitle);
252        targetDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
253 
254        sourceDirField = sourceDirPane.getField();
255        sourceDirField.setText(settings.getLastCreateComicSourceDir().getAbsolutePath());
256        sourceDirField.getDocument().addDocumentListener(this);
257        sourceDirPane.getChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
258        sourceDirPane.getLabel().setText(localeTools.getMessage("dialogs.createComic.sourceDir"));
259 
260        targetDirField = targetDirPane.getField();
261        targetDirField.setText(settings.getLastCreateComicTargetDir().getAbsolutePath());
262        targetDirField.getDocument().addDocumentListener(this);
263        targetDirPane.getLabel().setText(localeTools.getMessage("dialogs.createComic.targetDir"));
264 
265        openAfterwardsCheckBox = new BooleanSettingCheckBox(
266                localeTools.getMessage("dialogs.createComic.openNewComic"),
267                PropertyConstants.OPEN_NEW_COMIC, Commands.TOGGLE_OPEN_NEW_COMIC);
268        constraints.anchor = GridBagConstraints.LINE_START;
269        constraints.gridwidth = GridBagConstraints.REMAINDER;
270        constraints.gridx = 0;
271        constraints.gridy += 1;
272        result.add(openAfterwardsCheckBox, constraints);
273 
274        createComicForEachFolderCheckBox = new BooleanSettingCheckBox(
275                localeTools.getMessage("dialogs.createComic.createComicForEachSubFolder"),
276                PropertyConstants.CREATE_COMIC_FOR_EACH_SUB_FOLDER,
277                Commands.TOGGLE_CREATE_COMIC_FOR_EACH_SUB_FOLDER);
278        constraints.anchor = GridBagConstraints.LINE_START;
279        constraints.gridx = 0;
280        constraints.gridy += 1;
281        result.add(createComicForEachFolderCheckBox, constraints);
282 
283        return result;
284    }
285 
286    private void updateEnabledButtons() {
287        boolean hasSourceImages = (sourceDirField.getDocument().getLength() > 0);
288        boolean hasTargetComicDir = (targetDirField.getDocument().getLength() > 0);
289        boolean ready = hasSourceImages && hasTargetComicDir;
290 
291        createButton.setEnabled(ready);
292    }
293}

[all classes][net.sf.jomic.ui]
EMMA 2.0.4217 (C) Vladimir Roubtsov