1 //Frame for the Sketcher application
2 import javax.swing.*;3 import javax.swing.border.*;4 import java.awt.event.*;5 import java.awt.*;6
7 import static java.awt.event.InputEvent.*;8 import static java.awt.Color.*;9 import static Constants.SketcherConstants.*;10 import static javax.swing.Action.*;11
12 @SuppressWarnings("serial")13 public class SketcherFrame extendsJFrame {14 //Constructor
15 publicSketcherFrame(String title, Sketcher theApp) {16 setTitle(title); //Set the window title
17 this.theApp = theApp; //Save app. object reference
18 setJMenuBar(menuBar); //Add the menu bar to the window
19 setDefaultCloseOperation(EXIT_ON_CLOSE); //Default is exit the application
20
21 createFileMenu(); //Create the File menu
22 createElementMenu(); //Create the element menu
23 createColorMenu(); //Create the element menu
24 createToolbar();25 toolBar.setRollover(true);26 getContentPane().add(toolBar, BorderLayout.NORTH); //Add the toolbar
27 getContentPane().add(statusBar, BorderLayout.SOUTH); //Add the statusbar
28 }29
30 //Create File menu item actions
31 private voidcreateFileMenuActions() {32 newAction = new FileAction("New", 'N', CTRL_DOWN_MASK);33 openAction = new FileAction("Open", 'O', CTRL_DOWN_MASK);34 closeAction = new FileAction("Close");35 saveAction = new FileAction("Save", 'S', CTRL_DOWN_MASK);36 saveAsAction = new FileAction("Save As...");37 printAction = new FileAction("Print", 'P', CTRL_DOWN_MASK);38 exitAction = new FileAction("Exit", 'X', CTRL_DOWN_MASK);39
40 //Initialize the array
41 FileAction[] actions ={openAction, closeAction, saveAction, saveAsAction, printAction, exitAction};42 fileActions =actions;43
44 //Add toolbar icons
45 newAction.putValue(LARGE_ICON_KEY, NEW24);46 openAction.putValue(LARGE_ICON_KEY, OPEN24);47 saveAction.putValue(LARGE_ICON_KEY, SAVE24);48 saveAsAction.putValue(LARGE_ICON_KEY, SAVEAS24);49 printAction.putValue(LARGE_ICON_KEY, PRINT24);50
51 //Add menu item icons
52 newAction.putValue(SMALL_ICON, NEW16);53 openAction.putValue(SMALL_ICON, OPEN16);54 saveAction.putValue(SMALL_ICON, SAVE16);55 saveAsAction.putValue(SMALL_ICON,SAVEAS16);56 printAction.putValue(SMALL_ICON, PRINT16);57
58 //Add tooltip text
59 newAction.putValue(SHORT_DESCRIPTION, "Create a new sketch");60 openAction.putValue(SHORT_DESCRIPTION, "Read a sketch from a file");61 closeAction.putValue(SHORT_DESCR