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

COVERAGE SUMMARY FOR SOURCE FILE [FullScreenPopupHandler.java]

nameclass, %method, %block, %line, %
FullScreenPopupHandler.java100% (1/1)100% (6/6)98%  (169/173)97%  (38.8/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FullScreenPopupHandler100% (1/1)100% (6/6)98%  (169/173)97%  (38.8/40)
findSetWriterMenu (): JMenu 100% (1/1)86%  (25/29)82%  (5.8/7)
FullScreenPopupHandler (JPopupMenu, WhiteBoardUserService, AccountRepository,... 100% (1/1)100% (26/26)100% (8/8)
contextChanged (GuiContext): void 100% (1/1)100% (95/95)100% (21/21)
getMenuLabel (Account): String 100% (1/1)100% (16/16)100% (1/1)
getPopup (): JPopupMenu 100% (1/1)100% (3/3)100% (1/1)
setGuiContext (GuiContext): void 100% (1/1)100% (4/4)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.view;
16 
17import java.awt.Component;
18import java.util.SortedMap;
19import java.util.TreeMap;
20 
21import javax.swing.Action;
22import javax.swing.JMenu;
23import javax.swing.JMenuItem;
24import javax.swing.JPopupMenu;
25 
26import org.jdesktop.application.Resource;
27 
28import net.sourceforge.hiveboard.Account;
29import net.sourceforge.hiveboard.WhiteBoardUserService;
30import net.sourceforge.hiveboard.command.GeneralSetWriter;
31import net.sourceforge.hiveboard.model.AccountRepository;
32import net.sourceforge.hiveboard.util.GuiContext;
33import net.sourceforge.hiveboard.util.GuiContextListener;
34import net.sourceforge.hiveboard.util.TokenSetterHelper;
35import net.sourceforge.hivegui.application.ApplicationContextHolder;
36import net.sourceforge.hivegui.application.HiveGuiApplicationMain;
37 
38/**
39 * Dynamically handles the content of the popup menu that shows in full screen
40 * mode. It is completely event-driven and dynamically updates the list of
41 * present participants to the currently showing whiteboard, instantiates
42 * commands for each of them, updates labels when needed (ie when visa or name 
43 * changes)...
44 *
45 * @author Jean-Francois Poilpret
46 */
47public class FullScreenPopupHandler implements GuiContextListener
48{
49        public FullScreenPopupHandler(        JPopupMenu                                        popup,
50                                                                        WhiteBoardUserService                service,
51                                                                        AccountRepository                        accounts,
52                                                                        ApplicationContextHolder        holder)
53        {
54                _application = holder.getApplication();
55                _popup = popup;
56                _service = service;
57                _accounts = accounts;
58 
59                // Find the "set-any-writer" menu for later update
60                _setWriterMenu = findSetWriterMenu();
61 
62                holder.getContext().getResourceMap(FullScreenPopupHandler.class).injectFields(this);
63        }
64        
65        public void        setGuiContext(GuiContext context)
66        {
67                context.addContextListener(this);
68        }
69        
70        public JPopupMenu        getPopup()
71        {
72                return _popup;
73        }
74 
75        private JMenu        findSetWriterMenu()
76        {
77                // Find the "set-any-writer" menu for later update
78                for (int i = 0; i < _popup.getComponentCount(); i++)
79                {
80                        Component comp = _popup.getComponent(i);
81                        if (comp instanceof JMenu)
82                        {
83                                JMenu menu = (JMenu) comp;
84                                if ("set-any-writer".equals(menu.getActionCommand()))
85                                {
86                                        return menu;
87                                }
88                        }
89                }
90                return null;
91        }
92 
93        public void contextChanged(GuiContext context)
94        {
95                if (context.getDrawBoard() == null)
96                {
97                        // Nothing to do, we cannot be in fullscreen mode currently!
98                        return;
99                }
100                // Check that we can give the token to participants
101                boolean enabled = TokenSetterHelper.canGiveToken(        context.getBoard(), 
102                                                                         context.getIdentity().getId());
103                _setWriterMenu.removeAll();
104                _setWriterMenu.setEnabled(enabled);
105                if (!enabled)
106                {
107                        return;
108                }
109                
110                // Reset content of "set-any-writer" menu item
111                int where = context.getBoard().getId();
112                SortedMap<String, JMenuItem> presents = new TreeMap<String, JMenuItem>();
113                for (int who: context.getBoard().getPresents())
114                {
115                        Account account = _accounts.getAccount(who);
116                        JMenuItem item = new JMenuItem();
117                        Action command = GeneralSetWriter.createAction(
118                                                                                _application, _service, account, where);
119                        command.putValue(Action.NAME, getMenuLabel(account));
120                        item.setAction(command);
121                        presents.put((String) command.getValue(Action.NAME), item);
122                }
123                // Add each item in the correct sort order
124                for (JMenuItem item: presents.values())
125                {
126                        _setWriterMenu.add(item);
127                }
128        }
129        
130        protected String        getMenuLabel(Account who)
131        {
132                return String.format(        _formatGiveToken,
133                                                                who.getVisa(),
134                                                                who.getName());
135        }
136 
137        private final HiveGuiApplicationMain        _application;
138        private final JPopupMenu                                _popup;
139        private final WhiteBoardUserService                _service;
140        private final AccountRepository                        _accounts;
141        private final JMenu                                                _setWriterMenu;
142 
143        @Resource(key = "Popup.formatGiveToken")
144        private String                                                        _formatGiveToken;
145}

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