package view;
//----- JDK Imports ------------------------------------------------------------
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
//----- Quicktime Imports ------------------------------------------------------
import quicktime.QTException;
import quicktime.std.StdQTException;
import quicktime.std.movies.Movie;
//----- Phoenix Imports --------------------------------------------------------
import controller.PhoenixController;
import controller.SchemeController;
import util.QTSessionCheck;
/**
* Video Phoenix
* Version 0.2.0
* Copyright (c) 2007 Lunderskov, Ian; Pan, Jiabei; Rebelsky, Samuel;
* Whisenhunt, Heather; Young, Ian; Zuleta Benavides, Luis.
* All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* The main Phoenix window, which provides a menu bar and contains all the
* sub-windows.
*
* @author Lunderskov, Ian; Pan, Jiabei; Rebelsky, Samuel; Whisenhunt, Heather;
* Young, Ian; Zuleta Benavides, Luis
* @author Glimmber Labs 2006-2007
* @author Samuel A. Rebelsky
* @version 0.2.0
*/
@SuppressWarnings("serial")
public class PhoenixWindow extends JFrame implements ActionListener
{
/*--------*-------------------------------------------------------------------
* Fields *
*--------*/
JMenuBar menubar;
// file menu and items
JMenu fileMenu;
JMenuItem menuOpen;
JMenuItem menuReset;
JMenuItem menuExit;
// view menu and items
JMenu viewMenu;
JMenuItem showClips;
JMenuItem showScheme;
JMenu helpMenu;
JMenuItem showHelp;
JMenuItem showLicense;
JLabel status;
static PhoenixController controller;
// most recently opened movie, from command line or ClipsWindow
public String name = "";
// PhoenixWindow's desktop
JDesktopPane desktop;
/*--------------*-------------------------------------------------------------
* Constructors *
*--------------*/
/**
* Create a new PhoenixWindow for the main display
*
* @param controller PhoenixController for this PhoenixWindow
*/
public PhoenixWindow(PhoenixController controller)
{
super("Phoenix");
PhoenixWindow.controller = controller;
// if window is closed, terminate the program
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// add a window listener to detect when window is closed
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
SchemeController.alive = false;
System.exit(0);
} // windowClosing(WindowEvent)
});
// set default size of the window, and desktop as content pane of window
this.setBounds(100, 100, 700, 480);
this.desktop = new JDesktopPane();
this.setContentPane(this.desktop);
// update UI while window is being dragged
this.desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
// initialize menu bar and menus
this.menubar = new JMenuBar();
this.setJMenuBar(this.menubar);
this.fileMenu = new JMenu("File");
this.menubar.add(this.fileMenu);
this.viewMenu = new JMenu("View");
this.menubar.add(this.viewMenu);
this.helpMenu = new JMenu("Help");
this.menubar.add(this.helpMenu);
// initialize file menu items
this.menuOpen = new JMenuItem("Open...");
this.fileMenu.add(this.menuOpen);
this.menuOpen.addActionListener(this);
this.menuOpen.setAccelerator(KeyStroke.getKeyStroke('O',
InputEvent.CTRL_MASK));
this.menuReset = new JMenuItem("Reset Scheme Environment");
this.fileMenu.add(this.menuReset);
this.menuReset.addActionListener(this);
this.menuReset.setAccelerator(KeyStroke.getKeyStroke('R',
InputEvent.CTRL_MASK));
this.menuExit = new JMenuItem("Exit");
this.menuExit.setAccelerator(KeyStroke.getKeyStroke('X',
InputEvent.CTRL_MASK));
this.fileMenu.addSeparator();
this.fileMenu.add(this.menuExit);
this.menuExit.addActionListener(this);
// initialize view menu items
this.showClips = new JMenuItem("Clips Window");
this.viewMenu.add(this.showClips);
this.showClips.addActionListener(this);
this.showScheme = new JMenuItem("Scheme Console");
this.viewMenu.add(this.showScheme);
this.showScheme.addActionListener(this);
// initialize help menu items
this.showHelp = new JMenuItem("Phoenix Help");
this.helpMenu.add(this.showHelp);
this.showHelp.addActionListener(this);
this.showLicense = new JMenuItem("About Phoenix");
this.helpMenu.add(this.showLicense);
this.showLicense.addActionListener(this);
this.setLayout(null);
// make sure the QuickTime environment is valid
try
{
QTSessionCheck.check();
} // try
catch (QTException qte)
{
qte.printStackTrace();
} // catch (QTException)
this.setVisible(true);
} // PhoenixWindow(PhoenixController)
/*---------*------------------------------------------------------------------
* Methods *
*---------*/
/**
* Get the PhoenixController for this PhoenixWindow
*
* @return controller PhoenixController for this PhoenixWindow
*/
public static PhoenixController getController()
{
return PhoenixWindow.controller;
} // getController()
/**
* Move a component to the front of its layer
*
* @param comp Component to be moved to the front
* @throws StdQTException
*/
public void moveToFront(Component comp)
throws StdQTException
{
this.desktop.moveToFront(comp);
} // moveToFront(Component)
/*------------------*---------------------------------------------------------
* Listener Methods *
*------------------*/
/**
* Handle mouse actions
*
* @param event mouse event
*/
public void actionPerformed(ActionEvent event)
{
JMenuItem source = (JMenuItem) event.getSource();
// if user clicked "open" from menu
if (source == this.menuOpen)
{
// open a file selector, add movie to ClipsWindow, and open movie
Movie mov = PhoenixController.movieController.openFile();
PhoenixController.clipsController.addClip(mov,
PhoenixController.movieController.name);
try
{
PhoenixController.movieController.showMovie(mov, "preview");
} // try
catch (Exception e)
{
e.printStackTrace();
} // catch (Exception)
} // if (source == this.menuOpen)
// if user clicked "reset scheme environment" from menu
else if (source == this.menuReset)
{
int confirm = JOptionPane.showConfirmDialog(
this,
"This will reset Phoenix's Scheme Environment.\n"
+ "All variables will be cleared. \n\n"
+ "Proceed?",
"Confirmation",
JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION)
{
controller.resetSchemeEnvironment();
} // if (confirm == JOptionPane.YES_OPTION)
} // else if (source == this.menuReset)
// if user clicked "exit" from menu
else if (source == this.menuExit)
{
// tell schemeInterpreter thread to die, then exit
SchemeController.alive = false;
System.exit(0);
} // else if (source == this.menuExit)
// if user clicked "clips window" from menu
else if (source == this.showClips)
{
PhoenixController.clipsController.window.setVisible(true);
} // else if (source == this.showClips)
// if user clicked "scheme console" from menu
else if (source == this.showScheme)
{
PhoenixController.schemeController.window.setVisible(true);
} // else if (source == this.showScheme)
// if user clicked "phoenix help" from menu
else if (source == this.showHelp)
{
// show help
PhoenixWindow.getController().showHelp();
} // else if (source = this.showHelp)
// if user clicked "about phoenix" from menu
else if (source == this.showLicense)
{
// show license
new InfoWindow(this, "License Information",
PhoenixWindow.getController().showFile("license.txt"));
} // else if (source == this.showLicense)
} // actionPerformed(ActionEvent)
} // PhoenixWindow