<commit_before>//----------------------------------------------------------------------------//
//                                                                            //
//                          S c o r e M a n a g e r                           //
//                                                                            //
//  Copyright (C) <NAME> 2000-2007. All rights reserved.               //
//  This software is released under the GNU General Public License.           //
//  Contact author at <EMAIL> to report bugs & suggestions. //
//----------------------------------------------------------------------------//
//
package omr.score;

import omr.Main;

import omr.score.visitor.ScoreExporter;

import omr.script.ExportTask;

import omr.ui.util.FileFilter;

import omr.util.Logger;

import java.io.*;
import java.util.*;

import javax.swing.JFileChooser;
import javax.swing.event.*;

/**
 * Class <code>ScoreManager</code> handles a collection of score instances.
 *
 * @author <NAME>
 * @version $Id$
 */
public class ScoreManager
{
    //~ Static fields/initializers ---------------------------------------------

    /** Usual logger utility */
    private static final Logger logger = Logger.getLogger(ScoreManager.class);

    /** The extension used for score output files: {@value} */
    public static final String SCORE_EXTENSION = ".xml";

    /** The single instance of this class */
    private static ScoreManager INSTANCE;

    //~ Constructors -----------------------------------------------------------

    //--------------//
    // ScoreManager //
    //--------------//
    /**
     * Creates a Score Manager.
     */
    private ScoreManager ()
    {
    }

    //~ Methods ----------------------------------------------------------------

    //-------------//
    // getInstance //
    //-------------//
    /**
     * Report the single instance of this class,
     *
     * @return the single instance
     */
    public static ScoreManager getInstance ()
    {
        if (INSTANCE == null) {
            INSTANCE = new ScoreManager();
        }

        return INSTANCE;
    }

    //--------//
    // export //
    //--------//
    /**
     * Export a score using the partwise structure of MusicXML, using the
     * default file for the provided score
     *
     * @param score the score to export
     */
    public void export (Score score)
    {
        export(score, null);
    }

    //--------//
    // export //
    //--------//
    /**
     * Export a score using the partwise structure of MusicXML to the provided
     * file
     *
     * @param score the score to export
     * @param xmlFile the xml file to write, or null
     */
    public void export (Score score,
                        File  xmlFile)
    {
        // Where do we write the score xml file?
        if (xmlFile == null) {
            xmlFile = new File(
                Main.getOutputFolder(),
                score.getRadix() + SCORE_EXTENSION);

            // Ask user confirmation, if Gui available
            if (Main.getGui() != null) {
                // Let the user select a score output file
                JFileChooser fc = new JFileChooser(Main.getOutputFolder());
                fc.addChoosableFileFilter(
                    new FileFilter(
                        "XML files",
                        new String[] { SCORE_EXTENSION }));
                fc.setSelectedFile(xmlFile);

                // Let the user play with the dialog
                int res = fc.showSaveDialog(Main.getGui().getFrame());

                if (res == JFileChooser.APPROVE_OPTION) {
                    xmlFile = fc.getSelectedFile();

                    // Remember (even across runs) the selected directory
                    Main.setOutputFolder(xmlFile.getParent());
                } else {
                    return;
                }
            }
        }

        if (xmlFile != null) {
            // Make sure the folder exists
            File folder = new File(xmlFile.getParent());

            if (folder.mkdirs()) {
                logger.info("Creating folder " + folder);
            }

            // Record this task in the sheet script
            score.getSheet()
                 .getScript()
                 .addTask(new ExportTask(xmlFile.getPath()));

            // Actually export the score material
            new ScoreExporter(score, xmlFile);
        }
    }
}<commit_msg>Native file chooser<commit_after>//----------------------------------------------------------------------------//
//                                                                            //
//                          S c o r e M a n a g e r                           //
//                                                                            //
//  Copyright (C) <NAME> 2000-2007. All rights reserved.               //
//  This software is released under the GNU General Public License.           //
//  Contact author at <EMAIL> to report bugs & suggestions. //
//----------------------------------------------------------------------------//
//
package omr.score;

import omr.Main;

import omr.score.visitor.ScoreExporter;

import omr.script.ExportTask;

import omr.ui.util.FileFilter;
import omr.ui.util.UIUtilities;

import omr.util.Logger;

import java.io.*;

/**
 * Class <code>ScoreManager</code> handles a collection of score instances.
 *
 * @author <NAME> and <NAME>
 * @version $Id$
 */
public class ScoreManager
{
    //~ Static fields/initializers ---------------------------------------------

    /** Usual logger utility */
    private static final Logger logger = Logger.getLogger(ScoreManager.class);

    /** The extension used for score output files: {@value} */
    public static final String SCORE_EXTENSION = ".xml";

    /** The single instance of this class */
    private static ScoreManager INSTANCE;

    //~ Constructors -----------------------------------------------------------

    //--------------//
    // ScoreManager //
    //--------------//
    /**
     * Creates a Score Manager.
     */
    private ScoreManager ()
    {
    }

    //~ Methods ----------------------------------------------------------------

    //-------------//
    // getInstance //
    //-------------//
    /**
     * Report the single instance of this class,
     *
     * @return the single instance
     */
    public static ScoreManager getInstance ()
    {
        if (INSTANCE == null) {
            INSTANCE = new ScoreManager();
        }

        return INSTANCE;
    }

    //--------//
    // export //
    //--------//
    /**
     * Export a score using the partwise structure of MusicXML, using the
     * default file for the provided score
     *
     * @param score the score to export
     */
    public void export (Score score)
    {
        export(score, null);
    }

    //--------//
    // export //
    //--------//
    /**
     * Export a score using the partwise structure of MusicXML to the provided
     * file
     *
     * @param score the score to export
     * @param xmlFile the xml file to write, or null
     */
    public void export (Score score,
                        File  xmlFile)
    {
        // Where do we write the score xml file?
        if (xmlFile == null) {
            xmlFile = new File(
                Main.getOutputFolder(),
                score.getRadix() + SCORE_EXTENSION);

            // Ask user confirmation, if Gui available
            if (Main.getGui() != null) {
                // Let the user select a score output file
                FileFilter filter = new FileFilter(
                        "XML files",
                        new String[] { SCORE_EXTENSION });
                xmlFile = UIUtilities.fileChooser(true, 
                	null, xmlFile.getPath(), filter);
            }
        }

        if (xmlFile != null) {
        	// Remember (even across runs) the selected directory
        	Main.setOutputFolder(xmlFile.getParent());
        	
            // Make sure the folder exists
            File folder = new File(xmlFile.getParent());

            if (folder.mkdirs()) {
                logger.info("Creating folder " + folder);
            }

            // Record this task in the sheet script
            score.getSheet()
                 .getScript()
                 .addTask(new ExportTask(xmlFile.getPath()));

            // Actually export the score material
            new ScoreExporter(score, xmlFile);
        }
    }
}
{'fraction_non_alphanumeric': 0.18973634651600754, 'fraction_numerical': 0.0018832391713747645, 'mean_word_length': 1.081577658010779, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '804945', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1967, 'n_words': 616}