ptolemy.vergil.basic
Class BasicGraphFrame

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
                              extended byptolemy.actor.gui.PtolemyFrame
                                  extended byptolemy.vergil.basic.BasicGraphFrame
All Implemented Interfaces:
javax.accessibility.Accessible, ChangeListener, java.awt.datatransfer.ClipboardOwner, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants
Direct Known Subclasses:
EditIconFrame, ExtendedGraphFrame

public abstract class BasicGraphFrame
extends PtolemyFrame
implements java.awt.print.Printable, java.awt.datatransfer.ClipboardOwner, ChangeListener

A simple graph view for ptolemy models. This represents a level of the hierarchy of a ptolemy model as a diva graph. Cut, copy and paste operations are supported using MoML.

Since:
Ptolemy II 2.0
Version:
$Id: BasicGraphFrame.java,v 1.78.2.1 2004/06/18 00:49:27 cxh Exp $
Author:
Steve Neuendorffer, Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (neuendor)

Nested Class Summary
 class BasicGraphFrame.ZoomFitAction
           
 class BasicGraphFrame.ZoomInAction
           
 class BasicGraphFrame.ZoomOutAction
           
 class BasicGraphFrame.ZoomResetAction
           
 
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  javax.swing.Action _copyAction
          The copy action.
protected  javax.swing.Action _cutAction
          The cut action.
protected  EditorDropTarget _dropTarget
          The instance of EditorDropTarget associated with this object.
protected  javax.swing.JMenu _editMenu
          The edit menu.
protected  JCanvasPanner _graphPanner
          The panner.
protected  JGraph _jgraph
          The instance of JGraph for this editor.
protected  javax.swing.JTree _library
          The library display widget.
protected  PTreeMenuCreator _libraryContextMenuCreator
          The library context menu creator.
protected  EntityTreeModel _libraryModel
          The library model.
protected  javax.swing.JScrollPane _libraryScrollPane
          The library scroll pane.
protected  javax.swing.JPanel _palettePane
          The library display panel.
protected  javax.swing.Action _pasteAction
          The paste action.
protected  javax.swing.JSplitPane _splitPane
          The split pane for library and editor.
protected  javax.swing.JToolBar _toolbar
          The toolbar.
protected  CompositeEntity _topLibrary
          The library.
protected static java.awt.Color BACKGROUND_COLOR
          Default background color is a light grey.
static java.lang.String VERGIL_USER_LIBRARY_NAME
          The name of the user library.
 
Fields inherited from class ptolemy.actor.gui.TableauFrame
_initialSaveAsFileName, _viewMenu, aboutFile, helpFile
 
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 java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
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
BasicGraphFrame(NamedObj entity, Tableau tableau)
          Construct a frame associated with the specified Ptolemy II model or object.
BasicGraphFrame(NamedObj entity, Tableau tableau, LibraryAttribute defaultLibrary)
          Construct a frame associated with the specified Ptolemy II model.
 
Method Summary
protected  void _addMenus()
          Create the menus that are used by this frame.
protected  boolean _close()
          Override the base class to remove the listeners we have created when the frame closes.
protected  CompositeEntity _createDefaultLibrary(Workspace workspace)
          Create the default library to use if an entity has no LibraryAttribute.
protected abstract  GraphPane _createGraphPane()
          Create a new graph pane.
protected  java.io.File _getDirectory()
          Get the directory that was last accessed by this window.
protected  void _setDirectory(java.io.File directory)
          Set the directory that was last accessed by this window.
protected  void _writeFile(java.io.File file)
          Write the model to the specified file.
 void changeExecuted(ChangeRequest change)
          React to the fact that a change has been successfully executed by marking the data associated with this window modified.
 void changeFailed(ChangeRequest change, java.lang.Exception exception)
          React to the fact that a change has triggered an error by doing nothing (the effigy is also listening and will report the error).
 void copy()
          Get the currently selected objects from this document, if any, and place them on the clipboard in MoML format.
 void createHierarchy()
          Create a typed composite actor that contains the selected actors and connections.
 void cut()
          Remove the currently selected objects from this document, if any, and place them on the clipboard.
 void delete()
          Delete the currently selected objects from this document.
 void dispose()
          Override the dispose method to unattach any listeners that may keep this model from getting garbage collected.
 java.awt.geom.Point2D getCenter()
          Return the center location of the visible part of the pane.
 JGraph getJGraph()
          Return the JGraph instance that this view uses to represent the ptolemy model.
 java.awt.geom.Rectangle2D getVisibleCanvasRectangle()
          Return the rectangle representing the visible part of the pane, transformed into canvas coordinates.
 java.awt.geom.Rectangle2D getVisibleRectangle()
          Return the rectangle representing the visible part of the pane, in pixel coordinates on the screen.
 void layoutGraph()
          Layout the graph view.
 void lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable transferable)
          Do nothing.
 void paste()
          Assuming the contents of the clipboard is MoML code, paste it into the current model by issuing a change request.
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat format, int index)
          Print the visible portion of the graph to a printer, which is represented by the specified graphics object.
 void redo()
          Redo the last undone change on the model
 void saveComponentInFile(Entity entity)
          Open a file browser and save the given entity in the file specified by the user.
static void saveComponentInLibrary(Configuration configuration, Entity entity)
          Save the given entity in the user library in the given configuration.
 void setCenter(java.awt.geom.Point2D center)
          Set the center location of the visible part of the pane.
 void undo()
          Undo the last undoable change on the model
 void zoom(double factor)
          Zoom in or out to magnify by the specified factor, from the current magnification.
 void zoomFit()
          Zoom to fit the current figures.
 void zoomReset()
          Set zoom to the nominal.
 
Methods inherited from class ptolemy.actor.gui.PtolemyFrame
_clear, _help, _print, _saveAs, _saveAsFileDialog, getModel, setModel
 
Methods inherited from class ptolemy.actor.gui.TableauFrame
_about, _confirmFile, _exit, _getDefaultIconImage, _getName, _read, _save, getConfiguration, getDirectory, getEffigy, getEffigy, getTableau, isModified, setModified, setTableau
 
Methods inherited from class ptolemy.gui.Top
_open, _openURL, _queryForSave, 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, 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

VERGIL_USER_LIBRARY_NAME

public static java.lang.String VERGIL_USER_LIBRARY_NAME
The name of the user library. The default value is "UserLibrary". The value of this variable is what appears in the Vergil left hand tree menu.


BACKGROUND_COLOR

protected static java.awt.Color BACKGROUND_COLOR
Default background color is a light grey.


_cutAction

protected javax.swing.Action _cutAction
The cut action.


_copyAction

protected javax.swing.Action _copyAction
The copy action.


_dropTarget

protected EditorDropTarget _dropTarget
The instance of EditorDropTarget associated with this object.


_editMenu

protected javax.swing.JMenu _editMenu
The edit menu.


_graphPanner

protected JCanvasPanner _graphPanner
The panner.


_jgraph

protected JGraph _jgraph
The instance of JGraph for this editor.


_library

protected javax.swing.JTree _library
The library display widget.


_libraryContextMenuCreator

protected PTreeMenuCreator _libraryContextMenuCreator
The library context menu creator.


_libraryModel

protected EntityTreeModel _libraryModel
The library model.


_libraryScrollPane

protected javax.swing.JScrollPane _libraryScrollPane
The library scroll pane.


_palettePane

protected javax.swing.JPanel _palettePane
The library display panel.


_pasteAction

protected javax.swing.Action _pasteAction
The paste action.


_splitPane

protected javax.swing.JSplitPane _splitPane
The split pane for library and editor.


_toolbar

protected javax.swing.JToolBar _toolbar
The toolbar.


_topLibrary

protected CompositeEntity _topLibrary
The library.

Constructor Detail

BasicGraphFrame

public BasicGraphFrame(NamedObj entity,
                       Tableau tableau)
Construct a frame associated with the specified Ptolemy II model or object. After constructing this, it is necessary to call setVisible(true) to make the frame appear. This is typically done by calling show() on the controlling tableau. This constructor results in a graph frame that obtains its library either from the model (if it has one) or the default library defined in the configuration.

Parameters:
entity - The model or object to put in this frame.
tableau - The tableau responsible for this frame.
See Also:
Tableau.show()

BasicGraphFrame

public BasicGraphFrame(NamedObj entity,
                       Tableau tableau,
                       LibraryAttribute defaultLibrary)
Construct a frame associated with the specified Ptolemy II model. After constructing this, it is necessary to call setVisible(true) to make the frame appear. This is typically done by calling show() on the controlling tableau. This constructor results in a graph frame that obtains its library either from the model (if it has one), or the defaultLibrary argument (if it is non-null), or the default library defined in the configuration.

Parameters:
entity - The model or object to put in this frame.
tableau - The tableau responsible for this frame.
defaultLibrary - An attribute specifying the default library to use if the model does not have a library.
See Also:
Tableau.show()
Method Detail

changeExecuted

public void changeExecuted(ChangeRequest change)
React to the fact that a change has been successfully executed by marking the data associated with this window modified. This will trigger a dialog when the window is closed, prompting the user to save the data.

Specified by:
changeExecuted in interface ChangeListener
Parameters:
change - The change that has been executed.

changeFailed

public void changeFailed(ChangeRequest change,
                         java.lang.Exception exception)
React to the fact that a change has triggered an error by doing nothing (the effigy is also listening and will report the error).

Specified by:
changeFailed in interface ChangeListener
Parameters:
change - The change that was attempted.
exception - The exception that resulted.

copy

public void copy()
Get the currently selected objects from this document, if any, and place them on the clipboard in MoML format.


createHierarchy

public void createHierarchy()
Create a typed composite actor that contains the selected actors and connections. The created typed composite actor is transparent. The resulting topology is the same in the sense of deep connectivities.


cut

public void cut()
Remove the currently selected objects from this document, if any, and place them on the clipboard.


delete

public void delete()
Delete the currently selected objects from this document.


dispose

public void dispose()
Override the dispose method to unattach any listeners that may keep this model from getting garbage collected.


getCenter

public java.awt.geom.Point2D getCenter()
Return the center location of the visible part of the pane.

Returns:
The center of the visible part.

getJGraph

public JGraph getJGraph()
Return the JGraph instance that this view uses to represent the ptolemy model.


getVisibleCanvasRectangle

public java.awt.geom.Rectangle2D getVisibleCanvasRectangle()
Return the rectangle representing the visible part of the pane, transformed into canvas coordinates. This is the range of locations that are visible, given the current pan and zoom.

Returns:
The rectangle representing the visible part.

getVisibleRectangle

public java.awt.geom.Rectangle2D getVisibleRectangle()
Return the rectangle representing the visible part of the pane, in pixel coordinates on the screen.

Returns:
A rectangle whose upper left corner is at (0, 0) and whose size is the size of the canvas component.

layoutGraph

public void layoutGraph()
Layout the graph view.


lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard clipboard,
                          java.awt.datatransfer.Transferable transferable)
Do nothing.

Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner

paste

public void paste()
Assuming the contents of the clipboard is MoML code, paste it into the current model by issuing a change request.


print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat format,
                 int index)
          throws java.awt.print.PrinterException
Print the visible portion of the graph to a printer, which is represented by the specified graphics object.

Specified by:
print in interface java.awt.print.Printable
Parameters:
graphics - The context into which the page is drawn.
format - The size and orientation of the page being drawn.
index - The zero based index of the page to be drawn.
Returns:
PAGE_EXISTS if the page is rendered successfully, or NO_SUCH_PAGE if pageIndex specifies a non-existent page.
Throws:
java.awt.print.PrinterException - If the print job is terminated.

redo

public void redo()
Redo the last undone change on the model


saveComponentInFile

public void saveComponentInFile(Entity entity)
                         throws java.lang.Exception
Open a file browser and save the given entity in the file specified by the user.

Parameters:
entity - The entity to save.
Throws:
If - something goes wrong.
java.lang.Exception
Since:
Ptolemy 4.0

saveComponentInLibrary

public static void saveComponentInLibrary(Configuration configuration,
                                          Entity entity)
Save the given entity in the user library in the given configuration.

Parameters:
configuration - The configuration.
entity - The entity to save.
Since:
Ptolemy 2.1

setCenter

public void setCenter(java.awt.geom.Point2D center)
Set the center location of the visible part of the pane. This will cause the panner to center on the specified location with the current zoom factor.

Parameters:
center - The center of the visible part.

undo

public void undo()
Undo the last undoable change on the model


zoom

public void zoom(double factor)
Zoom in or out to magnify by the specified factor, from the current magnification.

Parameters:
factor - The magnification factor (relative to 1.0).

zoomFit

public void zoomFit()
Zoom to fit the current figures.


zoomReset

public void zoomReset()
Set zoom to the nominal.


_addMenus

protected void _addMenus()
Create the menus that are used by this frame.

Overrides:
_addMenus in class TableauFrame

_close

protected boolean _close()
Override the base class to remove the listeners we have created when the frame closes. Specifically, remove our panner-updating listener from the entity. Also remove the listeners our graph model has created.

Overrides:
_close in class PtolemyFrame
Returns:
True if the close completes, and false otherwise.

_createDefaultLibrary

protected CompositeEntity _createDefaultLibrary(Workspace workspace)
Create the default library to use if an entity has no LibraryAttribute. Note that this is called in the constructor and therefore overrides in subclasses should not refer to any members that may not have been initialized. If no library is found in the configuration, then an empty one is created in the specified workspace.

Parameters:
workspace - The workspace in which to create the library, if one needs to be created.
Returns:
The new library, or null if there is no configuration.

_createGraphPane

protected abstract GraphPane _createGraphPane()
Create a new graph pane. Subclasses will override this to change the pane that is created. Note that this method is called in constructor, so derived classes must be careful to not reference local variables that may not have yet been created.

Returns:
The pane that is created.

_getDirectory

protected java.io.File _getDirectory()
Get the directory that was last accessed by this window.

Returns:
The directory last accessed.
See Also:
_setDirectory(java.io.File)

_setDirectory

protected void _setDirectory(java.io.File directory)
Set the directory that was last accessed by this window.

Parameters:
directory - The directory last accessed.
See Also:
_getDirectory()

_writeFile

protected void _writeFile(java.io.File file)
                   throws java.io.IOException
Write the model to the specified file. This overrides the base class to record the current size and position of the window in the model.

Overrides:
_writeFile in class PtolemyFrame
Parameters:
file - The file to write to.
Throws:
java.io.IOException - If the write fails.