ptolemy.actor.gui
Class TableauFrame

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byptolemy.gui.Top
                          extended byptolemy.actor.gui.TableauFrame
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants
Direct Known Subclasses:
ExpressionShellFrame, HTMLViewer, PlotTableauFrame, PtolemyFrame, TextEditor

public class TableauFrame
extends Top

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

   getContentPane().add(component, BorderLayout.CENTER);
   
The base class provides generic features for menubars and toolbars, and this class specializes the base class for Ptolemy II.

A help menu is provided with two entries, About and Help. In both cases, an HTML file is opened. The configuration can specify which HTML file to open by containing an instance of FileParameter with name "_about" or "_help". The value of this attribute is a file name (which may begin with the keywords $CLASSPATH or $PTII to specify that the file is located relative to the CLASSPATH or to the Ptolemy II installation directory).

Since:
Ptolemy II 1.0
Version:
$Id: TableauFrame.java,v 1.75.2.1 2004/06/18 00:48:53 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (celaine)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String _initialSaveAsFileName
          The initial filename to use in the SaveAs dialog
protected  javax.swing.JMenu _viewMenu
          The view menu.
 java.lang.String aboutFile
          The name of the default file to open when About is invoked.
 java.lang.String helpFile
          The name of the default file to open when Help is invoked.
 
Fields inherited from class ptolemy.gui.Top
_CANCELED, _directory, _DISCARDED, _FAILED, _fileFilter, _fileMenu, _fileMenuItems, _helpMenu, _helpMenuItems, _menubar, _SAVED, _statusBar
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
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
TableauFrame()
          Construct an empty top-level frame.
TableauFrame(Tableau tableau)
          Construct an empty top-level frame managed by the specified tableau and the default status bar.
TableauFrame(Tableau tableau, StatusBar statusBar)
          Construct an empty top-level frame managed by the specified tableau with the specified status bar.
 
Method Summary
protected  void _about()
          Override the base class to open the intro.htm splash window, which is in the directory ptolemy/configs.
protected  void _addMenus()
          Add a View menu and items to the File:New menu if a tableau was given in the constructor.
protected  boolean _close()
          Close the window.
protected  boolean _confirmFile(Entity model, java.io.File file)
          Confirm that writing the specified model to the specified file is OK.
protected  void _exit()
          Close all open tableaux, querying the user as necessary to save data, and then exit the application.
protected  java.awt.Image _getDefaultIconImage()
          Return the default icon image, or null if there is none.
protected  java.lang.String _getName()
          Get the name of this object, which in this class is the URI associated with the effigy, or the string "Unnamed" if none.
protected  void _help()
          Display the help file given by the configuration, or if there is none, then the file specified by the public variable helpFile.
protected  void _read(java.net.URL url)
          Read the specified URL.
protected  boolean _save()
          Save the model to the current file, determined by the uri parameter of the associated effigy, or if that has not been set or is not a writable file, or if the effigy has been set non-modifiable, then invoke _saveAs().
protected  boolean _saveAs()
          Query the user for a filename, save the model to that file, and open a new window to view the model.
protected  void _writeFile(java.io.File file)
          Write the model to the specified file.
 Configuration getConfiguration()
          Get the configuration at the top level of the hierarchy.
 ModelDirectory getDirectory()
          Get the model directory in the top level configuration.
 Effigy getEffigy()
          Get the effigy for the model associated with this window.
 PtolemyEffigy getEffigy(NamedObj model)
          Get the effigy for the specified Ptolemy model.
 Tableau getTableau()
          Get the tableau associated with this frame.
 boolean isModified()
          Return true if the data associated with this window has been modified since it was first read or last saved.
 void setModified(boolean modified)
          Record whether the data associated with this window has been modified since it was first read or last saved.
 void setTableau(Tableau tableau)
          Set the tableau associated with this frame.
 
Methods inherited from class ptolemy.gui.Top
_clear, _open, _openURL, _print, _queryForSave, _saveAsFileDialog, centerOnScreen, close, deferIfNecessary, getCentering, pack, report, report, report, setBackground, setCentering, show
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, 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, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, 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, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, 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
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

aboutFile

public java.lang.String aboutFile
The name of the default file to open when About is invoked. This file should be relative to the home installation directory. This file is used if the configuration does not specify an about file.


helpFile

public java.lang.String helpFile
The name of the default file to open when Help is invoked. This file should be relative to the home installation directory. This file is used if the configuration does not specify a help file.


_initialSaveAsFileName

protected java.lang.String _initialSaveAsFileName
The initial filename to use in the SaveAs dialog


_viewMenu

protected javax.swing.JMenu _viewMenu
The view menu. Note that this is only created if there are multiple views, so if derived classes use it, they must test to see whether it is null.

Constructor Detail

TableauFrame

public TableauFrame()
Construct an empty top-level frame. After constructing this, it is necessary to call setVisible(true) to make the frame appear. It may also be desirable to call centerOnScreen().


TableauFrame

public TableauFrame(Tableau tableau)
Construct an empty top-level frame managed by the specified tableau and the default status bar. After constructing this, it is necessary to call setVisible(true) to make the frame appear. It may also be desirable to call centerOnScreen().

Parameters:
tableau - The managing tableau.

TableauFrame

public TableauFrame(Tableau tableau,
                    StatusBar statusBar)
Construct an empty top-level frame managed by the specified tableau with the specified status bar. After constructing this, it is necessary to call setVisible(true) to make the frame appear. It may also be desirable to call centerOnScreen().

Parameters:
tableau - The managing tableau.
statusBar - The status bar, or null to not include one.
Method Detail

getConfiguration

public Configuration getConfiguration()
Get the configuration at the top level of the hierarchy.

Returns:
The configuration controlling this frame, or null if there isn't one.

getDirectory

public ModelDirectory getDirectory()
Get the model directory in the top level configuration.

Returns:
The model directory, or null if there isn't one.

getEffigy

public Effigy getEffigy()
Get the effigy for the model associated with this window.

Returns:
The effigy for the model, or null if none exists.

getEffigy

public PtolemyEffigy getEffigy(NamedObj model)
Get the effigy for the specified Ptolemy model. This searches all instances of PtolemyEffigy deeply contained by the directory, and returns the first one it encounters that is an effigy for the specified model.

Parameters:
model - The model for which an effigy is desired.
Returns:
The effigy for the model, or null if none exists.

getTableau

public Tableau getTableau()
Get the tableau associated with this frame.

Returns:
The tableau associated with this frame.

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.

Overrides:
isModified in class Top
Returns:
True if the data has been modified.

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. This overrides the base class to delegate to the effigy.

Overrides:
setModified in class Top
Parameters:
modified - True if the data has been modified.

setTableau

public void setTableau(Tableau tableau)
Set the tableau associated with this frame.

Parameters:
tableau - The tableau associated with this frame.

_about

protected void _about()
Override the base class to open the intro.htm splash window, which is in the directory ptolemy/configs.

Overrides:
_about in class Top

_addMenus

protected void _addMenus()
Add a View menu and items to the File:New menu if a tableau was given in the constructor.

Overrides:
_addMenus in class Top

_close

protected boolean _close()
Close the window. Derived classes should override this to release any resources or remove any listeners. In this class, if the data associated with this window has been modified, and there are no other tableaux in the parent effigy or any effigy that contains it, then ask the user whether to save the data before closing.

Overrides:
_close in class Top
Returns:
False if the user cancels on a save query.

_confirmFile

protected boolean _confirmFile(Entity model,
                               java.io.File file)
                        throws java.net.MalformedURLException
Confirm that writing the specified model to the specified file is OK. In particular, if the file exists, ask the user whether it is OK to overwrited. If there is an open model from the specified file, determine whether it has been modified, and prompt to discard changes if it has. Close the previously open model. If the previously open model on this file contains the specified model, the it is never OK to do the write, so return false.

Parameters:
model - The model to write to the file, or null specify that this will be delegated to the effigy associated with this tableau.
file - The file to write to.
Returns:
True if it is OK to write the model to the file.
Throws:
java.net.MalformedURLException

_exit

protected void _exit()
Close all open tableaux, querying the user as necessary to save data, and then exit the application. If the user cancels on any save, then do not exit.

Overrides:
_exit in class Top
See Also:
Tableau.close()

_getDefaultIconImage

protected java.awt.Image _getDefaultIconImage()
Return the default icon image, or null if there is none. Note that Frame.setIconImage(null) will set the image to the default platform dependent image for us.

Returns:
The default icon image, or null if there is none.

_getName

protected java.lang.String _getName()
Get the name of this object, which in this class is the URI associated with the effigy, or the string "Unnamed" if none. This overrides the base class to provide a reasonable name for the title of the window.

Overrides:
_getName in class Top
Returns:
The name.

_help

protected void _help()
Display the help file given by the configuration, or if there is none, then the file specified by the public variable helpFile. To specify a default help file in the configuration, create a FileParameter named "_help" whose value is the name of the file. If the specified file fails to open, then invoke the _about() method.

Overrides:
_help in class Top
See Also:
FileParameter

_read

protected void _read(java.net.URL url)
              throws java.lang.Exception
Read the specified URL. This delegates to the ModelDirectory to ensure that the preferred tableau of the model is opened, and that a model is not opened more than once.

Specified by:
_read in class Top
Parameters:
url - The URL to read.
Throws:
java.lang.Exception - If the URL cannot be read, or if there is no tableau.

_save

protected boolean _save()
Save the model to the current file, determined by the uri parameter of the associated effigy, or if that has not been set or is not a writable file, or if the effigy has been set non-modifiable, then invoke _saveAs(). This calls _writeFile() to perform the save.

Overrides:
_save in class Top
Returns:
True if the save succeeds.

_saveAs

protected boolean _saveAs()
Query the user for a filename, save the model to that file, and open a new window to view the model. This overrides the base class to update the entry in the ModelDirectory and to rename the model to match the file name.

Overrides:
_saveAs in class Top
Returns:
True if the save succeeds.

_writeFile

protected void _writeFile(java.io.File file)
                   throws java.io.IOException
Write the model to the specified file. This method delegates to the effigy containing the associated Tableau, if there is one, and otherwise throws an exception.

Specified by:
_writeFile in class Top
Parameters:
file - The file to write to.
Throws:
java.io.IOException - If the write fails.