/****************************************************************** * @(#) JsimFrame.java 1.3 * * Copyright (c) 2001 John Miller * All Right Reserved *----------------------------------------------------------------- * Permission to use, copy, modify and distribute this software and * its documentation without fee is hereby granted provided that * this copyright notice appears in all copies. * WE MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WE SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY ANY USER AS A RESULT OF USING, * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. *----------------------------------------------------------------- * * @version 1.3, 12 May 2001 * @author John Miller */ package jsim.util; import java.awt.*; import java.awt.event.*; import javax.swing.*; /****************************************************************** * This class allows common frames to be created, thereby reducing * repetitive code. Since event handling is situation dependent, * this class does not handle any events. */ public class JsimFrame extends JFrame { /** * Tracing messages. */ private static final Trace TRC = new Trace ("JsimFrame"); /** * Default size of frame. */ private static final Dimension DEFAULT_SIZE = new Dimension (800, 700); /** * Default location for frame. */ private static final Point DEFAULT_PLACE = new Point (100, 100); /** * Pane with scroll bars. */ protected JScrollPane sPane; /** * Bar holding drop down menus */ protected JMenuBar menuBar = new JMenuBar (); /************************************************************** * Construct a JSIM frame. * @param title title/name of the frame */ public JsimFrame (String title) { super ("JSIM " + title); addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } }); }; // JsimFrame /************************************************************** * Make the frame appear. * @param fileOption file menu items * @param editOption edit menu items * @param helpOption help menu items * @param mPanel main panel * @param dim size of frame * @param location position of frame */ public void start (JMenu fileMenu, JMenu editMenu, JMenu helpMenu, JPanel mPanel, Dimension dim, Point location) { if (fileMenu != null) menuBar.add (fileMenu); if (editMenu != null) menuBar.add (editMenu); menuBar.add (Box.createHorizontalGlue ()); if (helpMenu != null) menuBar.add (helpMenu); setJMenuBar (menuBar); sPane = new JScrollPane (mPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); getContentPane ().add (sPane, BorderLayout.CENTER); setLocation (location); setSize (dim); setVisible (true); TRC.show ("start", "frame started"); }; // start /************************************************************** * Main method for testing purposes only. * @param args command-line arguments */ public static void main (String [] args) { String [] mString = { "Start", "Quit" }; JMenuItem [] fileOption = new JMenuItem [mString.length]; for (int i = 0; i < mString.length; i++) { fileOption [i] = new JMenuItem (mString [i]); }; // for JMenu fileMenu = new JMenu ("File"); if (fileOption != null) { for (int i = 0; i < fileOption.length; i++) { fileMenu.add (fileOption [i]); }; // for }; // if JsimFrame frame = new JsimFrame ("TestFrame"); frame.start (fileMenu, null, null, new JPanel (), DEFAULT_SIZE, DEFAULT_PLACE); }; // main }; // JsimFrame class