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

COVERAGE SUMMARY FOR SOURCE FILE [TextTool.java]

nameclass, %method, %block, %line, %
TextTool.java100% (1/1)100% (2/2)100% (118/118)100% (23/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TextTool100% (1/1)100% (2/2)100% (118/118)100% (23/23)
TextTool (): void 100% (1/1)100% (42/42)100% (9/9)
execute (JComponent, Point): DrawingAction 100% (1/1)100% (76/76)100% (14/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.hiveboard.drawing;
16 
17import java.awt.Color;
18import java.awt.Font;
19import java.awt.FontMetrics;
20import java.awt.Point;
21 
22import javax.swing.JComponent;
23import javax.swing.JTextArea;
24import javax.swing.border.EmptyBorder;
25 
26// DrawingTool can be seen as any "tool" from the graphics toolbar
27public class TextTool extends AbstractToggleButtonTool implements MouseClickTool
28{
29        public TextTool()
30        {
31                _panel = new TextToolPanel();
32                _field.setBorder(new EmptyBorder(0, 0 , 0, 0));
33                _field.setOpaque(false);
34                _field.setName("toolbar-text-field");
35                _field.setSize(VIRTUAL_FIELD_SIZE, VIRTUAL_FIELD_SIZE);
36                _field.setDocument(_panel.getFieldDocument());
37        }
38        
39        public DrawingAction        execute(JComponent area, Point location)
40        {
41                Color penColor = (Color) _properties.get(ColorPropertyTool.TOOL_PROPERTY_COLOR);
42                Font font = (Font) _properties.get(FontPropertyTool.TOOL_PROPERTY_FONT);
43 
44                // Create a text field in the drawing area to show immediate feedback
45                _field.setFont(font);
46                _field.setForeground(penColor);
47                area.add(_field);
48                FontMetrics metrics = _field.getFontMetrics(font);
49                _field.setLocation(location.x, location.y - metrics.getAscent());
50                // Display dialog to enter text content
51                boolean accepted = _application.showDialog(_panel);
52                // Don't forget to remove feedback field from drawing are
53                area.remove(_field);
54                if (!accepted)
55                {
56                        area.repaint();
57                        return null;
58                }
59                TextAreaInfo info = new TextAreaInfo(_field);
60                return new TextDrawingAction(        location.x, 
61                                                     location.y,
62                                                                                info.getLines(),
63                                                                                font,
64                                                                                penColor,
65                                                                                info.getLineHeight());
66        }
67        
68        static final private int        VIRTUAL_FIELD_SIZE = 10000;
69 
70        final private TextToolPanel        _panel;
71        final private JTextArea                _field = new TextPaintingComponent();
72}

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