Search in sources :

Example 1 with FileChooserManager

use of blue.ui.utilities.FileChooserManager in project blue by kunstmusik.

the class FrozenSoundObjectEditor method saveCopy.

protected void saveCopy() {
    File f = BlueSystem.findFile(fso.getFrozenWaveFileName());
    if (f == null) {
        NotifyDescriptor descriptor = new NotifyDescriptor.Message("Could not locate frozen file:\n\n" + fso.getFrozenWaveFileName(), NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(descriptor);
        return;
    }
    final FileChooserManager fcm = FileChooserManager.getDefault();
    fcm.setCurrentDirectory(this, BlueSystem.getCurrentProjectDirectory());
    File retVal = fcm.showSaveDialog(this, WindowManager.getDefault().getMainWindow());
    if (retVal != null) {
        File dest = retVal;
        if (dest.exists()) {
            if (dest.isDirectory()) {
                NotifyDescriptor descriptor = new NotifyDescriptor.Message("Destination is a directory.", NotifyDescriptor.ERROR_MESSAGE);
                DialogDisplayer.getDefault().notify(descriptor);
                return;
            }
            if (dest.getName().startsWith("freeze")) {
                NotifyDescriptor descriptor = new NotifyDescriptor.Message("Can not overwrite freeze files.", NotifyDescriptor.ERROR_MESSAGE);
                DialogDisplayer.getDefault().notify(descriptor);
                return;
            }
            NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation("Overwrite file " + dest.getName() + "?", NotifyDescriptor.OK_CANCEL_OPTION);
            Object conf = DialogDisplayer.getDefault().notify(descriptor);
            if (!NotifyDescriptor.OK_OPTION.equals(conf)) {
                return;
            }
        }
        try {
            FileUtilities.copyFile(f, dest);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) FileChooserManager(blue.ui.utilities.FileChooserManager) FrozenSoundObject(blue.soundObject.FrozenSoundObject) ScoreObject(blue.score.ScoreObject) IOException(java.io.IOException) File(java.io.File)

Example 2 with FileChooserManager

use of blue.ui.utilities.FileChooserManager in project blue by kunstmusik.

the class ScannedMatrixEditor method saveMatrix.

public void saveMatrix() {
    if (matrixGridEditor.matrix == null) {
        return;
    }
    final FileChooserManager fcm = FileChooserManager.getDefault();
    File rValue = fcm.showSaveDialog(FILE_SAVE, null);
    if (rValue != null) {
        try {
            File temp = rValue;
            try (PrintWriter out = new PrintWriter(new FileWriter(temp))) {
                int val = 0;
                for (int i = 0; i < matrixGridEditor.matrix.length; i++) {
                    val = matrixGridEditor.matrix[i] ? 1 : 0;
                    out.write(val + "\n");
                }
                out.flush();
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, BlueSystem.getString("message.saveError.message"), BlueSystem.getString("message.saveError.title"), JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileChooserManager(blue.ui.utilities.FileChooserManager) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 3 with FileChooserManager

use of blue.ui.utilities.FileChooserManager in project blue by kunstmusik.

the class TrackEditor method initScaleFileSelector.

// GEN-LAST:event_addColumnButtonActionPerformed
private void initScaleFileSelector() {
    final FileChooserManager fcm = FileChooserManager.getDefault();
    if (fcm.isDialogDefined(FILE_CHOOSER_ID)) {
        return;
    }
    fcm.setDialogTitle(FILE_CHOOSER_ID, BlueSystem.getString("pianoRoll.selectScalaFile"));
    fcm.addFilter(FILE_CHOOSER_ID, new ExtensionFilter("Scala File (*.scl)", "*.scl"));
    // SET DEFAULT DIR
    String fileName = BlueSystem.getUserConfigurationDirectory();
    fileName += File.separator + "scl";
    File defaultDir = new File(fileName);
    if (defaultDir.exists() && defaultDir.isDirectory()) {
        fcm.setSelectedFile(FILE_CHOOSER_ID, defaultDir);
    }
}
Also used : ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) FileChooserManager(blue.ui.utilities.FileChooserManager) File(java.io.File)

Example 4 with FileChooserManager

use of blue.ui.utilities.FileChooserManager in project blue by kunstmusik.

the class ScaleSelectionPanel method initScaleFileSelector.

private void initScaleFileSelector() {
    final FileChooserManager fcm = FileChooserManager.getDefault();
    if (fcm.isDialogDefined(FILE_CHOOSER_ID)) {
        return;
    }
    fcm.setDialogTitle(FILE_CHOOSER_ID, BlueSystem.getString("pianoRoll.selectScalaFile"));
    fcm.addFilter(FILE_CHOOSER_ID, new ExtensionFilter("Scala File (*.scl)", "*.scl"));
    // SET DEFAULT DIR
    String fileName = BlueSystem.getUserConfigurationDirectory();
    fileName += File.separator + "scl";
    File defaultDir = new File(fileName);
    if (defaultDir.exists() && defaultDir.isDirectory()) {
        fcm.setSelectedFile(FILE_CHOOSER_ID, defaultDir);
    }
}
Also used : ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) FileChooserManager(blue.ui.utilities.FileChooserManager) File(java.io.File)

Example 5 with FileChooserManager

use of blue.ui.utilities.FileChooserManager in project blue by kunstmusik.

the class BlueProjectManager method saveAs.

public boolean saveAs() {
    FileChooserManager fcm = FileChooserManager.getDefault();
    if (getCurrentProject().getDataFile() != null) {
        fcm.setSelectedFile(this.getClass(), getCurrentProject().getDataFile());
    } else {
        fcm.setSelectedFile(this.getClass(), new File(GeneralSettings.getInstance().getDefaultDirectory() + File.separator + "default.blue"));
    }
    File rValue = fcm.showSaveDialog(this.getClass(), WindowManager.getDefault().getMainWindow());
    if (rValue != null) {
        File temp = rValue;
        if (!(temp.getName().trim().endsWith(".blue"))) {
            temp = new File(temp.getAbsolutePath() + ".blue");
        }
        if (temp.exists()) {
            NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation("Are you sure you would like to overwite the project file: " + temp.getAbsolutePath(), "Overwrite Project?");
            Object retVal = DialogDisplayer.getDefault().notify(descriptor);
            if (retVal != NotifyDescriptor.YES_OPTION) {
                return false;
            }
        }
        if (getCurrentProject().isOpenedFromTempFile()) {
            getCurrentProject().getTempFile().delete();
            getCurrentProject().setOpenedFromTempFile(false);
        }
        try (PrintWriter out = new PrintWriter(new FileWriter(temp))) {
            BlueData data = getCurrentProject().getData();
            out.print(data.saveAsXML().toString());
            out.flush();
        } catch (Exception e) {
            NotifyDescriptor descriptor = new NotifyDescriptor.Message("Could not save file:\n\n" + e.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notify(descriptor);
        }
        StatusDisplayer.getDefault().setStatusText("File saved: " + temp.getName());
        // ProgramOptions.addRecentFile(temp);
        // blueMenuBar.resetRecentFiles();
        // ProgramOptions.save();
        // 
        RecentProjectsList.getInstance().addFile(temp.getAbsolutePath());
        // fileName = temp;
        getCurrentProject().setDataFile(temp);
        BlueSystem.setCurrentProjectDirectory(temp.getParentFile());
        temp = null;
        fireProjectFileChanged();
        // setRevertEnabled();
        return true;
    // }
    // else if (rValue == JFileChooser.CANCEL_OPTION) {
    // StatusBar.updateStatus(BlueSystem.getString(
    // "message.actionCancelled"));
    // return false;
    } else {
        return false;
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) BlueData(blue.BlueData) FileWriter(java.io.FileWriter) FileChooserManager(blue.ui.utilities.FileChooserManager) PolyObject(blue.soundObject.PolyObject) File(java.io.File) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

FileChooserManager (blue.ui.utilities.FileChooserManager)7 File (java.io.File)7 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 ExtensionFilter (javafx.stage.FileChooser.ExtensionFilter)2 NotifyDescriptor (org.openide.NotifyDescriptor)2 BlueData (blue.BlueData)1 ScoreObject (blue.score.ScoreObject)1 AudioFile (blue.soundObject.AudioFile)1 FrozenSoundObject (blue.soundObject.FrozenSoundObject)1 PolyObject (blue.soundObject.PolyObject)1