ilog.views.appframe.docview
Class IlvFileDocumentTemplate

java.lang.Object
  extended by ilog.views.appframe.docview.IlvDocumentTemplate
      extended by ilog.views.appframe.docview.IlvFileDocumentTemplate
All Implemented Interfaces:
ActionHandler, IlvPropertyManager, ActionListener, EventListener

public class IlvFileDocumentTemplate
extends IlvDocumentTemplate

Defines document templates that create IlvFileDocument instances.
File document templates initialize from their settings a list of file filters that select the files that the document template can open documents for.
File filters are described in the settings element defining a file document template in the <filters> child element. This element contains a variable list of <filter> elements, each element defining a file filter. The format attribute of the <filter> element specifies a regular expression - like "*.txt" - that selects the file that the document template can open. The description attribute contains a string that describes the files open with this filter, like "Text Document (*.txt). This string should be a key to a string resource.

Filters of a file document template are accessible with the getFilter(int) and getFilterCount() methods. New file filters can be added with the method addFilter(ilog.views.appframe.docview.IlvFileFilter).


Field Summary
static String DEFAULT_FILE_FILTER_PROPERTY
          Bounds property for storing the default file filter to be used by this document template.
 
Fields inherited from class ilog.views.appframe.docview.IlvDocumentTemplate
DATA_CLASS_PROPERTY, DEFAULT_DOCUMENT_NAME_PROPERTY, DESCRIPTION_PROPERTY, DOCUMENT_CLASS_PROPERTY, ICON_PROPERTY, NAME_PROPERTY, SELECTED_CONFIGURATION_PROPERTY, SETTINGS_TYPE, SHORT_NAME_PROPERTY, UNDO_LIMIT_PROPERTY
 
Constructor Summary
IlvFileDocumentTemplate()
          Creates an IlvFileDocumentTemplate instance.
IlvFileDocumentTemplate(String name)
          Creates an IlvFileDocumentTemplate instance with the specified template name.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Invoked when an action occurs.
 void addFilter(IlvFileFilter fileFilter)
          Adds the specified fileFilter to the list of filters that this document template accepts.
 boolean appearsInLoadFileFilters()
          Determines whether files that can be opened by this file document template can be selected from the main application file chooser or the New document dialog box.
 boolean appearsInNewDocuments()
          Specifies whether this file document template is selectable in the New Document dialog box of the application.
protected  IlvFileFilter createFileFilter(String extension, String description)
          Factory method for creating a file filter for the specified file extension.
 IlvFileFilter getDefaultFilter()
          Returns the file filter of this document template that is selected by default in file choosers displayed for this file document template.
 IlvFileFilter getFilter(int index)
          Returns the file filter at the specified storage index in this document template.
 int getFilterCount()
          Returns the number of file filters that this file document template supports.
 int getFilterIndex(IlvFileFilter fileFilter)
          Returns the storage index of the specified fileFilter in the array of file filters of the document template.
 IlvFileFilter getMatchingFilter(String filename)
          Returns the file filter of this document template that matches the specified filename.
 IlvFileFilter getMatchingFilter(URL url)
          Returns the file filter of this document template that matches the specified url.
 void initializeFileChooser(JFileChooser fileChooser, boolean openMode)
          Initializes the specified file chooser with all the file filters of this document template that apply to the specified open mode.
 boolean isProcessingAction(String command)
          Determines whether the document template is able to perform the action with the specified command key.
 boolean matchPathName(String filename)
          Determines whether this document template can open a file with the specified filename.
 boolean matchPathName(URL url)
          Determines whether this document template can open a file with the specified url.
 boolean readDocument(IlvFileDocument document, URL url, IlvFileFilter fileFilter)
          Makes the specified file document read its data from the file with the specified url.
 boolean readDocument(IlvStreamDocument document, Reader reader, IlvFileFilter fileFilter)
          Makes the specified stream document read its data with the specified reader.
 boolean readSettings(IlvSettingsElement element, IlvApplication application)
          Reads the settings of the file document template from the specified settings element.
 boolean removeFilter(IlvFileFilter fileFilter)
          Removes the specified fileFilter from the list of filters that this document template accepts.
 boolean revertDocument(IlvFileDocument document)
          Reloads the document data from the file of the document.
 void setAppearsInLoadFileFilters(boolean appears)
          Specifies whether this file document template appears in the main file chooser or New document dialog box of the application.
 void setAppearsInNewDocuments(boolean appearsInNewDocuments)
          Specifies whether this file document template is selectable in the New Document dialog box of the application.
 IlvFileFilter setDefaultFilter(IlvFileFilter fileFilter)
          Specifies that the specified fileFilter of this document template will be selected by default in file choosers displayed for this file document template.
 void setDocumentPathName(IlvFileDocument document, URL path)
          Sets the document path of the specified document to the specified path.
 
Methods inherited from class ilog.views.appframe.docview.IlvDocumentTemplate
activateDocumentView, activateDocumentView, addPropertyChangeListener, alwaysShowMenu, canCloseViewContainer, closeDocument, closeDocumentView, closeDocumentViews, closeViewContainer, closeViewContainer, connectMainWindow, createDocument, createDocumentViews, documentActivated, documentViewExists, ensureDocumentViewExists, getApplication, getDataClass, getDefaultDocumentName, getDescription, getDocumentClass, getDocumentContainers, getIcon, getIcon, getMenuCompletion, getName, getProperty, getRecentFileListCommand, getSettings, getSettingsElement, getShortName, getViewConfiguration, getViewConfiguration, getViewConfigurationCount, hasOwnRecentFileList, initializeDocumentViews, insertBars, isMDI, matchData, newMDIViewContainer, newViewContainer, newViewContainer, readSettings, removeBars, removePropertyChangeListener, saveDocumentModifications, setApplication, setDefaultDocumentName, setDescription, setDocumentClass, setMDI, setName, setProperty, setSettings, setShortName, updateAction, updateViewContainerTitles
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FILE_FILTER_PROPERTY

public static final String DEFAULT_FILE_FILTER_PROPERTY
Bounds property for storing the default file filter to be used by this document template.

See Also:
Constant Field Values
Constructor Detail

IlvFileDocumentTemplate

public IlvFileDocumentTemplate()
Creates an IlvFileDocumentTemplate instance.


IlvFileDocumentTemplate

public IlvFileDocumentTemplate(String name)
Creates an IlvFileDocumentTemplate instance with the specified template name.

Parameters:
name - The name of the document template.
Method Detail

matchPathName

public boolean matchPathName(URL url)
Determines whether this document template can open a file with the specified url.

Returns:
true if the specified path matches with at least one of the document template filters.
See Also:
getMatchingFilter(java.net.URL)

matchPathName

public boolean matchPathName(String filename)
Determines whether this document template can open a file with the specified filename.

Returns:
true if the specified path matches with at least one of the document template filters.
See Also:
getMatchingFilter(String)

getMatchingFilter

public IlvFileFilter getMatchingFilter(URL url)
Returns the file filter of this document template that matches the specified url.

Returns:
The first file filter of the list of file filters that matches the specified url or null if no file filter could be found.

getMatchingFilter

public IlvFileFilter getMatchingFilter(String filename)
Returns the file filter of this document template that matches the specified filename.

Returns:
The first file filter of the list of file filters that matches the specified filename or null if no file filter could be found.
See Also:
getMatchingFilter(URL)

readDocument

public boolean readDocument(IlvFileDocument document,
                            URL url,
                            IlvFileFilter fileFilter)
Makes the specified file document read its data from the file with the specified url. The document is first cleaned, its IlvFileDocument.readDocument(java.net.URL, ilog.views.appframe.docview.IlvFileFilter) is called, and its modification state is then cleared.

Parameters:
document - The document to make read its data.
url - The URL of the file the document will read its data from.
fileFilter - The file filter selected when selecting the specified url.
Returns:
true if the document could read its data; false otherwise.
See Also:
readDocument(IlvStreamDocument, Reader, IlvFileFilter)

readDocument

public boolean readDocument(IlvStreamDocument document,
                            Reader reader,
                            IlvFileFilter fileFilter)
Makes the specified stream document read its data with the specified reader. The document is first cleaned, its IlvStreamDocument.readStreamDocument(java.io.Reader, ilog.views.appframe.docview.IlvFileFilter) is called, and its modification state is then cleared.

Parameters:
document - The document to make read its data.
reader - The reader to read the document data from.
fileFilter - The file filter corresponding to the specified stream.
Returns:
true if the document could read its data; false otherwise.
See Also:
readDocument(IlvFileDocument, URL, IlvFileFilter)

setDocumentPathName

public void setDocumentPathName(IlvFileDocument document,
                                URL path)
Sets the document path of the specified document to the specified path. This method must not be invoked explicitly: it is called by the document template when the document loads its data from a file or when the document saves its data with a new path through the File/Save As... menu item. By default, this method updates the title of the document if the title was not previously explicitly set using the method IlvDocument.setTitle(java.lang.String).


revertDocument

public boolean revertDocument(IlvFileDocument document)
Reloads the document data from the file of the document.
First, this method makes sure that the current document data can be cleaned, if the document has been modified. Then, the data is cleaned with the IlvDocument.clean() method and the method IlvFileDocument.readDocument(java.net.URL, IlvFileFilter) is called with the document path URL as the parameter.

Returns:
true if the document data could be loaded from the document file; false otherwise.

initializeFileChooser

public void initializeFileChooser(JFileChooser fileChooser,
                                  boolean openMode)
Initializes the specified file chooser with all the file filters of this document template that apply to the specified open mode.

Parameters:
fileChooser - The file chooser to initialize.
openMode - If true the file chooser is used for selecting a file to open; if false the file chooser is used for selecting a file for saving a document.

getFilterCount

public int getFilterCount()
Returns the number of file filters that this file document template supports.

Returns:
The file filter count.
See Also:
addFilter(ilog.views.appframe.docview.IlvFileFilter)

getFilter

public IlvFileFilter getFilter(int index)
Returns the file filter at the specified storage index in this document template.

See Also:
getFilterCount()

addFilter

public void addFilter(IlvFileFilter fileFilter)
Adds the specified fileFilter to the list of filters that this document template accepts.

Parameters:
fileFilter - The new file filter to add.
See Also:
removeFilter(ilog.views.appframe.docview.IlvFileFilter)

setDefaultFilter

public IlvFileFilter setDefaultFilter(IlvFileFilter fileFilter)
Specifies that the specified fileFilter of this document template will be selected by default in file choosers displayed for this file document template.

Parameters:
fileFilter - The new default file filter.
Returns:
The previous default file filter of this document template or null if no file filter was previously the default one.
See Also:
getDefaultFilter()

getDefaultFilter

public IlvFileFilter getDefaultFilter()
Returns the file filter of this document template that is selected by default in file choosers displayed for this file document template.

Returns:
The default file filter or null if no file filter has been specified as the default.
See Also:
setDefaultFilter(ilog.views.appframe.docview.IlvFileFilter)

removeFilter

public boolean removeFilter(IlvFileFilter fileFilter)
Removes the specified fileFilter from the list of filters that this document template accepts.

Parameters:
fileFilter - The file filter to remove.
Returns:
true if the filter is owned by the document template; false otherwise.
See Also:
addFilter(ilog.views.appframe.docview.IlvFileFilter)

getFilterIndex

public int getFilterIndex(IlvFileFilter fileFilter)
Returns the storage index of the specified fileFilter in the array of file filters of the document template.

Returns:
The storage index or -1 if the file filter is not owned by the document template.

appearsInLoadFileFilters

public boolean appearsInLoadFileFilters()
Determines whether files that can be opened by this file document template can be selected from the main application file chooser or the New document dialog box. By default, the file document template is taken into account in both dialogs.

Returns:
true if this document template is taken into account by the application when processing the IlvApplication.OPEN_DOCUMENT_CMD or IlvApplication.NEW_DOCUMENT_CMD; false otherwise.
See Also:
setAppearsInLoadFileFilters(boolean)

setAppearsInLoadFileFilters

public void setAppearsInLoadFileFilters(boolean appears)
Specifies whether this file document template appears in the main file chooser or New document dialog box of the application.

Parameters:
appears - If true, the document template appears in the main file chooser or New document dialog box of the application. If false, it does not.
See Also:
appearsInLoadFileFilters()

appearsInNewDocuments

public boolean appearsInNewDocuments()
Specifies whether this file document template is selectable in the New Document dialog box of the application. This dialog is launched when processing the action NewDocument.

Returns:
true if the document template is liste in the New Document dialog box. Otherwise, this method returns false.
Since:
JViews 6.5
See Also:
setAppearsInNewDocuments(boolean), appearsInLoadFileFilters()

setAppearsInNewDocuments

public void setAppearsInNewDocuments(boolean appearsInNewDocuments)
Specifies whether this file document template is selectable in the New Document dialog box of the application. This dialog is launched when processing the action NewDocument.

Parameters:
appearsInNewDocuments - If true, the document template appears in the New Document dialog box of the application. If false, it does not.
Since:
JViews 6.5
See Also:
appearsInNewDocuments()

actionPerformed

public void actionPerformed(ActionEvent e)
Invoked when an action occurs. A document template can handle action events only if a document of this document template is active in the application.
This method is invoked only if the isProcessingAction(java.lang.String) method returns true with the e.getActionCommand() value as the parameter.

Specified by:
actionPerformed in interface ActionListener
Overrides:
actionPerformed in class IlvDocumentTemplate
Parameters:
e - The action event.
See Also:
isProcessingAction(java.lang.String)

isProcessingAction

public boolean isProcessingAction(String command)
Determines whether the document template is able to perform the action with the specified command key. A document template can handle actions only if a document of this document template is active in the application.

Specified by:
isProcessingAction in interface ActionHandler
Overrides:
isProcessingAction in class IlvDocumentTemplate
Parameters:
command - The command key of the action.
Returns:
true if the document template can process the specified action; false otherwise.
See Also:
actionPerformed(java.awt.event.ActionEvent)

readSettings

public boolean readSettings(IlvSettingsElement element,
                            IlvApplication application)
Reads the settings of the file document template from the specified settings element.

Overrides:
readSettings in class IlvDocumentTemplate
Parameters:
element - The settings element to read the settings from.
application - The application of the document template. It can be used for localizing strings or resolving URLs.
Returns:
true if the settings of the document template could be read; false otherwise.

createFileFilter

protected IlvFileFilter createFileFilter(String extension,
                                         String description)
Factory method for creating a file filter for the specified file extension. This method is invoked when the file document template reads its filters from the settings.

Parameters:
extension - The file extension filtered by the filter to create.
description - The description associated with the file filter to create. This description should be a string resource key.
Returns:
The newly created IlvFileFilter instance.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.