EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.drawing]

COVERAGE SUMMARY FOR SOURCE FILE [LinePropertyTool.java]

nameclass, %method, %block, %line, %
LinePropertyTool.java100% (2/2)100% (10/10)100% (212/212)100% (43/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LinePropertyTool100% (1/1)100% (8/8)100% (190/190)100% (40/40)
LinePropertyTool (): void 100% (1/1)100% (44/44)100% (9/9)
accept (): void 100% (1/1)100% (14/14)100% (3/3)
access$000 (LinePropertyTool, float, Icon): void 100% (1/1)100% (5/5)100% (1/1)
addLineItem (int): void 100% (1/1)100% (66/66)100% (13/13)
initProperty (): void 100% (1/1)100% (8/8)100% (2/2)
initResources (ResourceMap): void 100% (1/1)100% (30/30)100% (7/7)
updateStroke (): void 100% (1/1)100% (17/17)100% (3/3)
updateStroke (float, Icon): void 100% (1/1)100% (6/6)100% (3/3)
     
class LinePropertyTool$1100% (1/1)100% (2/2)100% (22/22)100% (3/3)
LinePropertyTool$1 (LinePropertyTool, int, JCheckBoxMenuItem): void 100% (1/1)100% (12/12)100% (1/1)
actionPerformed (ActionEvent): void 100% (1/1)100% (10/10)100% (2/2)

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.hiveboard.drawing;
16 
17import java.awt.BasicStroke;
18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
20 
21import javax.swing.ButtonGroup;
22import javax.swing.Icon;
23import javax.swing.JCheckBoxMenuItem;
24import javax.swing.JPopupMenu;
25import javax.swing.SwingConstants;
26 
27import org.jdesktop.application.Resource;
28import org.jdesktop.application.ResourceMap;
29 
30// DrawingEditor can be seen as any "tool" from the graphics toolbar
31public class LinePropertyTool extends AbstractPushButtonTool
32{
33        static final public String                TOOL_PROPERTY_LINE = "Line";
34        
35        @Override protected void initProperty()
36        {
37                _properties.put(TOOL_PROPERTY_LINE, _stroke);
38        }
39 
40        @Override protected void initResources(ResourceMap map)
41        {
42                super.initResources(map);
43                // Now create the popup menu
44                _popup = new JPopupMenu();
45                _popup.setName("line-thickness-popup");
46                for (int i = 0; i < ITEMS_COUNT; i++)
47                {
48                        addLineItem(i);
49                }
50                ((JCheckBoxMenuItem) _popup.getComponent(0)).setSelected(true);
51        }
52        
53        private void        addLineItem(int index)
54        {
55                final int thickness = _linesThickness[index];
56                final JCheckBoxMenuItem item = new JCheckBoxMenuItem();
57                item.setName("line-thickness-item-" + thickness);
58                item.setHorizontalAlignment(SwingConstants.LEFT);
59                if (thickness <= 1)
60                {
61                        item.setText(_onePixelText);
62                }
63                else
64                {
65                        item.setText(String.format(_manyPixelsFormat, thickness));
66                }
67                item.setIcon(_icons[index]);
68                item.addActionListener(new ActionListener()
69                {
70                        public void        actionPerformed(ActionEvent e)
71                        {
72                                updateStroke(thickness, item.getIcon());
73                        }
74                });
75                _popup.add(item);
76                _group.add(item);
77        }
78 
79        @Override public void        accept()
80        {
81                // Open popup menu to choose line thickness
82                _popup.show(_button, 0, _button.getHeight());
83                _button.setSelected(false);
84        }
85        
86        private void        updateStroke(float thickness, Icon icon)
87        {
88                _thickness = thickness;
89                updateStroke();
90        }
91 
92        private void        updateStroke()
93        {
94                _stroke = new BasicStroke(        _thickness,
95                                                                        BasicStroke.CAP_ROUND,
96                                                                        BasicStroke.JOIN_ROUND,
97                                                                        0.0f,
98                                                                        _dash,
99                                                                        _dashPhase);
100                initProperty();
101        }
102 
103        static private final int        ITEMS_COUNT = 9;
104 
105        @Resource(key = "thickness")
106        private int[]                                _linesThickness = new int[ITEMS_COUNT];
107        @Resource(key = "icon")
108        private Icon[]                                _icons = new Icon[ITEMS_COUNT];
109        @Resource(key = "textOne")
110        private String                                _onePixelText;
111        @Resource(key = "textMany")
112        private String                                _manyPixelsFormat;
113 
114        private float                                _thickness = 1.0f;
115        private float[]                                _dash = null;
116        private float                                _dashPhase = 0.0f;
117        private JPopupMenu                        _popup = new JPopupMenu();
118        private ButtonGroup                        _group = new ButtonGroup();
119        private BasicStroke                        _stroke = new BasicStroke(        _thickness,
120                                                                                                                        BasicStroke.CAP_ROUND,
121                                                                                                                        BasicStroke.JOIN_ROUND,
122                                                                                                                        0.0f,
123                                                                                                                        _dash,
124                                                                                                                        _dashPhase);
125}

[all classes][net.sourceforge.hiveboard.drawing]
EMMA 2.0.5312 (C) Vladimir Roubtsov