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

COVERAGE SUMMARY FOR SOURCE FILE [TablePopupHandler.java]

nameclass, %method, %block, %line, %
TablePopupHandler.java0%   (0/3)0%   (0/14)0%   (0/150)0%   (0/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TablePopupHandler0%   (0/1)0%   (0/9)0%   (0/97)0%   (0/24)
TablePopupHandler (BeanTable, TableContribution): void 0%   (0/1)0%   (0/29)0%   (0/8)
access$100 (TablePopupHandler, MouseEvent): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$200 (TablePopupHandler): Action 0%   (0/1)0%   (0/3)0%   (0/1)
access$300 (TablePopupHandler): BeanTable 0%   (0/1)0%   (0/3)0%   (0/1)
addNotify (Container): void 0%   (0/1)0%   (0/11)0%   (0/3)
getDoubleClickCommand (): Action 0%   (0/1)0%   (0/3)0%   (0/1)
managePopupTrigger (MouseEvent): void 0%   (0/1)0%   (0/29)0%   (0/6)
removeNotify (Container): void 0%   (0/1)0%   (0/11)0%   (0/3)
setDoubleClickCommand (Action): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class TablePopupHandler$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class TablePopupHandler$TableMouseListener0%   (0/1)0%   (0/5)0%   (0/53)0%   (0/9)
TablePopupHandler$TableMouseListener (TablePopupHandler): void 0%   (0/1)0%   (0/6)0%   (0/1)
TablePopupHandler$TableMouseListener (TablePopupHandler, TablePopupHandler$1)... 0%   (0/1)0%   (0/4)0%   (0/1)
mouseClicked (MouseEvent): void 0%   (0/1)0%   (0/33)0%   (0/4)
mousePressed (MouseEvent): void 0%   (0/1)0%   (0/5)0%   (0/2)
mouseReleased (MouseEvent): void 0%   (0/1)0%   (0/5)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.table;
16 
17import java.awt.Container;
18import java.awt.event.ActionEvent;
19import java.awt.event.MouseAdapter;
20import java.awt.event.MouseEvent;
21import java.awt.event.MouseListener;
22 
23import javax.swing.Action;
24import javax.swing.JPopupMenu;
25import javax.swing.JViewport;
26 
27/**
28 * @author Jean-Francois Poilpret
29 */
30public class TablePopupHandler<T>
31{
32        public TablePopupHandler(BeanTable<T> table, TableContribution contrib)
33        {
34                _table = table;
35                _popup = contrib.getPopup();
36                _command = contrib.getDoubleClickCommand();
37                _mouseListener = new TableMouseListener();
38            _table.addMouseListener(_mouseListener);
39        }
40        
41        public void        setDoubleClickCommand(Action command)
42        {
43                _command = command;
44        }
45 
46        public Action        getDoubleClickCommand()
47        {
48                return _command;
49        }
50 
51        public void        addNotify(Container parent)
52        {
53                if (        parent instanceof JViewport
54                        &&        _mouseListener != null)
55                {
56                        parent.addMouseListener(_mouseListener);
57                }
58        }
59 
60        public void        removeNotify(Container parent)
61        {
62                if (        parent instanceof JViewport
63                        &&        _mouseListener != null)
64                {
65                        parent.removeMouseListener(_mouseListener);
66                }
67        }
68        
69        private void        managePopupTrigger(MouseEvent e)
70        {
71                if (e.isPopupTrigger() && _popup != null)
72                {
73                        // First select clicked row
74                        int index = _table.rowAtPoint(e.getPoint());
75                        if (index >= 0)
76                        {
77                                _table.setRowSelectionInterval(index, index);
78                        }
79                        _popup.show(_table, e.getX(), e.getY());
80                }
81        }
82        
83        private class TableMouseListener extends MouseAdapter
84        {
85                @Override public void        mousePressed(MouseEvent e)
86                {
87                        managePopupTrigger(e);
88                }
89 
90                @Override public void        mouseReleased(MouseEvent e)
91                {
92                        managePopupTrigger(e);
93                }
94 
95                @Override public void        mouseClicked(MouseEvent e)
96                {
97                        if (e.getClickCount() == 2 && _command != null && _command.isEnabled())
98                        {
99                                ActionEvent evt;
100                                evt = new ActionEvent(        _table, 
101                                                                                ActionEvent.ACTION_PERFORMED,
102                                                                                (String) _command.getValue(Action.ACTION_COMMAND_KEY));
103                                _command.actionPerformed(evt);
104                        }
105                }
106        }
107        
108        private final BeanTable<T>        _table;
109        private final JPopupMenu        _popup;
110        private Action                                _command;
111        private MouseListener                _mouseListener = null;
112}

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