/*============================================================================= | | NAME | | Prentice.java | | DESCRIPTION | | Artist's Software Apprentice. | | AUTHOR | | Sean E. O'Connor | | LEGAL | | Prentice Version 1.1 - An Artist's Software Apprentice. | Copyright (C) 2003-2008 by Sean Erik O'Connor. All Rights Reserved. | | This program is free software; you can redistribute it and/or | modify it under the terms of the GNU General Public License | as published by the Free Software Foundation; version 2 | of the License. | | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU General Public License | along with this program; if not, write to the Free Software | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | | The author's address is artifex@seanerikoconnor.freeservers.com. | | NOTES | | See readme.txt for full installation notes. | +============================================================================*/ package Prentice ; // Package name for this project. Must be the // same as the directory name containing these // source files. import java.awt.* ; // AWT basic window handling. import javax.swing.* ; // Swing main GUI package. import Model.* ; // Prentice stuff import View.* ; import Model.* ; /*============================================================================= | | NAME | | Prentice | | DESCRIPTION | | The Prentice application class. | | Create the Prentice process with top level frame, image and view. | | NOTES | | Algorithm_References_Tricks | +============================================================================*/ /** * Prentice top level class. * public makes it visible outside the package. */ public class Prentice { /*---------------------------------------------------------- | Top level elements of the GUI. ----------------------------------------------------------*/ /** * Handle to this application. Must be * a class variable because we create * the object later within this class. */ private static Prentice theApp ; private PrenticeFrame frame ; // Top level frame for this application. // containing menu and status bars. private PrenticeView view ; // View containing specialized buttons and // images. private PrenticeCanvas image ; // Rendered image to be displayed. private PrenticeModel model ; // Shared by all instances. private int imageWidth = 1024 ; private int imageHeight = 768 ; /*---------------------------------------------------------- | The bulk of the application code. ----------------------------------------------------------*/ public Prentice() { // Start logging diagnostics to a file. try { DebugLog.startLog( "log.txt" ) ; } catch( Exception e ) { System.err.println( "Debug logging failed." ) ; } DebugLog.off() ; DebugLog.println( "Entering Prentice" ) ; DebugLog.println( "Start wall clock time msec = " + System.currentTimeMillis() ) ; DebugLog.println( " frame = " + view ) ; DebugLog.println( " view = " + frame ) ; // Model creation first. model = new PrenticeModel( this, imageWidth, imageHeight ) ; image = new PrenticeCanvas( this, imageWidth, imageHeight ) ; frame = new PrenticeFrame( this ) ; view = new PrenticeView( this ) ; // Insert the view in the frame's content pane. frame.getContentPane().add( view, BorderLayout.CENTER ) ; // Pack the view and other components within the frame. frame.pack() ; // Center the frame position on the screen. Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize() ; frame.setLocation( new Point( screenDim.width / 2 - frame.getWidth() / 2, screenDim.height / 2 - frame.getHeight() / 2 ) ) ; // Show the frame. frame.setVisible( true ) ; DebugLog.print( "Leaving Prentice" ) ; DebugLog.print( "End wall clock time msec = " + System.currentTimeMillis() ) ; DebugLog.println( ) ; DebugLog.print( " frame = " + view ) ; DebugLog.print( " view = " + frame ) ; } // end Prentice /*---------------------------------------------------------- | Get functions to return frame, view and image handles | if we have the Prentice application handle. ----------------------------------------------------------*/ public PrenticeFrame getFrame() { return frame ; } public PrenticeView getView() { return view ; } public PrenticeCanvas getCanvas() { return image ; } public PrenticeModel getModel() { return model ; } /** * Entry point from the Java VM. * Do some preliminary work, on this initial thread. * Run the GUI on the separate event dispatching thread. */ public static void main( String[] args ) { // Check command line arguments are zero in number. if (args.length != 0) { System.err.println( "Usage: Prentice" ) ; System.err.println( "arg[ 1 ] = " + args[ 1 ] ) ; } // Schedule GUI on Swing's event-dispatching thread. SwingUtilities.invokeLater( // Anonymous class having threading functionality. new Runnable() { // Run the GUI function on this thread. public void run() { createAndShowGUI() ; } } ) ; } // end main static void createAndShowGUI() { // Set the look and feel of the GUI to reflect the platform // we are running on. try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ) ; } // Catch all exceptions. catch( Exception e ) { System.err.println( "Could not set look and feel." ) ; System.err.println( "Message :" + e.getMessage() ) ; System.err.println( "Stack trace" ) ; e.printStackTrace() ; } finally { // Come here first before throwing exceptions higher. } // Instantiate a new unique Prentice application object. // Save the handle to it in a Prentice class variable // (which exists before the Prentice object is created). theApp = new Prentice() ; DebugLog.print( "Leaving Prentice main" ) ; // Just testing... //assert false : "This is a test assert. Do not be alarmed." ; } // end createAndShowGUI } // end Prentice