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

COVERAGE SUMMARY FOR SOURCE FILE [HiveBoardChannelHooksInitializerImpl.java]

nameclass, %method, %block, %line, %
HiveBoardChannelHooksInitializerImpl.java100% (7/7)100% (19/19)100% (343/343)100% (78/78)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HiveBoardChannelHooksInitializerImpl100% (1/1)100% (7/7)100% (275/275)100% (60/60)
HiveBoardChannelHooksInitializerImpl (ApplicationContextHolder, ViewFactory, ... 100% (1/1)100% (39/39)100% (13/13)
changeBoardSelection (Board): void 100% (1/1)100% (13/13)100% (5/5)
openBoard (BoardImageModel): void 100% (1/1)100% (24/24)100% (5/5)
registerHooks (): void 100% (1/1)100% (109/109)100% (18/18)
removeBoard (int, Board): void 100% (1/1)100% (18/18)100% (4/4)
switchFullScreen (boolean): void 100% (1/1)100% (42/42)100% (11/11)
updateIdentity (): void 100% (1/1)100% (30/30)100% (4/4)
     
class HiveBoardChannelHooksInitializerImpl$1100% (1/1)100% (2/2)100% (11/11)100% (3/3)
HiveBoardChannelHooksInitializerImpl$1 (HiveBoardChannelHooksInitializerImpl)... 100% (1/1)100% (6/6)100% (1/1)
push (Object): void 100% (1/1)100% (5/5)100% (2/2)
     
class HiveBoardChannelHooksInitializerImpl$2100% (1/1)100% (2/2)100% (11/11)100% (3/3)
HiveBoardChannelHooksInitializerImpl$2 (HiveBoardChannelHooksInitializerImpl)... 100% (1/1)100% (6/6)100% (1/1)
push (Object): void 100% (1/1)100% (5/5)100% (2/2)
     
class HiveBoardChannelHooksInitializerImpl$3100% (1/1)100% (2/2)100% (10/10)100% (3/3)
HiveBoardChannelHooksInitializerImpl$3 (HiveBoardChannelHooksInitializerImpl)... 100% (1/1)100% (6/6)100% (1/1)
push (Account): void 100% (1/1)100% (4/4)100% (2/2)
     
class HiveBoardChannelHooksInitializerImpl$4100% (1/1)100% (2/2)100% (11/11)100% (3/3)
HiveBoardChannelHooksInitializerImpl$4 (HiveBoardChannelHooksInitializerImpl)... 100% (1/1)100% (6/6)100% (1/1)
push (Board): void 100% (1/1)100% (5/5)100% (2/2)
     
class HiveBoardChannelHooksInitializerImpl$5100% (1/1)100% (2/2)100% (11/11)100% (3/3)
HiveBoardChannelHooksInitializerImpl$5 (HiveBoardChannelHooksInitializerImpl)... 100% (1/1)100% (6/6)100% (1/1)
push (BoardImageModel): void 100% (1/1)100% (5/5)100% (2/2)
     
class HiveBoardChannelHooksInitializerImpl$6100% (1/1)100% (2/2)100% (14/14)100% (3/3)
HiveBoardChannelHooksInitializerImpl$6 (HiveBoardChannelHooksInitializerImpl)... 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (8/8)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.main;
16 
17import java.awt.BorderLayout;
18 
19import javax.swing.JToolBar;
20 
21import org.flexdock.docking.Dockable;
22import org.flexdock.docking.DockingManager;
23import org.flexdock.docking.DockingPort;
24import org.flexdock.view.View;
25import org.jdesktop.application.ApplicationContext;
26import org.jdesktop.application.ResourceMap;
27 
28import net.sourceforge.hiveboard.Account;
29import net.sourceforge.hiveboard.Board;
30import net.sourceforge.hiveboard.Event;
31import net.sourceforge.hiveboard.EventType;
32import net.sourceforge.hiveboard.docking.ViewHelper;
33import net.sourceforge.hiveboard.drawing.ToolHandler;
34import net.sourceforge.hiveboard.event.ConstraintEventFilter;
35import net.sourceforge.hiveboard.event.Constraints;
36import net.sourceforge.hiveboard.event.EventsPriorities;
37import net.sourceforge.hiveboard.event.PersistentDeferredConsumer;
38import net.sourceforge.hiveboard.model.BoardImageModel;
39import net.sourceforge.hiveboard.view.DrawingArea;
40import net.sourceforge.hiveboard.view.DrawingAreaPanel;
41import net.sourceforge.hiveevents.Channel;
42import net.sourceforge.hiveevents.PersistentConsumer;
43import net.sourceforge.hivegui.application.ApplicationContextHolder;
44import net.sourceforge.hivegui.application.HiveGuiApplicationMain;
45import net.sourceforge.hivegui.docking.DockingHelper;
46import net.sourceforge.hivegui.docking.EmptyableViewport;
47import net.sourceforge.hivegui.docking.ViewFactory;
48 
49public class HiveBoardChannelHooksInitializerImpl implements HiveBoardChannelHooksInitializer
50{
51        public HiveBoardChannelHooksInitializerImpl(ApplicationContextHolder        appHolder,
52                                                                                                ViewFactory                                        viewFactory,
53                                                                                                IdentityHolder                                holder,
54                                                                                                ToolHandler                                        toolHandler,
55                                                                                                Channel<Object>                                fullScreenMode,
56                                                                                                Channel<Object>                                windowMode,
57                                                                                                Channel<Account>                        identityChange,
58                                                                                                Channel<Board>                                selectBoardChannel,
59                                                                                                Channel<BoardImageModel>        openBoardChannel,
60                                                                                                Channel<Event>                                eventsChannel)
61        {
62                _context = appHolder.getContext();
63                _application = appHolder.getApplication();
64                _viewFactory = viewFactory;
65                _holder = holder;
66                _toolbar = toolHandler.getToolBar();
67                _fullScreenMode = fullScreenMode;
68                _windowMode = windowMode;
69                _identityChange = identityChange;
70                _selectedBoardChannel = selectBoardChannel;
71                _openBoardChannel = openBoardChannel;
72                _eventsChannel = eventsChannel;
73        }
74        
75        public void        registerHooks()
76        {
77                // Register consumer for screen mode switching channels
78                int priority = EventsPriorities.WINDOWSHELL_FULL_SWITCH;
79                _fullScreenMode.registerPushConsumer(priority, new PersistentConsumer<Object>()
80                {
81                        public void        push(Object event)
82                        {
83                                switchFullScreen(true);
84                        }
85                });
86                priority = EventsPriorities.WINDOWSHELL_WINDOW_SWITCH;
87                _windowMode.registerPushConsumer(priority, new PersistentConsumer<Object>()
88                {
89                        public void        push(Object event)
90                        {
91                                switchFullScreen(false);
92                        }
93                });
94                
95                // Register consumer for changes in self identity (to update main frame title)
96                priority = EventsPriorities.IDENTITY_GUI_UPDATE;
97                _identityChange.registerPushConsumer(priority, new PersistentConsumer<Account>()
98                {
99                        public void        push(Account event)
100                        {
101                                updateIdentity();
102                        }
103                });
104                
105                // Register consumer for change in board current selection 
106                // (to activate the matching drawing area view)
107                priority = EventsPriorities.SELECTED_BOARD_GUI_REFRESH;
108                _selectedBoardChannel.registerPushConsumer(priority, new PersistentConsumer<Board>()
109                {
110                        public void        push(Board board)
111                        {
112                                changeBoardSelection(board);
113                        }
114                });
115                
116                // Register consumer for board open after user request (and server response)
117                priority = EventsPriorities.BOARDSLIST_OPEN_BOARD;
118                _openBoardChannel.registerPushConsumer(        priority, 
119                                                                                                new PersistentConsumer<BoardImageModel>()
120                {
121                        public void        push(BoardImageModel model)
122                        {
123                                openBoard(model);
124                        }
125                });
126 
127                // Listen to LEAVE_BOARD & BOARD_DEL_PARTICIPANT events in order to remove
128                // board image panel
129                // Also listen to MODIFY_BOARD event (that may also remove self from participants)
130                String constraint1 = Constraints.eventTypeWho(
131                        _holder.getId(), EventType.EVT_LEAVE_BOARD, EventType.EVT_BOARD_DEL_PARTICIPANT);
132                String constraint2 = Constraints.eventType(EventType.EVT_MODIFY_BOARD);
133                String constraint = constraint1 + " || " + constraint2;
134                ConstraintEventFilter filter = new ConstraintEventFilter(constraint);
135                priority = EventsPriorities.BOARDSLIST_REMOVAL_UPDATE;
136                _eventsChannel.registerPushConsumer(priority, filter, new PersistentDeferredConsumer()
137                {
138                        @Override protected void pushEvent(Event event)
139                        {
140                                removeBoard(event.getWhere(), event.getBoard());
141                        }
142                });
143 
144                updateIdentity();
145        }
146 
147        protected void        switchFullScreen(boolean fullScreen)
148        {
149                View active = (View) EmptyableViewport.getEmptyablePort().getDockable(
150                                                                                                        DockingManager.CENTER_REGION);
151                DrawingAreaPanel activeArea = (DrawingAreaPanel) active.getContentPane();
152                if (fullScreen)
153                {
154                        activeArea.detachArea();
155                        _application.getMainFrame().setVisible(false);
156                        _application.getMainFrame().getContentPane().remove(_toolbar);
157                }
158                else
159                {
160                        _application.getMainFrame().getContentPane().add(_toolbar, BorderLayout.NORTH);
161                        _application.getMainFrame().setVisible(true);
162                        activeArea.attachArea();
163                }
164        }
165        
166        protected void        updateIdentity()
167        {
168                ResourceMap map = _context.getResourceMap();
169                String title = map.getString(        "usertitle", 
170                                                                                _holder.getIdentity().getVisa(), 
171                                                                                _holder.getIdentity().getName());
172                _application.getMainFrame().setTitle(title);
173        }
174        
175        protected void        changeBoardSelection(Board board)
176        {
177                if (board != null)
178                {
179                        View area = ViewHelper.findDrawingArea(board);
180                        if (area != null)
181                        {
182                                //#### Problem: BoardsList table does not have focus yet...
183                                DockingHelper.selectView(
184                                        EmptyableViewport.getEmptyablePort(), area.getPersistentId());
185                        }
186                }
187        }
188 
189        protected void        openBoard(BoardImageModel model)
190        {
191                DrawingAreaPanel area = new DrawingAreaPanel(new DrawingArea(model));
192                View view = _viewFactory.createView(
193                                                ViewHelper.getBoardAreaViewId(model.getBoard()), area);
194                EmptyableViewport port = EmptyableViewport.getEmptyablePort();
195                DockingManager.dock((Dockable) view, (DockingPort) port, DockingManager.CENTER_REGION);
196        }
197        
198        protected void        removeBoard(int idBoard, Board board)
199        {
200                View area = ViewHelper.findDrawingArea(idBoard);
201                if (        (area != null)
202                        &&        (board == null || !board.getParticipants().contains(_holder.getId())))
203                {
204                        DockingManager.close(area);
205                }
206        }
207 
208        final protected ApplicationContext                        _context;
209        final protected HiveGuiApplicationMain                _application;
210        final protected ViewFactory                                        _viewFactory;
211        final protected IdentityHolder                                _holder;
212        final protected JToolBar                                        _toolbar;
213        final protected Channel<Object>                                _fullScreenMode;
214        final protected Channel<Object>                                _windowMode;
215        final protected Channel<Account>                        _identityChange;
216        final protected Channel<Board>                                _selectedBoardChannel;
217        final protected Channel<BoardImageModel>        _openBoardChannel;
218        final protected Channel<Event>                                _eventsChannel;
219}

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