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

COVERAGE SUMMARY FOR SOURCE FILE [ListSnapshotsPanel.java]

nameclass, %method, %block, %line, %
ListSnapshotsPanel.java80%  (4/5)92%  (24/26)92%  (358/389)93%  (70/75)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListSnapshotsPanel$30%   (0/1)0%   (0/2)0%   (0/26)0%   (0/4)
ListSnapshotsPanel$3 (ListSnapshotsPanel): void 0%   (0/1)0%   (0/7)0%   (0/1)
succeeded (Void): void 0%   (0/1)0%   (0/19)0%   (0/3)
     
class ListSnapshotsPanel100% (1/1)100% (18/18)98%  (253/258)98%  (46/47)
accept (): Task 100% (1/1)80%  (20/25)80%  (4/5)
ListSnapshotsPanel (TableContribution, WhiteBoardUserService, ApplicationCont... 100% (1/1)100% (124/124)100% (24/24)
access$000 (ListSnapshotsPanel): Snapshot 100% (1/1)100% (3/3)100% (1/1)
access$002 (ListSnapshotsPanel, Snapshot): Snapshot 100% (1/1)100% (5/5)100% (1/1)
access$100 (ListSnapshotsPanel, int): void 100% (1/1)100% (4/4)100% (1/1)
access$200 (ListSnapshotsPanel): int 100% (1/1)100% (3/3)100% (1/1)
access$202 (ListSnapshotsPanel, int): int 100% (1/1)100% (5/5)100% (1/1)
access$300 (ListSnapshotsPanel): Image 100% (1/1)100% (3/3)100% (1/1)
access$302 (ListSnapshotsPanel, Image): Image 100% (1/1)100% (5/5)100% (1/1)
access$400 (ListSnapshotsPanel): Thumbnail 100% (1/1)100% (3/3)100% (1/1)
access$500 (ListSnapshotsPanel): void 100% (1/1)100% (3/3)100% (1/1)
access$600 (ListSnapshotsPanel): Map 100% (1/1)100% (3/3)100% (1/1)
access$700 (ListSnapshotsPanel): HiveGuiApplicationMain 100% (1/1)100% (3/3)100% (1/1)
access$800 (ListSnapshotsPanel): GenericDialog 100% (1/1)100% (3/3)100% (1/1)
loadThumbnail (): Task 100% (1/1)100% (5/5)100% (1/1)
reset (): void 100% (1/1)100% (10/10)100% (3/3)
updateCurrentImage (): void 100% (1/1)100% (24/24)100% (5/5)
updateSnapshot (int): void 100% (1/1)100% (27/27)100% (8/8)
     
class ListSnapshotsPanel$1100% (1/1)100% (2/2)100% (52/52)100% (12/12)
ListSnapshotsPanel$1 (ListSnapshotsPanel): void 100% (1/1)100% (6/6)100% (1/1)
push (Object): void 100% (1/1)100% (46/46)100% (11/11)
     
class ListSnapshotsPanel$2100% (1/1)100% (2/2)100% (38/38)100% (7/7)
ListSnapshotsPanel$2 (ListSnapshotsPanel): void 100% (1/1)100% (7/7)100% (1/1)
succeeded (Void): void 100% (1/1)100% (31/31)100% (6/6)
     
class ListSnapshotsPanel$AbstractThumbnailLoadTask100% (1/1)100% (2/2)100% (15/15)100% (5/5)
ListSnapshotsPanel$AbstractThumbnailLoadTask (ListSnapshotsPanel): void 100% (1/1)100% (10/10)100% (3/3)
doInBackground (): 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.dialog;
16 
17import java.awt.Color;
18import java.awt.Dimension;
19import java.awt.GridBagConstraints;
20import java.awt.GridBagLayout;
21import java.awt.Image;
22import java.awt.Insets;
23import java.util.HashMap;
24import java.util.Map;
25 
26import javax.swing.Icon;
27import javax.swing.JScrollPane;
28import javax.swing.border.LineBorder;
29 
30import org.jdesktop.application.Action;
31import org.jdesktop.application.Task;
32 
33import net.sourceforge.hiveboard.Board;
34import net.sourceforge.hiveboard.Snapshot;
35import net.sourceforge.hiveboard.WhiteBoardUserService;
36import net.sourceforge.hiveboard.command.AbstractTask;
37import net.sourceforge.hiveboard.command.ActionHelper;
38import net.sourceforge.hiveboard.event.EventsPriorities;
39import net.sourceforge.hiveboard.util.RGBImageHolder;
40import net.sourceforge.hiveevents.PersistentConsumer;
41import net.sourceforge.hivegui.application.ApplicationContextHolder;
42import net.sourceforge.hivegui.component.Thumbnail;
43import net.sourceforge.hivegui.table.BeanTable;
44import net.sourceforge.hivegui.table.DefaultDataListModel;
45import net.sourceforge.hivegui.table.TableContribution;
46 
47// CSOFF: ClassDataAbstractionCouplingCheck
48public class ListSnapshotsPanel extends AbstractBoardPanel
49{
50        static private final String        NAME = "snapshots-list";
51        
52        public ListSnapshotsPanel(        TableContribution                        snapshotsTableContrib,
53                                                                WhiteBoardUserService                service,
54                                                                ApplicationContextHolder        holder,
55                                                                Board                                                board,
56                                                                Snapshot[]                                        snapshots)
57        {
58                super(NAME);
59                setLayout(new GridBagLayout());
60                _board = board;
61                _service = service;
62 
63                DefaultDataListModel<Snapshot> model = 
64                                                                        new DefaultDataListModel<Snapshot>(Snapshot.class);
65                model.setRows(snapshots);
66                _tblSnapshots = new BeanTable<Snapshot>(model, snapshotsTableContrib, holder);
67                _tblSnapshots.setName(NAME + "-snapshots-list");
68                _tblSnapshots.setPreferredScrollableViewportSize(
69                                                                                                new Dimension(VIEWPORT_SIZE, VIEWPORT_SIZE));
70 
71                GridBagConstraints constraints;
72                constraints = new GridBagConstraints(        0, 0, 1, 1, 1.0, 1.0,
73                                                                                                GridBagConstraints.WEST,
74                                                                                                GridBagConstraints.BOTH,
75                                                                                                new Insets(2, 2, 2, 2), 0, 0);
76                
77                add(new JScrollPane(_tblSnapshots), constraints);
78                _thumbnail.setName(NAME + "-thumbnail");
79                _thumbnail.setBorder(new LineBorder(Color.GRAY));
80 
81                constraints.gridx = 1;
82                constraints.weightx = 0.0;
83                constraints.weighty = 0.0;
84                constraints.fill = GridBagConstraints.NONE;
85                add(_thumbnail, constraints);
86 
87                _tblSnapshots.clearSelection();
88                int priority = EventsPriorities.DEFAULT_PRIORITY;
89                _tblSnapshots.addSelectionConsumer(priority, new PersistentConsumer()
90                {
91                        public void        push(Object event)
92                        {
93                                if (event != null)
94                                {
95                                        setAcceptEnabled(true);
96                                        _snapshot = (Snapshot) event;
97                                        updateSnapshot(_snapshot.getId());
98                                }
99                                else
100                                {
101                                        setAcceptEnabled(false);
102                                        _currentId = -1;
103                                        _current = null;
104                                        _snapshot = null;
105                                        _thumbnail.setIcon((Icon) null);
106                                }
107                        }
108                });
109        }
110        
111        @Override public void reset()
112        {
113                setAcceptEnabled(false);
114                _tblSnapshots.setDoubleClickCommand(getAction("accept"));
115        }
116 
117        private void        updateSnapshot(int idSnapshot)
118        {
119                _currentId = idSnapshot;
120                Icon icon = _cache.get(_currentId);
121                _current = null;
122                if (icon != null)
123                {
124                        _thumbnail.setIcon(icon);
125                }
126                else
127                {
128                        // Get loadThumbnail action and execute it asynchroneously
129                        ActionHelper.execute(getAction("loadThumbnail"), this);
130                }
131        }
132        
133        private void        updateCurrentImage()
134        {
135                byte[] content = _service.getSnapshot(_currentId);
136                RGBImageHolder holder = new RGBImageHolder();
137                holder.setImage(_board.getWidth(), _board.getHeight(), content);
138                _current = holder.getImage();
139        }
140        
141        @Action
142        public Task        loadThumbnail()
143        {
144                return new AbstractThumbnailLoadTask()
145                {
146                        @Override protected void succeeded(Void result)
147                        {
148                                updateCurrentImage();
149                                _thumbnail.setIcon(_current);
150                                Icon icon = _thumbnail.getThumbnailIcon();
151                                _cache.put(_currentId, icon);
152                                _thumbnail.setIcon(icon);
153                        }
154                };
155        }
156        
157        @Action(enabledProperty = "acceptEnabled", block = Task.BlockingScope.ACTION)
158        public Task accept()
159        {
160                if (_current != null)
161                {
162                        // Now _current contains the full-size image
163                        SnapshotDetailPanel detail = new SnapshotDetailPanel(_board, _snapshot, _current);
164                        // Open new dialog to display image in real size
165                        _application.showDialog(detail);
166                        return null;
167                }
168                
169                return new AbstractThumbnailLoadTask()
170                {
171                        @Override protected void succeeded(Void result)
172                        {
173                                // Now _current contains the full-size image
174                                SnapshotDetailPanel detail =
175                                                new SnapshotDetailPanel(_board, _snapshot, _current);
176                                // Open new dialog to display image in real size
177                                _application.showDialog(detail);
178                        }
179                };
180        }
181        
182        abstract private class AbstractThumbnailLoadTask extends AbstractTask<Void, Void>
183        {
184                protected AbstractThumbnailLoadTask()
185                {
186                        super(ListSnapshotsPanel.this._application, _parent);
187                }
188                
189                @Override protected Void doInBackground() throws Exception
190                {
191                        updateCurrentImage();
192                        return null;
193                }
194        }
195        
196        static final private int        THUMBNAIL_SIZE = 200;
197        static final private int        VIEWPORT_SIZE = 300;
198 
199        private final Map<Integer, Icon>        _cache = new HashMap<Integer, Icon>();
200        private final WhiteBoardUserService        _service;
201        private final BeanTable<Snapshot>        _tblSnapshots;
202        private final Thumbnail                                _thumbnail = new Thumbnail(THUMBNAIL_SIZE);
203        private int                                                        _currentId;
204        private Snapshot                                        _snapshot;
205        private Image                                                _current;
206}
207// CSON: ClassDataAbstractionCouplingCheck

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