001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.tasks;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.gui.framework.*;
020: import net.sf.jftp.system.logging.Log;
021: import net.sf.jftp.util.*;
022:
023: import java.awt.*;
024: import java.awt.event.*;
025:
026: import java.io.*;
027:
028: import javax.swing.*;
029:
030: public class Displayer extends JInternalFrame implements ActionListener {
031: public static boolean showCloseButton = false;
032:
033: private JTextArea info = new JTextArea(25, 50) {
034: public Insets getInsets() {
035: Insets std = super .getInsets();
036:
037: return new Insets(std.top + 5, std.left + 5,
038: std.bottom + 5, std.right + 5);
039: }
040: };
041:
042: private JButton close = new JButton("Close");
043:
044: public Displayer(java.net.URL file, Font font) {
045: super (file.getFile(), true, true, true, true);
046: setLocation(50, 50);
047: setSize(600, 540);
048: getContentPane().setLayout(new BorderLayout());
049:
050: load(file);
051: if (font != null) {
052: info.setFont(font);
053: } else {
054: info.setFont(new Font("monospaced", Font.PLAIN, 11));
055: }
056: info.setEditable(false);
057:
058: JScrollPane jsp = new JScrollPane(info);
059: getContentPane().add("Center", jsp);
060:
061: HPanel closeP = new HPanel();
062: closeP.setLayout(new FlowLayout(FlowLayout.CENTER));
063: closeP.add(close);
064:
065: close.addActionListener(this );
066:
067: if (showCloseButton) {
068: getContentPane().add("South", closeP);
069: }
070:
071: info.setCaretPosition(0);
072:
073: setVisible(true);
074: }
075:
076: public void actionPerformed(ActionEvent e) {
077: if (e.getSource() == close) {
078: this .dispose();
079: }
080: }
081:
082: private void load(java.net.URL file) {
083: String data = "";
084: String now = "";
085:
086: try {
087: DataInput in = new DataInputStream(new BufferedInputStream(
088: file.openStream()));
089:
090: while ((data = in.readLine()) != null) {
091: now = now + data + "\n";
092: }
093: } catch (IOException e) {
094: Log.debug(e + " @Displayer.load()");
095: }
096:
097: info.setText(now);
098: }
099:
100: public Insets getInsets() {
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: }
|