private void printerActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_printerActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setPreferredSize(new Dimension(800, 500));

    chooser.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".html") || f.isDirectory();
          }

          @Override
          public String getDescription() {
            return "HTML Files";
          }
        });
    int r = chooser.showSaveDialog(this);

    while (r == 0) {
      String zipname = chooser.getSelectedFile().getPath();
      File f = new File(zipname);

      if (f.exists()) {
        int n =
            JOptionPane.showConfirmDialog(
                null,
                "Přejete si přepsat existující soubor ?",
                "",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if (n == 0) {
          try {
            GlobalSave.printedElement.saveFile(zipname);
            break;
          } catch (IOException ex) {
            JOptionPane.showMessageDialog(
                null, "Nepodařilo se otevřít soubor ", "", JOptionPane.ERROR_MESSAGE);
            break;
          }
        } else {
          r = chooser.showSaveDialog(this);
        }

      } else {
        try {
          GlobalSave.printedElement.saveFile(zipname);
          break;
        } catch (IOException ex) {
          JOptionPane.showMessageDialog(
              null, "Nepodařilo se otevřít soubor ", "", JOptionPane.ERROR_MESSAGE);
        }

        break;
      }
    }
  } // GEN-LAST:event_printerActionPerformed
Beispiel #2
0
 public void saveExpressionToFile(boolean collapse) {
   JFileChooser fileSaveChooser = new JFileChooser("Unnamed Expression.txt");
   FileNameExtensionFilter fnef = new FileNameExtensionFilter("Text Files", "txt");
   fileSaveChooser.setFileFilter(fnef);
   int returnValue = fileSaveChooser.showSaveDialog(this.getRegExInput());
   if (returnValue == JFileChooser.APPROVE_OPTION) {
     File saveFile = fileSaveChooser.getSelectedFile();
     try {
       String saveText = this.getRegExInput().getText();
       if (collapse) {
         saveText = saveText.replaceAll("\n|\t", "");
       }
       String fileName = saveFile.getName();
       String fileAbsolutePath = saveFile.getAbsolutePath();
       String filePath =
           fileAbsolutePath.substring(0, fileAbsolutePath.lastIndexOf(File.separator));
       if (!fileName.endsWith(".txt")) {
         fileName += ".txt";
       }
       FileUtils.writeStringToFile(
           new File(filePath + File.separator + fileName), saveText, "utf-8");
     } catch (IOException e1) {
       e1.printStackTrace();
     }
   }
 }
  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 #4
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Preferences pref = Preferences.userNodeForPackage(FSFrame.class);
      String saveDirName = pref.get(SAVE_DIR, System.getProperty("user.dir"));

      JFileChooser fileChooser = new JFileChooser(saveDirName);
      int result = fileChooser.showSaveDialog(FSFrame.this);
      if (result != JFileChooser.APPROVE_OPTION) {
        return;
      }
      File file = fileChooser.getSelectedFile();
      if (!file.getName().toLowerCase().endsWith(".fsext")) {
        file = new File(file.getAbsolutePath() + ".fsext");
      }
      if (file.exists()) {
        result =
            JOptionPane.showConfirmDialog(
                FSFrame.this, FSResource.getString("file_exists"), "", JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION) {
          return;
        }
      }
      pref.put(SAVE_DIR, file.getAbsolutePath());

      FileOutputStream fos = null;
      try {
        fos = new FileOutputStream(file);
        new Parser().write(panel.getModel(), fos);
      } catch (IOException ex) {
        JOptionPane.showMessageDialog(
            FSFrame.this, FSResource.resourceBundle.getString("failed_to_output"));
        ex.printStackTrace();
      }
    }
Beispiel #5
0
  private boolean checkForSave() {
    // build warning message
    String message;
    if (file == null) {
      message = "File has been modified.  Save changes?";
    } else {
      message = "File \"" + file.getName() + "\" has been modified.  Save changes?";
    }

    // show confirm dialog
    int r =
        JOptionPane.showConfirmDialog(
            this,
            new JLabel(message),
            "Warning!",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE);

    if (r == JOptionPane.YES_OPTION) {
      // Save File
      if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // write the file
        physWriteTextFile(fileChooser.getSelectedFile(), textView.getText());
      } else {
        // user cancelled save after all
        return false;
      }
    }
    return r != JOptionPane.CANCEL_OPTION;
  }
  private String chooseFileName(boolean ownXmlFormat, FileFilter filefilter) {
    String fileName = null;

    // filechooser must be recreated to avoid a bug where getSelectedFile() was null (if a file is
    // saved more than one time by doubleclicking on an existing file)
    reloadSaveFileChooser();

    setAvailableFileFilters(ownXmlFormat);
    saveFileChooser.setFileFilter(filefilter);

    int returnVal = saveFileChooser.showSaveDialog(Main.getInstance().getGUI());
    if (returnVal == JFileChooser.APPROVE_OPTION) {

      File selectedFileWithExt =
          new File(
              saveFileChooser.getSelectedFile().getName()
                  + "."
                  + fileextensions.get(saveFileChooser.getFileFilter()));
      // We must check for the file with and without extension (saving without adding the extension
      // automatically adds the selected extension)
      if (saveFileChooser.getSelectedFile().exists() || selectedFileWithExt.exists()) {
        int overwriteQuestionResult =
            JOptionPane.showConfirmDialog(
                Main.getInstance().getGUI(),
                "File already exists! Overwrite?",
                "Overwrite File",
                JOptionPane.YES_NO_OPTION);
        if (overwriteQuestionResult == JOptionPane.NO_OPTION)
          return chooseFileName(ownXmlFormat, filefilter);
      }
      fileName = saveFileChooser.getSelectedFile().getAbsolutePath();
    }
    return fileName;
  }
Beispiel #7
0
  /**
   * Ask use if they would like a dump file, if so, create one.
   *
   * @param pcap Reference to the PcapHandle.
   */
  @Override
  protected boolean beforeStart(Pcap pcap) {
    super.beforeStart(pcap);
    int option = JOptionPane.showConfirmDialog(GrassMarlin.window, "Create a dumpfile?");
    if (option == JOptionPane.OK_OPTION) {
      try {

        String filename = System.currentTimeMillis() + "_dump.pcap";
        File f = new File(Environment.DIR_LIVE_CAPTURE.getPath() + File.separator + filename);

        JFileChooser fc = new JFileChooser();
        fc.setSelectedFile(f);

        int i = fc.showSaveDialog(GrassMarlin.window.getContentPane());

        if (i == JFileChooser.APPROVE_OPTION) {
          dumper = pcap.dumpOpen(fc.getSelectedFile().getCanonicalPath());
        }

      } catch (Exception ex) {
        Logger.getLogger(LivePCAPImport.class.getName())
            .log(Level.SEVERE, "Failed to set dumpfile.", ex);
      }
    } else if (option == JOptionPane.CANCEL_OPTION) {
      return false;
    }
    isUsingDumpFile = dumper != null;
    return true;
  }
  void exportToExcel(JasperPrint jasperPrint) throws Exception {
    javax.swing.JFileChooser jfc = new javax.swing.JFileChooser("reportsample/");

    jfc.setDialogTitle("Send Report to Excel");
    jfc.setFileFilter(
        new javax.swing.filechooser.FileFilter() {
          public boolean accept(java.io.File file) {
            String filename = file.getName();
            return (filename.toLowerCase().endsWith(".xls")
                || file.isDirectory()
                || filename.toLowerCase().endsWith(".jrxml"));
          }

          public String getDescription() {
            return "Laporan *.xls";
          }
        });

    jfc.setMultiSelectionEnabled(false);

    jfc.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
    if (jfc.showSaveDialog(null) == javax.swing.JOptionPane.OK_OPTION) {

      JExcelApiExporter exporter = new JExcelApiExporter();
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
      exporter.setParameter(
          JRExporterParameter.OUTPUT_FILE_NAME,
          changeFileExtension(jfc.getSelectedFile().getPath(), "xls"));
      exporter.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
      exporter.setParameter(JExcelApiExporterParameter.IS_FONT_SIZE_FIX_ENABLED, Boolean.TRUE);
      exporter.exportReport();
    }
  }
Beispiel #9
0
  private void targetFileButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_targetFileButtonActionPerformed
    JFileChooser fc;
    String defFile = targetFileTextField.getText();
    if (defFile.length() > 0) {
      fc = new JFileChooser(FilePathParser.getDir(defFile));
    } else {
      fc = new JFileChooser(MusiteInit.defaultPath);
    }

    String ext = "txt";
    fc.setSelectedFile(new File(defFile));
    ArrayList<String> exts = new ArrayList<String>(1);
    exts.add(ext);
    fc.setFileFilter(new FileExtensionsFilter(exts, "Text file (.txt)"));
    // fc.setAcceptAllFileFilterUsed(true);
    fc.setDialogTitle("Save to...");
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      MusiteInit.defaultPath = file.getParent();

      String filePath = MusiteInit.defaultPath + File.separator + file.getName();
      targetFileTextField.setText(filePath);
    }
  } // GEN-LAST:event_targetFileButtonActionPerformed
Beispiel #10
0
    public static File saveFileAs(JComponent parent) {
      File f = null;
      try {
        JFileChooser jfc = new JFileChooser();

        FileNameExtensionFilter csvfilter = new FileNameExtensionFilter("CSV", "csv");
        jfc.addChoosableFileFilter(csvfilter);

        FileNameExtensionFilter tsvfilter = new FileNameExtensionFilter("TSV", "tsv");
        jfc.addChoosableFileFilter(tsvfilter);

        FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("XML", "xml");
        jfc.addChoosableFileFilter(xmlfilter);

        FileNameExtensionFilter txtfilter = new FileNameExtensionFilter("Text", "txt");
        jfc.addChoosableFileFilter(txtfilter);

        FileNameExtensionFilter jsonfilter = new FileNameExtensionFilter("JSON", "json");
        jfc.addChoosableFileFilter(jsonfilter);

        jfc.setDialogTitle("VirtualSPARQLer: FileSaver");
        jfc.showSaveDialog(parent);
        f = jfc.getSelectedFile();
        f.createNewFile();
      } catch (IOException ex) {
        mylogger.log(Level.SEVERE, "Error: Can not save file: {0}", ex.getMessage());
      } finally {
        return f;
      }
    }
Beispiel #11
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     JFileChooser f = new JFileChooser();
     f.setFileFilter(new MyFileFilter());
     int choose = f.showSaveDialog(getContentPane());
     if (choose == JFileChooser.APPROVE_OPTION) {
       BufferedWriter brw = null;
       try {
         File file = f.getSelectedFile();
         brw = new BufferedWriter(new FileWriter(file));
         int i = td.getSelectedIndex();
         TextDocument ta = (TextDocument) td.getComponentAt(i);
         ta.write(brw);
         ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱
         td.setTitleAt(td.getSelectedIndex(), ta.fileName);
         ta.file = file;
         ta.save = true; // 設定已儲存
         System.out.println("Save as pass!");
         td.setTitleAt(i, ta.fileName); // 更新標題名稱
       } catch (Exception exc) {
         exc.printStackTrace();
       } finally {
         try {
           brw.close();
         } catch (Exception ecx) {
           ecx.printStackTrace();
         }
       }
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Beispiel #12
0
  private void scormFileBtnActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_scormFileBtnActionPerformed

    if (scormFileChooser == null) {
      scormFileChooser = new JFileChooser();
      scormFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    }

    scormFile = StrUtils.nullableString(scormFileText.getText());
    if (scormFile != null) {
      try {
        File f = new File(scormFile);
        if (!f.getParentFile().exists()) {
          f.getParentFile().mkdirs();
        }
        scormFileChooser.setSelectedFile(f);
      } catch (Exception ex) {
        // Unable to create folders. By now, do nothing
      }
    }

    if (scormFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
      scormFile = scormFileChooser.getSelectedFile().getAbsolutePath();
      scormFileText.setText(scormFile);
    }
  } // GEN-LAST:event_scormFileBtnActionPerformed
Beispiel #13
0
 /** Exports the Last Deployment to an html file Called by the GuiMain in an action event */
 public void exportLastDeployment(ArrayList<DeployedVirtualMachine> deployed, Component parent) {
   if (deployed.size() != 0) {
     FileSystemView fsv = FileSystemView.getFileSystemView();
     JFileChooser chooser = new JFileChooser(fsv.getRoots()[0]);
     chooser.addChoosableFileFilter(new ReportGeneratorFileFilter());
     chooser.setSelectedFile(new File("report.html"));
     int choice = chooser.showSaveDialog(parent);
     if (choice == JFileChooser.APPROVE_OPTION) {
       try {
         LOG.write("Creating report...");
         new ReportGenerator().makeReport(chooser.getSelectedFile(), deployed, this);
         LOG.write("Report saved at " + chooser.getSelectedFile().getAbsolutePath());
       } catch (Exception e) {
         LOG.write("Error in generating the report");
         LOG.printStackTrace(e);
       }
     }
   } else {
     JOptionPane.showMessageDialog(
         main,
         "No deployment data exists.  \nUse the Deployment Wizard to start a "
             + "new deployment before creating a deployment report.",
         "Could not create report",
         JOptionPane.ERROR_MESSAGE);
   }
 }
 public void popupSaveDataAction() {
   JFileChooser saveChart = new JFileChooser();
   int val = saveChart.showSaveDialog(parent);
   if (val == JFileChooser.APPROVE_OPTION) {
     File file = saveChart.getSelectedFile();
     try {
       BufferedWriter writer = new BufferedWriter(new FileWriter(file));
       writer.write("#Chart data for file : " + currentName + "\n");
       Date now = new Date();
       SimpleDateFormat dateFormatter = new SimpleDateFormat("K:mm a, EEE, MMM d, yyyy");
       writer.write("#Created " + dateFormatter.format(now) + "\n");
       writer.write(
           "#Sliding window data, window size : "
               + windowSizeSpinner.getValue()
               + " window step : "
               + windowStepSpinner.getValue()
               + "\n");
       AbstractSeries data = chart.getSeries(0);
       if (data instanceof XYSeries) {
         XYSeries xyData = (XYSeries) data;
         for (int i = 0; i < data.size(); i++)
           writer.write(xyData.get(i).getX() + ",\t" + xyData.get(i).getY() + "\n");
       } else {
         ErrorWindow.showErrorWindow(
             new IllegalArgumentException(
                 "Cannot write non-xy series data (feature not implemented, yet)"));
       }
       writer.write("\n");
       writer.close();
       logger.info("Wrote data to file : " + file.getAbsolutePath());
     } catch (IOException ioe) {
       logger.warning("Error writing chart data to file : " + ioe.toString());
     }
   }
 }
  private void loadFile() {
    JFileChooser fileChooser = new JFileChooser();

    FileNameExtensionFilter filter =
        new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.setFileFilter(filter);

    if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
      fileChooser.setCurrentDirectory(
          new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
    } else {
      fileChooser.setCurrentDirectory(
          new File(internalBalloon.getBalloonContentPath().getStandardPath()));
    }
    int result = fileChooser.showSaveDialog(getTopLevelAncestor());
    if (result == JFileChooser.CANCEL_OPTION) return;
    try {
      String exportString = fileChooser.getSelectedFile().toString();
      browseText.setText(exportString);
      internalBalloon
          .getBalloonContentPath()
          .setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
      internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
    } catch (Exception e) {
      //
    }
  }
  /*
   * Handle button callbacks
   *
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   *
   */
  @Override
  public void actionPerformed(ActionEvent eventI) {

    Object source = eventI.getSource();

    if (source == null) {
      return;
    } else if (eventI.getActionCommand().equals("Browse...")) {
      // This was for a "Browse" button to locate a directory, but since
      // we're using this for filesystems and FTP, don't bother
      // Code largely taken from http://stackoverflow.com/questions/4779360/browse-for-folder-dialog
      JFileChooser fc = new JFileChooser();
      fc.setCurrentDirectory(new java.io.File("."));
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      int returnVal = fc.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File selectedFolder = fc.getSelectedFile();
        try {
          outputDirTF.setText(selectedFolder.getCanonicalPath());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    } else if (eventI.getActionCommand().equals("OK")) {
      okAction();
    } else if (eventI.getActionCommand().equals("Cancel")) {
      cancelAction();
    }
  }
Beispiel #17
0
  /**
   * Accionado quando se faz clique no botao para criar um ficheiro RFP.
   *
   * <p>Cria um novo ficheiro RFP. Pergunta ao utilizador o caminho onde será guardado o ficheiro.
   * Fecha o ficheiro RFP actual caso exista e faz um reset ao conteudo da tabela, mostrando de
   * seguida o conteudo do novo ficheiro RFP.
   *
   * <p>É lançado uma excepção caso seja impossivel criar o ficheiro na directoria de destino.
   *
   * @param evt
   */
  private void jMenuItem14ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem14ActionPerformed
    try {
      final JFileChooser fc = new JFileChooser();
      int returnVal = fc.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File dir = fc.getCurrentDirectory();
        File file = fc.getSelectedFile();

        if (rfpFile != null && !rfpFile.isClosed()) rfpFile.closeRFP();
        this.resetTable();
        this.resetVariables();

        rfpFile = new RFPBinaryFile(file.getName(), dir.getPath());
        rfpFile.openRFP();
        rfpFile.generateEmptyFile();
        rfpFile.readContents();
        nativePath = dir.getPath();
        this.showRFPContents();
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          null, "Impossivel criar ficheiro rfp.", "Novo Ficheiro RFP", JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jMenuItem14ActionPerformed
 /**
  * Opens a File chooser that lets you choose where to save a file Returns null if no file is
  * chosen.
  *
  * @param title The title for the chooser to display
  * @param defaultDirectory The directory that the chooser is initially viewing
  * @param extensions A String array of the file extensions (without the '.') that you want to be
  *     accepted
  * @return The save file
  */
 public static File chooseSaveLocation(String title, File defaultDirectory, String[] extensions) {
   JFileChooser fc = new JFileChooser(defaultDirectory);
   fc.setDialogTitle(title);
   fc.setFileFilter(new ExtensionFileFilter(extensions)); // Adding the file filter
   fc.showSaveDialog(null);
   return fc.getSelectedFile();
 }
Beispiel #19
0
 @Override
 public void actionPerformed(ActionEvent e) {
   JFileChooser saver = new JFileChooser();
   saver.showSaveDialog(null);
   String saveFile = saver.getSelectedFile().getAbsolutePath();
   download(saveFile);
 }
 /**
  * Saves the current chart as an image in png format. The user can select the filename, and is
  * asked to confirm the overwrite of an existing file.
  */
 public void saveImage() {
   JFileChooser fc = new JFileChooser();
   if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     File f = fc.getSelectedFile();
     if (f.exists()) {
       int ok =
           JOptionPane.showConfirmDialog(
               this,
               KstatResources.getString("SAVEAS.OVERWRITE.TEXT") + " " + f.toString(),
               KstatResources.getString("SAVEAS.CONFIRM.TEXT"),
               JOptionPane.YES_NO_OPTION);
       if (ok != JOptionPane.YES_OPTION) {
         return;
       }
     }
     BufferedImage bi = kbc.getChart().createBufferedImage(500, 300);
     try {
       ImageIO.write(bi, "png", f);
       /*
        * According to the API docs this should throw an IOException
        * on error, but this doesn't seem to be the case. As a result
        * it's necessary to catch exceptions more generally. Even this
        * doesn't work properly, but at least we manage to convey the
        * message to the user that the write failed, even if the
        * error itself isn't handled.
        */
     } catch (Exception ioe) {
       JOptionPane.showMessageDialog(
           this,
           ioe.toString(),
           KstatResources.getString("SAVEAS.ERROR.TEXT"),
           JOptionPane.ERROR_MESSAGE);
     }
   }
 }
  /** Selects a file to use as target for the report processing. */
  protected void performSelectFile() {
    if (fileChooser == null) {
      fileChooser = new JFileChooser();
      final FilesystemFilter filter =
          new FilesystemFilter(
              CSVDataExportDialog.CSV_FILE_EXTENSION,
              getResources().getString("csvexportdialog.csv-file-description")); // $NON-NLS-1$
      fileChooser.addChoosableFileFilter(filter);
      fileChooser.setMultiSelectionEnabled(false);
    }

    fileChooser.setSelectedFile(new File(getFilename()));
    final int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
      final File selFile = fileChooser.getSelectedFile();
      String selFileName = selFile.getAbsolutePath();

      // Test if ends on csv
      if (StringUtils.endsWithIgnoreCase(selFileName, CSVDataExportDialog.CSV_FILE_EXTENSION)
          == false) {
        selFileName = selFileName + CSVDataExportDialog.CSV_FILE_EXTENSION;
      }
      setFilename(selFileName);
    }
  }
  /**
   * Actions-handling method.
   *
   * @param e The event.
   */
  public void actionPerformed(ActionEvent e) {
    // Prepares the file chooser
    JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(idata.getInstallPath()));
    fc.setMultiSelectionEnabled(false);
    fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
    // fc.setCurrentDirectory(new File("."));

    // Shows it
    try {
      if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // We handle the xml data writing
        File file = fc.getSelectedFile();
        FileOutputStream out = new FileOutputStream(file);
        BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120);
        parent.writeXMLTree(idata.xmlData, outBuff);
        outBuff.flush();
        outBuff.close();

        autoButton.setEnabled(false);
      }
    } catch (Exception err) {
      err.printStackTrace();
      JOptionPane.showMessageDialog(
          this,
          err.toString(),
          parent.langpack.getString("installer.error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
  public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(FileChooserDemo.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        log.append("Opening: " + file.getName() + "." + newline);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      int returnVal = fc.showSaveDialog(FileChooserDemo.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would save the file.
        log.append("Saving: " + file.getName() + "." + newline);
      } else {
        log.append("Save command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
    }
  }
Beispiel #24
0
 private void saveBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == binFilter && !binFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + binFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       FileOutputStream output = new FileOutputStream(file);
       for (char i : binary) {
         output.write(i & 0xff);
         output.write((i >> 8) & 0xff);
       }
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
  protected void save(String text) {
    String title = "Save " + textType + " File";
    TextFileFilter fileFilter = getTextFileFilter(textType);
    chooser.setFileFilter(fileFilter);

    if (chooser.showSaveDialog(editor.getFrame()) == JFileChooser.APPROVE_OPTION) {
      String name = chooser.getSelectedFile().toString();
      if (!name.endsWith(fileFilter.getExtension())) {
        name = name + "." + fileFilter.getExtension();
      }
      try {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        FileOutputStream fos = new FileOutputStream(new File(name));
        fos.write(text.getBytes());
        fos.close();
        JOptionPane.showMessageDialog(
            editor.getFrame(),
            textType + " saved successfully to " + name,
            title,
            JOptionPane.INFORMATION_MESSAGE);
      } catch (Exception ex) {
        Logger.getLogger(FileMenuAction.class.getName()).log(Level.SEVERE, null, ex);
        ExceptionHandler.handleException(ex);
        return;
      } finally {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
    }
  }
Beispiel #26
0
 private void saveSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       PrintStream output = new PrintStream(file);
       output.print(sourceTextarea.getText());
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
  private void saveStyle() {
    if (_openedDocument == null) return;

    _openedDocument.putContents(_editorPane.getText());

    try {
      if (!_openedDocument.isSaved()) {
        JFileChooser fileChooser = new JFileChooser();
        int result = fileChooser.showSaveDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
          File f = fileChooser.getSelectedFile();
          String path = f.getAbsolutePath();

          _openedDocument.saveStyle(path);
          refreshUI();
        }
      } else {
        _openedDocument.saveStyle();
        refreshUI();
      }

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e.toString(), "Error while saving style", JOptionPane.ERROR_MESSAGE);
    }
  }
 public void stopRender() throws Exception {
   if (renderThread != null) {
     if (doRecordCBx.isSelected()) {
       actionRecorder.recordStop();
     }
     renderThread.setForceAbort(true);
     if (doRecordCBx.isSelected()) {
       JFileChooser chooser = new FlameFileChooser(prefs);
       if (prefs.getOutputFlamePath() != null) {
         try {
           chooser.setCurrentDirectory(new File(prefs.getOutputFlamePath()));
         } catch (Exception ex) {
           ex.printStackTrace();
         }
       }
       if (chooser.showSaveDialog(flameRootPanel) == JFileChooser.APPROVE_OPTION) {
         File file = chooser.getSelectedFile();
         prefs.setLastOutputFlameFile(file);
         PostRecordFlameGenerator generator =
             new PostRecordFlameGenerator(
                 Prefs.getPrefs(), project, actionRecorder, renderThread, project.getFFT());
         generator.createRecordedFlameFiles(file.getAbsolutePath());
       }
     }
     renderThread = null;
     actionRecorder = null;
   }
 }
Beispiel #29
0
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
  public void constructDialog() {
    sim.disableGUIComponents();

    String fileEnding = ".guiConf";
    if (dataFileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
      try {
        chosenFile = dataFileChooser.getSelectedFile();

        String filename = chosenFile.getName();

        if (!filename.endsWith(fileEnding)) {
          filename = filename.concat(fileEnding);

          if (!chosenFile.getName().equals(filename)) {
            File newChosenFile = new File(chosenFile.getParent(), filename);

            chosenFile = newChosenFile;
          }
        }

        Writer output = null;

        output = new BufferedWriter(new FileWriter(chosenFile));
        output.write(writeGUIConfig());

        output.close();
        System.out.println("Your file has been written");
      } catch (Exception e) {
        System.err.println("Error While Writting/Saving Gui Configuration File");
        e.printStackTrace();
      }
    }

    sim.enableGUIComponents();
  }