1 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 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 file) 90 { 91 String data = ""; 92 String 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 |