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

COVERAGE SUMMARY FOR SOURCE FILE [AccountDetailPanel.java]

nameclass, %method, %block, %line, %
AccountDetailPanel.java100% (5/5)100% (14/14)99%  (519/525)99%  (90.9/92)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountDetailPanel$4100% (1/1)100% (1/1)88%  (29/33)87%  (0.9/1)
<static initializer> 100% (1/1)88%  (29/33)87%  (0.9/1)
     
class AccountDetailPanel$1100% (1/1)100% (2/2)93%  (27/29)83%  (5/6)
passEvent (Event): boolean 100% (1/1)91%  (21/23)80%  (4/5)
AccountDetailPanel$1 (AccountDetailPanel): void 100% (1/1)100% (6/6)100% (1/1)
     
class AccountDetailPanel100% (1/1)100% (7/7)100% (430/430)100% (76/76)
AccountDetailPanel (Channel, Channel): void 100% (1/1)100% (181/181)100% (35/35)
access$000 (AccountDetailPanel): Account 100% (1/1)100% (3/3)100% (1/1)
access$100 (AccountDetailPanel): void 100% (1/1)100% (3/3)100% (1/1)
initComponentNames (): void 100% (1/1)100% (133/133)100% (12/12)
initEventConsumers (Channel, Channel): void 100% (1/1)100% (31/31)100% (7/7)
refreshAccount (): void 100% (1/1)100% (73/73)100% (18/18)
setAccount (Account): void 100% (1/1)100% (6/6)100% (3/3)
     
class AccountDetailPanel$2100% (1/1)100% (2/2)100% (22/22)100% (7/7)
AccountDetailPanel$2 (AccountDetailPanel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (16/16)100% (6/6)
     
class AccountDetailPanel$3100% (1/1)100% (2/2)100% (11/11)100% (3/3)
AccountDetailPanel$3 (AccountDetailPanel): void 100% (1/1)100% (6/6)100% (1/1)
push (Account): 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 javax.swing.ButtonGroup;
18import javax.swing.JCheckBox;
19import javax.swing.JLabel;
20import javax.swing.JPanel;
21import javax.swing.JRadioButton;
22import javax.swing.JTextField;
23 
24import net.sourceforge.hiveboard.Account;
25import net.sourceforge.hiveboard.AccountRole;
26import net.sourceforge.hiveboard.Event;
27import net.sourceforge.hiveboard.docking.Views;
28import net.sourceforge.hiveboard.event.DeferredConsumer;
29import net.sourceforge.hiveboard.event.EventsPriorities;
30import net.sourceforge.hiveevents.Channel;
31import net.sourceforge.hiveevents.Consumer;
32import net.sourceforge.hiveevents.Filter;
33import net.sourceforge.hiveevents.PersistentConsumer;
34 
35import zappini.designgridlayout.DesignGridLayout;
36import zappini.designgridlayout.Row;
37 
38public class AccountDetailPanel extends JPanel
39{
40        public AccountDetailPanel(        Channel<Account>        selectedAccount,
41                                                                Channel<Event>                eventChannel)
42        {
43                super();
44                
45                initComponentNames();
46                
47                _txfVisa.setEditable(false);
48                _txfName.setEditable(false);
49                _txfEmail.setEditable(false);
50                _cbxConnected.setEnabled(false);
51                _rbnRoleBasic.setEnabled(false);
52                _rbnRoleInitiator.setEnabled(false);
53                _cbxAdmin.setEnabled(false);
54 
55                ButtonGroup group = new ButtonGroup();
56                group.add(_rbnRoleBasic);
57                group.add(_rbnRoleInitiator);
58 
59                setAccount(null);
60 
61                DesignGridLayout layout = new DesignGridLayout(this); 
62                setLayout(layout);
63 
64                layout.setTop(BORDER_MARGIN).setBottom(BORDER_MARGIN);
65                layout.row().label(_lblVisa).add(_txfVisa).add(Row.EMPTY);
66                layout.row().label(_lblName).add(_txfName);
67                layout.row().label(_lblEmail).add(_txfEmail);
68                layout.row().label(_lblRole).add(_rbnRoleBasic, _rbnRoleInitiator);
69                layout.row().add(_cbxAdmin);
70                layout.row().add(_cbxConnected);
71                
72                // Listen to accounts-related events
73                initEventConsumers(selectedAccount, eventChannel);
74        }
75 
76        private void initComponentNames()
77        {
78                _lblVisa.setName(Views.ACCOUNT_DETAIL.id() + "-visa-label");
79                _txfVisa.setName(Views.ACCOUNT_DETAIL.id() + "-visa");
80                _lblName.setName(Views.ACCOUNT_DETAIL.id() + "-name-label");
81                _txfName.setName(Views.ACCOUNT_DETAIL.id() + "-name");
82                _lblEmail.setName(Views.ACCOUNT_DETAIL.id() + "-email-label");
83                _txfEmail.setName(Views.ACCOUNT_DETAIL.id() + "-email");
84                _cbxAdmin.setName(Views.ACCOUNT_DETAIL.id() + "-isadmin");
85                _cbxConnected.setName(Views.ACCOUNT_DETAIL.id() + "-connected");
86                _lblRole.setName(Views.ACCOUNT_DETAIL.id() + "-role-label");
87                _rbnRoleBasic.setName(Views.ACCOUNT_DETAIL.id() + "-role-basic");
88                _rbnRoleInitiator.setName(Views.ACCOUNT_DETAIL.id() + "-role-initiator");
89        }
90        
91        private void initEventConsumers(Channel<Account>        selectedAccount,
92                                                                        Channel<Event>                eventChannel)
93        {
94                int priority = EventsPriorities.ACCOUNT_DETAIL_UPDATE;
95                Filter<Event> filter = new Filter<Event>()
96                {
97                        public boolean        passEvent(Event event)
98                        {
99                                if (_account == null || event.getWho() != _account.getId())
100                                {
101                                        return false;
102                                }
103                                        
104                                switch (event.getType())
105                                {
106                                        case EVT_MODIFY_ACCOUNT:
107                                        case EVT_LOGIN:
108                                        case EVT_LOGOUT:
109                                        case EVT_DESTROY_ACCOUNT:
110                                        return true;
111                                        
112                                        default:
113                                        return false;
114                                }
115                        }
116                };
117                _consumer = new DeferredConsumer()
118                {
119                        @Override protected void pushEvent(Event event)
120                        {
121                                switch (event.getType())
122                                {
123                                        case EVT_MODIFY_ACCOUNT:
124                                        case EVT_LOGIN:
125                                        case EVT_LOGOUT:
126                                        refreshAccount();
127                                        break;
128                                        
129                                        case EVT_DESTROY_ACCOUNT:
130                                        setAccount(null);
131                                        break;
132                                        
133                                        default:
134                                        break;
135                                }
136                        }
137                };
138                eventChannel.registerPushConsumer(priority, filter, _consumer);
139 
140                priority = EventsPriorities.SELECTED_ACCOUNT_GUI_REFRESH;
141                selectedAccount.registerPushConsumer(priority, new PersistentConsumer<Account>()
142                {
143                        public void        push(Account account)
144                        {
145                                setAccount(account);
146                        }
147                });
148        }
149        
150        public void        setAccount(Account account)
151        {
152                _account = account;
153                refreshAccount();
154        }
155        
156        private void        refreshAccount()
157        {
158                if (_account == null)
159                {
160                        _txfVisa.setText("");
161                        _txfName.setText("");
162                        _txfEmail.setText("");
163                        _cbxConnected.setSelected(false);
164                        _rbnRoleBasic.setSelected(true);
165                        _cbxAdmin.setSelected(false);
166                }
167                else
168                {
169                        _txfVisa.setText(_account.getVisa());
170                        _txfName.setText(_account.getName());
171                        _txfEmail.setText(_account.getEmail());
172                        _cbxConnected.setSelected(_account.isConnected());
173                        if (_account.getRole() == AccountRole.BASIC)
174                        {
175                                _rbnRoleBasic.setSelected(true);
176                        }
177                        else
178                        {
179                                _rbnRoleInitiator.setSelected(true);
180                        }
181                        _cbxAdmin.setSelected(_account.isAdmin());
182                }
183        }
184        
185        static private final int        BORDER_MARGIN = 4;
186 
187        private Consumer<Event>                _consumer;
188        private Account                                _account;
189        private final JLabel                _lblVisa = new JLabel();
190        private final JTextField        _txfVisa = new JTextField();
191        private final JLabel                _lblName = new JLabel();
192        private final JTextField        _txfName = new JTextField();
193        private final JLabel                _lblEmail = new JLabel();
194        private final JTextField        _txfEmail = new JTextField();
195        private final JCheckBox                _cbxConnected = new JCheckBox();
196        private final JLabel                _lblRole = new JLabel();
197        private final JRadioButton        _rbnRoleBasic = new JRadioButton();
198        private final JRadioButton        _rbnRoleInitiator = new JRadioButton();
199        private final JCheckBox                _cbxAdmin = new JCheckBox();
200}

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