<commit_before>package cz.cuni.lf1.lge.ThunderSTORM;

import cz.cuni.lf1.lge.ThunderSTORM.ImportExport.IImportExport;
import cz.cuni.lf1.lge.ThunderSTORM.results.IJResultsTable;
import cz.cuni.lf1.lge.ThunderSTORM.UI.GUI;
import cz.cuni.lf1.lge.ThunderSTORM.UI.Help;
import cz.cuni.lf1.lge.ThunderSTORM.estimators.PSF.MoleculeDescriptor;
import cz.cuni.lf1.lge.ThunderSTORM.results.GenericTable;
import cz.cuni.lf1.lge.ThunderSTORM.results.IJGroundTruthTable;
import fiji.util.gui.GenericDialogPlus;
import ij.IJ;
import ij.Prefs;
import ij.WindowManager;
import ij.plugin.PlugIn;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Vector;
import javax.swing.JSeparator;

public class ImportExportPlugIn implements PlugIn, ItemListener, TextListener {

    public static final String IMPORT = "import";
    public static final String EXPORT = "export";
    private String[] modules = null;
    private String[] suffix = null;
    private Vector<IImportExport> ie = null;
    private Choice ftype;
    private TextField fpath;
    
    private int active_ie = 0;
    private int startingFrame = 1;
    private String path = null;
    private boolean resetFirst = true;
    private boolean livePreview = true;
    private boolean saveMeasurementProtocol = true;

    public ImportExportPlugIn() {
        super();
        this.path = null;
    }

    public ImportExportPlugIn(String path) {
        super();
        this.path = path;
    }

    @Override
    public void run(String command) {
        GUI.setLookAndFeel();
        loadPreferences();
        //
        String[] commands = command.split(";");
        if(commands.length != 2) {
            throw new IllegalArgumentException("Malformatted argument for Import/Export plug-in!");
        }
        //
        try {
            ie = ModuleLoader.getModules(IImportExport.class);

            // Create and show the dialog
            GenericDialogPlus gd = new GenericDialogPlus(commands[0] + " " + commands[1]);

            modules = new String[ie.size()];
            suffix = new String[ie.size()];
            for(int i = 0; i < modules.length; i++) {
                modules[i] = ie.elementAt(i).getName();
                suffix[i] = ie.elementAt(i).getSuffix();
            }
            gd.addChoice("File type", modules, modules[active_ie]);
            ftype = (Choice) gd.getChoices().get(0);
            ftype.addItemListener(this);
            if((path == null) || path.isEmpty()) {
                gd.addFileField("Choose a file", IJ.getDirectory("current") + commands[1] + "." + suffix[active_ie]);
            } else {
                gd.addFileField("Choose a file", path);
            }
            fpath = (TextField) gd.getStringFields().get(0);
            fpath.addTextListener(this);
            gd.addComponent(new JSeparator(JSeparator.HORIZONTAL));
            //
            String[] col_headers = null;
            if(EXPORT.equals(commands[0])) {
                col_headers = fillExportPane(commands[1], gd);
            } else if(IMPORT.equals(commands[0])) {
                fillImportPane(commands[1], gd);
            }
            gd.add(Help.createHelpButton("help"));
            gd.showDialog();

            if(!gd.wasCanceled()) {
                active_ie = gd.getNextChoiceIndex();
                String filePath = gd.getNextString();
                if(EXPORT.equals(commands[0])) {
                    runExport(commands[1], gd, filePath, col_headers);
                } else if(IMPORT.equals(commands[0])) {
                    runImport(commands[1], gd, filePath);
                }
                savePreferences();
            }
        } catch(Exception ex) {
            IJ.handleException(ex);
        }
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        String fp = fpath.getText();
        if(fp.endsWith("\\") || fp.endsWith("/")) {
            fpath.setText(fp + "results." + suffix[ftype.getSelectedIndex()]);
        } else {
            int dotpos = fp.lastIndexOf('.');
            if(dotpos < 0) {
                fpath.setText(fp + '.' + suffix[ftype.getSelectedIndex()]);
            } else {
                fpath.setText(fp.substring(0, dotpos + 1) + suffix[ftype.getSelectedIndex()]);
            }
        }
    }
<commit_msg>bugfix: store the path of imported/exported file in the settings<commit_after>package cz.cuni.lf1.lge.ThunderSTORM;

import cz.cuni.lf1.lge.ThunderSTORM.ImportExport.IImportExport;
import cz.cuni.lf1.lge.ThunderSTORM.results.IJResultsTable;
import cz.cuni.lf1.lge.ThunderSTORM.UI.GUI;
import cz.cuni.lf1.lge.ThunderSTORM.UI.Help;
import cz.cuni.lf1.lge.ThunderSTORM.estimators.PSF.MoleculeDescriptor;
import cz.cuni.lf1.lge.ThunderSTORM.results.GenericTable;
import cz.cuni.lf1.lge.ThunderSTORM.results.IJGroundTruthTable;
import fiji.util.gui.GenericDialogPlus;
import ij.IJ;
import ij.Prefs;
import ij.WindowManager;
import ij.plugin.PlugIn;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Vector;
import javax.swing.JSeparator;

public class ImportExportPlugIn implements PlugIn, ItemListener, TextListener {

    public static final String IMPORT = "import";
    public static final String EXPORT = "export";
    private String[] modules = null;
    private String[] suffix = null;
    private Vector<IImportExport> ie = null;
    private Choice ftype;
    private TextField fpath;
    
    private int active_ie = 0;
    private int startingFrame = 1;
    private String path = null;
    private boolean resetFirst = true;
    private boolean livePreview = true;
    private boolean saveMeasurementProtocol = true;

    public ImportExportPlugIn() {
        super();
        this.path = null;
    }

    public ImportExportPlugIn(String path) {
        super();
        this.path = path;
    }

    @Override
    public void run(String command) {
        GUI.setLookAndFeel();
        loadPreferences();
        //
        String[] commands = command.split(";");
        if(commands.length != 2) {
            throw new IllegalArgumentException("Malformatted argument for Import/Export plug-in!");
        }
        //
        try {
            ie = ModuleLoader.getModules(IImportExport.class);

            // Create and show the dialog
            GenericDialogPlus gd = new GenericDialogPlus(commands[0] + " " + commands[1]);

            modules = new String[ie.size()];
            suffix = new String[ie.size()];
            for(int i = 0; i < modules.length; i++) {
                modules[i] = ie.elementAt(i).getName();
                suffix[i] = ie.elementAt(i).getSuffix();
            }
            gd.addChoice("File type", modules, modules[active_ie]);
            ftype = (Choice) gd.getChoices().get(0);
            ftype.addItemListener(this);
            if((path == null) || path.isEmpty()) {
                gd.addFileField("Choose a file", IJ.getDirectory("current") + commands[1] + "." + suffix[active_ie]);
            } else {
                gd.addFileField("Choose a file", path);
            }
            fpath = (TextField) gd.getStringFields().get(0);
            fpath.addTextListener(this);
            gd.addComponent(new JSeparator(JSeparator.HORIZONTAL));
            //
            String[] col_headers = null;
            if(EXPORT.equals(commands[0])) {
                col_headers = fillExportPane(commands[1], gd);
            } else if(IMPORT.equals(commands[0])) {
                fillImportPane(commands[1], gd);
            }
            gd.add(Help.createHelpButton("help"));
            gd.showDialog();

            if(!gd.wasCanceled()) {
                active_ie = gd.getNextChoiceIndex();
                path = gd.getNextString();
                if(EXPORT.equals(commands[0])) {
                    runExport(commands[1], gd, path, col_headers);
                } else if(IMPORT.equals(commands[0])) {
                    runImport(commands[1], gd, path);
                }
                savePreferences();
            }
        } catch(Exception ex) {
            IJ.handleException(ex);
        }
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        String fp = fpath.getText();
        if(fp.endsWith("\\") || fp.endsWith("/")) {
            fpath.setText(fp + "results." + suffix[ftype.getSelectedIndex()]);
        } else {
            int dotpos = fp.lastIndexOf('.');
            if(dotpos < 0) {
                fpath.setText(fp + '.' + suffix[ftype.getSelectedIndex()]);
            } else {
                fpath.setText(fp.substring(0, dotpos + 1) + suffix[ftype.getSelectedIndex()]);
            }
        }
    }

{'fraction_non_alphanumeric': 0.12455830388692579, 'fraction_numerical': 0.006183745583038869, 'mean_word_length': 2.2369549678341674, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3016080', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2666, 'n_words': 518}