Пример #1
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;
  }
Пример #2
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();
   }
 }
Пример #3
0
 public void saveAs(ActionEvent e) {
   int returnVal = fc.showSaveDialog(this);
   if (returnVal != JFileChooser.APPROVE_OPTION) {
     return;
   }
   file = fc.getSelectedFile();
   save(e);
 }
Пример #4
0
 private void saveAs() {
   if (saveFC == null) {
     saveFC = new SaveDataFileChooser();
   }
   int ret = saveFC.showSaveDialog(this);
   if (ret == JFileChooser.APPROVE_OPTION) {
     saveDataToFile(saveFC.getSelectedFile());
   }
 }
    public void actionPerformed(ActionEvent a) {
      QuizCard card = new QuizCard(question.getText(), answer.getText());
      cardList.add(card);
      clearCard();

      JFileChooser fileSave = new JFileChooser();
      fileSave.showSaveDialog(frame);
      saveFile(fileSave.getSelectedFile());
    }
Пример #6
0
  public Path dateiAuswählen(Path neuesLaufwerk) {
    JFileChooser fc1 = new JFileChooser();
    fc1.setDialogTitle("SyncOrdner auswählen");
    fc1.setCurrentDirectory(neuesLaufwerk.toFile());
    fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
      return fc1.getSelectedFile().toPath();
    else return null;
  }
Пример #7
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
Пример #8
0
 protected void fileSaveXML() {
   JFileChooser chooser = null;
   if (currentFile == null) {
     chooser = new JFileChooser(startDirectory);
   } else {
     chooser = new JFileChooser(currentFile);
   }
   int returnVal = chooser.showSaveDialog(gw);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     currentFile = chooser.getSelectedFile();
     generalXML.saveGraph(currentFile);
   }
 }
Пример #9
0
 @SuppressWarnings("unchecked")
 private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {
   toggle(false);
   JFileChooser fc = new JFileChooser();
   String path =
       FileUtils.getUserDirectoryPath() + File.separator + treeViewNode.getText() + ".csv";
   fc.setSelectedFile(new File(path));
   fc.showSaveDialog(this);
   File target = fc.getSelectedFile();
   int row = model.getRowCount();
   try {
     boolean written;
     try (FileOutputStream fos = new FileOutputStream(target)) {
       while (--row > -1) {
         Vector v = (Vector) model.getDataVector().get(row);
         for (int i = 0; i < v.size(); i++) {
           if (v.get(i).toString().contains(",")) {
             v.set(i, ST.format("\"<%1>\"", v.get(i)));
           }
         }
         String line = ST.format("<%1:{ x |, <x>}>", v).substring(2);
         fos.write(line.getBytes(CHARSET));
         fos.write(Character.LINE_SEPARATOR);
       }
       written = true;
     }
     if (written) {
       LogEmitter.factory
           .get()
           .emit(
               this,
               Core.ALERT.INFO,
               ST.format("<%1> hosts written to <%2>", model.getRowCount(), target.getPath()));
     } else {
       LogEmitter.factory
           .get()
           .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
     }
   } catch (FileNotFoundException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   } catch (IOException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   }
   toggle(true);
 }
Пример #10
0
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showSaveDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      frame.setTitle(f.getName());
      Thread saver = new FileSaver(f, editor.getDocument());
      saver.start();
    }
Пример #11
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == save) {
     JFileChooser c = new JFileChooser(ResourceFactory.getRootDir());
     c.setDialogTitle("Save result");
     if (c.showSaveDialog(resultFrame) == JFileChooser.APPROVE_OPTION) {
       File output = c.getSelectedFile();
       if (output.exists()) {
         String[] options = {"Overwrite", "Cancel"};
         if (JOptionPane.showOptionDialog(
                 resultFrame,
                 output + "exists. Overwrite?",
                 "Save result",
                 JOptionPane.YES_NO_OPTION,
                 JOptionPane.WARNING_MESSAGE,
                 null,
                 options,
                 options[0])
             == 1) return;
       }
       try {
         PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(output)));
         w.println("Searched for unused strings");
         w.println("Number of hits: " + table.getRowCount());
         w.println("");
         for (int i = 0; i < table.getRowCount(); i++) {
           w.println(
               "StringRef: "
                   + table.getTableItemAt(i).getObjectAt(1)
                   + " /* "
                   + table
                       .getTableItemAt(i)
                       .toString()
                       .replaceAll("\r\n", System.getProperty("line.separator"))
                   + " */");
         }
         w.close();
         JOptionPane.showMessageDialog(
             resultFrame,
             "Result saved to " + output,
             "Save complete",
             JOptionPane.INFORMATION_MESSAGE);
       } catch (IOException ex) {
         JOptionPane.showMessageDialog(
             resultFrame, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE);
         ex.printStackTrace();
       }
     }
   }
 }
Пример #12
0
 public void saveFileAs() {
   // Force user to enter new file name
   if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = fileChooser.getSelectedFile();
   } else {
     // user cancelled save after all
     return;
   }
   // file selected, so write it.
   physWriteTextFile(file, textView.getText());
   // update status
   statusView.setText(" Saved file \"" + file.getName() + "\".");
   // reset dirty bit
   dirty = false;
 }
Пример #13
0
  /** Shows a file dialog and saves drawing. */
  public void promptSaveAs() {
    toolDone();
    JFileChooser saveDialog = createSaveFileChooser();
    getStorageFormatManager().registerFileFilters(saveDialog);

    if (saveDialog.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
      StorageFormat foundFormat =
          getStorageFormatManager().findStorageFormat(saveDialog.getFileFilter());
      if (foundFormat != null) {
        saveDrawing(foundFormat, saveDialog.getSelectedFile().getAbsolutePath());
      } else {
        showStatus("Not a valid file format: " + saveDialog.getFileFilter().getDescription());
      }
    }
  }
Пример #14
0
 protected void fileSaveSimple() {
   JFileChooser chooser = null;
   if (currentFile == null) {
     chooser = new JFileChooser(startDirectory);
   } else {
     chooser = new JFileChooser(currentFile);
     if (!currentFile.isDirectory()) {
       chooser.setSelectedFile(currentFile);
     }
   }
   int returnVal = chooser.showSaveDialog(gw);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     currentFile = chooser.getSelectedFile();
     graph.saveSimple(currentFile);
   }
 }
  private void jMenuItemSaveLSAResultsActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemSaveLSAResultsActionPerformed
    if (this.currentResults != null) {
      JFileChooser jfc = new JFileChooser();
      int fileDialogReturnVal = jfc.showSaveDialog(this);

      if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
        try {
          File outputFile = jfc.getSelectedFile();
          FileOutputStream fos = new FileOutputStream(outputFile);
          ObjectOutputStream oos = new ObjectOutputStream(fos);

          oos.writeObject(this.currentResults);
        } catch (IOException e) {
          System.out.println("IOexception");
          System.out.println(e.getMessage());
        }
      }
    }
  } // GEN-LAST:event_jMenuItemSaveLSAResultsActionPerformed
Пример #16
0
  /**
   * @todo this is reduced code from the image export in the ToscanaJMainPanel. Extract the full
   *     code into a new object, and use it here.
   */
  protected void exportImages() {
    disableStepControls();

    final JFileChooser saveDialog = new JFileChooser(this.lastImageExportFile);
    boolean formatDefined;
    do {
      formatDefined = true;
      final int rv = saveDialog.showSaveDialog(this);
      if (rv == JFileChooser.APPROVE_OPTION) {
        final File selectedFile = saveDialog.getSelectedFile();
        final GraphicFormat format = GraphicFormatRegistry.getTypeByExtension(selectedFile);
        if (format != null) {
          this.diagramExportSettings.setGraphicFormat(format);
        } else {
          if (selectedFile.getName().indexOf('.') != -1) {
            JOptionPane.showMessageDialog(
                this,
                "Sorry, no type with this extension known.\n"
                    + "Please use either another extension or try\n"
                    + "manual settings.",
                "Export failed",
                JOptionPane.ERROR_MESSAGE);
          } else {
            JOptionPane.showMessageDialog(
                this,
                "No extension given.\n"
                    + "Please give an extension or pick a file type\n"
                    + "from the options.",
                "Export failed",
                JOptionPane.ERROR_MESSAGE);
          }
          formatDefined = false;
        }

        if (formatDefined) {
          exportImages(selectedFile);
        }
      }
    } while (!formatDefined);
  }
  private void jMenuItemSaveProjectActionPerformed(
      java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemSaveProjectActionPerformed
      { // GEN-HEADEREND:event_jMenuItemSaveProjectActionPerformed
    if (this.theProject != null) {
      JFileChooser jfc = new JFileChooser();
      int fileDialogReturnVal = jfc.showSaveDialog(this);

      if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
        try {
          File outputFile = jfc.getSelectedFile();
          FileOutputStream fos = new FileOutputStream(outputFile);
          ObjectOutputStream oos = new ObjectOutputStream(fos);

          oos.writeObject(this.theProject);
          if (this.currentResults != null) {
            oos.writeObject(this.currentResults);
          }
        } catch (IOException e) {
          log.log(Log.ERROR, "Failed to save file\n" + e.getMessage());
        }
      }
    }
  } // GEN-LAST:event_jMenuItemSaveProjectActionPerformed
Пример #18
0
  // Saves the open project to a new file selected by the user
  public boolean saveFileAs() {
    // Filter the file chooser by Cue Masher files
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new CueFileFilter());

    // Display the existing file location by default if it exists
    String filePath = soundManager.getProjectFilePath();
    if (filePath != null) {
      File openProjectFile = new File(filePath);
      fileChooser.setSelectedFile(openProjectFile);
    }

    int choice = fileChooser.showSaveDialog(CueMasherPanel.this);
    if (choice == JFileChooser.APPROVE_OPTION) {
      // Get the name of the file the user selected
      File file = fileChooser.getSelectedFile();
      filePath = file.getAbsolutePath().trim();

      // Make sure that it has a Cue Masher file extension
      String cueMasherExt = CueFileFilter.CUE_MASHER_FILE_EXT;
      boolean addExt = false;
      if (filePath.length() < cueMasherExt.length()) addExt = true;
      else {
        String ext =
            filePath.substring(filePath.length() - cueMasherExt.length(), filePath.length());
        if (!ext.equalsIgnoreCase(cueMasherExt)) addExt = true;
      }

      // Add the cue masher file extension if it doesn't exist
      if (addExt) filePath = filePath + cueMasherExt;

      // Save the project to the selected file
      soundManager.setProjectFilePath(filePath);
      return soundManager.saveFile();
    }
    return false;
  }
  private ObjectOutputStream getObjectOutputStream() {
    File f = new File(".");
    String loadDirectory = f.getAbsolutePath();

    JFileChooser chooser = new JFileChooser(loadDirectory);
    chooser.setDialogTitle("Save Generation File As...");
    chooser.setMultiSelectionEnabled(false);

    int result = chooser.showSaveDialog(this);
    File selectedFile = chooser.getSelectedFile();

    if (result == JFileChooser.APPROVE_OPTION) {
      try {
        FileOutputStream fileStream = new FileOutputStream(selectedFile.getPath());
        ObjectOutputStream objectStream = new ObjectOutputStream(fileStream);

        return objectStream;
      } catch (IOException e) {
        System.err.println(e);
      }
    }

    return null;
  }
Пример #20
0
  /** @return true if file was saved, false if user canceled */
  boolean onSaveAsFileClicked() {
    try {

      JFileChooser fc = new JFileChooser();
      FileNameExtensionFilter filter1 =
          new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION);
      fc.setFileFilter(filter1);
      int rv = fc.showSaveDialog(this);

      if (rv == JFileChooser.APPROVE_OPTION) {
        currentFile = fc.getSelectedFile();
        if (!currentFile.getName().endsWith("." + EXTENSION)) {
          currentFile = new File(currentFile.getPath() + "." + EXTENSION);
        }
        doSave(currentFile);
        refresh();
        return true;
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE);
    }
    return false;
  }
  public void actionPerformed(ActionEvent ev) {

    String s = ev.getActionCommand();

    if (s == null) {
      if (ev.getSource() instanceof JMenuItem) {
        JMenuItem i;

        s = ((JMenuItem) ev.getSource()).getText();
      }
    }

    /*
    // button replace by toolbar
            if (s.equals("Execute")) {
                execute();
            } else
    */
    if (s.equals("Exit")) {
      windowClosing(null);
    } else if (s.equals("Transfer")) {
      Transfer.work(null);
    } else if (s.equals("Dump")) {
      Transfer.work(new String[] {"-d"});
    } else if (s.equals("Restore")) {
      Transfer.work(new String[] {"-r"});
    } else if (s.equals("Logging on")) {
      javaSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
      javaSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
      refreshTree();
    } else if (s.startsWith("#")) {
      int i = Integer.parseInt(s.substring(1));

      txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
      connect(ConnectionDialogSwing.createConnection(fMain, "Connect"));
      refreshTree();
    } else if (s.equals("Results in Grid")) {
      iResult = 0;

      pResult.removeAll();
      pResult.add(gScrollPane, BorderLayout.CENTER);
      pResult.doLayout();
      gResult.fireTableChanged(null);
      pResult.repaint();
    } else if (s.equals("Open Script...")) {
      JFileChooser f = new JFileChooser(".");

      f.setDialogTitle("Open Script...");

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setCurrentDirectory(new File(defDirectory));
      }

      int option = f.showOpenDialog(fMain);

      if (option == JFileChooser.APPROVE_OPTION) {
        File file = f.getSelectedFile();

        if (file != null) {
          StringBuffer buf = new StringBuffer();

          ifHuge = DatabaseManagerCommon.readFile(file.getAbsolutePath());

          if (4096 <= ifHuge.length()) {
            buf.append("This huge file cannot be edited. Please execute\n");
            txtCommand.setText(buf.toString());
          } else {
            txtCommand.setText(ifHuge);
          }
        }
      }
    } else if (s.equals("Save Script...")) {
      JFileChooser f = new JFileChooser(".");

      f.setDialogTitle("Save Script");

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setCurrentDirectory(new File(defDirectory));
      }

      int option = f.showSaveDialog(fMain);

      if (option == JFileChooser.APPROVE_OPTION) {
        File file = f.getSelectedFile();

        if (file != null) {
          DatabaseManagerCommon.writeFile(file.getAbsolutePath(), txtCommand.getText());
        }
      }
    } else if (s.equals("Save Result...")) {
      JFileChooser f = new JFileChooser(".");

      f.setDialogTitle("Save Result...");

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setCurrentDirectory(new File(defDirectory));
      }

      int option = f.showSaveDialog(fMain);

      if (option == JFileChooser.APPROVE_OPTION) {
        File file = f.getSelectedFile();

        if (file != null) {
          showResultInText();
          DatabaseManagerCommon.writeFile(file.getAbsolutePath(), txtResult.getText());
        }
      }
    } else if (s.equals("Results in Text")) {
      iResult = 1;

      pResult.removeAll();
      pResult.add(txtResultScroll, BorderLayout.CENTER);
      pResult.doLayout();
      showResultInText();
      pResult.repaint();
    } else if (s.equals("AutoCommit on")) {
      try {
        cConn.setAutoCommit(true);
      } catch (SQLException e) {
      }
    } else if (s.equals("AutoCommit off")) {
      try {
        cConn.setAutoCommit(false);
      } catch (SQLException e) {
      }
    } else if (s.equals("Commit")) {
      try {
        cConn.commit();
      } catch (SQLException e) {
      }
    } else if (s.equals("Insert test data")) {
      insertTestData();
    } else if (s.equals("Rollback")) {
      try {
        cConn.rollback();
      } catch (SQLException e) {
      }
    } else if (s.equals("Disable MaxRows")) {
      try {
        sStatement.setMaxRows(0);
      } catch (SQLException e) {
      }
    } else if (s.equals("Set MaxRows to 100")) {
      try {
        sStatement.setMaxRows(100);
      } catch (SQLException e) {
      }
    } else if (s.equals("SELECT")) {
      showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
      showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
      showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
      showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
      showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
      showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
      showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
      showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
      showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
      showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
      showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
      showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
      showHelp(DatabaseManagerCommon.testHelp);
    }
  }
Пример #22
0
 public void saveUnsaved() throws SaveAbortedException {
   if (!saved) {
     int option = 0;
     if (loadedFile == null)
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to UNTITLED?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     else
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to " + loadedFile.getName() + "?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) {
       if (loadedFile == null) // SAVE NEW FILE
       {
         if (nameTF.getText().equals("")) {
           JOptionPane.showMessageDialog(
               this,
               new JLabel("Please type in the Scale Name"),
               "Warning",
               JOptionPane.WARNING_MESSAGE);
           throw new SaveAbortedException();
         }
         fileChooser.setFileFilter(filter);
         int option2 = fileChooser.showSaveDialog(this);
         if (option2 == JFileChooser.APPROVE_OPTION) {
           File target = fileChooser.getSelectedFile();
           try {
             PrintStream stream = new PrintStream(new FileOutputStream(target), true);
             save(stream);
             stream.close();
           } catch (Exception ex) {
             JOptionPane.showMessageDialog(
                 this,
                 new JLabel("Error: " + ex.getMessage()),
                 "Error",
                 JOptionPane.ERROR_MESSAGE);
           }
         } else throw new SaveAbortedException();
         ;
       } else // save LOADED FILE
       {
         try {
           PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true);
           save(stream);
           stream.close();
         } catch (Exception ex) {
           JOptionPane.showMessageDialog(
               this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
         }
       }
     } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException();
     ;
   }
 }
Пример #23
0
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }