import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.awt.swing.*;
import java.awt.swing.event.*;
public class MovieApplet extends JApplet {
 Movie movie;
 Vector movieVector;
 MeterCanvas meterCanvas = new MeterCanvas();
 VectorChoiceList choiceList = new VectorChoiceList();
 ImageCanvas imageCanvas = new ImageCanvas(); 
 FormPanel formPanel = new FormPanel(); 
 JMenuBar menuBar = new JMenuBar(); 
 JMenu fileMenu = new JMenu("File"); 
 JMenuItem fileMenuGeneral = new JMenuItem("General"); 
 JMenuItem fileMenuHorror = new JMenuItem("Horror"); 
 public void init () {
  getContentPane().add("West", meterCanvas); 
  getContentPane().add("Center", new JScrollPane(choiceList));
  getContentPane().add("East", imageCanvas); 
  getContentPane().add("South", formPanel); 
  setJMenuBar(menuBar);          
  menuBar.add(fileMenu); 
  fileMenu.add(fileMenuGeneral); 
  fileMenu.add(fileMenuHorror); 
  fileMenuGeneral.addActionListener(new LocalActionListener(this)); 
  fileMenuHorror.addActionListener(new LocalActionListener(this)); 
  setMovieVector("general.movies");
  choiceList.addListSelectionListener(new LocalListener()); 
 }
 public void setMovieVector (String file) {      
  movieVector = MovieAuxiliaries.readMovieFile(file);    
  choiceList.setChoices(movieVector);                   
 }                                               
 public void setMovie(int n) { 
  if (0 <= n & n < movieVector.size()) { 
   movie = (Movie)movieVector.elementAt(n); 
   meterCanvas.attachObservable(movie); 
   imageCanvas.attachObservable(movie); 
   formPanel.attachObservable(movie); 
   movie.changed(); 
  } 
 } 
 class LocalListener implements ListSelectionListener {
  public void valueChanged(ListSelectionEvent e) { 
   setMovie(choiceList.getSelectedIndex());
  }
 }
 class LocalActionListener implements ActionListener {          
  MovieApplet parent;                                           
  LocalActionListener(MovieApplet p) {parent = p;}              
  public void actionPerformed (ActionEvent e) {                 
   if (e.getSource() == fileMenuGeneral) {                      
    parent.setMovieVector("general.movies");                    
   } else if (e.getSource() == fileMenuHorror) {                
    parent.setMovieVector("horror.movies");                     
   }                                                            
  }                                                             
 }                                                              
}
