FileDocCategorySizeDatePackage
FileViewer.javaAPI DocExample2512Sun Mar 28 19:08:34 BST 1999None

FileViewer

public class FileViewer extends JFrame implements WindowListener, ActionListener

Fields Summary
JFileChooser
fc
JStreamedTextArea
theView
ModePanel
mp
Constructors Summary
public FileViewer()


    
    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("");
        OutputStream out = theView.getOutputStream();
        try {
          FileInputStream in = new FileInputStream(f);
          FileDumper5.dump(in, out, mp.getMode(), mp.isBigEndian(),
           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)

  
    FileViewer fv = new FileViewer();
    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)