Class ModelLoader

java.lang.Object
common.xml.ModelLoader

public class ModelLoader extends Object

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
  • Field Details

  • 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 application
      defaultSaveFilter - default file save filter for current application
  • Method Details

    • getFailureMotivation

      public String getFailureMotivation()
      Gets the motivation of last failure
      Returns:
      the motivation of last failure
    • getLastWarnings

      public List<String> getLastWarnings()
      Gets a vector containing warnings of last performed operation
      Returns:
      a Vector of String with every found warning
    • getInputFileFormat

      public String getInputFileFormat()
      Returns:
      the format of opened input file
    • loadModel

      public int loadModel(Object modelData, Component parent, File file)
      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 thrown
      parent - parent component of loading window
      file - 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

      public File getSelectedFile()
      Returns name of selected file for i/o operations
      Returns:
      name of selected file for open or save
    • saveModel

      public int saveModel(Object modelData, Component parent, File file)
      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 thrown
      parent - parent window that will own the save as dialog
      file - 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

      protected int getXmlFileType(String fileName)
    • addCompatibleFilters

      protected void addCompatibleFilters()
      Adds only compatible filters to current dialog
    • showOpenDialog

      protected int showOpenDialog(Component parent)
      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

      protected int showSaveDialog(Component parent)
      Shows save file dialog
      Parameters:
      parent - the parent component of the dialog, can be null; see showDialog for 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: