/*============================================================================= | | NAME | | PrenticeFrame.java | | DESCRIPTION | | Top level frame for Prentice containing menus, toolbars, | viewing area. | | 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. | +============================================================================*/ package View ; // Package name for this project. import java.awt.* ; // AWT basic window handling. import java.awt.event.* ; // AWT basic event handling. import java.awt.geom.* ; // 2D graphics. import java.awt.image.* ; // Images and operations. import javax.swing.* ; // Swing main GUI package. import javax.swing.event.* ; // Swing GUI event handling. import Prentice.* ; // Prentice stuff. import Model.* ; /*============================================================================= | | NAME | | PrenticeFrame | | DESCRIPTION | | Top level frame for Prentice containing menus, toolbars, | viewing area. | | PUBLIC MEMBER FUNCTIONS | | DefaultConstructor WhatItDoesBriefly | ConstructorWithArguments WhatItDoesBriefly | MemberFunction1 WhatItDoesBriefly | MemberFunction2 WhatItDoesBriefly | MemberFunction3 WhatItDoesBriefly | | EXCEPTIONS | | Description | | NOTES | | | Frame showing title bars, menu bars, and toolbars. | | +---------------------------------------------------+ | | Prentice - An Artist's Software Ass | <--- Title Bar | +------+-----+--------------------------------------+ | | File | ... | | <--- Menu Bar with menu items. | +---------------------------------------------------+ | | New | | <--- Toolbar with menu subitems. | +---------+-----------------------------------------+ | | | | | | <--- View | | | | | | | +---------------------------------------------------+ | | | BUGS | | Bugs_Enhancements | +============================================================================*/ // Can access this class only within the SourceCode package. public class PrenticeFrame extends JFrame implements PrenticeConstants { private JMenuBar menuBar ; // Menu bar. // Menus. private JMenu fileMenu ; // File private JMenuItem newItem ; // Item for File->New private FileAction newAction ; // Action for File->New private FileAction openAction ; // Action for File->Open // Toolbar. private JToolBar toolBar ; // Helper function. private JMenuItem addMenuItem( JMenu menu, Action action ) { JMenuItem item = menu.add( action ) ; // Add menu item. KeyStroke keystroke = (KeyStroke) action.getValue( action.ACCELERATOR_KEY ) ; if (keystroke != null) item.setAccelerator( keystroke ) ; return item ; } /*---------------------------------------------------------- | Construct the frame, pull-down menus, toolbar, etc. ----------------------------------------------------------*/ public PrenticeFrame( Prentice app ) { DebugLog.println( "Entering PrenticeFrame" ) ; // Set the title bar of the frame's window. setTitle( APP_TITLE ) ; // Exit when the window is closed. setDefaultCloseOperation( EXIT_ON_CLOSE ) ; // Create the menu bar. menuBar = new JMenuBar() ; // -------------< FILE menu items >------------------ // First item in the menu is FILE. fileMenu = new JMenu( FILE ) ; // Shortcut key is ALT + N for FILE. fileMenu.setMnemonic( FILE_SHORTCUT ) ; // Submenu item FILE->NEW has an action, icon and tooltip. newAction = new FileAction( NEW, NEW_SHORTCUT, NEW_TOOLTIP ) ; newAction.putValue( Action.SMALL_ICON, new ImageIcon( "../data/newIcon.png" )) ; openAction = new FileAction( OPEN, OPEN_SHORTCUT, OPEN_TOOLTIP ) ; openAction.putValue( Action.SMALL_ICON, new ImageIcon( "../data/openIcon.png" )) ; // Link NEW action under FILE. addMenuItem( fileMenu, newAction ) ; // Link OPEN action under FILE. addMenuItem( fileMenu, openAction ) ; // Add separator bar. fileMenu.addSeparator() ; // Add FILE menu item to the menu bar. menuBar.add( fileMenu ) ; // Add menu bar to the frame. setJMenuBar( menuBar ) ; // -------------< Toolbar items >------------------ // Toolbar. toolBar = new JToolBar() ; // Add FILE->NEW and FILE->OPEN JButton button = toolBar.add( newAction ) ; button = toolBar.add( openAction ) ; button = null ; // Add toolbar to frame's pane. getContentPane().add( toolBar, BorderLayout.NORTH ) ; } } // end PrenticeFrame