FileDocCategorySizeDatePackage
FileViewer2.javaAPI DocExample2732Sun Mar 28 19:09:02 BST 1999None

FileViewer2

public class FileViewer2 extends JFrame implements WindowListener, ActionListener

Fields Summary
JFileChooser
fc
JStreamedTextArea
theView
ModePanel2
mp
Constructors Summary
public FileViewer2()


    
    super("FileViewer");
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

  
    if (e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
      File f = fc.getSelectedFile();
      if (f != null) {
        theView.setText("");
        try {
          InputStream in = new FileInputStream(f);
          OutputStream out = theView.getOutputStream();
          if (!mp.isText()) {
            FileDumper6.dump(in, out, mp.getMode(), mp.isBigEndian(),
             mp.isDeflated(), mp.isGZipped(), mp.getPassword());
          }
          else {
            FileDumper6.dump(in, out, mp.getEncoding(), null,
             mp.isDeflated(), mp.isGZipped(), mp.getPassword());        
          }
        }
        catch (IOException ex) {
        }
      }
      
    }
    else if (e.getActionCommand().equals(JFileChooser.CANCEL_SELECTION)) {
      this.closeAndQuit();
    }
    
  
private voidcloseAndQuit()

  
    this.setVisible(false);
    this.dispose();
    
    //
    System.exit(0);
  
  
public voidinit()

  
    this.addWindowListener(this);
   
    fc.setApproveButtonText("View File");
    fc.setApproveButtonMnemonic('V");
    fc.addActionListener(this);
    
    this.getContentPane().add("Center", fc);
    JScrollPane sp = new JScrollPane(theView);
    this.getContentPane().add("South", sp);
    this.getContentPane().add("West", mp);
    this.pack();
    
    // center on display
    Dimension display = getToolkit().getScreenSize();
    Dimension bounds = this.getSize();   
    
    int x = (display.width - bounds.width)/2;
    int y = (display.height - bounds.height)/2;
    if (x < 0) x = 10;
    if (y < 0) y = 15;
    this.setLocation(x, y);
    
  
public static voidmain(java.lang.String[] args)

  
    FileViewer2 fv = new FileViewer2();
    fv.init();
    fv.show();
    
  
public voidwindowActivated(java.awt.event.WindowEvent e)

public voidwindowClosed(java.awt.event.WindowEvent e)

public voidwindowClosing(java.awt.event.WindowEvent e)

    this.closeAndQuit();
  
public voidwindowDeactivated(java.awt.event.WindowEvent e)

public voidwindowDeiconified(java.awt.event.WindowEvent e)

public voidwindowIconified(java.awt.event.WindowEvent e)

public voidwindowOpened(java.awt.event.WindowEvent e)