JGraphpad Pro
v6.0.5.0


com.jgraph.pad.action
Class JGraphpadFileAction

java.lang.Object
  extended byjavax.swing.AbstractAction
      extended bycom.jgraph.editor.JGraphEditorAction
          extended bycom.jgraph.pad.action.JGraphpadFileAction
All Implemented Interfaces:
Action, ActionListener, Cloneable, EventListener, Serializable
Direct Known Subclasses:
JGraphpadDemo.JGraphpadDemoFileAction

public class JGraphpadFileAction
extends JGraphEditorAction

Implements all actions of the file menu. The openRecent menu is implemented using the JGraphpadOpenRecentMenu class, and the import/export actions are added to the file menu by plugins, so look for their implementations there.

See Also:
Serialized Form

Nested Class Summary
static class JGraphpadFileAction.AllActions
          Bundle of all actions in this class.
 
Nested classes inherited from class com.jgraph.editor.JGraphEditorAction
JGraphEditorAction.Bundle
 
Field Summary
protected static JGraphpadDialogs dlgs
          Shortcut to the shared JGraphpad dialogs.
protected  JGraphEditor editor
          References the enclosing editor.
static String KEY_EDGEPROTOTYPE
          Import actions require the action values for this key to be assigned.
static String KEY_MAINWINDOW
          Defines the key for the main windows object.
static String KEY_RECENTFILES
          Defines the key for the recent files user settings.
static String KEY_VERTEXPROTOTYPE
          Import actions require the action value for this key to be assigned.
protected  File lastDirectory
          Holds the last directory for file operations.
static int MAX_RECENTFILES
          Defines the maximum number of recent files to store under the KEY_RECENTFILES in the user settings file.
static String MIME_HTML
          Defines the text/plain mime-type.
static String MIME_PLAINTEXT
          Defines the text/plain mime-type.
static String NAME_CLOSE
          Specifies the name for the close action.
static String NAME_CLOSEALL
          Specifies the name for the closeAll action.
static String NAME_DOWNLOAD
          Specifies the name for the download action.
static String NAME_EXIT
          Specifies the name for the exit action.
static String NAME_IMPORTCSV
          Specifies the name for the importCSV action.
static String NAME_NEWDIAGRAM
          Specifies the name for the newDiagram action.
static String NAME_NEWDOCUMENT
          Specifies the name for the newDocument action.
static String NAME_NEWLIBRARY
          Specifies the name for the newLibrary action.
static String NAME_OPEN
          Specifies the name for the open action.
static String NAME_PAGESETUP
          Specifies the name for the pageSetup action.
static String NAME_PRINT
          Specifies the name for the print action.
static String NAME_REMOVEDIAGRAM
          Specifies the name for the removeDiagram action.
static String NAME_RENAMEDIAGRAM
          Specifies the name for the renameDiagram action.
static String NAME_SAVE
          Specifies the name for the save action.
static String NAME_SAVEALL
          Specifies the name for the saveAll action.
static String NAME_SAVEAS
          Specifies the name for the saveAs action.
static String NAME_SAVEIMAGE
          Specifies the name for the saveImage action.
static String NAME_UPLOADAS
          Specifies the name for the uploadAs action.
 
Fields inherited from class com.jgraph.editor.JGraphEditorAction
isToggleAction, PROPERTY_ISSELECTED, PROPERTY_ISVISIBLE
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
JGraphpadFileAction(String name, JGraphEditor editor)
          Constructs a new file action for the specified name and editor.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Executes the action based on the action name.
static String convert(OutputStream data, String mime)
          Converts the specified data stream into a string assuming the data stream is of the specified mime type.
protected  void doCloseAll()
          Closes all open files using doCloseFile(JGraphEditorFile, boolean) giving the user a chance to save unsaved changes before closing each file.
protected  void doCloseFile(JGraphEditorFile file, boolean remove)
          Closes the specified file by removing it from the parent.
protected  void doExit()
          Closes all open files using doCloseAll(), saves the user settings and terminates the program using System.exit(int).
protected  void doImportCSV(org.jgraph.graph.GraphLayoutCache cache, String filename)
          Displays a file- or URL-dialog and loads the selected file or URL into the specified diagram as a comma separated value file (CSV) using importCSVFile(GraphLayoutCache, InputStream, String, Object, Object, String).
protected  void doNewDiagram(JGraphEditorFile file)
          Inserts a new empty diagram into the specified file.
protected  void doNewDocument()
          Inserts a new empty document into the document model.
protected  void doNewLibrary()
          Inserts a new library into the given file.
protected  void doOpenFile(String filename, JGraphEditorFile file)
          Opens the specified filename using JGraphEditorModel.addFile(String) if a file for the specified name is not already open.
protected  void doPageSetup(JGraphEditorDiagramPane diagramPane)
          Displays the system page format dialog and updates the pageformat on the specified diagram pane.
protected  void doPrintDiagramPane(JGraphEditorDiagramPane diagramPane)
          Displays a system print dialog and prints the specified diagram pane.
protected  void doRemoveDiagram(JGraphEditorDiagram diagram)
          Removes the specified diagram from the parent file if the parent file contains at least one diagram after the removal.
protected  void doRenameDiagram(JGraphEditorDiagram diagram)
          Displays a dialog to enter the new name for the specified diagram and updates the name of the diagram using JGraphEditorModel.setName(JGraphEditorDiagram, String).
 void doSave(String filename, byte[] data)
          Saves the specified byte array to the specified file.
protected  void doSaveAll()
          Saves all open files using doSaveFile(JGraphEditorFile, boolean, boolean) showing file dialogs for files whose filename has not been assigned.
protected  void doSaveFile(JGraphEditorFile file, boolean forceFilenameDialog, boolean urlDialog)
          Saves the specified file displaying a filename dialog if the filename is not set or if forceFilenameDialog is true.
protected  void doSaveImage(JGraphEditorDiagramPane diagramPane, int inset, String filename)
          Saves the specified graph as an image using inset as the size of the empty border around the image.
static Object getCellForKey(org.jgraph.graph.GraphModel model, Object prototype, Hashtable map, String key, int cols, int w, int h, int offset, boolean image)
          Utility method to return the cell stored under key in the specified map or create the cell using the specified prototype and model and put it into the map under key.
protected  int getFileCount(boolean countLibraries)
          Uses isLibrary(JGraphEditorFile) to find the number of roots that are instances of JGraphEditorFile.
protected  int getFileCount(Object root, boolean countLibraries)
          Uses isLibrary(JGraphEditorFile) to find the number of roots that are instances of JGraphEditorFile.
static JGraphEditorFile getPermanentFocusOwnerFile()
          Returns the diagram for the permanent focus owner diagram pane.
static JGraphpadLibraryPane getPermanentFocusOwnerLibraryPane()
          Returns the permanent focus owner library pane.
static void importCSVFile(org.jgraph.graph.GraphLayoutCache cache, InputStream fstream, String delim, Object vertexPrototype, Object edgePrototype, String defaultEdgeLabel)
          Reads the specified input stream as a comma-delimeted file, using the following format: a,b[,c] where a and b are vertices and c is the label of the edge to be inserted between a and b.
protected  boolean isLibrary(JGraphEditorFile file)
          Returns true if the specified file is a library.
static String makeMimeForm(String fileName, String type, String path, String content, String comment, String sep)
          Returns a mime form using the specified parameters.
static boolean post(URL url, String path, String mime, OutputStream data)
          Posts the data to the specified url using path to specify the filename in the mime response for the specified mime type.
static boolean post(URL url, String path, String mime, String data)
          Posts the data to the specified url using path to specify the filename in the mime response for the specified mime type.
static boolean postPlain(URL url, String path, OutputStream data)
          Posts the data to the specified url using path to specify the filename in the mime response using for type MIME_PLAINTEXT.
 
Methods inherited from class com.jgraph.editor.JGraphEditorAction
getActiveFrame, getFrame, getJGraphpadPane, getJGraphpadPane, getName, getParentGraph, getPermanentFocusOwner, getPermanentFocusOwnerDiagram, getPermanentFocusOwnerDiagramPane, getPermanentFocusOwnerGraph, getPermanentFocusOwnerOrParent, getString, isSelected, isToggleAction, isVisible, setEnabled, setSelected, setToggleAction, setVisible
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIME_PLAINTEXT

public static final String MIME_PLAINTEXT
Defines the text/plain mime-type.

See Also:
Constant Field Values

MIME_HTML

public static final String MIME_HTML
Defines the text/plain mime-type.

See Also:
Constant Field Values

dlgs

protected static JGraphpadDialogs dlgs
Shortcut to the shared JGraphpad dialogs.


KEY_VERTEXPROTOTYPE

public static final String KEY_VERTEXPROTOTYPE
Import actions require the action value for this key to be assigned. The object under this key will be used to create new vertices for imports.

See Also:
Action.putValue(java.lang.String, java.lang.Object), Constant Field Values

KEY_EDGEPROTOTYPE

public static final String KEY_EDGEPROTOTYPE
Import actions require the action values for this key to be assigned. The object under this key will be used to create the edges for imports.

See Also:
Action.putValue(java.lang.String, java.lang.Object), Constant Field Values

KEY_MAINWINDOW

public static final String KEY_MAINWINDOW
Defines the key for the main windows object. This key is used to store a reference in the editor settings for the bounds of the application window. This class is in charge of storing the bounds in JGraphpad.PATH_USERSETTINGS on program termination.


KEY_RECENTFILES

public static final String KEY_RECENTFILES
Defines the key for the recent files user settings. This class is in charge of updating the list and storing it in JGraphpad.PATH_USERSETTINGS on program termination.

See Also:
Constant Field Values

MAX_RECENTFILES

public static int MAX_RECENTFILES
Defines the maximum number of recent files to store under the KEY_RECENTFILES in the user settings file. Default is 6.


NAME_NEWDOCUMENT

public static final String NAME_NEWDOCUMENT
Specifies the name for the newDocument action.

See Also:
Constant Field Values

NAME_NEWDIAGRAM

public static final String NAME_NEWDIAGRAM
Specifies the name for the newDiagram action.

See Also:
Constant Field Values

NAME_RENAMEDIAGRAM

public static final String NAME_RENAMEDIAGRAM
Specifies the name for the renameDiagram action.

See Also:
Constant Field Values

NAME_REMOVEDIAGRAM

public static final String NAME_REMOVEDIAGRAM
Specifies the name for the removeDiagram action.

See Also:
Constant Field Values

NAME_NEWLIBRARY

public static final String NAME_NEWLIBRARY
Specifies the name for the newLibrary action.

See Also:
Constant Field Values

NAME_OPEN

public static final String NAME_OPEN
Specifies the name for the open action.

See Also:
Constant Field Values

NAME_DOWNLOAD

public static final String NAME_DOWNLOAD
Specifies the name for the download action.

See Also:
Constant Field Values

NAME_CLOSE

public static final String NAME_CLOSE
Specifies the name for the close action.

See Also:
Constant Field Values

NAME_CLOSEALL

public static final String NAME_CLOSEALL
Specifies the name for the closeAll action.

See Also:
Constant Field Values

NAME_SAVE

public static final String NAME_SAVE
Specifies the name for the save action.

See Also:
Constant Field Values

NAME_SAVEAS

public static final String NAME_SAVEAS
Specifies the name for the saveAs action.

See Also:
Constant Field Values

NAME_UPLOADAS

public static final String NAME_UPLOADAS
Specifies the name for the uploadAs action.

See Also:
Constant Field Values

NAME_SAVEALL

public static final String NAME_SAVEALL
Specifies the name for the saveAll action.

See Also:
Constant Field Values

NAME_SAVEIMAGE

public static final String NAME_SAVEIMAGE
Specifies the name for the saveImage action.

See Also:
Constant Field Values

NAME_IMPORTCSV

public static final String NAME_IMPORTCSV
Specifies the name for the importCSV action.

See Also:
Constant Field Values

NAME_PAGESETUP

public static final String NAME_PAGESETUP
Specifies the name for the pageSetup action.

See Also:
Constant Field Values

NAME_PRINT

public static final String NAME_PRINT
Specifies the name for the print action.

See Also:
Constant Field Values

NAME_EXIT

public static final String NAME_EXIT
Specifies the name for the exit action.

See Also:
Constant Field Values

editor

protected JGraphEditor editor
References the enclosing editor.


lastDirectory

protected File lastDirectory
Holds the last directory for file operations.

Constructor Detail

JGraphpadFileAction

public JGraphpadFileAction(String name,
                           JGraphEditor editor)
Constructs a new file action for the specified name and editor.

Parameters:
name - The name of the action to be created.
editor - The enclosing editor for the action.
Method Detail

actionPerformed

public void actionPerformed(ActionEvent event)
Executes the action based on the action name.

Parameters:
event - The object that describes the event.

doSaveAll

protected void doSaveAll()
                  throws IOException
Saves all open files using doSaveFile(JGraphEditorFile, boolean, boolean) showing file dialogs for files whose filename has not been assigned.

Throws:
IOException - If there was an error saving the files.

doSaveFile

protected void doSaveFile(JGraphEditorFile file,
                          boolean forceFilenameDialog,
                          boolean urlDialog)
                   throws IOException
Saves the specified file displaying a filename dialog if the filename is not set or if forceFilenameDialog is true. If urlDialog is true, then the dialog will ask for an URL instead of a local file.
This implementation does the following additional checks: Furthermore, this implementation updates the isNew and modified state of the file if it has successfully been saved.

Parameters:
file - The file to be saved.
forceFilenameDialog - Whether to display a dialog regardless of the filename.
urlDialog - Whether to display an URL dialog to specifiy the filename.
Throws:
IOException - If the file cannot be saved.
See Also:
JGraphEditorModel.getOutputStream(String), postPlain(URL, String, OutputStream)

doSaveImage

protected void doSaveImage(JGraphEditorDiagramPane diagramPane,
                           int inset,
                           String filename)
                    throws IOException
Saves the specified graph as an image using inset as the size of the empty border around the image. This implementation displays a dialog to ask for transparency-support if the chosen fileformat supports it (eg. PNG, GIF). If filename is an URL it tries to upload the data to that URL.

Parameters:
diagramPane - The diagram pane to save to the image for.
inset - The size of the empty border around the image.
filename - The filename to save or upload the image to.
Throws:
IOException - If the image cannot be saved.
IllegalArgumentException - If the graph contains no cells.
See Also:
JGraph.getImage(Color, int), ImageIO.write(java.awt.image.RenderedImage, java.lang.String, java.io.OutputStream), JGraphEditorModel.getOutputStream(String), post(URL, String, String, OutputStream)

doSave

public void doSave(String filename,
                   byte[] data)
            throws Exception
Saves the specified byte array to the specified file.

Parameters:
filename - The filename of the file to be written.
data - The array of bytes to write to the file.
Throws:
Exception

doImportCSV

protected void doImportCSV(org.jgraph.graph.GraphLayoutCache cache,
                           String filename)
                    throws IOException
Displays a file- or URL-dialog and loads the selected file or URL into the specified diagram as a comma separated value file (CSV) using importCSVFile(GraphLayoutCache, InputStream, String, Object, Object, String).

Parameters:
cache - The graph layout cache to import into.
filename - The filename to import from.
Throws:
IOException - If the file cannot be read.
See Also:
JGraphEditorModel.getInputStream(String)

doPrintDiagramPane

protected void doPrintDiagramPane(JGraphEditorDiagramPane diagramPane)
                           throws PrinterException
Displays a system print dialog and prints the specified diagram pane.

Parameters:
diagramPane - The diagram pane to be printed.
Throws:
PrinterException - If the document can not be printed.

doPageSetup

protected void doPageSetup(JGraphEditorDiagramPane diagramPane)
Displays the system page format dialog and updates the pageformat on the specified diagram pane.

Parameters:
diagramPane - The diagram pane to set the page format.

doOpenFile

protected void doOpenFile(String filename,
                          JGraphEditorFile file)
                   throws MalformedURLException,
                          IOException
Opens the specified filename using JGraphEditorModel.addFile(String) if a file for the specified name is not already open.

Parameters:
filename - The name of the file to be opened.
Throws:
IOException - If there was an error reading the file.
MalformedURLException - If the filename is an URL but the URL is invalid.

doExit

protected void doExit()
               throws IOException
Closes all open files using doCloseAll(), saves the user settings and terminates the program using System.exit(int). This implementation allows the JGraphpad.PATH_USERSETTINGS to be a URL.

Throws:
IOException - If there was an error saving unsaved changes.

doCloseAll

protected void doCloseAll()
                   throws IOException
Closes all open files using doCloseFile(JGraphEditorFile, boolean) giving the user a chance to save unsaved changes before closing each file.

Throws:
IOException - If there was an error saving unsaved changes.

doCloseFile

protected void doCloseFile(JGraphEditorFile file,
                           boolean remove)
                    throws IOException
Closes the specified file by removing it from the parent. This implementation displays a dialog if there are unsaved changes and calls doSaveFile(JGraphEditorFile, boolean, boolean) if the user chooses to save the changes.

Parameters:
file - The file to be closed.
remove - Whether the file should be removed from the model.
Throws:
IOException - If the unsaved changes can not be saved.

doNewDocument

protected void doNewDocument()
Inserts a new empty document into the document model. The name is assigned automatically using the Document resource string and the number returned by getFileCount(boolean).


doNewDiagram

protected void doNewDiagram(JGraphEditorFile file)
Inserts a new empty diagram into the specified file. The name is assigned automatically using the Diagram resource string and the number returned by TreeModel.getChildCount(java.lang.Object) for the file.

Parameters:
file - The file to add the diagram to.

doNewLibrary

protected void doNewLibrary()
Inserts a new library into the given file. The name is assigned automatically using the Library resource string and the number returned by getFileCount(boolean).


doRemoveDiagram

protected void doRemoveDiagram(JGraphEditorDiagram diagram)
Removes the specified diagram from the parent file if the parent file contains at least one diagram after the removal. Otherwise the diagram is not removed. This implementation displays a confirmation dialog before actually removing the diagram.

Parameters:
diagram - The diagram to be removed from its parent file.
See Also:
JGraphpadDialogs.confirmDialog(Component, String, boolean, boolean)

doRenameDiagram

protected void doRenameDiagram(JGraphEditorDiagram diagram)
Displays a dialog to enter the new name for the specified diagram and updates the name of the diagram using JGraphEditorModel.setName(JGraphEditorDiagram, String).

Parameters:
diagram - The diagram to be renamed.
See Also:
JGraphpadDialogs.valueDialog(String, String)

getFileCount

protected int getFileCount(boolean countLibraries)
Uses isLibrary(JGraphEditorFile) to find the number of roots that are instances of JGraphEditorFile. If countLibraries is true, then the number of libraries is returned.
The following always holds: getFileCount(false) + getFileCount(true) == getChildCount(getRoot())

Parameters:
countLibraries - Whether libraries or non-libraries should be counted.
Returns:
Returns the number of libraries or non-libraries.

getFileCount

protected int getFileCount(Object root,
                           boolean countLibraries)
Uses isLibrary(JGraphEditorFile) to find the number of roots that are instances of JGraphEditorFile. If countLibraries is true, then the number of libraries is returned.
The following always holds: getFileCount(false) + getFileCount(true) == getChildCount(getRoot())

Parameters:
countLibraries - Whether libraries or non-libraries should be counted.
Returns:
Returns the number of libraries or non-libraries.

isLibrary

protected boolean isLibrary(JGraphEditorFile file)
Returns true if the specified file is a library. This implementation returns true if file is an instance of JGraphpadLibrary.

Parameters:
file - The file to be checked.
Returns:
Returns true if file is a library.

getPermanentFocusOwnerFile

public static JGraphEditorFile getPermanentFocusOwnerFile()
Returns the diagram for the permanent focus owner diagram pane.


importCSVFile

public static void importCSVFile(org.jgraph.graph.GraphLayoutCache cache,
                                 InputStream fstream,
                                 String delim,
                                 Object vertexPrototype,
                                 Object edgePrototype,
                                 String defaultEdgeLabel)
                          throws IOException
Reads the specified input stream as a comma-delimeted file, using the following format: a,b[,c] where a and b are vertices and c is the label of the edge to be inserted between a and b. For example, to create a triangle, use:
a,b,ab
b,c,bc
c,a,ca

Parameters:
cache - The layout cache to import the file into.
fstream - The stream to import the cells from.
delim - The delimeter to parse the tokens.
vertexPrototype - The prototype to create new vertices with.
edgePrototype - The prototype to create new edges with.
defaultEdgeLabel - The default label to use for edges if none is specified.
Throws:
IOException

getCellForKey

public static Object getCellForKey(org.jgraph.graph.GraphModel model,
                                   Object prototype,
                                   Hashtable map,
                                   String key,
                                   int cols,
                                   int w,
                                   int h,
                                   int offset,
                                   boolean image)
Utility method to return the cell stored under key in the specified map or create the cell using the specified prototype and model and put it into the map under key. The cells will be positioned into a matrix with cols columns and entries of size (w,h).

Parameters:
model - The model to use for cloning the prototype.
prototype - The prototype to use for creating new cells.
map - The map to check whether the cell exists for key.
key - The key to return the cell for.
cols - The number of columns for the matrix.
w - The width of the entries.
h - The height of the entries.
offset - The offset from the top left.
image - Whether to insert image or text cells.
Returns:
Returns the cell for the specified key.

postPlain

public static boolean postPlain(URL url,
                                String path,
                                OutputStream data)
                         throws IOException
Posts the data to the specified url using path to specify the filename in the mime response using for type MIME_PLAINTEXT.

Parameters:
url - The url to post the mime response to.
path - The filename to use in the mime response.
data - The binary data to send with the mime response.
Returns:
Returns true if the data was successfuly posted.
Throws:
IOException

post

public static boolean post(URL url,
                           String path,
                           String mime,
                           OutputStream data)
                    throws IOException
Posts the data to the specified url using path to specify the filename in the mime response for the specified mime type.

Parameters:
url - The url to post the mime response to.
path - The filename to use in the mime response.
mime - The mime type to use for the response.
data - The binary data to send with the mime response.
Returns:
Returns true if the data was successfuly posted.
Throws:
IOException

convert

public static String convert(OutputStream data,
                             String mime)
Converts the specified data stream into a string assuming the data stream is of the specified mime type. This performs a byte to char conversion on all mime types other than MIME_PLAINTEXT.

Parameters:
data - The data to be converted.
mime - The mime type to assume for the data.
Returns:
Returns a string representation of the data in the stream.

post

public static boolean post(URL url,
                           String path,
                           String mime,
                           String data)
                    throws IOException
Posts the data to the specified url using path to specify the filename in the mime response for the specified mime type.

Parameters:
url - The url to post the mime response to.
path - The filename to use in the mime response.
mime - The mime type to use for the response.
data - The binary data to send with the mime response.
Returns:
Returns true if the data was successfuly posted.
Throws:
IOException

makeMimeForm

public static String makeMimeForm(String fileName,
                                  String type,
                                  String path,
                                  String content,
                                  String comment,
                                  String sep)
Returns a mime form using the specified parameters.


getPermanentFocusOwnerLibraryPane

public static JGraphpadLibraryPane getPermanentFocusOwnerLibraryPane()
Returns the permanent focus owner library pane.


JGraphpad Pro
v6.0.5.0


Copyright (C) 2005 JGraph.com. All rights reserved.