Exemplo n.º 1
0
  /**
   * Use a JFileChooser in Save mode to select files to open. Use a filter for FileFilter subclass
   * to select for "*.java" files. If a file is selected, then this file will be used as final
   * output
   */
  boolean saveFile() {
    File file = null;
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(fJavaFilter);

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
      return true;
    } else if (result == JFileChooser.APPROVE_OPTION) {
      fFile = fc.getSelectedFile();
      String textFile = fFile.toString();
      if (fileNo.equalsIgnoreCase("SAVE")) {
        UpLoadFile.outputfile.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("SAVE2")) {
        UpLoadMAGEMLFile.outputfile1.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("SAVE3")) {
        UpLoadMAGEMLFile.outputfile2.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("SAVEJPAG")) {
        JPEGFileName = textFile;
        // System.out.println ("JPG filename OpenFileDir= " +JPEGFileName);
        File fFile = new File(JPEGFileName);
        if (fFile.exists()) {
          int response =
              JOptionPane.showConfirmDialog(
                  null,
                  "Overwrite existing file " + JPEGFileName + " ??",
                  "Confirm Overwrite",
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.QUESTION_MESSAGE);
          if (response == JOptionPane.CANCEL_OPTION) {
            /* go back to reload the file*/
            return false;
          }
        }
        SetUpPlotWindow.saveComponentAsJPEG(SetUpPlotWindow.content, JPEGFileName);
      }
      return true;

    } else {
      return false;
    }
  } // saveFile
Exemplo n.º 2
0
  /*
   * This function just finds and loads the file
   */
  private boolean loadFile() {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Load File");

    // Choose only files, not directories
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(fJavaFilter);

    // Now open chooser
    int result = fc.showOpenDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
      // return true;
    } else if (result == JFileChooser.APPROVE_OPTION) {

      fFile = fc.getSelectedFile();
      String textFile = fFile.toString();

      if (fileNo.equalsIgnoreCase("LOAD1")) {
        UpLoadFile.filePath1.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD2")) {
        UpLoadFile.filePath2.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD3")) {
        VisualizationInput.originalFilePath.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD4")) {
        VisualizationInput.DWDVecFilePath.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD5")) {
        VisualizationInput.DWDOutputFilePath.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD6")) {
        UpLoadMAGEMLFile.filePath1.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD7")) {
        UpLoadMAGEMLFile.filePath2.setText(textFile);
      }

      // Get the absolute path for the file being opened
      filePath = fFile.getAbsolutePath();

      if (filePath == null) {
        // fTextField.setText (filePath);
        return false;
      }

    } else {
      return false;
    }
    return true;
  } /*End of loadFile*/