Class ModelLoader
java.lang.Object
common.xml.ModelLoader
Title: Model Loader
Description: This class provides unified load/save functionality for every JMT application
- Author:
- Bertoli Marco Date: 15-feb-2006 Time: 15.36.51
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classCustom file chooser classstatic classInner class used to create simple file filters with only extension check -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ModelLoader.JmtFileFilterFilters for input filesstatic final ModelLoader.JmtFileFilterstatic final intprotected ModelLoader.JmtFileFilterprotected ModelLoader.JmtFileFilterprotected ModelLoader.JmtFileChooserprotected static final Stringprotected static final Stringprotected static final StringFailure motivationsstatic final intprotected Stringprotected static final intprotected Stringstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final ModelLoader.JmtFileFilterstatic final intConstants used for outputstatic final intprotected static final intprotected static final intprotected static final intprotected static final Stringprotected static final intprotected static final Stringprotected static final intprotected static final intprotected static final intConstants to define xml typesprotected XMLUtils -
Constructor Summary
ConstructorsConstructorDescriptionModelLoader(ModelLoader.JmtFileFilter defaultFilter, ModelLoader.JmtFileFilter defaultSaveFilter) Initializes a new model loader with specified default file filters -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds only compatible filters to current dialogGets the motivation of last failureGets a vector containing warnings of last performed operationReturns name of selected file for i/o operationsprotected intgetXmlFileType(String fileName) intLoads a model from a file into specified model dataintSaves specified model into specified file or shows save as window if file is nullprotected intshowOpenDialog(Component parent) Shows open file dialogprotected intshowSaveDialog(Component parent) Shows save file dialog
-
Field Details
-
ALL
Filters for input files -
ALL_NOTJABA
-
JMODEL
-
JSIM
-
JMVA
-
JABA
-
JMODEL_SAVE
-
JSIM_SAVE
-
JMVA_SAVE
-
JABA_SAVE
-
SUCCESS
public static final int SUCCESSConstants used for output- See Also:
-
CANCELLED
public static final int CANCELLED- See Also:
-
FAILURE
public static final int FAILURE- See Also:
-
WARNING
public static final int WARNING- See Also:
-
XML_SIM
protected static final int XML_SIMConstants to define xml types- See Also:
-
XML_ARCHIVE
protected static final int XML_ARCHIVE- See Also:
-
XML_MVA
protected static final int XML_MVA- See Also:
-
XML_JABA
protected static final int XML_JABA- See Also:
-
XML_RES_SIM
protected static final int XML_RES_SIM- See Also:
-
XML_RES_GUI
protected static final int XML_RES_GUI- See Also:
-
XML_PNML
protected static final int XML_PNML- See Also:
-
FILE_UNKNOWN
protected static final int FILE_UNKNOWN- See Also:
-
FAIL_UNKNOWN
-
FAIL_CONVERSION
- See Also:
-
FAIL_PNML_EXPORT
- See Also:
-
XML_MVA_ROOT
- See Also:
-
XML_PNML_ROOT
- See Also:
-
dialog
-
defaultFilter
-
defaultSaveFilter
-
failureMotivation
-
warnings
-
fileFormat
-
xmlutils
-
-
Constructor Details
-
ModelLoader
public ModelLoader(ModelLoader.JmtFileFilter defaultFilter, ModelLoader.JmtFileFilter defaultSaveFilter) Initializes a new model loader with specified default file filters- Parameters:
defaultFilter- default file filter for current applicationdefaultSaveFilter- default file save filter for current application
-
-
Method Details
-
getFailureMotivation
Gets the motivation of last failure- Returns:
- the motivation of last failure
-
getLastWarnings
-
getInputFileFormat
- Returns:
- the format of opened input file
-
loadModel
Loads a model from a file into specified model data- Parameters:
modelData- model data where information should be stored. Note that its type must be compatible with defaultFilter chosen in the constructor, otherwise a ClassCastException will be thrownparent- parent component of loading windowfile- model file where information should be loaded. If null, a Load window will be shown for choosing the file- Returns:
- SUCCESS on success, CANCELLED if loading is cancelled, FAILURE if an error occurs and WARNING is one or more warnings are generated due to format conversion
- Throws:
ClassCastException- if modelData is not of instance of the correct class- See Also:
-
getSelectedFile
Returns name of selected file for i/o operations- Returns:
- name of selected file for open or save
-
saveModel
Saves specified model into specified file or shows save as window if file is null- Parameters:
modelData- data file where information should be stored. Note that its type must be compatible with defaultFilter chosen in the constructor, otherwise a ClassCastException will be thrownparent- parent window that will own the save as dialogfile- location where pecified model must be saved or null if save as must be shown- Returns:
- SUCCESS on success, CANCELLED if loading is cancelled, FAILURE if an error occurs
- Throws:
ClassCastException- if modelData is not of instance of the correct class- See Also:
-
getXmlFileType
-
addCompatibleFilters
protected void addCompatibleFilters()Adds only compatible filters to current dialog -
showOpenDialog
Shows open file dialog- Parameters:
parent- parent component for this dialog- Returns:
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileCHooser.ERROR_OPTION if an error occurs or the dialog is dismissed
- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.
-
showSaveDialog
Shows save file dialog- Parameters:
parent- the parent component of the dialog, can benull; seeshowDialogfor details- Returns:
- the return state of the file chooser on popdown:
- JFileChooser.CANCEL_OPTION
- JFileChooser.APPROVE_OPTION
- JFileCHooser.ERROR_OPTION if an error occurs or the dialog is dismissed
- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-