EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hivegui.component]

COVERAGE SUMMARY FOR SOURCE FILE [Thumbnail.java]

nameclass, %method, %block, %line, %
Thumbnail.java0%   (0/1)0%   (0/9)0%   (0/146)0%   (0/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Thumbnail0%   (0/1)0%   (0/9)0%   (0/146)0%   (0/46)
Thumbnail (int): void 0%   (0/1)0%   (0/5)0%   (0/2)
Thumbnail (int, boolean): void 0%   (0/1)0%   (0/14)0%   (0/6)
getThumbnailIcon (): Icon 0%   (0/1)0%   (0/3)0%   (0/1)
getThumbnailSize (): int 0%   (0/1)0%   (0/3)0%   (0/1)
initSize (): void 0%   (0/1)0%   (0/37)0%   (0/11)
paintComponent (Graphics): void 0%   (0/1)0%   (0/44)0%   (0/10)
setFile (File): void 0%   (0/1)0%   (0/18)0%   (0/7)
setIcon (Icon): void 0%   (0/1)0%   (0/11)0%   (0/4)
setIcon (Image): void 0%   (0/1)0%   (0/11)0%   (0/4)

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.hivegui.component;
16 
17import java.awt.Dimension;
18import java.awt.Graphics;
19import java.awt.Image;
20import java.io.File;
21 
22import javax.swing.Icon;
23import javax.swing.ImageIcon;
24import javax.swing.JComponent;
25 
26/**
27 * @author Jean-Francois Poilpret
28 */
29public class Thumbnail extends JComponent
30{
31        public        Thumbnail(int size)
32        {
33                this(size, true);
34        }
35 
36        public        Thumbnail(int size, boolean square)
37        {
38                _size = size;
39                _square = square;
40                initSize();
41        }
42        
43        public int        getThumbnailSize()
44        {
45                return _size;
46        }
47 
48        private void        initSize()
49        {
50                int width;
51                int height;
52                if (_square || _thumbnail == null)
53                {
54                        width = _size;
55                        height = _size;
56                }
57                else
58                {
59                        width = _thumbnail.getIconWidth();
60                        height = _thumbnail.getIconHeight();
61                }
62                Dimension dim = new Dimension(width, height);
63                setPreferredSize(dim);
64                setMinimumSize(dim);
65                setMaximumSize(dim);
66        }
67 
68        public void                setFile(File file)
69        {
70                if (file == null)
71                {
72                        _thumbnail = null;
73                        initSize();
74                        repaint();
75                        return;
76                }
77                setIcon(new ImageIcon(file.getPath()));
78        }
79        
80        public Icon                getThumbnailIcon()
81        {
82                return _thumbnail;
83        }
84 
85        public void                setIcon(Icon icon)
86        {
87                _thumbnail = IconTools.scaleIcon(icon, _size);
88                initSize();
89                repaint();
90        }
91 
92        public void                setIcon(Image image)
93        {
94                _thumbnail = IconTools.scaleIcon(image, _size);
95                initSize();
96                repaint();
97        }
98 
99        @Override public void        paintComponent(Graphics g)
100        {
101                super.paintComponent(g);
102                if (_thumbnail == null)
103                {
104                        return;
105                }
106                if (_square)
107                {
108                        int x = (_size - _thumbnail.getIconWidth()) / 2;
109                        int y = (_size - _thumbnail.getIconHeight()) / 2;
110                        _thumbnail.paintIcon(this, g, x, y);
111                }
112                else
113                {
114                        _thumbnail.paintIcon(this, g, 0, 0);
115                }
116        }
117 
118        protected Icon                _thumbnail = null;
119        protected boolean        _square;
120        protected int                _size;
121}
122 

[all classes][net.sourceforge.hivegui.component]
EMMA 2.0.5312 (C) Vladimir Roubtsov