import java.net.*;
import java.io.*;
import java.awt.event.ActionEvent;
import javax.swing.*;

/**
  The FileOpenAction is just what it says. It displays
  a file dialog and allows the user to select an HTML
  file to open.
  <br><a href="../source/FileOpenAction.java">View Source File</a>
*/
public class FileOpenAction extends AbstractAction {
  Mozart mozart;

  public FileOpenAction(Mozart mz) {
    super("Open", new ImageIcon("images/open.gif"));
    mozart = mz;
  }

  public void actionPerformed(ActionEvent event) {
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showOpenDialog(mozart.getFrame());

    if (option == JFileChooser.APPROVE_OPTION) {
      File file = chooser.getSelectedFile();

      // Create an empty, new MozartInternalFrame
      MozartInternalFrame frame = new MozartInternalFrame(mozart);

      // Load the page
      frame.setPage(file);

      // Add it to the desktop
      mozart.mainFrame.addToDesktop(frame);
    }
  }
}
