EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hivegui.application]

COVERAGE SUMMARY FOR SOURCE FILE [CursorInfoConverter.java]

nameclass, %method, %block, %line, %
CursorInfoConverter.java0%   (0/1)0%   (0/4)0%   (0/239)0%   (0/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CursorInfoConverter0%   (0/1)0%   (0/4)0%   (0/239)0%   (0/44)
CursorInfoConverter (): void 0%   (0/1)0%   (0/125)0%   (0/18)
buildCursor (int): CursorInfo 0%   (0/1)0%   (0/6)0%   (0/1)
getHotspotRate (StringTokenizer): double 0%   (0/1)0%   (0/27)0%   (0/11)
parseString (String, ResourceMap): Object 0%   (0/1)0%   (0/81)0%   (0/14)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hivegui.application;
16 
17import java.awt.Cursor;
18import java.awt.Dimension;
19import java.awt.Point;
20import java.awt.Toolkit;
21import java.util.HashMap;
22import java.util.Map;
23import java.util.StringTokenizer;
24 
25import javax.swing.ImageIcon;
26 
27import org.jdesktop.application.ResourceConverter;
28import org.jdesktop.application.ResourceMap;
29 
30import net.sourceforge.hivegui.component.CursorInfo;
31import net.sourceforge.hivegui.component.Cursors;
32 
33public class CursorInfoConverter extends ResourceConverter
34{
35        public CursorInfoConverter()
36        {
37                super(CursorInfo.class);
38                _iconConverter = forType(ImageIcon.class);
39 
40                // Initialize pre-defined cursors first
41                // Initialize pre-defined cursors first
42                _cursors.put(Cursors.CROSSHAIR,        buildCursor(Cursor.CROSSHAIR_CURSOR));
43                _cursors.put(Cursors.HAND,                buildCursor(Cursor.HAND_CURSOR));
44                _cursors.put(Cursors.TEXT,                buildCursor(Cursor.TEXT_CURSOR));
45                _cursors.put(Cursors.WAIT,                buildCursor(Cursor.WAIT_CURSOR));
46                _cursors.put(Cursors.E_RESIZE,        buildCursor(Cursor.E_RESIZE_CURSOR));
47                _cursors.put(Cursors.W_RESIZE,        buildCursor(Cursor.W_RESIZE_CURSOR));
48                _cursors.put(Cursors.N_RESIZE,        buildCursor(Cursor.N_RESIZE_CURSOR));
49                _cursors.put(Cursors.S_RESIZE,        buildCursor(Cursor.S_RESIZE_CURSOR));
50                _cursors.put(Cursors.NE_RESIZE,        buildCursor(Cursor.NE_RESIZE_CURSOR));
51                _cursors.put(Cursors.SE_RESIZE,        buildCursor(Cursor.SE_RESIZE_CURSOR));
52                _cursors.put(Cursors.NW_RESIZE,        buildCursor(Cursor.NW_RESIZE_CURSOR));
53                _cursors.put(Cursors.SW_RESIZE,        buildCursor(Cursor.SW_RESIZE_CURSOR));
54                _cursors.put(Cursors.MOVE,                buildCursor(Cursor.MOVE_CURSOR));
55                _cursors.put(Cursors.DEFAULT,        buildCursor(Cursor.DEFAULT_CURSOR));
56        }
57        
58        private CursorInfo        buildCursor(int id)
59        {
60                return new CursorInfo(Cursor.getPredefinedCursor(id));
61        }
62        
63        @Override public Object parseString(String s, ResourceMap r)
64                throws ResourceConverterException
65        {
66                CursorInfo info = _cursors.get(s);
67                if (info == null)
68                {
69                        // Split s into: iconfile, hotspotx, hotspoty
70                        StringTokenizer tokenize = new StringTokenizer(s, ",");
71                        if (tokenize.countTokens() != 0 && tokenize.countTokens() != MAX_TOKENS)
72                        {
73                                throw new ResourceConverterException(
74                                        "Bad format, expected: \"icon[,hotspotx[,hotspoty]]", s);
75                        }
76                        ImageIcon icon = (ImageIcon) _iconConverter.parseString(tokenize.nextToken(), r);
77                        double x = getHotspotRate(tokenize);
78                        double y = getHotspotRate(tokenize);
79 
80                        Toolkit kit = Toolkit.getDefaultToolkit();
81                        Dimension dim = kit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
82                        Point hotspot = new Point((int) (x * dim.width), (int) (y * dim.height));
83                        info = new CursorInfo(icon, hotspot, dim);
84                        _cursors.put(s, info);
85                }
86                return info;
87        }
88        
89        static private double        getHotspotRate(StringTokenizer token)
90        {
91                if (!token.hasMoreTokens())
92                {
93                        return MEAN_COORDINATE;
94                }
95                try
96                {
97                        double coord = Double.parseDouble(token.nextToken());
98                        if (coord >= 1.0)
99                        {
100                                coord = MAX_COORDINATE;
101                        }
102                        else if (coord < 0.0)
103                        {
104                                coord = MEAN_COORDINATE;
105                        }
106                        return coord;
107                }
108                catch (NumberFormatException e)
109                {
110                        return MEAN_COORDINATE;
111                }
112        }
113 
114        static private final int                                MAX_TOKENS                = 3;
115        static private final double                                MAX_COORDINATE        = 0.99;
116        static private final double                                MEAN_COORDINATE        = 0.5;
117        
118        private final ResourceConverter                 _iconConverter;
119        private final Map<String, CursorInfo>        _cursors = new HashMap<String, CursorInfo>();
120}

[all classes][net.sourceforge.hivegui.application]
EMMA 2.0.5312 (C) Vladimir Roubtsov