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());
      }
    }
  }
Ejemplo n.º 2
0
 public void setDestinationName(String name) {
   destFileChooser.setName(name);
   destFileChooser.setSelectedFile(new File(name));
 }
Ejemplo n.º 3
0
 public void setSourceName(String name) {
   sourceFileChooser.setName(name);
   sourceFileChooser.setSelectedFile(new File(name));
 }