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

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