EMMA Coverage Report (generated Sat Oct 08 11:41:37 CEST 2011)
[all classes][net.sf.jomic.ui]

COVERAGE SUMMARY FOR SOURCE FILE [JomicToolbar.java]

nameclass, %method, %block, %line, %
JomicToolbar.java100% (1/1)90%  (9/10)82%  (330/400)88%  (68.8/78)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JomicToolbar100% (1/1)90%  (9/10)82%  (330/400)88%  (68.8/78)
actionPerformed (ActionEvent): void 0%   (0/1)0%   (0/5)0%   (0/2)
setUIState (String): void 100% (1/1)64%  (51/80)84%  (12.6/15)
<static initializer> 100% (1/1)68%  (17/25)70%  (1.4/2)
createButton (String, String, String): JButton 100% (1/1)73%  (65/89)80%  (12.8/16)
getPreferredSize (): Dimension 100% (1/1)75%  (12/16)75%  (3/4)
JomicToolbar (): void 100% (1/1)100% (133/133)100% (28/28)
addActionListener (ActionListener): void 100% (1/1)100% (5/5)100% (2/2)
dispose (): void 100% (1/1)100% (1/1)100% (1/1)
removeActionListener (ActionListener): void 100% (1/1)100% (5/5)100% (2/2)
setEnabledPageButtons (boolean, boolean): void 100% (1/1)100% (41/41)100% (6/6)

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.Dimension;
19import java.awt.event.ActionEvent;
20import java.awt.event.ActionListener;
21import java.net.URL;
22 
23import javax.swing.ImageIcon;
24import javax.swing.JButton;
25import javax.swing.JLabel;
26import javax.swing.JToolBar;
27 
28import net.sf.jomic.common.Settings;
29import net.sf.jomic.tools.ActionDelegate;
30import net.sf.jomic.tools.LocaleTools;
31 
32import org.apache.commons.logging.Log;
33import org.apache.commons.logging.LogFactory;
34 
35/**
36 *  Toolbar for essential comic operations.
37 *
38 * @author    Thomas Aglassinger
39 */
40public class JomicToolbar extends JToolBar implements ActionListener
41{
42    private static Log logger = LogFactory.getLog(JomicToolbar.class);
43    private ActionDelegate delegate;
44    private JButton exportButton;
45    private JButton firstButton;
46    private LocaleTools localeTools;
47    private JButton nextButton;
48    private JButton nextButtonFew;
49    private JLabel pageLabel;
50    private JButton previousButton;
51    private JButton previousButtonFew;
52    private Settings settings;
53    private JButton zoomToActualButton;
54    private JButton zoomToFitButton;
55 
56    public JomicToolbar() {
57        settings = Settings.instance();
58        localeTools = LocaleTools.instance();
59        firstButton = createButton("goFirst", Commands.FIRST_PAGE, "goToFront");
60        previousButtonFew = createButton("goPreviousFew", Commands.GO_PREVIOUS_FEW, null);
61        previousButton = createButton("goPrevious", Commands.GO_PREVIOUS, null);
62        nextButton = createButton("goNext", Commands.GO_NEXT, null);
63        nextButtonFew = createButton("goNextFew", Commands.GO_NEXT_FEW, null);
64        exportButton = createButton("export", Commands.EXPORT, "exportCurrentImage");
65        zoomToActualButton = createButton("zoomToActual", Commands.FIT_ACTUAL_SIZE, null);
66        zoomToFitButton = createButton("zoomToFit", Commands.FIT_WIDTH_AND_HEIGHT, null);
67        pageLabel = new JLabel();
68 
69        add(firstButton);
70        add(previousButtonFew);
71        add(previousButton);
72        add(nextButton);
73        add(nextButtonFew);
74        addSeparator();
75        add(exportButton);
76        addSeparator();
77        add(zoomToActualButton);
78        add(zoomToFitButton);
79        addSeparator();
80        add(pageLabel);
81        setUIState(UIStates.EMPTY);
82        setFloatable(false);
83 
84        delegate = new ActionDelegate(logger);
85    }
86 
87    /**
88     *  Enables/disables buttons to change page.
89     */
90    public final void setEnabledPageButtons(boolean isFirstPage, boolean isLastPage) {
91        firstButton.setEnabled(!isFirstPage);
92        previousButtonFew.setEnabled(!isFirstPage);
93        previousButton.setEnabled(!isFirstPage);
94        nextButton.setEnabled(!isLastPage);
95        nextButtonFew.setEnabled(!isLastPage);
96    }
97 
98    /**
99     * @see    #setEnabledPageButtons(boolean, boolean)
100     */
101    void setUIState(String state) {
102        assert UIStates.isValidState(state);
103        if (state.equals(UIStates.EMPTY)) {
104            firstButton.setEnabled(false);
105            previousButtonFew.setEnabled(false);
106            previousButton.setEnabled(false);
107            nextButton.setEnabled(false);
108            nextButtonFew.setEnabled(false);
109            exportButton.setEnabled(false);
110        } else if (state.equals(UIStates.OPENING)) {
111            if (logger.isDebugEnabled()) {
112                logger.debug("ignoring state=" + state);
113            }
114        } else if (state.equals(UIStates.VIEWING)) {
115            exportButton.setEnabled(true);
116        } else {
117            assert false : "state = " + state;
118        }
119    }
120 
121    /**
122     *  Depending on <code>Settings.getShowToolbar()</code>, either get the preferred size of the
123     *  super class, or a (0, 0).
124     */
125    public Dimension getPreferredSize() {
126        Dimension result;
127 
128        if (settings.getShowToolbar()) {
129            result = super.getPreferredSize();
130        } else {
131            result = new Dimension(0, 0);
132        }
133        return result;
134    }
135 
136    public final void actionPerformed(ActionEvent event) {
137        delegate.actionPerformed(event);
138    }
139 
140    public final void addActionListener(ActionListener listener) {
141        delegate.addActionListener(listener);
142    }
143 
144    public final void removeActionListener(ActionListener listener) {
145        delegate.removeActionListener(listener);
146    }
147 
148    public void dispose() {
149        // Do nothing for now.
150    }
151 
152    private JButton createButton(
153            String imageName,
154            String command,
155            String toolTipTextKey) {
156        assert imageName != null;
157        assert command != null;
158 
159        String imgLocation = "/net/sf/jomic/images/" + imageName + ".png";
160        URL imageURL = JomicToolbar.class.getResource(imgLocation);
161        JButton button = new JButton();
162        String toolTipText = null;
163 
164        if (toolTipTextKey != null) {
165            toolTipText = localeTools.getMessage("toolbars.viewer.tooltips." + toolTipTextKey);
166            button.setToolTipText(toolTipText);
167        }
168 
169        if (imageURL != null) {
170            // Image found
171            button.setIcon(new ImageIcon(imageURL));
172        } else {
173            // No image found
174            String message = localeTools.getMessage("errors.cannotFindToolbarImage", imgLocation);
175 
176            throw new IllegalArgumentException(message);
177        }
178        button.setActionCommand(command);
179        button.addActionListener(this);
180        return button;
181    }
182}

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