lapis.swing
Class FileAction

java.lang.Object
  extended bylapis.swing.FileAction

public abstract class FileAction
extends Object


Nested Class Summary
static class FileAction.Close
          Action that closes a browser window.
static class FileAction.Exit
          Action that exits LAPIS.
static class FileAction.New
          Action that creates a blank text document.
static class FileAction.NewBrowser
          Action that creates a new Browser window by cloning the current window.
static class FileAction.Open
          Action that pops up a file-open dialog to open a file into the browser.
static class FileAction.Save
          Action invoked by File/Save command.
static class FileAction.SaveAs
          Action invoked by File/Save As command.
 
Constructor Summary
FileAction()
           
 
Method Summary
static File getFile(Document doc)
          Get local filename corresponding to a document.
static boolean isDirty(Document doc)
          Get a document's dirty flag.
static boolean isReadOnly(Document doc)
          Test whether a document is marked read-only.
static JFileChooser makeFileChooser(Browser browser, File filename)
          Make a JFileChooser for a browser.
static boolean okToClear(Browser browser, Enumeration docs)
          Check dirty flags on a set of documents and asks the user if the dirty ones should be saved.
static boolean save(Browser browser, Document doc)
           
static boolean save(Browser browser, File f, Document doc)
          Save browser contents to a local file.
static boolean saveAs(Browser browser, Document doc)
          Pop up a save-as dialog box to save a document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileAction

public FileAction()
Method Detail

makeFileChooser

public static JFileChooser makeFileChooser(Browser browser,
                                           File filename)
Make a JFileChooser for a browser.

Parameters:
browser - Browser to use for current directory
filename - Default selected file, or null if no default should be selected
Returns:
If filename is non-null, returns a JFileChooser that starts with that filename selected. Otherwise, returns a JFileChooser that starts showing the current directory of browser.

save

public static boolean save(Browser browser,
                           Document doc)

saveAs

public static boolean saveAs(Browser browser,
                             Document doc)
Pop up a save-as dialog box to save a document.

Parameters:
browser - Browser to use for feedback
doc - Document to save
Returns:
true if file was successfully saved (no cancellation or error).
Effects:
If user chooses a filename from the dialog box, then the content of doc is saved to that filename. If an error occurs, pops up an error message dialog.

save

public static boolean save(Browser browser,
                           File f,
                           Document doc)
Save browser contents to a local file.

Parameters:
browser - Browser to use for feedback
f - Filename for saved document
doc - Document to save
Effects:
Saves content of doc as filename f. If an error occurs, pops up an error message dialog.

getFile

public static File getFile(Document doc)
Get local filename corresponding to a document.

Parameters:
doc - Document
Returns:
doc's filename, or null if document was not obtained from local disk.

okToClear

public static boolean okToClear(Browser browser,
                                Enumeration docs)
Check dirty flags on a set of documents and asks the user if the dirty ones should be saved.

Parameters:
browser - Browser to use for popping up dialog boxes
docs - Enumeration of Documents that should be checked
Effects:
For each document in docs, if the document has been edited since it was last saved, a dialog box is popped up asking the user if it should be saved.

isDirty

public static boolean isDirty(Document doc)
Get a document's dirty flag.

Parameters:
doc - Document to test
Returns:
true if document has been edited since it was last saved.

isReadOnly

public static boolean isReadOnly(Document doc)
Test whether a document is marked read-only.

Parameters:
doc - Document to test
Returns:
true if document has the "read-only" property. An HTML page has this property if it had a read-only META tag (<META name="read-only" content="true">) when it was loaded. Tutorial and help pages are marked this way to discourage the user from overwriting them by accident.