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

COVERAGE SUMMARY FOR SOURCE FILE [ColorButton.java]

nameclass, %method, %block, %line, %
ColorButton.java100% (1/1)80%  (4/5)54%  (53/99)58%  (13.4/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ColorButton100% (1/1)80%  (4/5)54%  (53/99)58%  (13.4/23)
actionPerformed (ActionEvent): void 0%   (0/1)0%   (0/38)0%   (0/9)
<static initializer> 100% (1/1)68%  (17/25)70%  (1.4/2)
ColorButton (Color): void 100% (1/1)100% (15/15)100% (6/6)
dispose (): void 100% (1/1)100% (4/4)100% (2/2)
setColor (Color): void 100% (1/1)100% (17/17)100% (4/4)

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.Color;
19import java.awt.event.ActionEvent;
20import java.awt.event.ActionListener;
21import java.awt.image.BufferedImage;
22 
23import javax.swing.ImageIcon;
24import javax.swing.JButton;
25import javax.swing.JColorChooser;
26 
27import net.sf.jomic.tools.ImageTools;
28 
29import org.apache.commons.logging.Log;
30import org.apache.commons.logging.LogFactory;
31 
32/**
33 *  Button to show a color, and open a JColorChooser to change it once clicked.
34 *
35 * @author    Thomas Aglassinger
36 */
37public class ColorButton extends JButton implements ActionListener
38{
39    private static final int COLOR_BOX_SIZE = 32;
40    private static final String COMMAND_CHOOSE = "choose";
41    private static Log logger = LogFactory.getLog(ColorButton.class);
42    private Color color;
43    private ImageTools imageTools;
44 
45    public ColorButton(Color newColor) {
46        imageTools = ImageTools.instance();
47        setActionCommand(COMMAND_CHOOSE);
48        addActionListener(this);
49        setColor(newColor);
50    }
51 
52    public void setColor(Color newColor) {
53        BufferedImage image = imageTools.createColorBox(COLOR_BOX_SIZE, COLOR_BOX_SIZE, newColor);
54 
55        setIcon(new ImageIcon(image));
56        color = newColor;
57    }
58 
59    public void actionPerformed(ActionEvent event) {
60        assert event != null;
61        String command = event.getActionCommand();
62 
63        if (command.equals(COMMAND_CHOOSE)) {
64            Color newColor = JColorChooser.showDialog(this, "Choose border color", color);
65 
66            if (newColor != null) {
67                setColor(newColor);
68            }
69        } else {
70            logger.warn("unknown command: " + command);
71        }
72    }
73 
74    public void dispose() {
75        removeActionListener(this);
76    }
77}

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