KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
19 import net.sf.jftp.gui.framework.*;
20 import net.sf.jftp.system.logging.Log;
21 import net.sf.jftp.util.*;
22
23 import java.awt.*;
24 import java.awt.event.*;
25
26 import java.io.*;
27
28 import javax.swing.*;
29
30
31 public class Displayer extends JInternalFrame implements ActionListener
32 {
33     public static boolean showCloseButton = false;
34     
35     private JTextArea info = new JTextArea(25, 50) {
36         public Insets getInsets() {
37             Insets std = super.getInsets();
38             
39             return new Insets(std.top + 5, std.left + 5, std.bottom + 5,
40                     std.right + 5);
41         }
42     };
43     
44     private JButton close = new JButton("Close");
45
46     public Displayer(java.net.URL JavaDoc file, Font font)
47     {
48         super(file.getFile(), true, true, true, true);
49         setLocation(50, 50);
50         setSize(600, 540);
51         getContentPane().setLayout(new BorderLayout());
52
53         load(file);
54         if(font != null) {
55             info.setFont(font);
56         }
57         else {
58             info.setFont(new Font("monospaced",Font.PLAIN, 11));
59         }
60         info.setEditable(false);
61
62         JScrollPane jsp = new JScrollPane(info);
63         getContentPane().add("Center", jsp);
64
65         HPanel closeP = new HPanel();
66         closeP.setLayout(new FlowLayout(FlowLayout.CENTER));
67         closeP.add(close);
68
69         close.addActionListener(this);
70
71         if(showCloseButton)
72         {
73             getContentPane().add("South", closeP);
74         }
75         
76         info.setCaretPosition(0);
77
78         setVisible(true);
79     }
80
81     public void actionPerformed(ActionEvent e)
82     {
83         if(e.getSource() == close)
84         {
85             this.dispose();
86         }
87     }
88
89     private void load(java.net.URL JavaDoc file)
90     {
91         String JavaDoc data = "";
92         String JavaDoc now = "";
93
94         try
95         {
96             DataInput in = new DataInputStream(new BufferedInputStream(file.openStream()));
97
98             while((data = in.readLine()) != null)
99             {
100                 now = now + data + "\n";
101             }
102         }
103         catch(IOException e)
104         {
105             Log.debug(e + " @Displayer.load()");
106         }
107
108         info.setText(now);
109     }
110
111     public Insets getInsets()
112     {
113         Insets std = super.getInsets();
114
115         return new Insets(std.top + 5, std.left + 5, std.bottom + 5,
116                           std.right + 5);
117     }
118 }
119
Popular Tags