Ejemplo n.º 1
0
  /**
   * Gets called when the menu option export is called.
   *
   * @param e The action event.
   */
  public void actionPerformed(final ActionEvent e) {
    saveFile();
    if (getMenuView().hasLastFileLocation()) {
      if (!allGoalFilesExist()) {
        ScenarioEditor.getOptionPrompt()
            .showMessageDialog(null, "Warning: Some goal files are missing.");
      }
      File saveLocation = new File(getMenuView().getLastFileLocation());

      JFileChooser filechooser = getCurrentFileChooser();

      filechooser.setSelectedFile(new File(saveLocation.getName().split("\\.")[0]));
      filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      filechooser.setAcceptAllFileFilterUsed(false);
      filechooser.setFileFilter(FileFilters.masFilter());

      if (filechooser.showDialog(getController().getMainView(), "Export MAS project")
          == JFileChooser.APPROVE_OPTION) {
        File xmlFile = filechooser.getSelectedFile();
        exportAsMASProject(xmlFile);
      }
    } else {
      ScenarioEditor.getOptionPrompt()
          .showMessageDialog(null, "Error: Can not export an unsaved scenario.");
    }
  }
Ejemplo n.º 2
0
  /**
   * Exoirts as a mas project
   *
   * @param xmlFile
   */
  private void exportAsMASProject(File xmlFile) {
    try {
      String saveDirectory = xmlFile.getAbsolutePath();

      String extension = ".xml";
      if (!saveDirectory.endsWith(extension)) {
        saveDirectory += extension;
      }

      saveConfigAsXMLFile(saveDirectory);
      BW4TClientConfig configuration = BW4TClientConfig.fromXML(saveDirectory);

      /* Split the name into two around the ., and pass the name without the extension */
      ExportToMAS.export(xmlFile.getParent(), configuration, xmlFile.getName().split("\\.")[0]);
    } catch (JAXBException ex) {
      ScenarioEditor.handleException(ex, "Error: Saving to XML has failed.");
    } catch (FileNotFoundException ex) {
      ScenarioEditor.handleException(ex, "Error: No file has been found.");
    }
  }
Ejemplo n.º 3
0
  /**
   * Listens to the map file chooser and sets a map file
   *
   * <p>Actionhandler that listens to the map file chooser. It creates a filter for MAP files in the
   * file dialog and makes sure only MAP files are accepted and set.
   *
   * @param actionEvent is the event.
   */
  public void actionPerformed(final ActionEvent actionEvent) {
    /** Create a file chooser, opening at the last path location saved in the configuration panel */
    JFileChooser fc = view.getConfigurationPanel().getFileChooser();

    /** Create a file name extension filter to filter on MAP files */
    int returnVal = fc.showOpenDialog(view);
    File file = fc.getSelectedFile();
    String mapExtension = ".map";

    /** Makes sure only files with the right extension are accepted */
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      if (file.getName().endsWith(mapExtension)) {
        view.getConfigurationPanel().setMapFile(file.getPath());
      } else {
        ScenarioEditor.getOptionPrompt().showMessageDialog(view, "This is not a valid file.");
      }
    }
  }
Ejemplo n.º 4
0
  @Before
  public void setUp() throws IOException, JAXBException {
    /* Delete the export directory and everything in it */
    FileUtils.deleteDirectory(new File(EXPORT_DIR));

    /* Mock the alert boxes in ScenarioEditor in the case of an error (unexpected) so Jenkins doesn't freeze */
    ScenarioEditor.setOptionPrompt(OptionPromptHelper.getYesOptionPrompt());

    configuration = BW4TClientConfig.fromXML(CONFIG_PATH);

    /*
     * Nasty hack time:
     * The exporter supports loading an existing GOAL file and copying it to the directory.
     * To test this is a challenge since paths aren't equal across computers.
     *
     * The solution is to copy the robot.goal file to the working directory, thus making it available for loading
     * during the test, and in the test breakdown to delete it.
     */
    FileUtils.copyFile(new File(AGENT_GOAL_FILE), new File(AGENT_GOAL_FILE_WORKING));

    // The actual export.
    ExportToMAS.export(EXPORT_DIR, configuration, CONFIG_NAME);
  }
Ejemplo n.º 5
0
 public BW4TClientConfig getClientConfig() {
   return parent.getController().getModel();
 }