FileDocCategorySizeDatePackage
FileViewer.javaAPI DocExample2332Tue Feb 14 13:50:38 GMT 2006None

FileViewer

public class FileViewer extends JFrame implements ActionListener

Fields Summary
private JFileChooser
chooser
private com.elharo.io.ui.JStreamedTextArea
theView
private ModePanel
mp
Constructors Summary
public FileViewer()


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

  
    if (evt.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) {
      File f = chooser.getSelectedFile();
      if (f != null) {
        theView.reset();
        try {
          InputStream in = new FileInputStream(f);
          in = new ProgressMonitorInputStream(this, "Reading...", in);
          OutputStream out = theView.getOutputStream();
          FileDumper5.dump(in, out, mp.getMode(), mp.isBigEndian(),
           mp.isDeflated(), mp.isGZipped(), mp.getPassword());
        }
        catch (IOException ex) {
          JOptionPane.showMessageDialog(this, ex.getMessage(), 
            "I/O Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    }
    else if (evt.getActionCommand().equals(JFileChooser.CANCEL_SELECTION)) {
      this.setVisible(false);
      this.dispose();
    }
  
public voidinit()

    chooser.setApproveButtonText("View File");
    chooser.setApproveButtonMnemonic('V");
    chooser.addActionListener(this);
    
    this.getContentPane().add(BorderLayout.CENTER, chooser);
    JScrollPane sp = new JScrollPane(theView);
    sp.setPreferredSize(new Dimension(640, 400));
    this.getContentPane().add(BorderLayout.SOUTH, sp);
    this.getContentPane().add(BorderLayout.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 viewer = new FileViewer();
    viewer.init();
    // This is a single window application
    viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    viewer.setVisible(true);