ptolemy.actor.gui
Class TableauFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by ptolemy.gui.Top
                          extended by ptolemy.actor.gui.TableauFrame
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants
Direct Known Subclasses:
BacktrackControllerFrame, CustomizableRunFrame, ExecShellTableau.ExecShellFrame, ExpressionShellFrame, HTMLViewer, ImageDisplay.ImageWindow, PlotTableauFrame, PtolemyFrame, PythonShellTableau.PythonShellFrame, RunLayoutFrame, TclShellTableau.TclShellFrame, 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 59344 2010-09-29 21:35:46Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (celaine)
Proposed Rating:
Green (eal)

Nested Class Summary
static class TableauFrame.ExtensionFileFilter
          File filter that filters out files that do not have one of a pre-specified list of extensions.
(package private)  class TableauFrame.ViewMenuListener
          Listener for view menu commands.
 
Nested classes/interfaces inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private static java.awt.Image _defaultIconImage
           
private  TableauFactory _factoryContainer
           
protected  java.lang.String _initialSaveAsFileName
          The initial filename to use in the SaveAs dialog.
private  boolean _packCalled
          Set to true when the pack() method is called.
private  Placeable _placeable
          Associated placeable.
private  Tableau _tableau
           
private  TopPack _topPack
          Set in pack() if an alternate topPack is used.
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.
TableauFrame(Tableau tableau, StatusBar statusBar, Placeable placeable)
          Construct an empty top-level frame managed by the specified tableau with the specified status bar and associated Placeable object.
 
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.
private  boolean _checkForDerivedObjects()
          If the model has children, then issue a warning that those children will persist in modified form.
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  boolean _saveAs(java.lang.String extension)
          Query the user for a filename, save the model to that file, and open a new window to view the model.
protected  java.net.URL _saveAsHelper(java.lang.String extension)
          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.
 TopPack getAlternateTopPack()
          Get the alternative pack() interface for the ptolemy.gui.Top JFrame.
 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 pack()
          Optionally invoke an alternative pack() method.
 void printPDF()
          If a PDF printer is available print to it.
 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, _createFileMenuItems, _getCurrentDirectory, _open, _openURL, _print, _printCrossPlatform, _printNative, _printPDF, _queryForSave, _saveAsFileDialog, centerOnScreen, close, deferIfNecessary, getCentering, hideMenuBar, isMenuPopulated, report, report, report, setBackground, setCentering, setDirectory, 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, setIconImage, 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, 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, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, 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, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, 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, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, 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.


_factoryContainer

private TableauFactory _factoryContainer

_tableau

private Tableau _tableau

_defaultIconImage

private static java.awt.Image _defaultIconImage

_placeable

private Placeable _placeable
Associated placeable.


_packCalled

private boolean _packCalled
Set to true when the pack() method is called. Used by TopPack.pack().


_topPack

private TopPack _topPack
Set in pack() if an alternate topPack is used.

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.

TableauFrame

public TableauFrame(Tableau tableau,
                    StatusBar statusBar,
                    Placeable placeable)
Construct an empty top-level frame managed by the specified tableau with the specified status bar and associated Placeable object. Associating an instance of Placeable with this frame has the effect that when this frame is closed, if the placeable contains instances of WindowSizeAttribute and/or SizeAttribute, then the window sizes are recorded. 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.
placeable - The associated Placeable.
Method Detail

getAlternateTopPack

public TopPack getAlternateTopPack()
Get the alternative pack() interface for the ptolemy.gui.Top JFrame.

Returns:
the alternative pack() interface if one was set by the _alternateTopPackClass in the Configuration. If one there is no TopPack, then return null.
See Also:
pack()

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.
See Also:
setTableau(Tableau)

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.
See Also:
getTableau()

pack

public void pack()
Optionally invoke an alternative pack() method. If the _alternateTopPackClass attribute in the Configuration is set to the name of a class that implements the TopPack interface, then TopPack.pack(Top, boolean) is called. If the _alternateTopPackClass attribute is not set or set improperly, then Top.pack() is called from this method.

Overrides:
pack in class Top

printPDF

public void printPDF()
              throws java.awt.print.PrinterException
If a PDF printer is available print to it.

Throws:
java.awt.print.PrinterException - If a printer with the string "PDF" cannot be found or if the job cannot be set to the PDF print service or if there is another problem printing.

_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.

If the configuration has a _disableFileNew parameter that is set to true, then we do not populate the File->New menu.

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 have 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 overwrite. 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 - If the file cannot be converted to a URL.

_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. If the configuration contains a FileAttribute called _applicationIcon, then the value of the _applicationIcon is used. Otherwise, the default value is ptolemy/actor/gui/PtolemyIISmallIcon.gif, which is looked for in the classpath.

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.

_saveAs

protected boolean _saveAs(java.lang.String extension)
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.

Parameters:
extension - If non-null, then the extension that is appended to the file name if there is no extension.
Returns:
True if the save succeeds.

_saveAsHelper

protected java.net.URL _saveAsHelper(java.lang.String extension)
Query the user for a filename, save the model to that file, and open a new window to view the model.

Parameters:
extension - If non-null, then the extension that is appended to the file name if there is no extension.
Returns:
URL of the saved file if the save succeeds, null if save fails.

_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.

_checkForDerivedObjects

private boolean _checkForDerivedObjects()
If the model has children, then issue a warning that those children will persist in modified form. Give the user the chance to cancel.

Returns:
False if there are children and the user cancels. True otherwise.