package controller;
//----- JDK Imports ------------------------------------------------------------
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.UIManager;
//----- SISC Imports -----------------------------------------------------------
import sisc.interpreter.AppContext;
import sisc.interpreter.Context;
//----- Phoenix Imports --------------------------------------------------------
import util.CutDetector;
import util.Kluberizer;
import util.TrackKluberizer;
import view.ColorWindow;
import view.InfoWindow;
import view.PhoenixWindow;
/**
* 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.
* @author Lunderskov, Ian; Pan, Jiabei; Rebelsky, Samuel; Whisenhunt, Heather;
* Young, Ian; Zuleta Benavides, Luis
* @author Glimmer Labs
* @version 0.2.0
*
*/
public class PhoenixController
{
/*--------*-------------------------------------------------------------------
* Fields *
*--------*/
// name of the movie to be accessed by MovieWindow
public static String name = "";
// one window for this controller; main display
public PhoenixWindow view;
// controllers and other objects
public static SchemeController schemeController;
public static ClipsController clipsController;
public static MovieController movieController;
public static HistogramController histogramController;
public static PictController pictController;
public static CutDetector cutDetector;
public static Kluberizer kluberizer;
public static TrackKluberizer trackKluberizer;
// directory where Phoenix files reside
public static String dir = System.getProperty("user.dir");
/*--------------*-------------------------------------------------------------
* Constructors *
*--------------*/
/**
* Create a new PhoenixController
*/
public PhoenixController()
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame.setDefaultLookAndFeelDecorated(true);
// create main window
this.view = new PhoenixWindow(this);
this.view.setVisible(true);
} // try
catch (Exception e)
{
e.printStackTrace();
} // catch (Exception)
// create controllers and other objects
PhoenixController.schemeController = new SchemeController(this);
PhoenixController.clipsController = new ClipsController(this);
PhoenixController.movieController = new MovieController(this);
PhoenixController.histogramController = new HistogramController(this);
PhoenixController.pictController = new PictController(this);
PhoenixController.cutDetector = new CutDetector();
PhoenixController.kluberizer = new Kluberizer();
PhoenixController.trackKluberizer = new TrackKluberizer();
} // PhoenixController()
/*---------*------------------------------------------------------------------
* Methods *
*---------*/
/**
* Get the main display window for this instance of Phoenix
*
* @return view Main display window
*/
public PhoenixWindow getWindow()
{
return this.view;
} // getWindow()
/**
* Get the ClipsController for this instance of Phoenix
*
* @return clipsController ClipsController
*/
public static ClipsController getClipsController()
{
return PhoenixController.clipsController;
} // getClipsController()
/**
* Get the HistogramController for this instance of Phoenix
*
* @return histogramController HistogramController
*/
public static HistogramController getHistogramController()
{
return PhoenixController.histogramController;
} // getHistogramController()
/**
* Get the PictController for this instance of Phoenix
*
* @return pictController PictController
*/
public static PictController getPictController()
{
return PhoenixController.pictController;
} // getPictController()
/**
* Get the MovieController for this instance of Phoenix
*
* @return movieController MovieController
*/
public static MovieController getMovieController()
{
return PhoenixController.movieController;
} // getMovieController()
/**
* Get the SchemeController for this instance of Phoenix
*
* @return schemeController SchemeController
*/
public static SchemeController getSchemeController()
{
return PhoenixController.schemeController;
} // getSchemeController()
/**
* Get the CutDetector for this instance of Phoenix
*
* @return cutDetector CutDetector
*/
public static CutDetector getCutDetector()
{
return PhoenixController.cutDetector;
} // getCutDetector()
/**
* Get the Kluberizer for this instance of Phoenix
*
* @return kluberizer Kluberizer
*/
public static Kluberizer getKluberizer()
{
return PhoenixController.kluberizer;
} // getKluberizer()
/**
* Get the TrackKluberizer for this instance of Phoenix
*
* @return trackKluberizer TrackKluberizer
*/
public static TrackKluberizer getTrackKluberizer()
{
return PhoenixController.trackKluberizer;
} // getTrackKluberizer()
/**
* Get the contents of a file as a String
*
* @param filename Name of the file to be read
* @return contents Contents of the file
*/
public String showFile(String filename)
{
String str;
String temp = "";
try
{
BufferedReader in = new BufferedReader(new FileReader(
PhoenixController.getFile(filename)));
while ((str = in.readLine()) != null)
{
temp = temp + str + "\n";
} // while ((str == in.readLine()) != null)
in.close();
} // try
catch (Exception e)
{
e.printStackTrace();
} // catch (Exception)
return temp;
} // showFile(String)
/**
* Reset Scheme environment and variables.
*/
public void resetSchemeEnvironment()
{
MovieController.movieList.clear();
PhoenixController.clipsController.clear();
PhoenixController.clipsController.window.updateUI();
PhoenixController.schemeController.window.outputArea.setText("");
PhoenixController.schemeController.window.inputArea.setText("");
// reload the heap
AppContext ctx = new AppContext();
try
{
ctx.addHeap(AppContext.openHeap(new URL("file://"
+ PhoenixController.getFile("sisc.shp"))));
} // try
catch (Exception e)
{
e.printStackTrace();
} // catch (Exception)
PhoenixController.schemeController.schemeHandler = Context.enter(ctx);
// print another welcome message
PhoenixController.schemeController.printStyledText("Welcome to Phoenix!\n",
"output");
PhoenixController.schemeController.printStyledText("Phoenix version 0.2.0,"
+ " Copyright (c) 2007 Lunderskov, Ian; Pan, Jiabei; Rebelsky, Samuel;"
+ " Whisenhunt, Heather; Young, Ian; Zuleta Benavides, Luis\n");
PhoenixController.schemeController.printStyledText("Video Phoenix comes"
+ " with ABSOLUTELY NO WARRANTY.\n");
PhoenixController.schemeController.printStyledText("This is free software,"
+ " and you are welcome to redistribute it subject to certain terms and"
+ " conditions; for details see Help > About Phoenix.\n");
SchemeController.schemeCall("(include \"resources/InitialScheme.scm\")",
false);
} // resetSchemeEnvironment()
/**
* Get a complete path for a file in the "resources" folder
*
* @param name Local name of file in "resources" folder
* @return filename Complete path for file
*/
public static String getFile(String name)
{
return dir + "/resources/" + name;
} // getFile(String)
/**
* Get a complete path for an image in the "resources/icons" folder
*
* @param name Local name of file in "resources/icons" folder
* @return filename Complete path for image
*/
public static String getImage(String name)
{
return dir + "/resources/icons/" + name;
} // getImage(String)
/**
* Show the help file in a new window
*/
public void showHelp()
{
new InfoWindow(this.view, "Help", showFile("help.txt"));
} // showHelp()
/**
* Show color swatches of predefined colors in a new window
*/
public void showColors()
{
new ColorWindow(this);
} // showColors()
} // class PhoenixController