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

COVERAGE SUMMARY FOR SOURCE FILE [BoardDetailPanel.java]

nameclass, %method, %block, %line, %
BoardDetailPanel.java100% (5/5)100% (17/17)99%  (523/527)100% (89.8/90)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BoardDetailPanel$4100% (1/1)100% (1/1)88%  (23/26)88%  (0.9/1)
<static initializer> 100% (1/1)88%  (23/26)88%  (0.9/1)
     
class BoardDetailPanel$1100% (1/1)100% (2/2)98%  (41/42)99%  (6.9/7)
passEvent (Event): boolean 100% (1/1)97%  (35/36)98%  (5.9/6)
BoardDetailPanel$1 (BoardDetailPanel): void 100% (1/1)100% (6/6)100% (1/1)
     
class BoardDetailPanel100% (1/1)100% (10/10)100% (426/426)100% (73/73)
BoardDetailPanel (Channel, Channel, AccountRepository): void 100% (1/1)100% (152/152)100% (29/29)
access$000 (BoardDetailPanel): Board 100% (1/1)100% (3/3)100% (1/1)
access$100 (BoardDetailPanel): void 100% (1/1)100% (3/3)100% (1/1)
initComponentNames (): void 100% (1/1)100% (121/121)100% (11/11)
initEventConsumers (Channel, Channel): void 100% (1/1)100% (31/31)100% (7/7)
refreshBoard (): void 100% (1/1)100% (94/94)100% (16/16)
setBoard (Board): void 100% (1/1)100% (6/6)100% (3/3)
setDateFormat (String): void 100% (1/1)100% (8/8)100% (2/2)
setInitiatorFormat (String): void 100% (1/1)100% (4/4)100% (2/2)
setSizeFormat (String): void 100% (1/1)100% (4/4)100% (2/2)
     
class BoardDetailPanel$2100% (1/1)100% (2/2)100% (22/22)100% (7/7)
BoardDetailPanel$2 (BoardDetailPanel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (16/16)100% (6/6)
     
class BoardDetailPanel$3100% (1/1)100% (2/2)100% (11/11)100% (3/3)
BoardDetailPanel$3 (BoardDetailPanel): void 100% (1/1)100% (6/6)100% (1/1)
push (Board): void 100% (1/1)100% (5/5)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.text.SimpleDateFormat;
18 
19import javax.swing.JFormattedTextField;
20import javax.swing.JLabel;
21import javax.swing.JPanel;
22import javax.swing.JTextField;
23import javax.swing.text.DateFormatter;
24 
25import net.sourceforge.hiveboard.Account;
26import net.sourceforge.hiveboard.Board;
27import net.sourceforge.hiveboard.Event;
28import net.sourceforge.hiveboard.docking.Views;
29import net.sourceforge.hiveboard.event.DeferredConsumer;
30import net.sourceforge.hiveboard.event.EventsPriorities;
31import net.sourceforge.hiveboard.model.AccountRepository;
32import net.sourceforge.hiveevents.Channel;
33import net.sourceforge.hiveevents.Consumer;
34import net.sourceforge.hiveevents.Filter;
35import net.sourceforge.hiveevents.PersistentConsumer;
36 
37import zappini.designgridlayout.DesignGridLayout;
38import zappini.designgridlayout.Row;
39 
40public class BoardDetailPanel extends JPanel
41{
42        public BoardDetailPanel(Channel<Board>                selectedBoard,
43                                                        Channel<Event>                eventChannel,
44                                                        AccountRepository        repository)
45        {
46                super();
47                _repository = repository;
48                
49                initComponentNames();
50 
51                _txfName.setEditable(false);
52                _txfDescription.setEditable(false);
53                _txfSize.setEditable(false);
54                _txfInitiator.setEditable(false);
55                _txfCreation.setEditable(false);
56 
57                DesignGridLayout layout = new DesignGridLayout(this); 
58                setLayout(layout);
59                
60                // Add widgets to the panel
61                layout.setTop(BORDER_MARGIN).setBottom(BORDER_MARGIN);
62                layout.row().label(_lblName).add(_txfName);
63                layout.row().label(_lblDescription).add(_txfDescription);
64                layout.row().label(_lblSize).add(_txfSize).add(Row.EMPTY);
65                layout.row().label(_lblInitiator).add(_txfInitiator);
66                layout.row().label(_lblCreation).add(_txfCreation).add(Row.EMPTY);
67 
68                // Listen to boards and account-related events
69                initEventConsumers(selectedBoard, eventChannel);
70        }
71        
72        public void setDateFormat(String dateFormat)
73        {
74                _dateFormatter.setFormat(new SimpleDateFormat(dateFormat));
75        }
76 
77        public void setInitiatorFormat(String initiatorFormat)
78        {
79                _initiatorFormat = initiatorFormat;
80        }
81 
82        public void setSizeFormat(String sizeFormat)
83        {
84                _sizeFormat = sizeFormat;
85        }
86 
87        private void initComponentNames()
88        {
89                _lblName.setName(Views.BOARD_DETAIL.id() + "-name-label");
90                _txfName.setName(Views.BOARD_DETAIL.id() + "-name");
91                _lblDescription.setName(Views.BOARD_DETAIL.id() + "-description-label");
92                _txfDescription.setName(Views.BOARD_DETAIL.id() + "-description");
93                _lblSize.setName(Views.BOARD_DETAIL.id() + "-size-label");
94                _txfSize.setName(Views.BOARD_DETAIL.id() + "-size");
95                _lblInitiator.setName(Views.BOARD_DETAIL.id() + "-initiator-label");
96                _txfInitiator.setName(Views.BOARD_DETAIL.id() + "-initiator");
97                _lblCreation.setName(Views.BOARD_DETAIL.id() + "-creation-label");
98                _txfCreation.setName(Views.BOARD_DETAIL.id() + "-creation");
99        }
100        
101        private void initEventConsumers(Channel<Board>        selectedBoard,
102                                                                        Channel<Event>        eventChannel)
103        {
104                int priority = EventsPriorities.BOARD_DETAIL_UPDATE;
105                Filter<Event> filter = new Filter<Event>()
106                {
107                        public boolean        passEvent(Event event)
108                        {
109                                if (_board == null)
110                                {
111                                        return false;
112                                }
113                                        
114                                switch (event.getType())
115                                {
116                                        case EVT_MODIFY_BOARD:
117                                        case EVT_DESTROY_BOARD:
118                                        return (event.getWhere() == _board.getId());
119                                        
120                                        case EVT_MODIFY_ACCOUNT:
121                                        return (event.getWho() == _board.getInitiator());
122                                        
123                                        default:
124                                        return false;
125                                }
126                        }
127                };
128                _consumer = new DeferredConsumer()
129                {
130                        @Override protected void pushEvent(Event event)
131                        {
132                                switch (event.getType())
133                                {
134                                        case EVT_MODIFY_BOARD:
135                                        // Fall through
136                                        case EVT_MODIFY_ACCOUNT:
137                                        refreshBoard();
138                                        break;
139 
140                                        case EVT_DESTROY_BOARD:
141                                        setBoard(null);
142                                        break;
143 
144                                        default:
145                                        break;
146                                }
147                        }
148                };
149                eventChannel.registerPushConsumer(priority, filter, _consumer);
150 
151                priority = EventsPriorities.SELECTED_BOARD_GUI_REFRESH;
152                selectedBoard.registerPushConsumer(priority, new PersistentConsumer<Board>()
153                {
154                        public void        push(Board board)
155                        {
156                                setBoard(board);
157                        }
158                });
159        }
160        
161        public void        setBoard(Board board)
162        {
163                _board = board;
164                refreshBoard();
165        }
166        
167        private void        refreshBoard()
168        {
169                if (_board == null)
170                {
171                        _txfName.setText("");
172                        _txfDescription.setText("");
173                        _txfSize.setText("");
174                        _txfInitiator.setText("");
175                        _txfCreation.setValue(null);
176                }
177                else
178                {
179                        _txfName.setText(_board.getName());
180                        _txfDescription.setText(_board.getDescription());
181                        String size = String.format(_sizeFormat,
182                                                                                _board.getWidth(),
183                                                                                _board.getHeight());
184                        _txfSize.setText(size);
185                        Account account = _repository.getAccount(_board.getInitiator());
186                        String initiator = String.format(        _initiatorFormat,
187                                                                                                account.getVisa(),
188                                                                                                account.getName());
189                        _txfInitiator.setText(initiator);
190                        _txfCreation.setValue(_board.getCreationDate());
191                }
192        }
193 
194        static private final int                        BORDER_MARGIN = 4;
195 
196        private final AccountRepository                _repository;
197        private Consumer<Event>                                _consumer;
198        private Board                                                _board;
199 
200        private final JLabel                                _lblName = new JLabel();
201        private final JTextField                        _txfName = new JTextField();
202        private final JLabel                                _lblDescription = new JLabel();
203        private final JTextField                        _txfDescription = new JTextField();
204        private final JLabel                                _lblSize = new JLabel();
205        private final JTextField                        _txfSize = new JTextField();
206        private final JLabel                                _lblInitiator = new JLabel();
207        private final JTextField                        _txfInitiator = new JTextField();
208        private final JLabel                                _lblCreation = new JLabel();
209        private final DateFormatter                        _dateFormatter = new DateFormatter();
210        private final JFormattedTextField        _txfCreation = new JFormattedTextField(_dateFormatter);
211        
212        private String                                                _initiatorFormat;
213        private String                                                _sizeFormat;
214}

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