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

COVERAGE SUMMARY FOR SOURCE FILE [SelectAllFocusListener.java]

nameclass, %method, %block, %line, %
SelectAllFocusListener.java0%   (0/3)0%   (0/10)0%   (0/84)0%   (0/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SelectAllFocusListener0%   (0/1)0%   (0/6)0%   (0/54)0%   (0/14)
<static initializer> 0%   (0/1)0%   (0/5)0%   (0/1)
SelectAllFocusListener (): void 0%   (0/1)0%   (0/3)0%   (0/1)
focusGained (FocusEvent): void 0%   (0/1)0%   (0/18)0%   (0/4)
focusLost (FocusEvent): void 0%   (0/1)0%   (0/18)0%   (0/4)
setAutoSelect (JSpinner): void 0%   (0/1)0%   (0/6)0%   (0/2)
setAutoSelect (JTextComponent): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class SelectAllFocusListener$10%   (0/1)0%   (0/2)0%   (0/13)0%   (0/3)
SelectAllFocusListener$1 (SelectAllFocusListener, JTextComponent): void 0%   (0/1)0%   (0/9)0%   (0/1)
run (): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class SelectAllFocusListener$20%   (0/1)0%   (0/2)0%   (0/17)0%   (0/3)
SelectAllFocusListener$2 (SelectAllFocusListener, JTextComponent): void 0%   (0/1)0%   (0/9)0%   (0/1)
run (): void 0%   (0/1)0%   (0/8)0%   (0/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.hivegui.component;
16 
17import java.awt.EventQueue;
18import java.awt.event.FocusEvent;
19import java.awt.event.FocusListener;
20 
21import javax.swing.JSpinner;
22import javax.swing.text.JTextComponent;
23 
24public class SelectAllFocusListener implements FocusListener
25{
26        static private final FocusListener        SELECT_ALL_FOCUS_LISTENER =
27                                                                                                new SelectAllFocusListener();
28        
29        // NB: must be called after the spinner has been added to the layout (why????)
30        static public void        setAutoSelect(JSpinner spinner)
31        {
32                setAutoSelect(((JSpinner.DefaultEditor) spinner.getEditor()).getTextField());
33        }
34 
35        static public void        setAutoSelect(JTextComponent field)
36        {
37                field.addFocusListener(SELECT_ALL_FOCUS_LISTENER);
38        }
39 
40        public void focusGained(FocusEvent e)
41        {
42                if (        (!e.isTemporary())
43                        &&        (e.getComponent() instanceof JTextComponent))
44                {
45                        final JTextComponent field = (JTextComponent) e.getComponent();
46                        EventQueue.invokeLater(new Runnable()
47                        {
48                                public void        run()
49                                {
50                                        field.selectAll();
51                                }
52                        });
53                }
54        }
55        
56        public void focusLost(FocusEvent e)
57        {
58                if (        (!e.isTemporary())
59                        &&        (e.getComponent() instanceof JTextComponent))
60                {
61                        final JTextComponent field = (JTextComponent) e.getComponent();
62                        EventQueue.invokeLater(new Runnable()
63                        {
64                                public void        run()
65                                {
66                                        field.setCaretPosition(field.getText().length());
67                                }
68                        });
69                }
70        }
71}

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