jApp
Class Document

java.lang.Object
  extended by jApp.Document

public class Document
extends java.lang.Object

The Document class represents the document in memory. Each document is associated with a disk file and a file type. Document objects are NOT created directly, instead they must be registered to the FileTypeRegistry . The Documents are then created,by theApplication, in responce to user actions (e.g. selecting 'New' from 'File' menu).

Document is a base class for the actual document classes. A separate, derived, class is needed for each file type the application handles. Most appilications handle only one file type, although they can convert to and from many file types.

The contents of the document are maintained by the derived class and stored to / read from a File maintained by the Document. The derived class needs to override writeToStream(java.io.ObjectOutputStream) and readFromStream(java.io.ObjectInputStream) to store and retrieve the contents of the Document.

Some (or all) content of the document can be stored in Variables, the Document maintains a list of named variables and handles the storing / restoring of their values automatically in a file in a version independent maner.

The Document is not a visible user interface component, instead a document is associated with on or more DocumentWindows. The Document maintains a list of windows associated with it.

Each Document stores a reference to the active Command. At most one Command can be active at a time.

Each Document is also associated with a AbstractSelection to facilitate the implementation of object oriented user interface.

Author:
Kustaa Nyholm / SpareTimeLabs

Nested Class Summary
protected static class Document.SaveOptions
          The save options that can be passed to the save(SaveOptions).
 
Field Summary
protected  java.awt.print.PageFormat m_PageFormat
           
protected  Variable m_PrintRequestAttributes
           
protected  Variable m_SelectedPrintService
           
protected  Selection m_Selection
           
protected  Undoer m_Undoer
           
protected  Variable m_WindowStates
           
static boolean TRACK_RESPONCE
           
 
Constructor Summary
protected Document()
          The sole constructor.
 
Method Summary
 void addItemsToRightClick(javax.swing.JPopupMenu popupMenu)
          Handles right clicks.
 Variable addVariable(java.util.LinkedList list, java.lang.String name, Variable variable)
          Adds a variable to this document Document.
 BooleanVariable addVariable(java.lang.String name, BooleanVariable variable)
          Adds a <BooleanVariable to this document Document.
 DoubleVariable addVariable(java.lang.String name, DoubleVariable variable)
          Adds a <DoubleVariable to this document Document.
 LongVariable addVariable(java.lang.String name, LongVariable variable)
          Adds a <LongVariable to this document Document.
 StringVariable addVariable(java.lang.String name, StringVariable variable)
          Adds a <StringVariable to this document Document.
 Variable addVariable(java.lang.String name, Variable variable)
          Adds a variable to this document Document.
protected  boolean canPaste(java.awt.datatransfer.DataFlavor[] availableFlavors)
          Checks if any of the availableFlavors can be pasted.
 void causeRegen()
          Causes all the DocumentWindows associated with this Document to be regenerated.
 void cleanUp()
          Called to do cleam up once the document has been closed.
protected  int confirmRevert()
          Confirms Reverting a Document.
protected  int confirmSave()
          Confirms saving a Document.
protected  boolean confirmWrite(java.io.File file)
          Checks that the given file can be overwriten and if not show a dialog informing the user.
protected  java.awt.datatransfer.Clipboard createClipboard()
          Creates the default Clipboard object.
protected  javax.swing.Action createCopyAction()
          Creates the default 'Copy' action.
protected  javax.swing.Action createCutAction()
          Creates the default 'Cut' action.
 DataTransferHandler createDataTransferHandler()
          The Document initialization code calls this method once to create the a DataTransferHandler for this Document, which can then be accessed using getDataTransferHandler().
protected  javax.swing.Action createDeleteAction()
          Creates the default 'Delete' action.
protected  java.io.ObjectInputStream createObjectInputStream(java.io.FileInputStream stream)
          Method readFromStream(FileInputStream) calls this to create the input stream.
protected  java.io.ObjectOutputStream createObjectOutputStream(java.io.FileOutputStream stream)
          Method writeToStream(ObjectOutputStream) calls this to create the input stream.
protected  javax.swing.Action createPasteAction()
          Creates the default 'Paste' action.
 PreviewDialog createPreviewDialog(Document d)
          Creates and returns a new PreviewDialog for this document.
protected  Selection createSelection()
          Creates the default Selection object.
protected  Undoer createUndoer()
          Creates the Undoer object for this Document.
protected  void createWindows()
          Application calls this to create windows for a document.
 void detachFile()
          Detaches this Document from the disk file.
 void execute(jApp.UndoableTask task)
           
 Variable getActiveCommandVariable()
          Gets the variable that is used to store a referece to the currently active command.
 DocumentWindow getActiveWindow()
          Gets the active DocumentWindow for this Document which should be the top most visible window on the screen that is associted with this Document.
 Application getApplication()
          Gets the Application object that instantiated this Document.
 java.awt.datatransfer.Clipboard getClipboard()
          Gets the default Clipboard
 javax.swing.Action getCloseAction()
          Gets the built in 'Close' action.
 javax.swing.KeyStroke getCloseShortCut()
          Gets the built in 'Close' keyboard shortcut.
 Command getCommand()
          Gets the currently active command for this Document.
 javax.swing.Action getCopyAction()
          Gets the built in 'Copy' action.
 javax.swing.KeyStroke getCopyShortcut()
          Gets the built in 'Copy' keyboard shortcut.
 javax.swing.Action getCutAction()
          Gets the built in 'Cut' action.
 javax.swing.KeyStroke getCutShortcut()
          Gets the built in 'Cut' keyboard shortcut.
 DataTransferHandler getDataTransferHandler()
          Returns the DataTransferHandler for this Document.
 javax.swing.Action getDeleteAction()
          Gets the built in 'Delete' action.
 javax.swing.KeyStroke getDeleteShortcut()
          Gets the built in 'Delete' keyboard shortcut.
 DocumentPrinter getDocumentPrinter()
          Creates and returns a new DocumentPrinter for this document.
 javax.swing.Action getExitAction()
          Gets the built in 'Exit' action.
 javax.swing.KeyStroke getExitShortcut()
          Gets the built in 'Exit/Quit' keyboard shortcut.
 java.io.File getFile()
          Gets the file associated with this document.
 FileType getFileType()
          Gets the FileType for this document.
 javax.swing.KeyStroke getNextWindowShortcut()
          Gets the built in 'Cycle Windows' keyboard shortcut.
protected  java.awt.Component getParentComponentForDialogs()
          Returns a component that is used in calls to JOptionPane.showXXX calls as the parentComponent.
 javax.swing.Action getPasteAction()
          Gets the built in 'Paste' action.
 javax.swing.KeyStroke getPasteShortcut()
          Gets the built in 'Paste' keyboard shortcut.
 javax.swing.Action getPrintAction()
          Gets the built in 'Print' action.
 javax.swing.KeyStroke getPrintShortcut()
          Gets the built in 'Print' keyboard shortcut.
 javax.swing.Action getRedoAction()
          Gets the built in 'Redo' action.
 javax.swing.KeyStroke getRedoShortCut()
          Gets the built in 'Redor' keyboard shortcut.
 javax.swing.Action getRevertAction()
          Gets the built in 'Revert' action.
 javax.swing.Action getSaveAction()
           
 javax.swing.Action getSaveAsAction()
          Gets the built in 'SaveAs' action.
 javax.swing.Action getSaveCopyAction()
          Gets the built in 'SaveCopy' action.
 javax.swing.KeyStroke getSaveShortcut()
          Gets the built in 'Save' keyboard shortcut.
protected  java.io.File getSaveToFile()
          Gets a file to save the Document to using the Application JFileChooser.
 Selection getSelection()
          Gets the selection object associated with this Document.
 javax.swing.Action getUndoAction()
          Gets the built in 'Undo' action.
 Undoer getUndoer()
          Gets the Undoer object for this Document.
 javax.swing.KeyStroke getUndoShortCut()
          Gets the built in 'Undo' keyboard shortcut.
 java.util.Map<java.lang.String,Variable> getVariables()
          Gets the Variables for this document.
 java.util.LinkedList<DocumentWindow> getWindows()
          Gets the list of open DocumentWindows.
protected  void initialize()
          The jApp / Application calls this both for new and old documents.
protected  void initNewDocument()
          The Application calls this for new documents only, it is not called for documents that are read from files.
 boolean isDirty()
          Used to check if the file has been changed and the contents needs to be 'saved' to a file when this Document is 'closed'.
 void markDirty()
          The same as callingmarkDirty(String)}.
 void markDirty(java.lang.String name)
          Marks the document dirty and associates a name with this (to be used by the undo/redo system).
 void markNotDirty()
          Marks the document as not dirty.
protected  boolean okToSaveToFile(java.io.File f, FileType ft)
          Checks if it is ok to save to a file of the given type.
protected  void openWindows()
          Opens all the DocumentWindows for this Document.
protected  void performCopy(java.lang.String actionName)
          Performs the default copy operation by calling DataTransferHandler.createTransferable(javax.swing.JComponent, MouseEvent) on the transfer handler returned by getDataTransferHandler() if any.
protected  void performCut(java.lang.String actionName)
          Performs the default cut operation by first calling DataTransferHandler.createTransferable(javax.swing.JComponent, MouseEvent) on the transfer handler returned by getDataTransferHandler() if any and then performDelete(String).
protected  void performDelete(java.lang.String actionName)
          The dafaul delete implementation, which does nothing.
protected  void performPaste(java.lang.String actionName)
          Performs the default paste operaton by first calling DataTransferHandler.importData(Transferable, javax.swing.JComponent, Point) on the transfer handler returned by getDataTransferHandler() with the Transferable retrieved from the clipboard retrived using getClipboard().
protected  void postInitilize()
          The Application calls this both for new and old documents.
protected  void readFromFile(java.io.File file)
          The Application calls this to read documen contents from a file.
protected  void readFromStream(java.io.FileInputStream fstream)
          The jApp / Document calls this to read the contents of a document from a stream.
protected  void readFromStream(java.io.ObjectInputStream stream)
          The jApp / Document calls this to read the contents of a document from an object stream.
protected  void readPageFormat(java.io.ObjectInputStream fstream)
          The jApp / Document calls this to read the PageFormat from a stream.
protected  void removeWindow(DocumentWindow window)
          Removes a DocumentWindow from this document.
 void reportException(java.lang.Exception e)
          Short cut to reportException(Exception).
protected  boolean save(Document.SaveOptions saveMode)
          Performs the saving of the document through a temporari file according to save mode.
 void selectCommand(Command command)
          Short cut to selectCommand(Command cmd,false).
 void selectCommand(Command command, boolean asTemp)
          Makes a Command the active command for this document.
 int showConfirmDialog(java.lang.String message, java.lang.String title, int type)
          Calls Application.showConfirmDialog(Component, Object, String, int) with the active window of this document as the Component parameter.
 void showErrorMessage(java.lang.String message, java.lang.String title)
          Calls Application.showMessageDialog(Component, Object, String, int) with the active window of this document as the Component parameter and JOptionPane.ERROR_MESSAGE as the type parameter.
 void showInfoMessage(java.lang.String message, java.lang.String title)
          Calls Application.showMessageDialog(Component, Object, String, int) with the active window of this document as the Component parameter and JOptionPane.INFORMATION_MESSAGE as the type parameter.
 void showWarningMessage(java.lang.String message, java.lang.String title)
          Calls Application.showMessageDialog(Component, Object, String, int) with the active window of this document as the Component parameter and JOptionPane.WARNING_MESSAGE as the type parameter.
 boolean tryCloseDocument()
          Tries to close the Document.
 boolean tryCloseWindow(DocumentWindow window)
          Closes the given DocumentWindow.
protected  void tryPrint(DocumentPrinter printer, boolean showDialog, boolean withPreview)
          Tries to print the Document.
 boolean tryRevertDocument()
          Tries to revert the Document to the last saved version.
 void updateFeedback()
          Calls updateFeedback() for all open windows.
protected  void writePageFormat(java.io.ObjectOutputStream fstream)
          The jApp / Document calls this to write the writePageFormat to a stream.
protected  void writeToStream(java.io.FileOutputStream fstream)
          The jApp / Document calls this to read the contents of a document to a stream.
protected  void writeToStream(java.io.ObjectOutputStream stream)
          The jApp / Document calls this to write the contents of a document to an object stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACK_RESPONCE

public static final boolean TRACK_RESPONCE
See Also:
Constant Field Values

m_Undoer

protected Undoer m_Undoer

m_Selection

protected Selection m_Selection

m_PageFormat

protected java.awt.print.PageFormat m_PageFormat

m_SelectedPrintService

protected final Variable m_SelectedPrintService

m_PrintRequestAttributes

protected final Variable m_PrintRequestAttributes

m_WindowStates

protected final Variable m_WindowStates
Constructor Detail

Document

protected Document()
The sole constructor. Protected so that only derived classes can be instantiated.

Method Detail

getApplication

public Application getApplication()
Gets the Application object that instantiated this Document.

Returns:
the Application object

confirmWrite

protected boolean confirmWrite(java.io.File file)
Checks that the given file can be overwriten and if not show a dialog informing the user.

Parameters:
file - the file to be written
Returns:
true if the file can be overwriten

detachFile

public void detachFile()
Detaches this Document from the disk file. After calling this the disk file no longer 'belongs to' this document and can be overwriten, all locks and references to it are released. This Document behaves as though it had never been saved before. The in-memory contents of the document are not cleared. The main use of this function is in implementing the template document functionality where the template is read as any regular document and then attached from the template file.


markNotDirty

public void markNotDirty()
Marks the document as not dirty. jApp tries to save dirty documents before closing them, of course consulting the user first.


getFile

public java.io.File getFile()
Gets the file associated with this document.

Returns:
The file, if any, associted with this Document. Can return null.

isDirty

public boolean isDirty()
Used to check if the file has been changed and the contents needs to be 'saved' to a file when this Document is 'closed'.

Returns:
true if the contents of this Document have been changed.

getActiveCommandVariable

public Variable getActiveCommandVariable()
Gets the variable that is used to store a referece to the currently active command. The variable is usefull to register listener that want to know when the active command changes.

Returns:
the currently active command

getSelection

public Selection getSelection()
Gets the selection object associated with this Document.

Returns:
the selection object associated with this Document

markDirty

public void markDirty(java.lang.String name)
Marks the document dirty and associates a name with this (to be used by the undo/redo system). The name is passed to the Undoer.

Parameters:
name - the name of the action that can be undone /redone. Passing null is equivalent to passing "".

execute

public void execute(jApp.UndoableTask task)

markDirty

public void markDirty()
The same as callingmarkDirty(String)}.


causeRegen

public void causeRegen()
Causes all the DocumentWindows associated with this Document to be regenerated.


getActiveWindow

public DocumentWindow getActiveWindow()
Gets the active DocumentWindow for this Document which should be the top most visible window on the screen that is associted with this Document.

Returns:
the active DocumentWindow, could return null

getCommand

public Command getCommand()
Gets the currently active command for this Document.

Returns:
the active Command, if any. Can return null

selectCommand

public void selectCommand(Command command,
                          boolean asTemp)
Makes a Command the active command for this document. Terminates or suspends the previously active command. The new active command can be selected temporarily in which case case the currently active command is suspened otherwise it is terminated.

Parameters:
command - the command to be active command
asTemp - true the previously active command is to be suspended (not terminated).

reportException

public void reportException(java.lang.Exception e)
Short cut to reportException(Exception).

Parameters:
e - the exception

selectCommand

public void selectCommand(Command command)
Short cut to selectCommand(Command cmd,false).

Parameters:
command - the Command

getDocumentPrinter

public DocumentPrinter getDocumentPrinter()
Creates and returns a new DocumentPrinter for this document. Override this method if the default DocumentPrinter is not what you require.

Returns:
a DocumentPrinter object

createPreviewDialog

public PreviewDialog createPreviewDialog(Document d)
Creates and returns a new PreviewDialog for this document. Override this method if the default PreviewDialog is not what you require.

Returns:
a PreviewDialog object

tryPrint

protected void tryPrint(DocumentPrinter printer,
                        boolean showDialog,
                        boolean withPreview)
Tries to print the Document.

Parameters:
printer - The printer object that actual does the painting
showDialog - true to show the Print Dialog
withPreview - true to show the Preview Dialog

removeWindow

protected void removeWindow(DocumentWindow window)
Removes a DocumentWindow from this document.


getUndoer

public final Undoer getUndoer()
Gets the Undoer object for this Document. Final, cannot be overriden, see createUndoer()

Returns:
the Undoer object.

createUndoer

protected Undoer createUndoer()
Creates the Undoer object for this Document. Override if you need some other undoer than Undoer

Returns:
the Undoer object

getFileType

public FileType getFileType()
Gets the FileType for this document.

Returns:
the file type

initialize

protected void initialize()
The jApp / Application calls this both for new and old documents. This gets called before readFromFile(File) or initDocument(Application, FileType)


postInitilize

protected void postInitilize()
The Application calls this both for new and old documents. This gets called after readFromFile or initNewDocument


initNewDocument

protected void initNewDocument()
The Application calls this for new documents only, it is not called for documents that are read from files.


createWindows

protected void createWindows()
Application calls this to create windows for a document. Override to open some windows.


openWindows

protected void openWindows()
Opens all the DocumentWindows for this Document. If no info on old windows is available then calls createWindows().


readFromFile

protected void readFromFile(java.io.File file)
                     throws java.lang.Exception
The Application calls this to read documen contents from a file. Calls readFromStream(FileInputStream), override if that to read the contents of your documents, ovveride this if you do need to perform file reading as opposed to stream reading.

Parameters:
file - the file to read from.
Throws:
java.lang.Exception

addVariable

public final Variable addVariable(java.util.LinkedList list,
                                  java.lang.String name,
                                  Variable variable)
Adds a variable to this document Document. Adds an additional reference to the variable to a list if a list is provided.

Parameters:
list - this to add the variable to, can be null
name - the name for the variable.
variable - the variable.
Returns:
the param variable.

addVariable

public final Variable addVariable(java.lang.String name,
                                  Variable variable)
Adds a variable to this document Document. Save as calling addVariable(LinkedList, String, Variable) with the list parameter set to null

Parameters:
name - the name for the variable.
variable - the variable.
Returns:
the param variable

addVariable

public final LongVariable addVariable(java.lang.String name,
                                      LongVariable variable)
Adds a <LongVariable to this document Document. Save as calling addVariable(LinkedList, String, Variable) with the list parameter set to null

Parameters:
name - the name for the variable.
variable - the variable.
Returns:
the param variable

addVariable

public final StringVariable addVariable(java.lang.String name,
                                        StringVariable variable)
Adds a <StringVariable to this document Document. Save as calling addVariable(LinkedList, String, Variable) with the list parameter set to null

Parameters:
name - the name for the variable.
variable - the variable.
Returns:
the param variable

addVariable

public final DoubleVariable addVariable(java.lang.String name,
                                        DoubleVariable variable)
Adds a <DoubleVariable to this document Document. Save as calling addVariable(LinkedList, String, Variable) with the list parameter set to null

Parameters:
name - the name for the variable.
variable - the variable.
Returns:
the param variable

addVariable

public final BooleanVariable addVariable(java.lang.String name,
                                         BooleanVariable variable)
Adds a <BooleanVariable to this document Document. Save as calling addVariable(LinkedList, String, Variable) with the list parameter set to null

Parameters:
name - the name for the variable.
variable - the variable.
Returns:
the param variable

writeToStream

protected void writeToStream(java.io.ObjectOutputStream stream)
                      throws java.lang.Exception
The jApp / Document calls this to write the contents of a document to an object stream. Override to implement persistency of documents using object serialization.

Parameters:
stream - the stream to write the contents to.
Throws:
java.lang.Exception - if something goes wrong

readFromStream

protected void readFromStream(java.io.ObjectInputStream stream)
                       throws java.lang.Exception
The jApp / Document calls this to read the contents of a document from an object stream. Override to implement persistency of documents using object serialization.

Parameters:
stream - the stream to write the contents to.
Throws:
java.lang.Exception - if something goes wrong

writePageFormat

protected void writePageFormat(java.io.ObjectOutputStream fstream)
                        throws java.lang.Exception
The jApp / Document calls this to write the writePageFormat to a stream.

Throws:
java.lang.Exception

readPageFormat

protected void readPageFormat(java.io.ObjectInputStream fstream)
                       throws java.lang.Exception
The jApp / Document calls this to read the PageFormat from a stream.

Throws:
java.lang.Exception

getVariables

public java.util.Map<java.lang.String,Variable> getVariables()
Gets the Variables for this document.


writeToStream

protected void writeToStream(java.io.FileOutputStream fstream)
                      throws java.lang.Exception
The jApp / Document calls this to read the contents of a document to a stream. By default calls writeToStream(ObjectOutputStream), override to implement peristency with plain file streams.

Parameters:
fstream - the stream to write the contents to.
Throws:
java.lang.Exception - if something goes wrong

createObjectOutputStream

protected java.io.ObjectOutputStream createObjectOutputStream(java.io.FileOutputStream stream)
                                                       throws java.io.IOException
Method writeToStream(ObjectOutputStream) calls this to create the input stream. Override and return a derived class for example to override methods of the object stream when necessary.

Parameters:
stream - the FileOutputStream to read the objects from
Returns:
the ObjectOutputStream to read from
Throws:
java.io.IOException

readFromStream

protected void readFromStream(java.io.FileInputStream fstream)
                       throws java.lang.Exception
The jApp / Document calls this to read the contents of a document from a stream. By default calls readFromStream(ObjectInputStream), override to implement peristency with plain file streams.

Parameters:
fstream - the stream to write the contents to.
Throws:
java.lang.Exception - if something goes wrong

createObjectInputStream

protected java.io.ObjectInputStream createObjectInputStream(java.io.FileInputStream stream)
                                                     throws java.io.IOException
Method readFromStream(FileInputStream) calls this to create the input stream. Override and return a derived class for example to override methods of the object stream when necessary.

Parameters:
stream - the FileInputStream to read the objects from
Returns:
the ObjectInputStream to read from
Throws:
java.io.IOException

confirmRevert

protected int confirmRevert()
                     throws java.lang.Exception
Confirms Reverting a Document.

Returns:
true if the user confirms.
Throws:
java.lang.Exception - if something unexpectedly goes wrong

confirmSave

protected int confirmSave()
                   throws java.lang.Exception
Confirms saving a Document.

Returns:
JOptionPane.YES_OPTION, JOptionPane.NO_OPTION or JOptionPane.CANCEL_OPTION
Throws:
java.lang.Exception - if something unexpected happens

okToSaveToFile

protected boolean okToSaveToFile(java.io.File f,
                                 FileType ft)
Checks if it is ok to save to a file of the given type. Override if you need to perform this check, for example if your Document can open multiple types but save to one type of file only.

Parameters:
f - the file to check.
ft - the tile tape to save to
Returns:
true if it is ok to save, by default returns true

getSaveToFile

protected java.io.File getSaveToFile()
                              throws java.lang.Exception
Gets a file to save the Document to using the Application JFileChooser.

Returns:
the file to save to or null if the user cancels.
Throws:
java.lang.Exception - if something unexpected happens.

save

protected boolean save(Document.SaveOptions saveMode)
                throws java.lang.Exception
Performs the saving of the document through a temporari file according to save mode.

Parameters:
saveMode - the save mode as per {Document#SaveOptions}
Returns:
true if the save was success full, false if the user cancels
Throws:
java.lang.Exception - if something goes wrong

tryCloseWindow

public boolean tryCloseWindow(DocumentWindow window)
                       throws java.lang.Exception
Closes the given DocumentWindow. If the window is the last (open) window for this document tries to close the Document if this fails for any reason (for example the user cancels) neither the window nor the document is closed.

Parameters:
window - the window to close
Returns:
true if the window (and possibly the document) was closed succesfully
Throws:
java.lang.Exception

tryRevertDocument

public boolean tryRevertDocument()
                          throws java.lang.Exception
Tries to revert the Document to the last saved version.

Returns:
true if succesfull
Throws:
java.lang.IllegalStateException - if there is no previous version (document is un-saved)
java.lang.Exception

tryCloseDocument

public boolean tryCloseDocument()
                         throws java.lang.Exception
Tries to close the Document.

Returns:
true if succesfull false if user cancels.
Throws:
java.lang.Exception - if something unexpected happens.

cleanUp

public void cleanUp()
Called to do cleam up once the document has been closed.


getWindows

public java.util.LinkedList<DocumentWindow> getWindows()
Gets the list of open DocumentWindows.

Returns:
list of DocumentWindows associated with this Document.

updateFeedback

public void updateFeedback()
Calls updateFeedback() for all open windows.


getSaveAction

public javax.swing.Action getSaveAction()

getSaveAsAction

public javax.swing.Action getSaveAsAction()
Gets the built in 'SaveAs' action. Override to re-implement the operation.


getSaveCopyAction

public javax.swing.Action getSaveCopyAction()
Gets the built in 'SaveCopy' action. Override to re-implement the operation.


getRevertAction

public javax.swing.Action getRevertAction()
Gets the built in 'Revert' action. Override to re-implement the operation.


getCloseAction

public javax.swing.Action getCloseAction()
Gets the built in 'Close' action. Override to re-implement the operation.


getPrintAction

public javax.swing.Action getPrintAction()
Gets the built in 'Print' action. Override to re-implement the operation.


getExitAction

public javax.swing.Action getExitAction()
Gets the built in 'Exit' action. Override to re-implement the operation.


getCopyAction

public javax.swing.Action getCopyAction()
Gets the built in 'Copy' action. Override to re-implement the operation.


getCutAction

public javax.swing.Action getCutAction()
Gets the built in 'Cut' action. Override to re-implement the operation.


getPasteAction

public javax.swing.Action getPasteAction()
Gets the built in 'Paste' action. Override to re-implement the operation.


getDeleteAction

public javax.swing.Action getDeleteAction()
Gets the built in 'Delete' action. Override to re-implement the operation.


getUndoAction

public javax.swing.Action getUndoAction()
Gets the built in 'Undo' action. Override to re-implement the operation.


getRedoAction

public javax.swing.Action getRedoAction()
Gets the built in 'Redo' action. Override to re-implement the operation.


getNextWindowShortcut

public javax.swing.KeyStroke getNextWindowShortcut()
Gets the built in 'Cycle Windows' keyboard shortcut. Override to change it.


getSaveShortcut

public javax.swing.KeyStroke getSaveShortcut()
Gets the built in 'Save' keyboard shortcut. Override to change it.


getCloseShortCut

public javax.swing.KeyStroke getCloseShortCut()
Gets the built in 'Close' keyboard shortcut. Override to change it.


getPrintShortcut

public javax.swing.KeyStroke getPrintShortcut()
Gets the built in 'Print' keyboard shortcut. Override to change it.


getExitShortcut

public javax.swing.KeyStroke getExitShortcut()
Gets the built in 'Exit/Quit' keyboard shortcut. Override to change it.


getUndoShortCut

public javax.swing.KeyStroke getUndoShortCut()
Gets the built in 'Undo' keyboard shortcut. Override to change it.


getRedoShortCut

public javax.swing.KeyStroke getRedoShortCut()
Gets the built in 'Redor' keyboard shortcut. Override to change it.


getCopyShortcut

public javax.swing.KeyStroke getCopyShortcut()
Gets the built in 'Copy' keyboard shortcut. Override to change it.


getCutShortcut

public javax.swing.KeyStroke getCutShortcut()
Gets the built in 'Cut' keyboard shortcut. Override to change it.


getPasteShortcut

public javax.swing.KeyStroke getPasteShortcut()
Gets the built in 'Paste' keyboard shortcut. Override to change it.


getDeleteShortcut

public javax.swing.KeyStroke getDeleteShortcut()
Gets the built in 'Delete' keyboard shortcut. Override to change it.


showConfirmDialog

public int showConfirmDialog(java.lang.String message,
                             java.lang.String title,
                             int type)
Calls Application.showConfirmDialog(Component, Object, String, int) with the active window of this document as the Component parameter.

Parameters:
message - the message to show in the confirm dialog
title - the title for the dialog
type - the type parameter passed to the JOptionPane
Returns:
the return value from the JOptionPane

showInfoMessage

public void showInfoMessage(java.lang.String message,
                            java.lang.String title)
Calls Application.showMessageDialog(Component, Object, String, int) with the active window of this document as the Component parameter and JOptionPane.INFORMATION_MESSAGE as the type parameter.

Parameters:
message - the message to show in the confirm dialog
title - the title for the dialog

showErrorMessage

public void showErrorMessage(java.lang.String message,
                             java.lang.String title)
Calls Application.showMessageDialog(Component, Object, String, int) with the active window of this document as the Component parameter and JOptionPane.ERROR_MESSAGE as the type parameter.

Parameters:
message - the message to show in the confirm dialog
title - the title for the dialog

showWarningMessage

public void showWarningMessage(java.lang.String message,
                               java.lang.String title)
Calls Application.showMessageDialog(Component, Object, String, int) with the active window of this document as the Component parameter and JOptionPane.WARNING_MESSAGE as the type parameter.

Parameters:
message - the message to show in the confirm dialog
title - the title for the dialog

getParentComponentForDialogs

protected java.awt.Component getParentComponentForDialogs()
Returns a component that is used in calls to JOptionPane.showXXX calls as the parentComponent. The default implementation returns null which results in centering the dialogs on screen, which is propably the best option.

Returns:
the component to center the dialogs on

addItemsToRightClick

public void addItemsToRightClick(javax.swing.JPopupMenu popupMenu)
Handles right clicks.

Parameters:
popupMenu - the popup menu to fill in

createCopyAction

protected javax.swing.Action createCopyAction()
Creates the default 'Copy' action. The action's actionPerformed calls performCopy(String). The action is associated with the Documents Selection and enabled if the Selection is not empty. The Document initialization code calls this method once to create a default 'Copy' action which can be access using getCopyAction().

Returns:
the default 'Copy' action.

createCutAction

protected javax.swing.Action createCutAction()
Creates the default 'Cut' action. The action's actionPerformed calls performCut(String). The action is associated with the Documents Selection and enabled if the Selection is not empty. The Document initialization code calls this method once to create a default 'Cut' action which can be access using getCutAction().

Returns:
the default 'Cut' action.

createPasteAction

protected javax.swing.Action createPasteAction()
Creates the default 'Paste' action. The action's actionPerformed calls performPaste(String). The action is associated with the Clipboards and enabled if the canPaste(DataFlavor[]) return true for the available DataFlavors. The Document initialization code calls this method once to create a default 'Paste' action which can be access using getPasteAction().

Returns:
the default 'Paste' action.

createDeleteAction

protected javax.swing.Action createDeleteAction()
Creates the default 'Delete' action. The action's actionPerformed calls performDelete(String). The action is associated with the Documents Selection and enabled if the Selection is not empty. The Document initialization code calls this method once to create a default 'Delete' action which can be access using getDeleteAction().

Returns:
the default 'Delete' action.

performCopy

protected void performCopy(java.lang.String actionName)
Performs the default copy operation by calling DataTransferHandler.createTransferable(javax.swing.JComponent, MouseEvent) on the transfer handler returned by getDataTransferHandler() if any.

Parameters:
actionName - the name of the operation, i.e. "Copy"

performCut

protected void performCut(java.lang.String actionName)
Performs the default cut operation by first calling DataTransferHandler.createTransferable(javax.swing.JComponent, MouseEvent) on the transfer handler returned by getDataTransferHandler() if any and then performDelete(String).

Parameters:
actionName - the name of the operation, i.e. "Cut"

performPaste

protected void performPaste(java.lang.String actionName)
Performs the default paste operaton by first calling DataTransferHandler.importData(Transferable, javax.swing.JComponent, Point) on the transfer handler returned by getDataTransferHandler() with the Transferable retrieved from the clipboard retrived using getClipboard().

Parameters:
actionName - the name of the operation, i.e. "Paste"

canPaste

protected boolean canPaste(java.awt.datatransfer.DataFlavor[] availableFlavors)
Checks if any of the availableFlavors can be pasted. The default implementation consults the document's DataTransferHandler's DataTransferHandler.canImport(javax.swing.JComponent, DataFlavor[]) method.

Parameters:
availableFlavors - the flavors that are available for pasting
Returns:
true if any of the flavors can be pasted

performDelete

protected void performDelete(java.lang.String actionName)
The dafaul delete implementation, which does nothing.

Parameters:
actionName - the name of the operation, "Delete","Cut" or "Remove"

createClipboard

protected java.awt.datatransfer.Clipboard createClipboard()
Creates the default Clipboard object. The implemention is Document returns the system clipboard. (On Mac OS this actually returns a proxy clipboard to implement a workaround for some bugs in Apple JVM/JRE). The Document initialization code calls this method once to create the default clipboad, which can then be accessed using getClipboard().

Returns:
the clipboard object
See Also:
getClipboard()

getClipboard

public java.awt.datatransfer.Clipboard getClipboard()
Gets the default Clipboard

Returns:
the clipboard.
See Also:
createClipboard()

createSelection

protected Selection createSelection()
Creates the default Selection object. The Document initialization code calls this method once to create the default Selection object, which can then be accessed using getSelection(). Unless overriden this routine returns an instance of SimpleSelction.

Returns:
the selection object for this Document
See Also:
createSelection(), Selection

createDataTransferHandler

public DataTransferHandler createDataTransferHandler()
The Document initialization code calls this method once to create the a DataTransferHandler for this Document, which can then be accessed using getDataTransferHandler(). The default implementation here returns null. Override to return a concrete class to enable the Copy/Paste and Drag/Drop functionality.

Returns:
null, unless overriden
See Also:
()

getDataTransferHandler

public DataTransferHandler getDataTransferHandler()
Returns the DataTransferHandler for this Document.

Returns:
the data transfer handler
See Also:
createDataTransferHandler()