utils.ptplot5_2.ptolemy.gui
Class Top

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--utils.ptplot5_2.ptolemy.gui.Top
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public abstract class Top
extends javax.swing.JFrame

This is a top-level window with a menubar and status bar. Derived classes should add components to the content pane using a line like:

     getContentPane().add(component, BorderLayout.CENTER);
 
Derived classes may wish to modify the menus. The File and Help menus are exposed as protected members. The File menu items in the _fileMenuItems protected array are, in order, Open File, Open URL, New, Save, SaveAs, Print, Close, and Exit. The Help menu items in the _helpMenuItems protected array are, in order, About and Help.

A derived class can use the insert() methods of JMenu to insert a menu item defined by an Action or a JMenuItem into a specified position in the menu. Derived classes can also insert separators using the insertSeparator() method of JMenu. In principle, derived classes can also remove menu items using the remove() methods of JMenu; however, we discourage this. A basic principle of user interface design is habituation, where there is considerable value in having menus that have consistent contents and layout throughout the application (Microsoft, for example, violates this principle with adaptive menus).

Instead of removing items from the menu, they can be disabled. For example, to disable the "Save" item in the File menu, do

     _fileMenuItems[3].setEnabled(false);
 

Some menu items are provided, but are disabled by default. The "New" item, for example, can be enabled with

     _fileMenuItems[2].setEnabled(true);
 
A derived class that enables this menu item can populate the menu with submenu items. This particular entry in the _fileMenuItems[2] is a JMenu, not just a JMenuItem, so it can have menu items added to it.

A derived class can add an entirely new menu (many do that). However, at this time, the JMenuBar interface does not support putting a new menu into an arbitrary position. For this reason, derived classes should insert new menus into the menu bar only in the _addMenus() protected method. This ensures that the File menu is always the rightmost menu, and the Help menu is always the leftmost menu. The _addMenus() method is called when the window is first packed.

Since:
Ptolemy II 1.0
Version:
$Id: Top.html,v 1.1.1.1 2003/07/10 12:20:41 dsagnol Exp $
Author:
Edward A. Lee and Steve Neuendorffer
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Top()
          Construct an empty top-level frame.
 
Method Summary
 void centerOnScreen()
          Center the window on the screen.
static java.lang.String getLastOverallURL()
          Return the most recently entered URL in the most recently invoked Open URL dialog box.
 boolean isModified()
          Return true if the data associated with this window has been modified since it was first read or last saved.
 void pack()
          Size this window to its preferred size and make it displayable, and override the base class to populate the menu bar if the menus have not already been populated.
 void report(java.lang.Exception ex)
          Report an exception.
 void report(java.lang.String message)
          Report a message to the user by displaying it in a status bar.
 void report(java.lang.String message, java.lang.Exception ex)
          Report an exception.
 void setBackground(java.awt.Color background)
          Set background color.
static void setLastOverallURL(java.lang.String lastOverallURL)
          Set the value of the last overall URL.
 void setModified(boolean modified)
          Record whether the data associated with this window has been modified since it was first read or last saved.
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

Top

public Top()
Construct an empty top-level frame. After constructing this, it is necessary to call pack() to have the menus added, and then setVisible(true) to make the frame appear. It may also be desirable to call centerOnScreen(). This can be done after pack() and before setVisible().

Method Detail

centerOnScreen

public void centerOnScreen()
Center the window on the screen. This must be called after the window is populated with its contents, since it depends on the size being known.


getLastOverallURL

public static java.lang.String getLastOverallURL()
Return the most recently entered URL in the most recently invoked Open URL dialog box. Note that each Top has its own last url, this method returns the value of the last Open URL dialog. If the Open URL menu choice has not yet been invoked, then return null.

The value returned by getLastOverallURL() is used by MoMLParser to determine whether we should display a Security concern dialog and ask the user if they want to download a model from outside the value of getLastOverallURL().

Returns:
the most recently entered URL in the most recently invoked Open URL dialog box.
See Also:
setLastOverallURL(java.lang.String)

isModified

public boolean isModified()
Return true if the data associated with this window has been modified since it was first read or last saved. This returns the value set by calls to setModified(), or false if that method has not been called.

Returns:
True if the data has been modified.

report

public void report(java.lang.Exception ex)
Report an exception. This displays a message in a dialog by calling the two-argument version with an empty string as the first argument.

Parameters:
ex - The exception to report.
See Also:
report(String, Exception)

report

public void report(java.lang.String message)
Report a message to the user by displaying it in a status bar.

Parameters:
message - The message to report.

report

public void report(java.lang.String message,
                   java.lang.Exception ex)
Report an exception. This pops up a window with the option of examining the stack trace.

Parameters:
message - The message.
ex - The exception to report.

setBackground

public void setBackground(java.awt.Color background)
Set background color. This overrides the base class to set the background of contained ModelPane.

Overrides:
setBackground in class java.awt.Component
Parameters:
background - The background color.

setLastOverallURL

public static void setLastOverallURL(java.lang.String lastOverallURL)
Set the value of the last overall URL.

Parameters:
lastOverallURL - The last overall URL
See Also:
getLastOverallURL()

setModified

public void setModified(boolean modified)
Record whether the data associated with this window has been modified since it was first read or last saved. If you call this with a true argument, then subsequent attempts to close the window will trigger a dialog box to confirm the closing.

Parameters:
modified - Indicator of whether the data has been modified.

pack

public void pack()
Size this window to its preferred size and make it displayable, and override the base class to populate the menu bar if the menus have not already been populated. This is done here rather than in the constructor so that derived classes are assured that their constructors have been fully executed when _addMenus() is called.

Overrides:
pack in class java.awt.Window