EMMA Coverage Report (generated Sun Apr 20 22:38:01 CEST 2008)
[all classes][net.sf.jomic.ui]

COVERAGE SUMMARY FOR SOURCE FILE [SystemInfoFrame.java]

nameclass, %method, %block, %line, %
SystemInfoFrame.java100% (1/1)88%  (15/17)95%  (473/500)94%  (90/96)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SystemInfoFrame100% (1/1)88%  (15/17)95%  (473/500)94%  (90/96)
windowDeiconified (WindowEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
windowIconified (WindowEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
<static initializer> 100% (1/1)80%  (12/15)80%  (0.8/1)
updateMemoryStatus (): void 100% (1/1)84%  (83/99)89%  (14.2/16)
SystemInfoFrame (): void 100% (1/1)100% (45/45)100% (12/12)
actionPerformed (ActionEvent): void 100% (1/1)100% (3/3)100% (2/2)
createImageFormatPanel (): JPanel 100% (1/1)100% (46/46)100% (8/8)
createPlatformInfoPanel (): JPanel 100% (1/1)100% (183/183)100% (28/28)
createUI (): JPanel 100% (1/1)100% (39/39)100% (9/9)
getCacheDescription (CacheInfo): String 100% (1/1)100% (9/9)100% (1/1)
getCacheDescription (long, long, int): String 100% (1/1)100% (34/34)100% (4/4)
setVisible (boolean): void 100% (1/1)100% (8/8)100% (4/4)
windowActivated (WindowEvent): void 100% (1/1)100% (1/1)100% (1/1)
windowClosed (WindowEvent): void 100% (1/1)100% (1/1)100% (1/1)
windowClosing (WindowEvent): void 100% (1/1)100% (4/4)100% (2/2)
windowDeactivated (WindowEvent): void 100% (1/1)100% (1/1)100% (1/1)
windowOpened (WindowEvent): void 100% (1/1)100% (4/4)100% (2/2)

1// Jomic - a viewer for comic book archives.
2// Copyright (C) 2004-2008 Thomas Aglassinger
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16package net.sf.jomic.ui;
17 
18import java.awt.BorderLayout;
19import java.awt.Dimension;
20import java.awt.GridBagConstraints;
21import java.awt.GridBagLayout;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24import java.awt.event.WindowEvent;
25import java.awt.event.WindowListener;
26 
27import javax.media.jai.JAI;
28import javax.swing.BorderFactory;
29import javax.swing.JFrame;
30import javax.swing.JLabel;
31import javax.swing.JPanel;
32import javax.swing.JScrollPane;
33import javax.swing.JTable;
34import javax.swing.Timer;
35 
36import net.sf.jomic.comic.ComicCache;
37import net.sf.jomic.common.JomicTools;
38import net.sf.jomic.tools.ArchiveCache;
39import net.sf.jomic.tools.CacheInfo;
40import net.sf.jomic.tools.LocaleTools;
41import net.sf.jomic.tools.SystemTools;
42import net.sf.jomic.tools.UiTools;
43 
44/**
45 *  Frame to show information about environment, relevant version numbers, and supported image
46 *  formats.
47 *
48 * @author    Thomas Aglassinger
49 */
50public class SystemInfoFrame extends JFrame implements ActionListener, WindowListener
51{
52    private static final int INSET = 4;
53    private static final String KEY_ARCHIVE_CACHE = "dialogs.systemInformation.archiveCache";
54    private static final String KEY_IMAGE_CACHE = "dialogs.systemInformation.imageCache";
55    private static final String KEY_MEMORY = "dialogs.systemInformation.memory";
56    private static final String KEY_THUMB_CACHE = "dialogs.systemInformation.thumbCache";
57    private static final int MEMORY_INFO_REFRESH_DELAY = 1000;
58    private static final int PREFERRED_TABLE_HEIGHT = 150;
59    private static final int PREFERRED_TABLE_WIDTH = 500;
60    private JLabel archiveCacheInfoLabel;
61    private JLabel imageCacheInfoLabel;
62    private JomicTools jomicTools;
63    private LocaleTools localeTools;
64    private JLabel memoryInfoLabel;
65    private Timer memoryInfoUpdateTimer;
66    private SystemTools systemTools;
67    private JLabel thumbCacheInfoLabel;
68    private UiTools uiTools;
69 
70    public SystemInfoFrame() {
71        jomicTools = JomicTools.instance();
72        localeTools = LocaleTools.instance();
73        systemTools = SystemTools.instance();
74        uiTools = UiTools.instance();
75        memoryInfoUpdateTimer = new Timer(MEMORY_INFO_REFRESH_DELAY, this);
76        memoryInfoUpdateTimer.setInitialDelay(0);
77 
78        setTitle(localeTools.getMessage("dialogs.systemInformation.title"));
79        getContentPane().add(createUI());
80        jomicTools.setIconToJomicLogo(this);
81        addWindowListener(this);
82    }
83 
84    public void setVisible(boolean isVisible) {
85        if (isVisible) {
86            updateMemoryStatus();
87        }
88        super.setVisible(isVisible);
89    }
90 
91    private String getCacheDescription(CacheInfo usage) {
92        return getCacheDescription(usage.getUsedSize(), usage.getMaxSize(), usage.getEntryCount());
93    }
94 
95    private String getCacheDescription(long bytesUsed, long bytesAvailable, int entriesUsed) {
96        String memoryUsed = localeTools.asByteText(bytesUsed);
97        String memoryAvailable = localeTools.asByteText(bytesAvailable);
98        String result = localeTools.getMessage(
99                "dialogs.systemInformation.xOfYUsedByZEntries",
100                new Object[]{memoryUsed, memoryAvailable, new Integer(entriesUsed)});
101 
102        return result;
103    }
104 
105    public void actionPerformed(ActionEvent event) {
106        updateMemoryStatus();
107    }
108 
109    public void windowActivated(WindowEvent event) {
110        // Do nothing.
111    }
112 
113    public void windowClosed(WindowEvent event) {
114        // Do nothing.
115    }
116 
117    public void windowClosing(WindowEvent event) {
118        memoryInfoUpdateTimer.stop();
119    }
120 
121    public void windowDeactivated(WindowEvent event) {
122        // Do nothing.
123    }
124 
125    public void windowDeiconified(WindowEvent event) {
126        memoryInfoUpdateTimer.restart();
127    }
128 
129    public void windowIconified(WindowEvent event) {
130        memoryInfoUpdateTimer.stop();
131    }
132 
133    public void windowOpened(WindowEvent event) {
134        memoryInfoUpdateTimer.restart();
135    }
136 
137    private JPanel createImageFormatPanel() {
138        JPanel result = new JPanel();
139 
140        result.setLayout(new BorderLayout());
141 
142        JTable formatTable = new JTable(new ImageFormatTableModel());
143 
144        uiTools.initColumnWidths(formatTable);
145        // TODO: compute dimension depending on data
146        formatTable.setPreferredScrollableViewportSize(
147                new Dimension(PREFERRED_TABLE_WIDTH, PREFERRED_TABLE_HEIGHT));
148        result.add(new JLabel(
149                localeTools.getMessage("dialogs.systemInformation.supportedImageFormats")),
150                BorderLayout.NORTH);
151        result.add(new JScrollPane(formatTable), BorderLayout.CENTER);
152        return result;
153    }
154 
155    private JPanel createPlatformInfoPanel() {
156        JPanel result = new JPanel();
157        String platform = systemTools.getPlatformInfo();
158        String language = systemTools.getLocaleInfo();
159        String javaVersion = systemTools.getJavaInfo();
160        String jaiVersion = JAI.getBuildVersion();
161 
162        String[] keyValues = new String[]{
163                "dialogs.systemInformation.platform", platform,
164                "dialogs.systemInformation.language", language,
165                "dialogs.systemInformation.javaVersion", javaVersion,
166                "dialogs.systemInformation.jaiVersion", jaiVersion,
167                KEY_MEMORY, "",
168                KEY_IMAGE_CACHE, "",
169                KEY_THUMB_CACHE, "",
170                KEY_ARCHIVE_CACHE, ""
171                };
172        GridBagConstraints constraints = new GridBagConstraints();
173 
174        constraints.anchor = GridBagConstraints.LINE_START;
175        result.setLayout(new GridBagLayout());
176        for (int i = 0; i < keyValues.length; i += 2) {
177            String key = keyValues[i];
178            String value = keyValues[i + 1];
179            String message = localeTools.getMessage(key);
180 
181            constraints.gridx = 0;
182            constraints.gridy = i / 2;
183            result.add(new JLabel(message), constraints);
184            constraints.gridx += 1;
185 
186            JLabel infoLabel = new JLabel(value);
187 
188            result.add(infoLabel, constraints);
189            if (key.equals(KEY_ARCHIVE_CACHE)) {
190                archiveCacheInfoLabel = infoLabel;
191            } else if (key.equals(KEY_IMAGE_CACHE)) {
192                imageCacheInfoLabel = infoLabel;
193            } else if (key.equals(KEY_MEMORY)) {
194                memoryInfoLabel = infoLabel;
195            } else if (key.equals(KEY_THUMB_CACHE)) {
196                thumbCacheInfoLabel = infoLabel;
197            }
198        }
199 
200        return result;
201    }
202 
203    private JPanel createUI() {
204        JPanel result = new JPanel();
205 
206        result.setLayout(new BorderLayout());
207 
208        JPanel platformInfoPane = createPlatformInfoPanel();
209        JPanel imageFormatPane = createImageFormatPanel();
210 
211        platformInfoPane.setBorder(BorderFactory.createEmptyBorder(2 * INSET, 2 * INSET, INSET, 2 * INSET));
212        imageFormatPane.setBorder(BorderFactory.createEmptyBorder(INSET, 2 * INSET, INSET, 2 * INSET));
213        result.add(platformInfoPane, BorderLayout.NORTH);
214        result.add(imageFormatPane, BorderLayout.CENTER);
215        return result;
216    }
217 
218    private void updateMemoryStatus() {
219        assert archiveCacheInfoLabel != null;
220        assert imageCacheInfoLabel != null;
221        assert memoryInfoLabel != null;
222        assert thumbCacheInfoLabel != null;
223 
224        ComicCache cache = ComicCache.instance();
225        long freeMemory = Runtime.getRuntime().freeMemory();
226        long availableMemory = Runtime.getRuntime().maxMemory();
227        long usedMemory = availableMemory - freeMemory;
228        Object[] options = new Object[]{localeTools.asByteText(usedMemory), localeTools.asByteText(availableMemory)};
229        String memoryStatus = localeTools.getMessage(
230                "dialogs.systemInformation.xOfYUsed", options);
231        ArchiveCache archiveCache = cache.getArchiveCache();
232 
233        memoryInfoLabel.setText(memoryStatus);
234        imageCacheInfoLabel.setText(getCacheDescription(cache.getImageCache()));
235        thumbCacheInfoLabel.setText(getCacheDescription(cache.getThumbCache()));
236        archiveCacheInfoLabel.setText(getCacheDescription(archiveCache));
237    }
238}

[all classes][net.sf.jomic.ui]
EMMA 2.0.4217 (C) Vladimir Roubtsov