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

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