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

COVERAGE SUMMARY FOR SOURCE FILE [ImageRenderSettings.java]

nameclass, %method, %block, %line, %
ImageRenderSettings.java100% (1/1)58%  (7/12)42%  (87/206)49%  (19.7/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ImageRenderSettings100% (1/1)58%  (7/12)42%  (87/206)49%  (19.7/40)
getSelectionColor (): Color 0%   (0/1)0%   (0/4)0%   (0/1)
rotateLeft (): void 0%   (0/1)0%   (0/25)0%   (0/5)
rotateRight (): void 0%   (0/1)0%   (0/25)0%   (0/5)
setFillColor (Color): void 0%   (0/1)0%   (0/13)0%   (0/3)
setSelectionColor (Color): void 0%   (0/1)0%   (0/13)0%   (0/3)
getScaleMode (): String 100% (1/1)37%  (11/30)60%  (3/5)
setScaleMode (String): void 100% (1/1)50%  (12/24)75%  (3/4)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
ImageRenderSettings (): void 100% (1/1)88%  (35/40)99%  (8.9/9)
getFillColor (): Color 100% (1/1)100% (4/4)100% (1/1)
getRotation (): int 100% (1/1)100% (6/6)100% (1/1)
setRotation (int): void 100% (1/1)100% (7/7)100% (2/2)

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.tools;
17 
18import java.awt.Color;
19 
20import javax.swing.UIManager;
21 
22import net.sf.wraplog.Logger;
23 
24/**
25 *  Settings to specify how to render an image depending on user preferences and window size.
26 *
27 * @author    Thomas Aglassinger
28 */
29public class ImageRenderSettings extends BasicSettings
30{
31    public static final String DEFAULT_FILL_COLOR = "#ffffff";
32    public static final int DEFAULT_ROTATION = ImageTools.ROTATE_NONE;
33    public static final String DEFAULT_SCALE_MODE = ImageTools.SCALE_FIT;
34 
35    /**
36     *  Color to use when filling the border in case two pages do not have a similar aspect ratio
37     *  (specified using the HTML-like "#rrggbb" format).
38     */
39    public static final String FILL_COLOR = "fillColor";
40    public static final int MAX_ROTATION = 2;
41    public static final int MIN_ROTATION = -1;
42    public static final String ROTATION = "rotation";
43    public static final String SCALE_MODE = "scaleMode";
44 
45    /**
46     *  Color use when selection an image or a part of it.
47     */
48    public static final String SELECTION_COLOR = "selectionColor";
49 
50    private ImageTools imageTools;
51    private Logger logger;
52    private StringTools stringTools;
53 
54    public ImageRenderSettings() {
55        logger = Logger.getLogger(ImageRenderSettings.class);
56        imageTools = ImageTools.instance();
57        stringTools = StringTools.instance();
58        setDefault(FILL_COLOR, DEFAULT_FILL_COLOR);
59        setDefault(ROTATION, DEFAULT_ROTATION);
60        setDefault(SCALE_MODE, DEFAULT_SCALE_MODE);
61        setDefault(SELECTION_COLOR,
62                stringTools.colorString(UIManager.getColor("TextArea.selectionBackground")));
63    }
64 
65    public void setFillColor(Color newColor) {
66        assert newColor != null;
67        setColorProperty(FILL_COLOR, newColor);
68    }
69 
70    public void setRotation(int newRotation) {
71        setLimitedIntProperty(ROTATION, newRotation, MIN_ROTATION, MAX_ROTATION);
72    }
73 
74    public void setScaleMode(String mode) {
75        if (imageTools.isValidScaleMode(mode)) {
76            setProperty(SCALE_MODE, mode);
77        } else {
78            throw new IllegalArgumentException("scaleMode=" + mode);
79        }
80    }
81 
82    public void setSelectionColor(Color newColor) {
83        assert newColor != null;
84        setColorProperty(SELECTION_COLOR, newColor);
85    }
86 
87    public Color getFillColor() {
88        return getColorProperty(FILL_COLOR);
89    }
90 
91    /**
92     *  Get the current rotation.
93     *
94     * @return    one of ImageTools.ROTATE_*
95     * @see       ImageTools#ROTATE_NONE
96     * @see       ImageTools#ROTATE_CLOCKWISE
97     * @see       ImageTools#ROTATE_COUNTERCLOCKWISE
98     * @see       ImageTools#ROTATE_UPSIDE_DOWN
99     */
100    public int getRotation() {
101        return getLimitedIntProperty(ROTATION, MIN_ROTATION, MAX_ROTATION);
102    }
103 
104    public String getScaleMode() {
105        String result = getProperty(SCALE_MODE);
106 
107        if (!imageTools.isValidScaleMode(result)) {
108            logger.warn(
109                    "changing property "
110                    + SCALE_MODE
111                    + " from \""
112                    + result
113                    + "\" to \""
114                    + DEFAULT_SCALE_MODE
115                    + "\"");
116            result = DEFAULT_SCALE_MODE;
117        }
118        return result;
119    }
120 
121    public Color getSelectionColor() {
122        return getColorProperty(SELECTION_COLOR);
123    }
124 
125    public void rotateLeft() {
126        int newRotation = imageTools.getLeftRotation(getRotation());
127 
128        if (logger.isDebugEnabled()) {
129            logger.debug("rotate left: rotation = " + newRotation);
130        }
131        setRotation(newRotation);
132    }
133 
134    public void rotateRight() {
135        int newRotation = imageTools.getRightRotation(getRotation());
136 
137        if (logger.isDebugEnabled()) {
138            logger.debug("rotate right: rotation = " + newRotation);
139        }
140        setRotation(newRotation);
141    }
142 
143}

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