Package xal.extension.application
Class XalInternalDocument
java.lang.Object
xal.extension.application.XalInternalDocument
- All Implemented Interfaces:
Pageable
The base class for custom documents. Subclasses of this class need to define
the logic for their document. Every document has a main window and a URL
source that provides persistent storage.
- Author:
- t6p
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected XalInternalWindow
this document's associated windowprotected MessageCenter
Local message centerstatic final int
protected static final String
protected URL
The persistent storage URL for the documentstatic final String
wildcard file extensionprotected xal.extension.application.XalInternalDocument.WindowEventHandler
this document's window event handlerstatic final int
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the listener for events from this document.boolean
This method is a request to close a document.void
customizeCommands
(Commander commander) Override this method to register custom document commands if any.protected void
customizeDesktopCommands
(Commander commander) Subclasses should override this method to register custom document commands (if any) for the desktop menu.int
displayConfirmDialog
(String title, String message) Display a confirmation dialog with a title and messagevoid
displayError
(Exception exception) Display an error dialog box with information about the exception and provide an audible alert.void
displayError
(String title, String message) Display an error dialog box and provide an audible alert.void
displayError
(String title, String prefix, Exception exception) Display an error dialog box with information about the exception and provide an audible alert.void
displayWarning
(Exception exception) Display a warning dialog box with information about the exception and provide an audible alert.void
displayWarning
(String title, String message) Display a warning dialog box and provide an audible alert.void
displayWarning
(String title, String prefix, Exception exception) Display a warning dialog box with information about the exception and provide an audible alert.void
Dispose of custom document resources.final void
Free document resources.void
Generate and set the title for this document.protected String
Subclasses should override this method if this document should use a menu definition other than the default specified in application adaptor.Subclasses should override this method if this document should use a menu definition other than the default specified in application adaptor.Get the default document folder.Get the default document folder as a URL.By default the file path to display for this document is set to the file path of the document or the default empty document file path if the document does not yet have a file store.Implement the method for XalAbstractDocument.Get the default file path to use for empty documentsGet the base file name to use when saving a new file.Get the main window for this document.getNewDocumentName
(String baseName) Get the default file path to use for empty documentsGet the file name (including extension but without path) for a new file.Get the prefix for a new file (precedes timestamp) defaulting to the application name.int
Implement the Pageable interface.getPageFormat
(int pageIndex) Implement the Pageable interface.getPrintable
(int pageIndex) Implement the Pageable interface.Get the URL of the persistent storage for this document.getTitle()
Get the document title.void
handleDataWrittenTo
(DataListener dataRoot, URL url) Subclasses may override this empty method to implement custom code called by writeDataTo() after data has been successfully written to the specified URL.boolean
Indicates if there are changes that need saving.void
Hide this document.boolean
isEmpty()
Check if the document is empty.protected Commander
Subclasses may override this method to provide a custom Commander.abstract void
Subclasses must implement this method to make their custom main window.void
Register this document as a source of DocumentListener events.void
Remove the listener from event from this document.void
Save this document to its persistent storage source.abstract void
saveDocumentAs
(URL url) Subclasses need to implement this method for saving the document to a URL.void
setHasChanges
(boolean changeStatus) Set the whether this document has changes.void
Set the URL of the persistent storage for this document.void
Set the document title.void
Make this document's window visible.boolean
Determine whether the user should be warned when closing a document with unsaved changes.void
Called when the document will be closed.void
Hook indicating that the window was opened.void
Hook indicating that the window will be opened.String[]
Subclasses should implement this method to return the array of file suffixes identifying the files that can be written by the document.void
writeDataTo
(DataListener dataRoot, URL url) Convenience method typically called in saveDocumentAs() to save a document rooted in a data listener source.
-
Field Details
-
mainWindow
this document's associated window -
windowEventHandler
protected xal.extension.application.XalInternalDocument.WindowEventHandler windowEventHandlerthis document's window event handler -
WILDCARD_FILE_EXTENSION
wildcard file extension- See Also:
-
YES_OPTION
public static final int YES_OPTION- See Also:
-
NO_OPTION
public static final int NO_OPTION- See Also:
-
SAVE_FAILED_TITLE
- See Also:
-
messageCenter
Local message center -
source
The persistent storage URL for the document
-
-
Constructor Details
-
XalInternalDocument
protected XalInternalDocument()Constructor for new documents
-
-
Method Details
-
registerEvents
public void registerEvents()Register this document as a source of DocumentListener events. -
addXalInternalDocumentListener
Add the listener for events from this document. -
removeXalInternalDocumentListener
Remove the listener from event from this document. -
makeCommander
Subclasses may override this method to provide a custom Commander. -
setTitle
Set the document title.- Parameters:
newTitle
- The new title for this document.
-
setHasChanges
public void setHasChanges(boolean changeStatus) Set the whether this document has changes.- Parameters:
changeStatus
- Status to set whether this document has changes that need saving.
-
closeDocument
public boolean closeDocument()This method is a request to close a document. It may be called when, for example, the user selects "Close" from the File menu, or when the user closes the window with the close button, or when the application quits. This request starts a series of events which closes the document. Xal document listeners are notified that the document will close. They may perform any cleanup as necessary before the document closes. Then the listeners are informed that the document has closed. The application removes the document from its list of open documents and informs its listeners that the document has been closed. If there are any unsaved changes, the user is given an opportunity to not close the document so they can save the changes. -
freeResources
public final void freeResources()Free document resources. -
getMainWindow
Get the main window for this document.- Returns:
- The main window for this document.
-
getDocumentView
Implement the method for XalAbstractDocument.- Returns:
- The main window for this document.
-
customizeDesktopCommands
Subclasses should override this method to register custom document commands (if any) for the desktop menu. You do so by registering actions with the commander. Those action instances should have a reference to this document so the action is executed on the document when the action is activated. The default implementation of this method does nothing.- Parameters:
commander
- The commander that manages commands.- See Also:
-
getCustomInternalMenuDefinitionResource
Subclasses should override this method if this document should use a menu definition other than the default specified in application adaptor. The document menu inherits the application menu definition. This custom path allows the document to modify the application wide definitions for this document. By default this method returns null.- Returns:
- The menu definition properties file name
-
writableDocumentTypes
Subclasses should implement this method to return the array of file suffixes identifying the files that can be written by the document. By default this method returns the same types as specified by the application adaptor.- Returns:
- An array of file suffixes corresponding to writable files
-
makeMainWindow
public abstract void makeMainWindow()Subclasses must implement this method to make their custom main window. -
customizeCommands
Override this method to register custom document commands if any. You do so by registering actions with the commander. Those action instances should have a reference to this document so the action is executed on the document when the action is activated. The default implementation of this method does nothing.- Parameters:
commander
- The commander that manages commands.- See Also:
-
getCustomMenuDefinitionResource
Subclasses should override this method if this document should use a menu definition other than the default specified in application adaptor. The document menu inherits the application menu definition. This custom path allows the document to modify the application wide definitions for this document. By default this method returns null.- Returns:
- The menu definition properties file name
-
getTitle
Get the document title.- Returns:
- The title of the document.
-
getSource
Get the URL of the persistent storage for this document.- Returns:
- The URL of this document's persistent storage.
-
getDefaultFolder
Get the default document folder.- Returns:
- the default folder for documents or null if none has been set.
-
getDefaultFolderURL
Get the default document folder as a URL.- Returns:
- the default folder for documents as a URL or null if none has been set.
-
setSource
Set the URL of the persistent storage for this document.- Parameters:
url
- The URL of the persistent storage to set for this document.
-
isEmpty
public boolean isEmpty()Check if the document is empty. An empty document has no source file and has not been edited.- Returns:
- true if this document is empty and false if not
-
generateDocumentTitle
public void generateDocumentTitle()Generate and set the title for this document. By default the title is set to the file path of the document or the default empty document file path if the document does not have a file store. -
getDisplayFilePath
By default the file path to display for this document is set to the file path of the document or the default empty document file path if the document does not yet have a file store.- Returns:
- the file path of the document or the default empty document file path as appropriate
-
getFileNameForSaving
Get the base file name to use when saving a new file.- Returns:
- the new file name for new documents and the source's file path for existing documents
-
getNewFileNamePrefix
Get the prefix for a new file (precedes timestamp) defaulting to the application name. Subclasses can override this method to provide an alternative prefix.- Returns:
- prefix for a new file
-
getNewFileName
Get the file name (including extension but without path) for a new file. Subclasses can override this method to provide an alternative name.- Returns:
- file name for a new file
-
getNewDocumentName
Get the default file path to use for empty documents- Parameters:
baseName
- the base name to use for an empty document- Returns:
- "{baseName}." + the first writable document type or simply "{baseName}" if there are none
-
getEmptyDocumentPath
Get the default file path to use for empty documents- Returns:
- "Untitled." + the first writable document type or simply "Untitled" if there are none
-
hasChanges
public boolean hasChanges()Indicates if there are changes that need saving.- Returns:
- Status of whether this document has changes that need saving.
-
saveDocumentAs
Subclasses need to implement this method for saving the document to a URL.- Parameters:
url
- The URL to which this document should be saved.
-
saveDocument
public void saveDocument()Save this document to its persistent storage source. -
writeDataTo
Convenience method typically called in saveDocumentAs() to save a document rooted in a data listener source.- Parameters:
dataRoot
- DataListener root of the document to saveurl
- The URL to which the document should be saved.
-
handleDataWrittenTo
Subclasses may override this empty method to implement custom code called by writeDataTo() after data has been successfully written to the specified URL.- Parameters:
dataRoot
- DataListener root of the document to saveurl
- The URL to which the document should be saved.
-
warnUserOfUnsavedChangesWhenClosing
public boolean warnUserOfUnsavedChangesWhenClosing()Determine whether the user should be warned when closing a document with unsaved changes. The default behavior is to warn the user if they have unsaved changes. Override this method if you don't want the user to be warned of unsaved changes.- Returns:
- true if the user should be warned and false if not.
-
freeCustomResources
public void freeCustomResources()Dispose of custom document resources. Subclasses should override this method to provide custom disposal of resources. The default implementation does nothing. -
willClose
public void willClose()Called when the document will be closed. The default implementation does nothing. Subclasses should override this method if they need to handle this event. -
windowWillOpen
public void windowWillOpen()Hook indicating that the window will be opened. Called after the window is created but before it is displayed by the document. -
windowOpened
public void windowOpened()Hook indicating that the window was opened. -
showDocument
public void showDocument()Make this document's window visible. -
hideDocument
public void hideDocument()Hide this document. -
displayConfirmDialog
Display a confirmation dialog with a title and message- Parameters:
title
- The title of the dialogmessage
- The message to display- Returns:
- YES_OPTION or NO_OPTION
-
displayWarning
Display a warning dialog box and provide an audible alert.- Parameters:
title
- Title of the warning dialog box.message
- The warning message to appear in the warning dialog box.
-
displayWarning
Display a warning dialog box with information about the exception and provide an audible alert.- Parameters:
exception
- The exception about which the warning dialog is displayed.
-
displayWarning
Display a warning dialog box with information about the exception and provide an audible alert. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").- Parameters:
title
- Title of the warning dialog box.prefix
- Text that should appear in the dialog box before the exception messasge.exception
- The exception about which the warning dialog is displayed.
-
displayError
Display an error dialog box and provide an audible alert.- Parameters:
title
- Title of the warning dialog box.message
- The warning message to appear in the warning dialog box.
-
displayError
Display an error dialog box with information about the exception and provide an audible alert.- Parameters:
exception
- The exception about which the warning dialog is displayed.
-
displayError
Display an error dialog box with information about the exception and provide an audible alert. This method allows clarification about the consequences of the exception (e.g. "Save Failed:").- Parameters:
title
- Title of the warning dialog box.prefix
- Text that should appear in the dialog box before the exception messasge.exception
- The exception about which the warning dialog is displayed.
-
getNumberOfPages
public int getNumberOfPages()Implement the Pageable interface. Subclasses may override this implementation to support custom document printing. Returns the number of pages to print. This default implementation simply returns one for printing a single page.- Specified by:
getNumberOfPages
in interfacePageable
- Returns:
- The number of pages to print
-
getPageFormat
Implement the Pageable interface. Subclasses may override this implementation to support custom document printing. This default implementation gets the page format from the default print manager.- Specified by:
getPageFormat
in interfacePageable
- Parameters:
pageIndex
- The page number corresponding to the page format to return- Returns:
- PageFormat for printing the specified page
- Throws:
IndexOutOfBoundsException
- when the page index is out of range- See Also:
-
PrintManager.getPageFormat()
-
getPrintable
Implement the Pageable interface. Subclasses may override this implementation to support custom document printing. This default implementation simply returns a printable object that prints one page of the document's main window.- Specified by:
getPrintable
in interfacePageable
- Parameters:
pageIndex
- The page to print- Returns:
- The printable object responsible for printing the main window
- Throws:
IndexOutOfBoundsException
- when the page index is out of range
-