KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > tasks > ImageViewer


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package net.sf.jftp.gui.tasks;
17
18 import net.sf.jftp.config.Settings;
19 import net.sf.jftp.gui.*;
20 import net.sf.jftp.gui.framework.*;
21 import net.sf.jftp.util.*;
22
23 import java.awt.*;
24
25 import java.io.*;
26
27 import java.net.*;
28
29 import java.util.*;
30
31 import javax.swing.*;
32
33
34 public class ImageViewer extends JInternalFrame
35 {
36     public ImageViewer(String JavaDoc img)
37     {
38         super(img, true, true, true, true);
39         setLocation(150, 50);
40         setSize(400, 300);
41
42         setLayout(new BorderLayout(2, 2));
43
44         ImagePanel p = new ImagePanel(img);
45         JScrollPane scroll = new JScrollPane(p);
46
47         getContentPane().add("Center", scroll);
48
49         p.setMinimumSize(new Dimension(1500, 1500));
50         p.setPreferredSize(new Dimension(1500, 1500));
51         p.setMaximumSize(new Dimension(1500, 1500));
52
53         setVisible(true);
54
55         //doLayout();
56
//validate();
57
//p.repaint();
58
//Log.out(""+p.getSize().width);
59
}
60 }
61
62
63 class ImagePanel extends JPanel
64 {
65     private Image img;
66
67     public ImagePanel(String JavaDoc url)
68     {
69         try
70         {
71             setBackground(Color.white);
72
73             img = Toolkit.getDefaultToolkit().getImage(new URL(url));
74
75             MediaTracker mt = new MediaTracker(this);
76             mt.addImage(img, 1);
77             mt.waitForAll();
78
79             //System.out.println(img);
80
//setVisible(true);
81
repaint();
82
83             //validate();
84
}
85         catch(Exception JavaDoc ex)
86         {
87             ex.printStackTrace();
88         }
89     }
90
91     public void paintComponent(Graphics g)
92     {
93         g.setColor(Color.white);
94         g.fillRect(0, 0, 1500, 1500);
95         g.drawImage(img, 0, 0, null);
96     }
97
98     public void update(Graphics g)
99     {
100         paintComponent(g);
101     }
102 }
103
Popular Tags