KickJava   Java API By Example, From Geeks To Geeks.

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


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 ExternalDisplayer extends HFrame implements ActionListener
32 {
33     private JTextArea info = new JTextArea(25, 50);
34     private JButton close = new JButton("Close");
35
36     public ExternalDisplayer(java.net.URL JavaDoc file)
37     {
38         setTitle("Info...");
39         setLocation(50, 50);
40         setSize(600, 540);
41         getContentPane().setLayout(new BorderLayout());
42
43         addWindowListener(new WindowAdapter()
44             {
45                 public void windowClosing(WindowEvent e)
46                 {
47                     dispose();
48                 }
49             });
50         load(file);
51         info.setEditable(false);
52
53         JScrollPane jsp = new JScrollPane(info);
54         getContentPane().add("Center", jsp);
55
56         HPanel closeP = new HPanel();
57         closeP.setLayout(new FlowLayout(FlowLayout.CENTER));
58         closeP.add(close);
59
60         close.addActionListener(this);
61
62         getContentPane().add("South", closeP);
63
64         info.setCaretPosition(0);
65         setVisible(true);
66         pack();
67     }
68
69     public void actionPerformed(ActionEvent e)
70     {
71         if(e.getSource() == close)
72         {
73             this.dispose();
74         }
75     }
76
77     private void load(java.net.URL JavaDoc file)
78     {
79         String JavaDoc data = "";
80         String JavaDoc now = "";
81
82         try
83         {
84             DataInput in = new DataInputStream(new BufferedInputStream(file.openStream()));
85
86             while((data = in.readLine()) != null)
87             {
88                 now = now + data + "\n";
89             }
90         }
91         catch(IOException e)
92         {
93             Log.debug(e + " @Displayer.load()");
94         }
95
96         info.setText(now);
97     }
98
99     public Insets getInsets()
100     {
101         Insets std = super.getInsets();
102
103         return new Insets(std.top + 5, std.left + 5, std.bottom + 5,
104                           std.right + 5);
105     }
106 }
107
Popular Tags