<commit_before>/*
* XalFxDocument.java
*
* Created on January 31, 2018
*/

package xal.extension.fxapplication;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.HostServices;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import xal.extension.jelog.PostEntryDialog;
import xal.smf.Accelerator;


/**
* The base class for custom documents for JavaFX applications.
*
* @author  <NAME> <<EMAIL>>
*/
abstract public class XalFxDocument {
    /** wildcard file extension */
    protected String FILETYPE_DESCRIPTION = "Any XML File";
    protected String WILDCARD_FILE_EXTENSION = "*.xml";
    protected String DEFAULT_FILENAME = "DefaultFileName.xml";
    protected SimpleStringProperty sourceString;
    /** The persistent storage URL for the document */
    protected URL source;
    protected boolean hasChanges;
    /** The accelerator file in use */
    protected AcceleratorProperty accelerator;
    /** The selected Sequence/ComboSequence */
    protected SimpleStringProperty sequence;
    /** The selected Stage for eLog Posts */
    protected Stage mainStage;
    private final String HELP_WIKI_BASE;
    /** PageID of the Confluence page or web page with the help about the application */
    protected String HELP_PAGEID;

    public XalFxDocument() {
        this.HELP_WIKI_BASE = "https://confluence.esss.lu.se/pages/viewpage.action?pageId=";
        this.accelerator = new AcceleratorProperty();
        this.sequence = new SimpleStringProperty();
    }

    public XalFxDocument(Stage stage) {
        this();
        this.mainStage = stage;
    }

    /**
     * Set the whether this document has changes.
     * @param changeStatus Status to set whether this document has changes that need saving.
     */
    public void setHasChanges( final boolean changeStatus ) {
        // Add a * after the file name in title bar in case there are changes to the file
        if (!hasChanges)
            sourceString.set(source+"*");
        hasChanges = changeStatus;
    }

    /**
    * Indicates if there are changes that need saving.
    * @return Status of whether this document has changes that need saving.
    */
    public boolean hasChanges() {
        return hasChanges;
    }

    public boolean sourceSetAndValid() {
        if (source==null)
            return false;
        return true;
    }

    public void setSource(File newSource) {
        // Checking that we are allowed to write to the folder where this file is from
        if (newSource.getParentFile().canWrite()) {
            try {
                Logger.getLogger(XalFxDocument.class.getName()).log(Level.FINER, "Changing document source {0}",newSource);
                source = newSource.toURI().toURL();
                sourceString.set(newSource.toString());
            } catch (MalformedURLException ex) {
                Logger.getLogger(XalFxDocument.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            Logger.getLogger(XalFxDocument.class.getName()).log(Level.WARNING, "Not possible to write to file {0}",newSource);
        }
    }

    /**
     * Subclasses need to implement this method for saving the document to a URL.
     * @param url The File to which this document should be saved.
     */
    abstract public void saveDocumentAs( final URL url );

    /**
     * Subclasses need to implement this method for saving the document to a URL.
     * @param url The URL to which this document should be saved.
     */
    abstract public void loadDocument( final URL url );

    /**
     * Save this document to its persistent storage source.
     */
    public void saveDocument() {
        if ( sourceSetAndValid() ) {
            Logger.getLogger(XalFxDocument.class.getName()).log(Level.FINER, "Saving document using source {0}",source);
            saveDocumentAs( source );
        }
    }

    /**
    * Method for creating an eLog Post.
    */
    public void eLogPost(){
        Logger.getLogger(XalFxDocument.class.getName()).log(Level.FINER, "New e-log entry");
        try {
            WritableImage[] snapshots = new WritableImage[1];
            snapshots[0] = mainStage.getScene().snapshot(null);
            PostEntryDialog.post(snapshots, "Studies");
        } catch (Exception ex) {
            Logger.getLogger(XalFxDocument.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
    * Method for redirecting to the applications web page/internal page.
    */
    public void help(){<commit_msg>[extension.fxapplication] remove * indicator on save When clicking File->Save, the * indicator should disappear in the menu bar, the * indicates an unsaved document<commit_after>/*
* XalFxDocument.java
*
* Created on January 31, 2018
*/

package xal.extension.fxapplication;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.HostServices;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import xal.extension.jelog.PostEntryDialog;
import xal.smf.Accelerator;


/**
* The base class for custom documents for JavaFX applications.
*
* @author  <NAME> <<EMAIL>>
*/
abstract public class XalFxDocument {
    /** wildcard file extension */
    protected String FILETYPE_DESCRIPTION = "Any XML File";
    protected String WILDCARD_FILE_EXTENSION = "*.xml";
    protected String DEFAULT_FILENAME = "DefaultFileName.xml";
    protected SimpleStringProperty sourceString;
    /** The persistent storage URL for the document */
    protected URL source;
    protected boolean hasChanges;
    /** The accelerator file in use */
    protected AcceleratorProperty accelerator;
    /** The selected Sequence/ComboSequence */
    protected SimpleStringProperty sequence;
    /** The selected Stage for eLog Posts */
    protected Stage mainStage;
    private final String HELP_WIKI_BASE;
    /** PageID of the Confluence page or web page with the help about the application */
    protected String HELP_PAGEID;

    public XalFxDocument() {
        this.HELP_WIKI_BASE = "https://confluence.esss.lu.se/pages/viewpage.action?pageId=";
        this.accelerator = new AcceleratorProperty();
        this.sequence = new SimpleStringProperty();
    }

    public XalFxDocument(Stage stage) {
        this();
        this.mainStage = stage;
    }

    /**
     * Set the whether this document has changes.
     * @param changeStatus Status to set whether this document has changes that need saving.
     */
    public void setHasChanges( final boolean changeStatus ) {
        // Add a * after the file name in title bar in case there are changes to the file
        if (!hasChanges)
            sourceString.set(source+"*");
        hasChanges = changeStatus;
    }

    /**
    * Indicates if there are changes that need saving.
    * @return Status of whether this document has changes that need saving.
    */
    public boolean hasChanges() {
        return hasChanges;
    }

    public boolean sourceSetAndValid() {
        if (source==null)
            return false;
        return true;
    }

    public void setSource(File newSource) {
        // Checking that we are allowed to write to the folder where this file is from
        if (newSource.getParentFile().canWrite()) {
            try {
                Logger.getLogger(XalFxDocument.class.getName()).log(Level.FINER, "Changing document source {0}",newSource);
                source = newSource.toURI().toURL();
                sourceString.set(newSource.toString());
            } catch (MalformedURLException ex) {
                Logger.getLogger(XalFxDocument.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            Logger.getLogger(XalFxDocument.class.getName()).log(Level.WARNING, "Not possible to write to file {0}",newSource);
        }
    }

    /**
     * Subclasses need to implement this method for saving the document to a URL.
     * @param url The File to which this document should be saved.
     */
    abstract public void saveDocumentAs( final URL url );

    /**
     * Subclasses need to implement this method for saving the document to a URL.
     * @param url The URL to which this document should be saved.
     */
    abstract public void loadDocument( final URL url );

    /**
     * Save this document to its persistent storage source.
     */
    public void saveDocument() {
        if ( sourceSetAndValid() ) {
            Logger.getLogger(XalFxDocument.class.getName()).log(Level.FINER, "Saving document using source {0}",source);
            saveDocumentAs( source );
            sourceString.set( source.toString() );
        }
    }

    /**
    * Method for creating an eLog Post.
    */
    public void eLogPost(){
        Logger.getLogger(XalFxDocument.class.getName()).log(Level.FINER, "New e-log entry");
        try {
            WritableImage[] snapshots = new WritableImage[1];
            snapshots[0] = mainStage.getScene().snapshot(null);
            PostEntryDialog.post(snapshots, "Studies");
        } catch (Exception ex) {
            Logger.getLogger(XalFxDocument.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
    * Method for redirecting to the applications web page/internal page.
    */
    public void help(){
{'fraction_non_alphanumeric': 0.09687237615449203, 'fraction_numerical': 0.0023089840470193117, 'mean_word_length': 2.70633994554648, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3318424', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2546, 'n_words': 799}