Package xal.extension.application.smf
Class AcceleratorDocument
java.lang.Object
xal.extension.application.XalDocument
xal.extension.application.smf.AcceleratorDocument
- All Implemented Interfaces:
Pageable
AcceleratorDocument is a subclass of XalDocument for accelerator based
applications.
- Author:
- tap
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Accelerator
protected String
protected MessageCenter
Local message centerstatic final int
protected static final String
protected AcceleratorSeq
protected List<AcceleratorSeq>
protected URL
The persistent storage URL for the documentstatic final String
wildcard file extensionstatic final int
Fields inherited from class xal.extension.application.XalDocument
mainWindow
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new instance of AcceleratorDocument -
Method Summary
Modifier and TypeMethodDescriptionvoid
Hook for handling the accelerator change event.void
Hook for handling the accelerator file path change event.Attempt to load the accelerator with the specified path and if none exists, then request a substitute accelerator from the user.protected void
Standard way of catching XML Write exceptionsvoid
customizeCommands
(Commander commander) Override this method to register custom document commands if any.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.void
Generate and set the title for this document.Get the accelerator managed by this document.Get the path to the xml file of the accelerator managed by this document.Get the accelerator window managed by this documentSubclasses 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.Get the default file path to use for empty documentsGet the base file name to use when saving a new file.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 selected sequence ID if any or the super class's default if no sequence is selected.int
Implement the Pageable interface.getPageFormat
(int pageIndex) Implement the Pageable interface.getPrintable
(int pageIndex) Implement the Pageable interface.Get the selected accelerator sequence managed by this document.Get the selected sequence listGet 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.boolean
Is the sequence selected a ring?protected boolean
Attempt to load the user's default accelerator.abstract void
Subclasses must implement this method to make their custom main window.Get the channel factory which is used to instantiate the NEXT accelerator within 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
Hook for handling the selected sequence change event.void
setAccelerator
(Accelerator newAccelerator, String newPath) Set the accelerator managed by the document.void
setAcceleratorFilePath
(String newPath) Set the accelerator file path.void
setSelectedSequence
(AcceleratorSeq selection) Set the selected accelerator sequence managed by this document.void
setSelectedSequenceList
(List<AcceleratorSeq> seqList) Set a list of selected sequencesvoid
Set the URL of the persistent storage for this document.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.Methods inherited from class xal.extension.application.XalDocument
addXalDocumentListener, closeDocument, freeResources, getDefaultWindowReference, getDocumentView, getMainWindow, registerEvents, removeXalDocumentListener, setHasChanges, setTitle
-
Field Details
-
accelerator
-
selectedSequence
-
acceleratorFilePath
-
selectedSequenceList
-
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
-
AcceleratorDocument
protected AcceleratorDocument()Creates a new instance of AcceleratorDocument
-
-
Method Details
-
nextChannelFactory
Get the channel factory which is used to instantiate the NEXT accelerator within this document. Note that this channel factory does not necessarily match the channel factory of the current accelerator in this document. The base AcceleratorDocument class returns ChannelFactory.defaultFactory(). Subclasses may override this method to provide a custom channel factory if desired.- Returns:
- the channel factory to initialize a new accelerator
-
getAcceleratorWindow
Get the accelerator window managed by this document- Returns:
- this document's accelerator window
-
generateDocumentTitle
public void generateDocumentTitle()Generate and set the title for this document. -
getNewFileNamePrefix
Get the prefix for a new file (precedes timestamp) defaulting to the selected sequence ID if any or the super class's default if no sequence is selected.- Returns:
- prefix for a new file
-
applySelectedAcceleratorWithDefaultPath
Attempt to load the accelerator with the specified path and if none exists, then request a substitute accelerator from the user.- Parameters:
filePath
- file path to the accelerator for which to first attempt to load
-
setAccelerator
Set the accelerator managed by the document. Every document manages one accelerator (or possibly null).- Parameters:
newAccelerator
- The accelerator managed by this document.newPath
- The path to the accelerator managed by this document.
-
getAccelerator
Get the accelerator managed by this document.- Returns:
- The accelerator managed by this document.
-
setAcceleratorFilePath
Set the accelerator file path. Every document manages one accelerator (or possibly null).- Parameters:
newPath
- The path to the accelerator managed by this document.
-
getAcceleratorFilePath
Get the path to the xml file of the accelerator managed by this document.- Returns:
- path to the xml file of the accelerator managed by this document.
-
loadDefaultAccelerator
protected boolean loadDefaultAccelerator()Attempt to load the user's default accelerator. If no default accelerator is specified, then prompt the user to specify the default optics path. The document's accelerator file is set to the user's default accelerator.- Returns:
- true if the default accelerator was successfully loaded
-
setSelectedSequence
Set the selected accelerator sequence managed by this document.- Parameters:
selection
- The accelerator sequence to be managed by this document.
-
setSelectedSequenceList
Set a list of selected sequences- Parameters:
seqList
- The list of selected sequences
-
getSelectedSequence
Get the selected accelerator sequence managed by this document.- Returns:
- The sequence managed by this document.
-
getSelectedSequenceList
Get the selected sequence list- Returns:
- the selected sequence list
-
isSelectedSequenceRing
public boolean isSelectedSequenceRing()Is the sequence selected a ring? -
acceleratorChanged
public void acceleratorChanged()Hook for handling the accelerator change event. Subclasses should override this method to provide custom handling. The default handler does nothing. -
selectedSequenceChanged
public void selectedSequenceChanged()Hook for handling the selected sequence change event. Subclasses should override this method to provide custom handling. The default handler does nothing. -
acceleratorFilePathChanged
public void acceleratorFilePathChanged()Hook for handling the accelerator file path change event. Subclasses should override this method to provide custom handling. The default handler does nothing. -
catchXmlDataAdaptorException
Standard way of catching XML Write exceptions -
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
-
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
-
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
-