
// ImageViewer.java
// Michael Kolling and David J Barnes 
// version 0.5
// Modified by Andrew Davison, Jan 2018, ad@fivedots.coe.psu.ac.th

/* ImageViewer is the main class of the image viewer application. It builds
   and displays the application GUI and initialises all other components. 

   This version displays a label and a menu.
   Uses anonymous listeners for the two menu items
*/


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class ImageViewer extends JFrame
{

  public ImageViewer()
  {
    super("ImageViewer 0.5");

    // create the GUI
    makeMenuBar();

    Container c = getContentPane();
    JLabel label = new JLabel("I am a label. I can display some text.");
    c.add(label);

    // set close behaviour for JFrame as exit
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    pack(); // reduce frame size to fit GUI component
    setVisible(true);
  }  // end of ImageViewer()



  // Create the main frame's menu bar.
  private void makeMenuBar()
  {
    JMenuBar menubar = new JMenuBar();
    setJMenuBar(menubar);
        
    // create the File menu
    JMenu fileMenu = new JMenu("File");
    menubar.add(fileMenu);
        
    JMenuItem openItem = new JMenuItem("Open");
    openItem.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent e)
      { openFile(); }
    });
    // openItem.addActionListener( e -> openFile() );
    fileMenu.add(openItem);

    JMenuItem quitItem = new JMenuItem("Quit");
    quitItem.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent e)
      { System.exit(0); }
    });
    // quitItem.addActionListener( e -> System.exit(0) );
    fileMenu.add(quitItem);
  }  // end of makeMenuBar()


  private void openFile()
  // open a Swing file chooser to select a new image file
  {
    // test output, until we do this properly
    System.out.println("open file");
  }  // end of openFile()
    


  // ----------------------------------------------

  public static void main(String[] args) 
  { new ImageViewer(); } 

} // end of ImageViewer class
