public void saveScriptToFile(
      String code, String filename, Component parent, PropertyPanelController cont) {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setDialogTitle("Save to file");
    String currentDirectory = new File(".").getAbsolutePath();

    fileChooser.setSelectedFile(new File(currentDirectory, filename));
    fileChooser.setName(FILE_CHOOSER);

    if (fileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();

      try {
        if (file.createNewFile()) {
          OutputStream out = new FileOutputStream(file);
          out.write(code.getBytes());
          out.close();

          cont.fileSaveSuccess(file.getAbsolutePath());
        }
      } catch (IOException e) {
        Log.error(e.getMessage(), e);

        cont.fileSaveError(file.getAbsolutePath());
      }
    }
  }
Beispiel #2
0
 public void setDestinationName(String name) {
   destFileChooser.setName(name);
   destFileChooser.setSelectedFile(new File(name));
 }
Beispiel #3
0
 public void setSourceName(String name) {
   sourceFileChooser.setName(name);
   sourceFileChooser.setSelectedFile(new File(name));
 }