/*
 * MainFrame.java
 *
 * Created on 15 September 2008, 16:41
 */

package gudrunn;

/**
 *
 * @author  aks45
 */

import gudrunlibrary.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;

public class MainNeutronFrame extends javax.swing.JFrame {
    
    /** Creates new form MainFrame */
    public MainNeutronFrame() {
         initComponents();
         UsingDefaultDataFileDirLabel.setVisible(false);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PurgeParameters = new javax.swing.JDialog();
        PurgeParValues = new javax.swing.JPanel();
        NoStdLabel = new javax.swing.JLabel();
        NoStd = new javax.swing.JTextField();
        MaxStdLabel = new javax.swing.JLabel();
        MaxStd = new javax.swing.JTextField();
        PurgeParDone = new javax.swing.JButton();
        IgnoreLabel = new javax.swing.JLabel();
        Ignore = new javax.swing.JCheckBox();
        SystemValues = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        GudrunExeLabel = new javax.swing.JLabel();
        GudrunExe = new javax.swing.JTextField();
        Purge_DetExeLabel = new javax.swing.JLabel();
        Purge_DetExe = new javax.swing.JTextField();
        GnuplotExeLabel = new javax.swing.JLabel();
        GnuplotExe = new javax.swing.JTextField();
        SaveSystemValues = new javax.swing.JButton();
        BrowseGudrunDcsExec = new javax.swing.JButton();
        BrowsePurge_DetExec = new javax.swing.JButton();
        BrowseGnuplotExec = new javax.swing.JButton();
        StartupFilenameLabel = new javax.swing.JLabel();
        StartupFilename = new javax.swing.JTextField();
        BrowseStartupFilename = new javax.swing.JButton();
        GNUplotPlotCommandLabel = new javax.swing.JLabel();
        GNUplotPlotCommand = new javax.swing.JTextField();
        BrowseGNUplotPlotCommand = new javax.swing.JButton();
        GroupPlotSequenceLabel = new javax.swing.JLabel();
        GroupPlotSequence = new javax.swing.JTextField();
        DefaultDataFileDirLabel = new javax.swing.JLabel();
        DefaultDataFileDir = new javax.swing.JTextField();
        BrowseDefaultDataFileDir = new javax.swing.JButton();
        setSampleName = new javax.swing.JDialog();
        SampleName = new javax.swing.JTextField();
        SampleNameHeader = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        SampleNameOK = new javax.swing.JButton();
        SampleNameUseDefault = new javax.swing.JButton();
        setAnotherSampleName = new javax.swing.JDialog();
        AnotherSampleNameHeader = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        AnotherSampleName = new javax.swing.JTextField();
        AnotherSampleNameOK = new javax.swing.JButton();
        AnotherSampleNameUseDefault = new javax.swing.JButton();
        FileNotFoundMessages = new javax.swing.JDialog();
        FileNotFoundMessagePanel = new javax.swing.JPanel();
        FileNotFoundLabel = new javax.swing.JLabel();
        OKFileNotFound = new javax.swing.JButton();
        WarningLabel = new javax.swing.JLabel();
        FileNotFoundPanel = new javax.swing.JPanel();
        AllFilesFoundMessage = new javax.swing.JDialog();
        AllFilesFoundMessagePanel = new javax.swing.JPanel();
        OKAllFilesFound = new javax.swing.JButton();
        AllFilesFound = new javax.swing.JLabel();
        SaveGUIOnExitDialog = new javax.swing.JDialog();
        SaveGUIOnExitPanel = new javax.swing.JPanel();
        SaveGUIOnExitLabel = new javax.swing.JLabel();
        SaveGUIOnExitYesButton = new javax.swing.JButton();
        SaveGUIOnExitNoButton = new javax.swing.JButton();
        SaveGUIOnExitCancelButton = new javax.swing.JButton();
        SaveAsGUIOnExitButton = new javax.swing.JButton();
        CurrentInputFileName = new javax.swing.JTextField();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        OPTIONS = new javax.swing.JTabbedPane();
        INSTRUMENT = new gudrunn.InstrumentPanel(vs);
        BEAM = new gudrunn.BeamPanel(vs);
        NORMALISATION = new gudrunn.NormalisationPanel(vs);
        CurrentInputFile = new javax.swing.JScrollPane();
        ContentsOfCurrentInputFile = new javax.swing.JTextArea();
        UsingDefaultDataFileDirLabel = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        jSeparator7 = new javax.swing.JSeparator();
        openMenuItem = new javax.swing.JMenuItem();
        reloadMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        updateMenuItem = new javax.swing.JMenuItem();
        getMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();
        Edit = new javax.swing.JMenu();
        insertSample = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        insertContainer = new javax.swing.JMenuItem();
        jSeparator12 = new javax.swing.JSeparator();
        insertSampleBackground = new javax.swing.JMenuItem();
        jSeparator8 = new javax.swing.JSeparator();
        cutSelection = new javax.swing.JMenuItem();
        jSeparator15 = new javax.swing.JSeparator();
        copySelection = new javax.swing.JMenuItem();
        jSeparator9 = new javax.swing.JSeparator();
        pasteSelection = new javax.swing.JMenuItem();
        jSeparator10 = new javax.swing.JSeparator();
        removeSelection = new javax.swing.JMenuItem();
        jSeparator11 = new javax.swing.JSeparator();
        changeSampleName = new javax.swing.JMenuItem();
        RunMenu = new javax.swing.JMenu();
        checkFilenamesExist = new javax.swing.JMenuItem();
        jSeparator14 = new javax.swing.JSeparator();
        WritePurgeFile = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        RunPurge = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        RunGudrun = new javax.swing.JMenuItem();
        PlotMenu = new javax.swing.JMenu();
        getPlotDialog = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JSeparator();
        RunGnuplot = new javax.swing.JMenuItem();
        SystemMenu = new javax.swing.JMenu();
        GetSystemValues = new javax.swing.JMenuItem();
        jSeparator13 = new javax.swing.JSeparator();
        UseDefaultDataFileDir = new javax.swing.JCheckBoxMenuItem();

        PurgeParameters.setTitle("Specify purge parameters and write file");
        PurgeParameters.setMinimumSize(new java.awt.Dimension(750, 250));
        PurgeParameters.setModal(true);

        PurgeParValues.setMinimumSize(new java.awt.Dimension(500, 300));

        NoStdLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        NoStdLabel.setText("Specify the number of standard deviations allowed above and below the mean ratio.");

        NoStd.setText("10");
        NoStd.setToolTipText("Reduce to eliminate more detectors");
        NoStd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NoStdActionPerformed(evt);
            }
        });

        MaxStdLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        MaxStdLabel.setText("Specify the range of std's allowed around the mean standard deviation.");

        MaxStd.setText("10");

        PurgeParDone.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        PurgeParDone.setText("Press to write purge_det.dat");
        PurgeParDone.setPreferredSize(new java.awt.Dimension(300, 50));
        PurgeParDone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PurgeParDoneActionPerformed(evt);
            }
        });

        IgnoreLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
        IgnoreLabel.setText("Ignore any existing bad spectrum and spike files (spec.bad, spike.dat)?");
        IgnoreLabel.setToolTipText("Check box to make sure spec.bad is ignored");

        Ignore.setSelected(true);

        javax.swing.GroupLayout PurgeParValuesLayout = new javax.swing.GroupLayout(PurgeParValues);
        PurgeParValues.setLayout(PurgeParValuesLayout);
        PurgeParValuesLayout.setHorizontalGroup(
            PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PurgeParValuesLayout.createSequentialGroup()
                .addGroup(PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PurgeParValuesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(IgnoreLabel))
                    .addGroup(PurgeParValuesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(MaxStdLabel))
                    .addGroup(PurgeParValuesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(NoStdLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Ignore, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(MaxStd, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(NoStd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PurgeParValuesLayout.createSequentialGroup()
                .addContainerGap(183, Short.MAX_VALUE)
                .addComponent(PurgeParDone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(233, 233, 233))
        );
        PurgeParValuesLayout.setVerticalGroup(
            PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PurgeParValuesLayout.createSequentialGroup()
                .addGroup(PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NoStdLabel)
                    .addComponent(NoStd))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(MaxStdLabel)
                    .addComponent(MaxStd, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PurgeParValuesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(Ignore, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(IgnoreLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PurgeParDone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        PurgeParameters.getContentPane().add(PurgeParValues, java.awt.BorderLayout.CENTER);

        PurgeParameters.getAccessibleContext().setAccessibleName("");

        SystemValues.setTitle("Pathnames for executables used by GudrunGUI");
        SystemValues.setMinimumSize(new java.awt.Dimension(650, 400));
        SystemValues.setModal(true);

        jPanel1.setBackground(new java.awt.Color(228, 228, 242));

        GudrunExeLabel.setFont(GudrunExeLabel.getFont().deriveFont(GudrunExeLabel.getFont().getSize()+1f));
        GudrunExeLabel.setText("Full path for Gudrun executable:");

        GudrunExe.setText("C:\\Gudrun\\GudrunSourceGUI_1\\CygGudrun_dcs.exe");

        Purge_DetExeLabel.setFont(Purge_DetExeLabel.getFont().deriveFont(Purge_DetExeLabel.getFont().getSize()+1f));
        Purge_DetExeLabel.setText("Full path for Purge_Det executable:");

        Purge_DetExe.setText("C:\\Gudrun\\GudrunSourceGUI_1\\Cygpurge_det.exe");

        GnuplotExeLabel.setFont(GnuplotExeLabel.getFont().deriveFont(GnuplotExeLabel.getFont().getSize()+1f));
        GnuplotExeLabel.setText("Full path for GNUplot executable");

        GnuplotExe.setText("C:\\EPSR\\Gnuplot\\pgnuplot.exe");

        SaveSystemValues.setFont(SaveSystemValues.getFont().deriveFont(SaveSystemValues.getFont().getSize()+1f));
        SaveSystemValues.setText("Save these values");
        SaveSystemValues.setMaximumSize(new java.awt.Dimension(150, 50));
        SaveSystemValues.setPreferredSize(new java.awt.Dimension(150, 50));
        SaveSystemValues.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveSystemValuesActionPerformed(evt);
            }
        });

        BrowseGudrunDcsExec.setFont(BrowseGudrunDcsExec.getFont().deriveFont(BrowseGudrunDcsExec.getFont().getSize()+1f));
        BrowseGudrunDcsExec.setText("Browse");
        BrowseGudrunDcsExec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowseGudrunDcsExecActionPerformed(evt);
            }
        });

        BrowsePurge_DetExec.setFont(BrowsePurge_DetExec.getFont().deriveFont(BrowsePurge_DetExec.getFont().getSize()+1f));
        BrowsePurge_DetExec.setText("Browse");
        BrowsePurge_DetExec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowsePurge_DetExecActionPerformed(evt);
            }
        });

        BrowseGnuplotExec.setFont(BrowseGnuplotExec.getFont().deriveFont(BrowseGnuplotExec.getFont().getSize()+1f));
        BrowseGnuplotExec.setText("Browse");
        BrowseGnuplotExec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowseGnuplotExecActionPerformed(evt);
            }
        });

        StartupFilenameLabel.setFont(StartupFilenameLabel.getFont().deriveFont(StartupFilenameLabel.getFont().getSize()+1f));
        StartupFilenameLabel.setText("Full path for startup file");

        StartupFilename.setFont(StartupFilename.getFont().deriveFont(StartupFilename.getFont().getSize()+1f));

        BrowseStartupFilename.setFont(BrowseStartupFilename.getFont().deriveFont(BrowseStartupFilename.getFont().getSize()+1f));
        BrowseStartupFilename.setText("Browse");
        BrowseStartupFilename.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowseStartupFilenameActionPerformed(evt);
            }
        });

        GNUplotPlotCommandLabel.setFont(GNUplotPlotCommandLabel.getFont().deriveFont(GNUplotPlotCommandLabel.getFont().getSize()+1f));
        GNUplotPlotCommandLabel.setText("Full path for GNUplot plot command");

        GNUplotPlotCommand.setFont(GNUplotPlotCommand.getFont().deriveFont(GNUplotPlotCommand.getFont().getSize()+1f));

        BrowseGNUplotPlotCommand.setFont(BrowseGNUplotPlotCommand.getFont().deriveFont(BrowseGNUplotPlotCommand.getFont().getSize()+1f));
        BrowseGNUplotPlotCommand.setText("Browse");
        BrowseGNUplotPlotCommand.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowseGNUplotPlotCommandActionPerformed(evt);
            }
        });

        GroupPlotSequenceLabel.setFont(GroupPlotSequenceLabel.getFont().deriveFont(GroupPlotSequenceLabel.getFont().getSize()+1f));
        GroupPlotSequenceLabel.setText("Group plotting sequence");

        GroupPlotSequence.setFont(GroupPlotSequence.getFont().deriveFont(GroupPlotSequence.getFont().getSize()+1f));

        DefaultDataFileDirLabel.setFont(DefaultDataFileDirLabel.getFont().deriveFont(DefaultDataFileDirLabel.getFont().getSize()+1f));
        DefaultDataFileDirLabel.setText("Default data file directory");

        BrowseDefaultDataFileDir.setFont(BrowseDefaultDataFileDir.getFont().deriveFont(BrowseDefaultDataFileDir.getFont().getSize()+1f));
        BrowseDefaultDataFileDir.setText("Browse");
        BrowseDefaultDataFileDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BrowseDefaultDataFileDirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(DefaultDataFileDirLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(DefaultDataFileDir, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(Purge_DetExeLabel)
                                    .addComponent(GNUplotPlotCommandLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(Purge_DetExe, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
                                    .addComponent(GNUplotPlotCommand, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(GudrunExeLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(GudrunExe, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(GnuplotExeLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(GnuplotExe, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(StartupFilenameLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(StartupFilename, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(BrowseDefaultDataFileDir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(BrowseGNUplotPlotCommand, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(BrowseStartupFilename, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                            .addComponent(BrowseGudrunDcsExec, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                            .addComponent(BrowsePurge_DetExec, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(BrowseGnuplotExec, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(SaveSystemValues, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(GroupPlotSequenceLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(GroupPlotSequence, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(GudrunExeLabel)
                    .addComponent(GudrunExe, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BrowseGudrunDcsExec, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Purge_DetExeLabel)
                    .addComponent(Purge_DetExe, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BrowsePurge_DetExec, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(GnuplotExeLabel)
                    .addComponent(GnuplotExe, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BrowseGnuplotExec, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(GNUplotPlotCommandLabel)
                    .addComponent(GNUplotPlotCommand, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BrowseGNUplotPlotCommand, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StartupFilenameLabel)
                    .addComponent(StartupFilename, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BrowseStartupFilename, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DefaultDataFileDirLabel)
                    .addComponent(BrowseDefaultDataFileDir, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DefaultDataFileDir, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(GroupPlotSequenceLabel)
                    .addComponent(GroupPlotSequence, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SaveSystemValues, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(120, 120, 120))
        );

        SystemValues.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        SystemValues.getAccessibleContext().setAccessibleParent(this);

        setSampleName.setMinimumSize(new java.awt.Dimension(600, 400));
        setSampleName.setModal(true);
        setSampleName.addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                setSampleNameWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        SampleName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                SampleNameFocusGained(evt);
            }
        });

        SampleNameHeader.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        SampleNameHeader.setText("SAMPLE or CONTAINER name");

        jTextPane1.setEditable(false);
        jTextPane1.setText("Choose a name for this sample or container.\n\nSuggest to use up to ~10 characters\n\nPress OK when done.\n\nPress \"Use default\" to get the GUI to choose a name for you.");
        jScrollPane2.setViewportView(jTextPane1);

        SampleNameOK.setText("OK");
        SampleNameOK.setSelected(true);
        SampleNameOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SampleNameOKActionPerformed(evt);
            }
        });

        SampleNameUseDefault.setText("Use default");
        SampleNameUseDefault.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SampleNameUseDefaultActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout setSampleNameLayout = new javax.swing.GroupLayout(setSampleName.getContentPane());
        setSampleName.getContentPane().setLayout(setSampleNameLayout);
        setSampleNameLayout.setHorizontalGroup(
            setSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setSampleNameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(setSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(SampleNameHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, setSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(SampleName, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, setSampleNameLayout.createSequentialGroup()
                            .addComponent(SampleNameOK, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(SampleNameUseDefault, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        setSampleNameLayout.setVerticalGroup(
            setSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setSampleNameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(SampleNameHeader)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SampleName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(setSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SampleNameUseDefault)
                    .addComponent(SampleNameOK))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setAnotherSampleName.setMinimumSize(new java.awt.Dimension(600, 400));
        setAnotherSampleName.setModal(true);

        AnotherSampleNameHeader.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        AnotherSampleNameHeader.setText("SAMPLE or CONTAINER name");

        jTextPane2.setEditable(false);
        jTextPane2.setText("The name you chose already exists - choose another.\n\nSuggest to use up to ~10 characters.\n\nPress OK when done.\n\nPress \"Use default\" to get the GUI to choose a name for you.");
        jScrollPane3.setViewportView(jTextPane2);

        AnotherSampleNameOK.setText("OK");
        AnotherSampleNameOK.setFocusCycleRoot(true);
        AnotherSampleNameOK.setSelected(true);
        AnotherSampleNameOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AnotherSampleNameOKActionPerformed(evt);
            }
        });

        AnotherSampleNameUseDefault.setText("Use default");
        AnotherSampleNameUseDefault.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AnotherSampleNameUseDefaultActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout setAnotherSampleNameLayout = new javax.swing.GroupLayout(setAnotherSampleName.getContentPane());
        setAnotherSampleName.getContentPane().setLayout(setAnotherSampleNameLayout);
        setAnotherSampleNameLayout.setHorizontalGroup(
            setAnotherSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setAnotherSampleNameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(setAnotherSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(AnotherSampleNameHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, setAnotherSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(AnotherSampleName, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, setAnotherSampleNameLayout.createSequentialGroup()
                            .addComponent(AnotherSampleNameOK, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(AnotherSampleNameUseDefault, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        setAnotherSampleNameLayout.setVerticalGroup(
            setAnotherSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setAnotherSampleNameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(AnotherSampleNameHeader)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(AnotherSampleName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(setAnotherSampleNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AnotherSampleNameUseDefault)
                    .addComponent(AnotherSampleNameOK))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        FileNotFoundMessages.setModal(true);

        FileNotFoundLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        FileNotFoundLabel.setText("jLabel1");
        FileNotFoundLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        OKFileNotFound.setText("OK");
        OKFileNotFound.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKFileNotFoundActionPerformed(evt);
            }
        });

        WarningLabel.setFont(WarningLabel.getFont().deriveFont(WarningLabel.getFont().getSize()+10f));
        WarningLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        WarningLabel.setText("WARNING!");
        WarningLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout FileNotFoundPanelLayout = new javax.swing.GroupLayout(FileNotFoundPanel);
        FileNotFoundPanel.setLayout(FileNotFoundPanelLayout);
        FileNotFoundPanelLayout.setHorizontalGroup(
            FileNotFoundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 625, Short.MAX_VALUE)
        );
        FileNotFoundPanelLayout.setVerticalGroup(
            FileNotFoundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 27, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout FileNotFoundMessagePanelLayout = new javax.swing.GroupLayout(FileNotFoundMessagePanel);
        FileNotFoundMessagePanel.setLayout(FileNotFoundMessagePanelLayout);
        FileNotFoundMessagePanelLayout.setHorizontalGroup(
            FileNotFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(FileNotFoundMessagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(FileNotFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(OKFileNotFound, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(FileNotFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(FileNotFoundLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(WarningLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
                        .addComponent(FileNotFoundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(298, Short.MAX_VALUE))
        );
        FileNotFoundMessagePanelLayout.setVerticalGroup(
            FileNotFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(FileNotFoundMessagePanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(WarningLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(FileNotFoundLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(FileNotFoundPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(OKFileNotFound, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout FileNotFoundMessagesLayout = new javax.swing.GroupLayout(FileNotFoundMessages.getContentPane());
        FileNotFoundMessages.getContentPane().setLayout(FileNotFoundMessagesLayout);
        FileNotFoundMessagesLayout.setHorizontalGroup(
            FileNotFoundMessagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(FileNotFoundMessagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        FileNotFoundMessagesLayout.setVerticalGroup(
            FileNotFoundMessagesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(FileNotFoundMessagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        AllFilesFoundMessage.setMinimumSize(new java.awt.Dimension(300, 200));
        AllFilesFoundMessage.setModal(true);

        OKAllFilesFound.setText("OK");
        OKAllFilesFound.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKAllFilesFoundActionPerformed(evt);
            }
        });

        AllFilesFound.setFont(AllFilesFound.getFont().deriveFont(AllFilesFound.getFont().getSize()+5f));
        AllFilesFound.setText("All files found!");

        javax.swing.GroupLayout AllFilesFoundMessagePanelLayout = new javax.swing.GroupLayout(AllFilesFoundMessagePanel);
        AllFilesFoundMessagePanel.setLayout(AllFilesFoundMessagePanelLayout);
        AllFilesFoundMessagePanelLayout.setHorizontalGroup(
            AllFilesFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AllFilesFoundMessagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(AllFilesFound)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(OKAllFilesFound)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        AllFilesFoundMessagePanelLayout.setVerticalGroup(
            AllFilesFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AllFilesFoundMessagePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(AllFilesFoundMessagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AllFilesFound)
                    .addComponent(OKAllFilesFound))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout AllFilesFoundMessageLayout = new javax.swing.GroupLayout(AllFilesFoundMessage.getContentPane());
        AllFilesFoundMessage.getContentPane().setLayout(AllFilesFoundMessageLayout);
        AllFilesFoundMessageLayout.setHorizontalGroup(
            AllFilesFoundMessageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGroup(AllFilesFoundMessageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(AllFilesFoundMessageLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(AllFilesFoundMessagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        AllFilesFoundMessageLayout.setVerticalGroup(
            AllFilesFoundMessageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(AllFilesFoundMessageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(AllFilesFoundMessageLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(AllFilesFoundMessagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        SaveGUIOnExitDialog.setMinimumSize(new java.awt.Dimension(490, 120));
        SaveGUIOnExitDialog.setModal(true);
        SaveGUIOnExitDialog.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                SaveGUIOnExitDialogWindowClosing(evt);
            }
        });

        SaveGUIOnExitLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        SaveGUIOnExitLabel.setText("Do you wish to save the current GUI?"); // NOI18N

        SaveGUIOnExitYesButton.setText("Save"); // NOI18N
        SaveGUIOnExitYesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveGUIOnExitYesButtonActionPerformed(evt);
            }
        });

        SaveGUIOnExitNoButton.setText("No"); // NOI18N
        SaveGUIOnExitNoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveGUIOnExitNoButtonActionPerformed(evt);
            }
        });

        SaveGUIOnExitCancelButton.setText("Cancel"); // NOI18N
        SaveGUIOnExitCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveGUIOnExitCancelButtonActionPerformed(evt);
            }
        });

        SaveAsGUIOnExitButton.setText("Save As"); // NOI18N
        SaveAsGUIOnExitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveAsGUIOnExitButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout SaveGUIOnExitPanelLayout = new javax.swing.GroupLayout(SaveGUIOnExitPanel);
        SaveGUIOnExitPanel.setLayout(SaveGUIOnExitPanelLayout);
        SaveGUIOnExitPanelLayout.setHorizontalGroup(
            SaveGUIOnExitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SaveGUIOnExitPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(SaveGUIOnExitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(SaveGUIOnExitLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
                    .addGroup(SaveGUIOnExitPanelLayout.createSequentialGroup()
                        .addComponent(SaveGUIOnExitYesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SaveAsGUIOnExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SaveGUIOnExitNoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SaveGUIOnExitCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        SaveGUIOnExitPanelLayout.setVerticalGroup(
            SaveGUIOnExitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SaveGUIOnExitPanelLayout.createSequentialGroup()
                .addComponent(SaveGUIOnExitLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(SaveGUIOnExitPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SaveGUIOnExitYesButton)
                    .addComponent(SaveAsGUIOnExitButton)
                    .addComponent(SaveGUIOnExitNoButton)
                    .addComponent(SaveGUIOnExitCancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout SaveGUIOnExitDialogLayout = new javax.swing.GroupLayout(SaveGUIOnExitDialog.getContentPane());
        SaveGUIOnExitDialog.getContentPane().setLayout(SaveGUIOnExitDialogLayout);
        SaveGUIOnExitDialogLayout.setHorizontalGroup(
            SaveGUIOnExitDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SaveGUIOnExitDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(SaveGUIOnExitPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        SaveGUIOnExitDialogLayout.setVerticalGroup(
            SaveGUIOnExitDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SaveGUIOnExitDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(SaveGUIOnExitPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("GudrunGUI_2");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        CurrentInputFileName.setEditable(false);
        CurrentInputFileName.setFont(new java.awt.Font("DejaVu Sans", 0, 18));
        CurrentInputFileName.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        CurrentInputFileName.setText("Gudrun Input File");
        CurrentInputFileName.setOpaque(false);

        jSplitPane1.setDividerLocation(1200);
        jSplitPane1.setAutoscrolls(true);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(1300, 986));

        OPTIONS.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        OPTIONS.setFont(OPTIONS.getFont().deriveFont(OPTIONS.getFont().getSize()+3f));
        OPTIONS.setName(""); // NOI18N
        OPTIONS.setPreferredSize(new java.awt.Dimension(1200, 984));
        OPTIONS.addTab("INSTRUMENT", INSTRUMENT);
        INSTRUMENT.getAccessibleContext().setAccessibleName("");

        OPTIONS.addTab("BEAM", BEAM);
        OPTIONS.addTab("NORMALISATION", NORMALISATION);

        jScrollPane1.setViewportView(OPTIONS);

        jSplitPane1.setLeftComponent(jScrollPane1);

        ContentsOfCurrentInputFile.setColumns(20);
        ContentsOfCurrentInputFile.setRows(5);
        CurrentInputFile.setViewportView(ContentsOfCurrentInputFile);

        jSplitPane1.setRightComponent(CurrentInputFile);

        UsingDefaultDataFileDirLabel.setBackground(new java.awt.Color(255, 0, 0));
        UsingDefaultDataFileDirLabel.setFont(UsingDefaultDataFileDirLabel.getFont().deriveFont(UsingDefaultDataFileDirLabel.getFont().getSize()+2f));
        UsingDefaultDataFileDirLabel.setForeground(new java.awt.Color(255, 255, 255));
        UsingDefaultDataFileDirLabel.setText(" Using default data file directory ");
        UsingDefaultDataFileDirLabel.setOpaque(true);

        jMenuBar1.setBackground(new java.awt.Color(204, 204, 204));

        FileMenu.setMnemonic('f');
        FileMenu.setText("File");
        FileMenu.add(jSeparator7);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setMnemonic('o');
        openMenuItem.setText("Open ...");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(openMenuItem);

        reloadMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        reloadMenuItem.setText("Reload");
        reloadMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reloadMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(reloadMenuItem);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setMnemonic('s');
        saveMenuItem.setText("Save");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(saveMenuItem);

        saveAsMenuItem.setMnemonic('a');
        saveAsMenuItem.setText("Save As ...");
        saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(saveAsMenuItem);
        FileMenu.add(jSeparator1);

        updateMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        updateMenuItem.setMnemonic('u');
        updateMenuItem.setText("Transfer out ->");
        updateMenuItem.setToolTipText("Writes the contents of the GUI to the text window");
        updateMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(updateMenuItem);

        getMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        getMenuItem.setMnemonic('u');
        getMenuItem.setText("Transfer in <-");
        getMenuItem.setToolTipText("Gets the contents of the text window into the GUI");
        getMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(getMenuItem);
        FileMenu.add(jSeparator2);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(exitMenuItem);

        jMenuBar1.add(FileMenu);

        Edit.setText("Edit");

        insertSample.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        insertSample.setText("Insert SAMPLE");
        insertSample.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertSampleActionPerformed(evt);
            }
        });
        Edit.add(insertSample);
        Edit.add(jSeparator3);

        insertContainer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
        insertContainer.setText("Insert CONTAINER");
        insertContainer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertContainerActionPerformed(evt);
            }
        });
        Edit.add(insertContainer);
        Edit.add(jSeparator12);

        insertSampleBackground.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        insertSampleBackground.setText("Insert SAMPLE BACKGROUND");
        insertSampleBackground.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertSampleBackgroundActionPerformed(evt);
            }
        });
        Edit.add(insertSampleBackground);
        Edit.add(jSeparator8);

        cutSelection.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        cutSelection.setText("Cut");
        cutSelection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cutSelectionActionPerformed(evt);
            }
        });
        Edit.add(cutSelection);
        Edit.add(jSeparator15);

        copySelection.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        copySelection.setText("Copy");
        copySelection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copySelectionActionPerformed(evt);
            }
        });
        Edit.add(copySelection);
        Edit.add(jSeparator9);

        pasteSelection.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        pasteSelection.setText("Paste");
        pasteSelection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pasteSelectionActionPerformed(evt);
            }
        });
        Edit.add(pasteSelection);
        Edit.add(jSeparator10);

        removeSelection.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        removeSelection.setText("Delete");
        removeSelection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeSelectionActionPerformed(evt);
            }
        });
        Edit.add(removeSelection);
        Edit.add(jSeparator11);

        changeSampleName.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        changeSampleName.setText("Rename");
        changeSampleName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeSampleNameActionPerformed(evt);
            }
        });
        Edit.add(changeSampleName);

        jMenuBar1.add(Edit);

        RunMenu.setText("Run");

        checkFilenamesExist.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        checkFilenamesExist.setText("Check files exist");
        checkFilenamesExist.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkFilenamesExistActionPerformed(evt);
            }
        });
        RunMenu.add(checkFilenamesExist);
        RunMenu.add(jSeparator14);

        WritePurgeFile.setText("Write purge file");
        WritePurgeFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WritePurgeFileActionPerformed(evt);
            }
        });
        RunMenu.add(WritePurgeFile);
        RunMenu.add(jSeparator4);

        RunPurge.setText("Run purge");
        RunPurge.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunPurgeActionPerformed(evt);
            }
        });
        RunMenu.add(RunPurge);
        RunMenu.add(jSeparator5);

        RunGudrun.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        RunGudrun.setText("Run Gudrun");
        RunGudrun.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunGudrunActionPerformed(evt);
            }
        });
        RunMenu.add(RunGudrun);

        jMenuBar1.add(RunMenu);

        PlotMenu.setText("Plot");

        getPlotDialog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        getPlotDialog.setText("Generate GNUplot plotting file");
        getPlotDialog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getPlotDialogActionPerformed(evt);
            }
        });
        PlotMenu.add(getPlotDialog);
        PlotMenu.add(jSeparator6);

        RunGnuplot.setText("Run Gnuplot");
        RunGnuplot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RunGnuplotActionPerformed(evt);
            }
        });
        PlotMenu.add(RunGnuplot);

        jMenuBar1.add(PlotMenu);

        SystemMenu.setText("System");

        GetSystemValues.setText("Set system path names");
        GetSystemValues.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GetSystemValuesActionPerformed(evt);
            }
        });
        SystemMenu.add(GetSystemValues);
        SystemMenu.add(jSeparator13);

        UseDefaultDataFileDir.setText("Use default data file directory");
        UseDefaultDataFileDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UseDefaultDataFileDirActionPerformed(evt);
            }
        });
        SystemMenu.add(UseDefaultDataFileDir);

        jMenuBar1.add(SystemMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(UsingDefaultDataFileDirLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CurrentInputFileName, javax.swing.GroupLayout.DEFAULT_SIZE, 1237, Short.MAX_VALUE))
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1456, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(CurrentInputFileName)
                    .addComponent(UsingDefaultDataFileDirLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 927, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        /** This method is called when File -> Open menu item is invoked.
         * It displays a dialog to choose the file to be opened and edited.
         * @param evt ActionEvent instance passed from actionPerformed event.
         */
        //First check whether the current GUI has changed since it was last saved
        checkContentsOfCurrentInputFile();
        if (carryon) {
            gudrunlibrary.FileChooserPanel fcp = new gudrunlibrary.FileChooserPanel();
            // Use the openFile method within the file chooser panel
            String[] filetypes = {"txt"};
            fcp.openFile(vs, "InputFileDir", "InputFileName", "Choose a Gudrun input file", filetypes);
            InputFileName = vs.getVar("InputFileName");
            InputFileDir = vs.getVar("InputFileDir");
            if (!InputFileName.isEmpty()) {
                CurrentInputFileName.setText("Gudrun Input File: " + InputFileName);
                FileInputStream fis = null;
                String str = null;
                try {
                    fis = new FileInputStream(InputFileName);
                    int size = fis.available();
                    byte[] bytes = new byte[size];
                    fis.read(bytes);
                    str = new String(bytes);
                } catch (IOException e) {
                } finally {
                    try {
                        fis.close();
                    } catch (IOException e2) {
                    }
                }

                if (str != null) {
                    ContentsOfCurrentInputFile.setText(str);
                    // Attempt to parse the string to update the values in the GUI
                    getContentsOfCurrentInputFile();
                    //Need to restore the correct value of input file directory, in case it was changed by getContentsOfCCurrentInputFile
                    vs.setVar(InputFileDir, "InputFileDir");
                    //Put the stored values into their correct places
                    getVariableStore();
                }

            } else {
                //Restore the current values to the variable store
                setVariableStore();
            }
        }
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        /** This method is called when File -> Save menu item is invoked.
         * It saves the current opened file.
         * @param evt ActionEvent instance passed from actionPerformed event.
         */
        InputFileName = vs.getVar("InputFileName");
        
        if ((new File(InputFileName)).exists()) {
            doSave(InputFileName);
        } else {
            doSaveAs();
        }
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
        /** This method is called when File -> Save as menu item is invoked.
         * It asks for a new file name, then saves the file.
         * @param evt ActionEvent instance passed from actionPerformed event.
         */
        
        doSaveAs();
    }//GEN-LAST:event_saveAsMenuItemActionPerformed

    private void updateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMenuItemActionPerformed
        /** This method is called when File -> Update menu item is invoked.
         * It clears the editor pane and then regenerates it based on the current parameters
         * @param evt ActionEvent instance passed from actionPerformed event.
         */
        
        updateContentsOfCurrentInputFile();
    }//GEN-LAST:event_updateMenuItemActionPerformed

    private void getMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getMenuItemActionPerformed
        getContentsOfCurrentInputFile();
    }//GEN-LAST:event_getMenuItemActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        exitGUIAction();
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void WritePurgeFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WritePurgeFileActionPerformed
        PurgeParameters.setSize(610,180);
        PurgeParameters.setLocationByPlatform(true);
        PurgeParameters.setVisible(true);
    }//GEN-LAST:event_WritePurgeFileActionPerformed

    private void RunPurgeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunPurgeActionPerformed
        writePurgeDetDat();
        RunACommand cmd = new RunACommand(fck.convertToAbsolute(Purge_DetExe.getText()), new java.io.File(INSTRUMENT.getInputFileDir()), "Purge_det", true);
        //Attempt to load the group calibration table if it has been created
        INSTRUMENT.getGroupCalibrationTable();
    }//GEN-LAST:event_RunPurgeActionPerformed

    private void RunGudrunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunGudrunActionPerformed
        updateContentsOfCurrentInputFile();
        if (ErrorReporter.size() == 0) {
            RunACommand cmd = new RunACommand(fck.convertToAbsolute(GudrunExe.getText()), new java.io.File(INSTRUMENT.getInputFileDir()), "Gudrun_dcs", true);
            //Attempt to load the group calibration table if it has been created
            INSTRUMENT.getGroupCalibrationTable();
        }
    }//GEN-LAST:event_RunGudrunActionPerformed

    private void RunGnuplotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RunGnuplotActionPerformed
        RunACommand cmd = new RunACommand(fck.convertToAbsolute(GnuplotExe.getText()), new java.io.File(vs.getVar("InputFileDir")), "Gnuplot", false);
    }//GEN-LAST:event_RunGnuplotActionPerformed

    private void GetSystemValuesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GetSystemValuesActionPerformed
        SystemValues.setSize(610,300);
        SystemValues.setLocationRelativeTo(SystemMenu);
        SystemValues.setVisible(true);
    }//GEN-LAST:event_GetSystemValuesActionPerformed

    private void NoStdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NoStdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NoStdActionPerformed

    private void PurgeParDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PurgeParDoneActionPerformed
        PurgeParameters.setVisible(false);
        writePurgeDetDat();
    }//GEN-LAST:event_PurgeParDoneActionPerformed

    private void SaveSystemValuesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveSystemValuesActionPerformed
        saveSystemValues();
        vs.setVar(fck.convertToAbsolute(GnuplotExe.getText()), "GNUplotExe");
        vs.setVar(fck.convertToAbsolute(GNUplotPlotCommand.getText()), "GNUplotPlotCommand");
        SystemValues.setVisible(false);
    }//GEN-LAST:event_SaveSystemValuesActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // Initialise the store.
        initialiseStore();
        // Initialise the file checker
        fck = new gudrunlibrary.FileCheck(vs);
        getSystemValues();
        //Load the default startup file
        loadStartupFile();
//        setVariableStore();
    }//GEN-LAST:event_formComponentShown

    private void insertSampleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertSampleActionPerformed
        if(SampleBackgrounds.size() > 0) {
            insertSampleAtSelection(null);
        }
        // TODO add your handling code here:
}//GEN-LAST:event_insertSampleActionPerformed

    private void removeSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeSelectionActionPerformed
        removeSelection();
        // TODO add your handling code here:
}//GEN-LAST:event_removeSelectionActionPerformed

    private void insertContainerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertContainerActionPerformed
        if(Samples.size() > 0) {insertContainerAtSelection(null);}
        // TODO add your handling code here:
}//GEN-LAST:event_insertContainerActionPerformed

    private void BrowseGudrunDcsExecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseGudrunDcsExecActionPerformed
        FileChooserPanel fcp = new FileChooserPanel();
        String[] filetypes = {null};
        fcp.BrowseFilename(GudrunExe,"Choose Gudrun_DCS executable",filetypes,System.getProperty("user.dir"));
        //Convert file to relative
        GudrunExe.setText(fck.convertToRelative(GudrunExe.getText()));
    }//GEN-LAST:event_BrowseGudrunDcsExecActionPerformed

    private void BrowsePurge_DetExecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowsePurge_DetExecActionPerformed
        FileChooserPanel fcp = new FileChooserPanel();
        String[] filetypes = {null};
        fcp.BrowseFilename(Purge_DetExe,"Choose purge_det executable",filetypes,System.getProperty("user.dir"));
        Purge_DetExe.setText(fck.convertToRelative(Purge_DetExe.getText()));
    }//GEN-LAST:event_BrowsePurge_DetExecActionPerformed

    private void BrowseGnuplotExecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseGnuplotExecActionPerformed
        FileChooserPanel fcp = new FileChooserPanel();
        String[] filetypes = {null};
        fcp.BrowseFilename(GnuplotExe,"Choose gnuplot executable",filetypes,System.getProperty("user.dir"));
        GnuplotExe.setText(fck.convertToRelative(GnuplotExe.getText()));
    }//GEN-LAST:event_BrowseGnuplotExecActionPerformed

    private void BrowseStartupFilenameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseStartupFilenameActionPerformed
        FileChooserPanel fcp = new FileChooserPanel();
        String[] filetypes = {null};
        fcp.BrowseFilename(StartupFilename,"Choose startup file",filetypes,System.getProperty("user.dir"));
        StartupFilename.setText(fck.convertToRelative(StartupFilename.getText()));// TODO add your handling code here:
    }//GEN-LAST:event_BrowseStartupFilenameActionPerformed

    private void copySelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copySelectionActionPerformed
        copySelection();
    }//GEN-LAST:event_copySelectionActionPerformed

    private void pasteSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteSelectionActionPerformed
        pasteSelection();
    }//GEN-LAST:event_pasteSelectionActionPerformed

    private void insertSampleBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertSampleBackgroundActionPerformed
        insertSampleBackgroundAtSelection(null);
    }//GEN-LAST:event_insertSampleBackgroundActionPerformed

    private void SampleNameOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SampleNameOKActionPerformed
        setSampleName.setVisible(false);
    }//GEN-LAST:event_SampleNameOKActionPerformed

    private void SampleNameUseDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SampleNameUseDefaultActionPerformed
        String sn = "";
        SampleName.setText(sn);
        setSampleName.setVisible(false);
        
    }//GEN-LAST:event_SampleNameUseDefaultActionPerformed

    private void AnotherSampleNameOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnotherSampleNameOKActionPerformed
        setAnotherSampleName.setVisible(false);
        // TODO add your handling code here:
}//GEN-LAST:event_AnotherSampleNameOKActionPerformed

    private void AnotherSampleNameUseDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnotherSampleNameUseDefaultActionPerformed
        String sname = "";
        String sn = "";
        nsamplesnames = 0;
        //Need to ensure the name of the new sample is different from any in the current list
        boolean test = true;
        while (test) {
            int i = 0;
            test = false;
            nsamplesnames++;
            sn = "S"+String.valueOf(nsamplesnames);
            sname = "SAMPLE " + sn;
            for (i = 0; i < OPTIONS.getTabCount() && !test; i++) {
                if (i != ignoretab) {test = OPTIONS.getTitleAt(i).equals(sname);}
//                System.out.println(String.valueOf(i) + " " + sname + " " + OPTIONS.getTitleAt(i));
            }
        }
        AnotherSampleName.setText(sn);
        SampleName.setText(sn);
        // TODO add your handling code here:
        setAnotherSampleName.setVisible(false);//GEN-LAST:event_AnotherSampleNameUseDefaultActionPerformed
        setSampleName.setVisible(false);

}

    private void changeSampleNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeSampleNameActionPerformed
        //First check which SAMPLE BACKGROUND, SAMPLE or CONTAINER tab is selected
        int currenttab=OPTIONS.getSelectedIndex();
        int icountsamplebackgrounds = -1;
        int icountsamples = -1;
        int icountcontainers = -1;
        int icounttabs = 0;
        while (icounttabs <= currenttab) {
            if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND")  ) {
                icountsamplebackgrounds++;
            } else if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE")) {
                icountsamples++;
            } else if (OPTIONS.getTitleAt(icounttabs).contains("CONTAINER")){
                icountcontainers++;
            }
            icounttabs++;
        }
        String tname = OPTIONS.getTitleAt(currenttab);
        if (tname.contains("SAMPLE") && !tname.contains("SAMPLE BACKGROUND") ) {
            //Remove the "SAMPLE " from this name
            if (tname.length() > 7 ) {tname = tname.substring(7,tname.length());} else {tname = "";}
            SampleName.setText(tname);
        //Set the ignoretab value to the current sample tab, so that this tab is not tested for duplicates
            ignoretab = currenttab;
            setSampleName.setVisible(true);
            tname="SAMPLE " + SampleName.getText();
            //Change the name of the current sample and tab
            Samples.get(icountsamples).setName(tname);
            Samples.get(icountsamples).DataFiles.DataFilesLabel.setText(tname + " data files");
            OPTIONS.setTitleAt(currenttab, tname);
        } else if (tname.contains("CONTAINER")) {
            //Remove the "CONTAINER " from this name
            if (tname.length() > 10 ) {tname = tname.substring(10,tname.length());} else {tname = "";}
            SampleName.setText(tname);
            //Set the ignoretab value to the current sample tab, so that this tab is not tested for duplicates
            ignoretab = currenttab;
            setSampleName.setVisible(true);
            tname="CONTAINER " + SampleName.getText();
            //Change the name of the current sample and tab
            Containers.get(icountcontainers).setName(tname);
            Containers.get(icountcontainers).DataFiles.DataFilesLabel.setText(tname + " data files");
            OPTIONS.setTitleAt(currenttab, tname);
        }
    }//GEN-LAST:event_changeSampleNameActionPerformed

    private void getPlotDialogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getPlotDialogActionPerformed
//        gwf.setSize(1200,400);
        gwf.setLocationRelativeTo(PlotMenu);
        gwf.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_getPlotDialogActionPerformed

    private void BrowseGNUplotPlotCommandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseGNUplotPlotCommandActionPerformed
        FileChooserPanel fcp = new FileChooserPanel();
        String[] filetypes = {null};
        fcp.BrowseFilename(GNUplotPlotCommand,"Choose gnuplot plot command",filetypes,System.getProperty("user.dir"));
        GNUplotPlotCommand.setText(fck.convertToRelative(GNUplotPlotCommand.getText()));
        // TODO add your handling code here:
    }//GEN-LAST:event_BrowseGNUplotPlotCommandActionPerformed

    private void OKFileNotFoundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKFileNotFoundActionPerformed
        FileNotFoundMessages.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_OKFileNotFoundActionPerformed

    private void BrowseDefaultDataFileDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BrowseDefaultDataFileDirActionPerformed
        FileChooserPanel fcp = new FileChooserPanel();
        fcp.BrowseFileDir(DefaultDataFileDir,"Choose default data file directory", vs.getVar("DataFileDir"));
        if (UseDefaultDataFileDir.isSelected()) {
            INSTRUMENT.DataFileDir.setText(DefaultDataFileDir.getText());
            vs.setVar(DefaultDataFileDir.getText(), "DataFileDir");
            //Disable the edit and browse buttons in this window
            INSTRUMENT.DataFileDir.setEditable(false);
            INSTRUMENT.BrowseDataFileDir.setEnabled(false);
        } else {
            INSTRUMENT.DataFileDir.setEditable(true);
            INSTRUMENT.BrowseDataFileDir.setEnabled(true);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_BrowseDefaultDataFileDirActionPerformed

    private void UseDefaultDataFileDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UseDefaultDataFileDirActionPerformed
        if (UseDefaultDataFileDir.isSelected()) {
            INSTRUMENT.DataFileDir.setText(DefaultDataFileDir.getText());
            vs.setVar(DefaultDataFileDir.getText(), "DataFileDir");
            //Disable the edit and browse buttons in this window
            INSTRUMENT.DataFileDir.setEditable(false);
            INSTRUMENT.BrowseDataFileDir.setEnabled(false);
            UsingDefaultDataFileDirLabel.setVisible(true);
        } else {
            INSTRUMENT.DataFileDir.setEditable(true);
            INSTRUMENT.BrowseDataFileDir.setEnabled(true);
            UsingDefaultDataFileDirLabel.setVisible(false);
        }
        // TODO add your handling code here:
}//GEN-LAST:event_UseDefaultDataFileDirActionPerformed

    private void checkFilenamesExistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkFilenamesExistActionPerformed
        // TODO add your handling code here:
        gudrunlibrary.CheckFilenameExists cfe = new gudrunlibrary.CheckFilenameExists(vs);
        checkFilenamesExist(cfe);
        //Print out a warning if some files were not found
        if(Integer.valueOf(vs.getVar("FileNotFound")) > 0) {
            //Remove any existing FileNotFoundMessages
            FNFMs.clear();
            if(Integer.valueOf(vs.getVar("FileNotFound")) > 1) {
                FileNotFoundLabel.setText("The following files were not found in current input file");
            } else {
                FileNotFoundLabel.setText("The following file was not found in current input file");
            }
            //Populate the message board with the list of files not found
            for (int i = 0; i < cfe.FilenamesNotFound.size(); i++) {
                System.out.println(cfe.FilenamesNotFound.get(i) + " " + cfe.TabnamesNotFound.get(i));
                FNFMs.add(new gudrunlibrary.FileNotFoundMessagePanel(cfe.FilenamesNotFound.get(i), cfe.TabnamesNotFound.get(i)));
            }
            //Remove all the existing file not found messages
            FileNotFoundPanel.removeAll();
            //Following code is borrowed from above to add the new filename panel to the jPanel
            javax.swing.GroupLayout FileNotFoundPanelLayout = new javax.swing.GroupLayout(FileNotFoundPanel);
            FileNotFoundPanel.setLayout(FileNotFoundPanelLayout);
        
            //Horizontal group
            GroupLayout.ParallelGroup hgroup =  FileNotFoundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
            for (int i = 0; i < FNFMs.size(); i++) {hgroup.addComponent(FNFMs.get(i), javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE);}
            FileNotFoundPanelLayout.setHorizontalGroup(hgroup);
        
            //Vertical group
            GroupLayout.SequentialGroup vgroup = FileNotFoundPanelLayout.createSequentialGroup();
            for (int i = 0; i < FNFMs.size(); i++) {vgroup.addComponent(FNFMs.get(i), javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE);}
            FileNotFoundPanelLayout.setVerticalGroup(vgroup);
        
            FileNotFoundMessages.setSize(FNFMs.get(0).getPreferredSize().width+100, FNFMs.get(0).getPreferredSize().height*FNFMs.size()+300);
            FileNotFoundMessages.setVisible(true);
        } else {
            FileNotFoundMessages.setVisible(false);
            AllFilesFoundMessage.setVisible(true);
        }
    }//GEN-LAST:event_checkFilenamesExistActionPerformed

    private void reloadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reloadMenuItemActionPerformed
        InputFileName = vs.getVar("InputFileName");
        InputFileDir = vs.getVar("InputFileDir");
        if (!InputFileName.isEmpty()) { 
            FileInputStream fis = null;
            String str = null;
            try {
                fis = new FileInputStream(InputFileName);
                int size = fis.available();
                byte[] bytes = new byte [size];
                fis.read(bytes);
                str = new String(bytes);
            } catch (IOException e) {
            } finally {
                try {
                    fis.close();
                } catch (IOException e2) {
                }
            }
        
            if (str != null) {
                ContentsOfCurrentInputFile.setText(str);
                SaveContentsOfCurrentInputFile = str;
                // Attempt to parse the string to update the values in the GUI
                getContentsOfCurrentInputFile();
                //Need to restore the correct value of input file directory, in case it was changed by getContentsOfCCurrentInputFile
                vs.setVar(InputFileDir,"InputFileDir");
                //Put the stored values into their correct places
                getVariableStore();
            }

        } else {
            //Restore the current values to the variable store
            setVariableStore();
        }
// TODO add your handling code here:
    }//GEN-LAST:event_reloadMenuItemActionPerformed

    private void cutSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cutSelectionActionPerformed
        copySelection();
        removeSelection();
    }//GEN-LAST:event_cutSelectionActionPerformed

    private void SampleNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_SampleNameFocusGained
        System.out.println("SampleName has focus " + SampleName.hasFocus());
        // TODO add your handling code here:
    }//GEN-LAST:event_SampleNameFocusGained

    private void setSampleNameWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_setSampleNameWindowGainedFocus
        System.out.println("setSampleName is visible " + setSampleName.isVisible());
        SampleName.requestFocusInWindow();
        // TODO add your handling code here:
    }//GEN-LAST:event_setSampleNameWindowGainedFocus

    private void OKAllFilesFoundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKAllFilesFoundActionPerformed
        AllFilesFoundMessage.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_OKAllFilesFoundActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        exitGUIAction();
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    private void SaveGUIOnExitYesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveGUIOnExitYesButtonActionPerformed
        InputFileName = vs.getVar("InputFileName");
        if ((new File(InputFileName)).exists()) {
            doSave(InputFileName);
            carryon = true;
        } else {
            carryon = doSaveAsCarryOn();
        }
        SaveGUIOnExitDialog.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_SaveGUIOnExitYesButtonActionPerformed

    private void SaveGUIOnExitNoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveGUIOnExitNoButtonActionPerformed
        carryon = true;
        SaveGUIOnExitDialog.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_SaveGUIOnExitNoButtonActionPerformed

    private void SaveGUIOnExitCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveGUIOnExitCancelButtonActionPerformed
        carryon = false;
        SaveGUIOnExitDialog.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_SaveGUIOnExitCancelButtonActionPerformed

    private void SaveAsGUIOnExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveAsGUIOnExitButtonActionPerformed
        carryon = doSaveAsCarryOn();
        SaveGUIOnExitDialog.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_SaveAsGUIOnExitButtonActionPerformed

    private void SaveGUIOnExitDialogWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_SaveGUIOnExitDialogWindowClosing
        carryon = false;
        // TODO add your handling code here:
    }//GEN-LAST:event_SaveGUIOnExitDialogWindowClosing

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                  new gudrunn.MainNeutronFrame().setVisible(true);
            }
        });
    }

    public void initialiseStore() {
        //Initialise the store
        vs.initialise();
        //Set up the variables to be stored
        vs.addVar("InputFileDir");
        vs.addVar("OldInputFileDir");
        vs.addVar("InputFileName");
        vs.addVar("DataFileDir");
        vs.addVar("DataFileType");
        vs.addVar("SampleGeom");
        vs.addVar("LogQbins");
        vs.addVar("NotQbins");
        vs.addVar("GNUplotExe");
        vs.addVar("GNUplotPlotCommand");
        vs.addVar("GroupPlotSequence");
        vs.addVar("PlotFilename");
        vs.setVar("GNUplot.plt", "PlotFilename");
        vs.addVar("FileNotFound");
        vs.addVar("DefaultDataFileDir");
        vs.addVar("GudrunStartupFolder");
        //Select the first tab (Instrument)
        OPTIONS.setSelectedIndex(0);
        //Make the default data file dir label invisible
        UsingDefaultDataFileDirLabel.setVisible(false);
    }
    
    private void setVariableStore() {
        //Set the values in the variable store
        //Store the input file directory, data file directory, data file type, and sample geometry
        InputFileDir = INSTRUMENT.getInputFileDir();
        vs.setVar(InputFileDir, "InputFileDir");
        DataFileDir = INSTRUMENT.getDataFileDir();
        vs.setVar(DataFileDir, "DataFileDir");
        DataFileType = INSTRUMENT.getDataFileType();
        vs.setVar(DataFileType, "DataFileType");
        SampleGeom = BEAM.getSampleGeometry();
        vs.setVar(SampleGeom, "SampleGeom");
        //GNUplot commands
        vs.setVar(GnuplotExe.getText(), "GNUplotExe");
        vs.setVar(GNUplotPlotCommand.getText(), "GNUplotPlotCommand");
    }
    
    private void getVariableStore() {
        INSTRUMENT.setInputFileDir(vs.getVar("InputFileDir"));
        INSTRUMENT.setDataFileDir(vs.getVar("DataFileDir"));
        INSTRUMENT.setDataFileType(vs.getVar("DataFileType"));
        BEAM.setSampleGeometry(vs.getVar("SampleGeom"));
        InputFileDir = INSTRUMENT.getInputFileDir();
        DataFileDir = INSTRUMENT.getDataFileDir();
        DataFileType = INSTRUMENT.getDataFileType();
        SampleGeom = BEAM.getSampleGeometry();
    }
    
    private String getSampleName(String text) {
        SampleName.setText("");
        setSampleName.setVisible(true);
        return  text + " " + SampleName.getText();
    }
    
    private void copySelection() {
        //Remove all entries in the Error Reporter
        while (ErrorReporter.size() > 0 ) ErrorReporter.remove(ErrorReporter.size()-1);
        //Initial view is that nothing has been copied
        isSampleBackgroundClipboard = false;
        isSampleClipboard = false;
        isContainerClipboard = false;
         //Get the selected tab 
        int currenttab = OPTIONS.getSelectedIndex();
        //Do nothing if this is less than 3 - cannot copy the first 3 tabs
        if(currenttab > 2) {
            //First check which SAMPLE BACKGROUND, SAMPLE or CONTAINER tab is selected
            int icountsamplebackgrounds = -1;
            int icountsamples = -1;
            int icountcontainers = -1;
            int icounttabs = 0;
            while (icounttabs <= currenttab) {
                if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND")  ) {
                    icountsamplebackgrounds++;
                } else if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE")) {
                    icountsamples++;
                } else if (OPTIONS.getTitleAt(icounttabs).contains("CONTAINER")){
                    icountcontainers++;
                }
                icounttabs++;
            }
            //Determine if this is a sample background, sample or a container
            String title = OPTIONS.getTitleAt(currenttab);            
            if (title.contains("SAMPLE BACKGROUND")) {
                //Create the clipboard
                clipboardi=icountsamplebackgrounds;
                clipboardtab=currenttab;
                SampleBackgroundClipboard = SampleBackgrounds.get(clipboardi).getaClone(spc2, spc5, pathSeparator, 
                         ErrorReporter);
                isSampleBackgroundClipboard = true;
                isSampleClipboard = false;
                isContainerClipboard = false;
            } else if (title.contains("SAMPLE")) {
                //SAMPLE: find the corresponding SAMPLE name in the list of Samples and save it
                //Create the clipboard
                clipboardi=icountsamples;
                clipboardtab=currenttab;
                SampleClipboard = Samples.get(clipboardi).getaClone(spc2, spc5, pathSeparator, 
                         ErrorReporter);
                isSampleBackgroundClipboard = false;
                isSampleClipboard = true;
                isContainerClipboard = false;
            } else if (title.contains("CONTAINER")) {
                //Container: find the corresponding container name in the list of containers and save it
                //Create the clipboard
                clipboardi=icountcontainers;
                clipboardtab=currenttab;
                ContainerClipboard = Containers.get(clipboardi).getaClone(spc2, spc5, pathSeparator, 
                         ErrorReporter);
                isSampleBackgroundClipboard = false;
                isSampleClipboard = false;
                isContainerClipboard = true;
            }
        }
        if (ErrorReporter.size() > 0) {
            String GINstring = "*** WARNING! ***\n";
            for (int i = 0; i < ErrorReporter.size(); i++) {
                GINstring = GINstring + ErrorReporter.get(i) + "\n";
            }
            ContentsOfCurrentInputFile.setText(GINstring);
        }
    }
    
    private void pasteSelection() {
        if (isSampleBackgroundClipboard) {insertSampleBackgroundAtSelection(SampleBackgroundClipboard);}
        if (isSampleClipboard) {insertSampleAtSelection(SampleClipboard);}
        if (isContainerClipboard) {insertContainerAtSelection(ContainerClipboard);}
    }
    
    private void removeSelection() {
        //Get the title of the selected tab - this is also the name of the object to be removed 
        int currenttab = OPTIONS.getSelectedIndex();
        //Must not remove the first 4 tabs
        if ( currenttab  > 3 ) {
            //First check which SAMPLE BACKGROUND, SAMPLE or CONTAINER tab is selected
            int icountsamplebackgrounds = -1;
            int icountsamples = -1;
            int icountcontainers = -1;
            int icounttabs = 0;
            while (icounttabs <= currenttab) {
                if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND")  ) {
                    icountsamplebackgrounds++;
                } else if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE")) {
                    icountsamples++;
                } else if (OPTIONS.getTitleAt(icounttabs).contains("CONTAINER")){
                    icountcontainers++;
                }
                icounttabs++;
            }
            //If this is a sample background tab, simply remove tab
            if(OPTIONS.getTitleAt(currenttab).contains("SAMPLE BACKGROUND")) {
                SampleBackgrounds.remove(icountsamplebackgrounds);
                nsamplebackgrounds=SampleBackgrounds.size();
                //Remove the tab
                OPTIONS.removeTabAt(currenttab);
            } else if (OPTIONS.getTitleAt(currenttab).contains("SAMPLE")) {
                //Remove the sample from the list if it was found
                Samples.remove(icountsamples);
                nsamples=Samples.size();
                //Remove the tab
                OPTIONS.removeTabAt(currenttab);
            } else if (OPTIONS.getTitleAt(currenttab).contains("CONTAINER")) {
                //Remove container
                Containers.remove(icountcontainers);
                ncontainers=Containers.size();
                //Remove the tab
                OPTIONS.removeTabAt(currenttab);
            }
        }
    }

    private void insertSampleAtSelection(SamplePanel SampleInsert) {
        //Obtain the index of the currently selected pane
        int currenttab = OPTIONS.getSelectedIndex();
        //If currenttab < 3 do nothing since we must be at or beyond the first sample background.
        if (currenttab < 3) return;
        //Start a new SamplePanel to be inserted
        SamplePanel s;
        String sname = "";
        if (SampleInsert == null) {
            s = new SamplePanel(vs);
            sname = getSampleName("SAMPLE");
            s.setName(sname);
            s.DataFiles.DataFilesLabel.setText(sname + " data files");
        } else {
            s = SampleInsert.getaClone(spc2, spc5, pathSeparator, ErrorReporter);
            sname = s.getName();
        }
        //Count the number of sample tabs up to this point
        int icountsamples = 0;
        int icounttabs = 0;
        while (icounttabs <= currenttab) {
            //Don't include sample backgrounds!!
            if(OPTIONS.getTitleAt(icounttabs).contains("SAMPLE") && !OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND")) {
                icountsamples++;
            }
            icounttabs++;
        }
        Samples.add(icountsamples, s);
        nsamples=Samples.size();
        OPTIONS.insertTab(sname, null, s, null, icounttabs);
        OPTIONS.setSelectedIndex(icounttabs);
        //Set the ignoretab value to the current tab so that this tab is not checked when testing for names
        ignoretab = OPTIONS.getSelectedIndex();
    }
    
    private void insertContainerAtSelection(ContainerPanel ContainerInsert) {
        //This method will insert the new container AFTER the current selection and it give a name
        //corresponding the nearest previous sample
        //Can only insert a container if at least one sample is already defined
        if (Samples.size() > 0 ) {
            //Obtain the index of the currently selected pane
            int currenttab = OPTIONS.getSelectedIndex();
            //If currenttab < 4 do nothing since we must be at or beyond the first sample.
            if (currenttab < 4) return;
            //Also cannot insert a container after a sample background
            if (OPTIONS.getTitleAt(currenttab).contains("SAMPLE BACKGROUND")) return;
            //Container to insert
            ContainerPanel c;
            String cname = "";
            if (ContainerInsert == null) {
                c = new ContainerPanel(vs);
                cname = getSampleName("CONTAINER");
                c.setName(cname);
                c.DataFiles.DataFilesLabel.setText(cname + " data files");
            } else {
                c = ContainerInsert.getaClone(spc2, spc5, pathSeparator, ErrorReporter);
                cname = c.getName();
            }
            //Search for the container object immediately prior to the one to be inserted
            int icountcontainers = 0; //This is used to count the number of containers already existing up to this point.
            int icounttabs = 4; //This is used to count the tabs up to the present selected tab. It starts at 4 because the first 4 tabs are preassigned
            while (icounttabs <= currenttab) {
                if (OPTIONS.getTitleAt(icounttabs).contains("CONTAINER")) {
                    icountcontainers++;
                }
                icounttabs++;
            }
            Containers.add(icountcontainers, c);
            ncontainers=Containers.size();
            OPTIONS.insertTab(cname, null, c, null, icounttabs);
            OPTIONS.setSelectedIndex(icounttabs);
        }
        ignoretab = OPTIONS.getSelectedIndex();
    }
        
    private void insertSampleBackgroundAtSelection(SampleBackgroundPanel SampleBackgroundInsert) {
        //Get current tab. If this is less than 3, the sample background tab will be inserted at tab 3
        int currenttab = OPTIONS.getSelectedIndex();
        //SAMPLE BACKGROUND will be inserted either before the next sample. or else after the last container
        int icounttabs = currenttab;
        String CurrentTabTitle = OPTIONS.getTitleAt(icounttabs);
        //If the current tab contains "SAMPLE" move on to the next
        if (CurrentTabTitle.contains("SAMPLE")) {
            icounttabs++;
            if (icounttabs < OPTIONS.getTabCount()) CurrentTabTitle = OPTIONS.getTitleAt(icounttabs);
        }
        while (icounttabs < OPTIONS.getTabCount() && !(CurrentTabTitle.contains("SAMPLE"))) {
            icounttabs++;
            if (icounttabs < OPTIONS.getTabCount()) CurrentTabTitle = OPTIONS.getTitleAt(icounttabs);
        }
        int samplebackgroundtab = icounttabs;
        //Ensure new tab is not inserted before the first three tabs
        if (samplebackgroundtab < 3) {samplebackgroundtab = 3;}
        //Determine how many SAMPLE BACKGROUND tabs have already been inserted
        int icountsamplebackgrounds = 0; //This is used to count the number of sample backgrounds already existing up to this point.
        icounttabs = 0; //This is used to count the tabs up to the present selected tab. 
        while (icounttabs < samplebackgroundtab) {
            if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND")) {
                icountsamplebackgrounds++;
            }
            icounttabs++;
        }
        //Generate the sample background panel if it does not already exist
        //Sample background to insert
        SampleBackgroundPanel sb;
        String sbname = "";
        if (SampleBackgroundInsert == null) {
            sb = new SampleBackgroundPanel(vs);
            sbname = "SAMPLE BACKGROUND";
            sb.DataFiles.DataFilesLabel.setText(sbname + " data files");
            sb.setName(sbname);
        } else {
            sb= SampleBackgroundInsert.getaClone(spc2, spc5, pathSeparator, ErrorReporter);
            sbname = sb.getName();
        }
        //Insert the SampleBackground BEFORE the SAMPLE tab, but ensure this is after the third tab
        if (icounttabs > 2) {
            SampleBackgrounds.add(icountsamplebackgrounds, sb);
            nsamplebackgrounds=SampleBackgrounds.size();
            OPTIONS.insertTab(sbname, null, sb, null, icounttabs);
            OPTIONS.setSelectedIndex(icounttabs);
        }
        ignoretab = OPTIONS.getSelectedIndex();
    }
        
    private void getSystemValues() {
        
        String GudrunSystemFileName = System.getProperty("user.dir") + pathSeparator + "GudrunGUI.syspar";
        FileInputStream fis = null;
        String str = GudrunSystemFileName + "\n";
        try {
            fis = new FileInputStream(GudrunSystemFileName);
            int size = fis.available();
            byte[] bytes = new byte [size];
            fis.read(bytes);
            str = str + new String(bytes);
        } catch (IOException e) {
        } finally {
            try {
               fis.close();
            } catch (IOException e2) {
            }
        }

        if (str != null) {
            ContentsOfCurrentInputFile.setText(str);
        }
        
        // Parse str for newline characters. Put each line into the appropriate textfield
        
        int index1=str.indexOf("\n")+1;
        int index2=str.indexOf(";",index1);
        GudrunExe.setText(fck.convertToRelative(str.substring(index1,index2)));
        index1=str.indexOf("\n",index2)+1;
        index2=str.indexOf(";",index1);
        Purge_DetExe.setText(fck.convertToRelative(str.substring(index1,index2)));
        index1=str.indexOf("\n",index2)+1;
        index2=str.indexOf(";",index1);
        GnuplotExe.setText(fck.convertToRelative(str.substring(index1,index2)));
        vs.setVar(fck.convertToAbsolute(GnuplotExe.getText()), "GNUplotExe");
        index1=str.indexOf("\n",index2)+1;
        index2=str.indexOf(";",index1);
        GNUplotPlotCommand.setText(fck.convertToRelative(str.substring(index1,index2)));
        vs.setVar(fck.convertToAbsolute(GNUplotPlotCommand.getText()), "GNUplotPlotCommand");
        index1=str.indexOf("\n",index2)+1;
        index2=str.indexOf(";",index1);
        StartupFilename.setText(fck.convertToRelative(str.substring(index1,index2)));
//        GudrunStartupFolder = fck.convertToAbsoluteFile(StartupFilename.getText()).getParentFile();
//        vs.setVar(GudrunStartupFolder.getAbsolutePath(), "GudrunStartupFolder");
        vs.setVar(System.getProperty("user.dir"), "GudrunStartupFolder");
    }

    private void saveSystemValues() {
        
        String GudrunSystemFileName = System.getProperty("user.dir") + pathSeparator + "GudrunGUI.syspar";
        FileOutputStream fos = null;
        String str = null;
        str = fck.convertToRelative(GudrunExe.getText()) + ";\n";
        str = str + fck.convertToRelative(Purge_DetExe.getText()) + ";\n";
        str = str + GnuplotExe.getText() + ";\n";
        str = str + GNUplotPlotCommand.getText() + ";\n";
        str = str + fck.convertToRelative(StartupFilename.getText()) + ";\n";
        str = str + DefaultDataFileDir.getText() + ";\n";
        try {
            fos = new FileOutputStream(GudrunSystemFileName);
            fos.write(str.getBytes());
        } catch (IOException e) {
        } finally {
            try {
                fos.close();
            } catch (IOException e2) {
            }
        }
        //Need to save the Group plot sequence to the startup file
        //Save values to the variable store
        vs.setVar(GnuplotExe.getText(), "GNUplotExe");
        vs.setVar(GNUplotPlotCommand.getText(), "GNUplotPlotCommand");
        //Only insert the group plot sequence if it is not empty, otherwise insert a "1".
        if (GroupPlotSequence.getText().isEmpty()) {
            vs.setVar("1", "GroupPlotSequence");
        } else {
            vs.setVar(GroupPlotSequence.getText(), "GroupPlotSequence");
        }
        GudrunStartupFolder = fck.convertToAbsoluteFile(StartupFilename.getText()).getParentFile();
        vs.setVar(System.getProperty("user.dir"), "GudrunStartupFolder");
        
    }

    private void doSave(String GudrunInputFileName) {

        //Save the current values of the input file directory and the data file directory

        INSTRUMENT.setInputFileDir(vs.getVar("InputFileDir"));
        INSTRUMENT.setDataFileDir(vs.getVar("DataFileDir"));
        
        // Before saving we need to update ContentsOfCurrentInputfile
        
        updateContentsOfCurrentInputFile();
        
//        if (ErrorReporter.size() == 0) {
            FileOutputStream fos = null;
            String str = ContentsOfCurrentInputFile.getText();
            //Save these contents in case you attempt to close the GUI without saving it
            SaveContentsOfCurrentInputFile = str;
            try {
                fos = new FileOutputStream(GudrunInputFileName);
                fos.write(str.getBytes());
            } catch (IOException e) {
            } finally {
                 try {
                    fos.close();
                } catch (IOException e2) {
                }
            }
//        }
    }

    /** Asks for a file name. then saves the current content of editor pane to the file.
     */
    private void doSaveAs() {
        //Save the current input file directory. This is so that filenames that do not currently have an absolute path
        // will be given one if the save directory is different to the current input file directory
        vs.setVar(vs.getVar("InputFileDir"), "OldInputFileDir") ;
        //Instantiate a new file chooser panel
        FileChooserPanel fcp = new FileChooserPanel();
        //Use the doSaveAS method within this panel
        String[] filetypes = {"txt"};
        fcp.doSaveAs(vs, "InputFileDir", "InputFileName", "Save Gudrun input file", filetypes);
        //Get the new input file directory and file name
        InputFileName = vs.getVar("InputFileName");
        //Get the current input file directory
        InputFileDir = (new File(InputFileName)).getParent();
        vs.setVar(InputFileDir, "InputFileDir");
        CurrentInputFileName.setText("Gudrun Input File: " + InputFileName);
        System.out.println(vs.getVar("OldInputFileDir") + " " + vs.getVar("InputFileDir") + " " +InputFileName);
        //Check the files exist, and reset filenames if necessary
        gudrunlibrary.CheckFilenameExists cfe = new gudrunlibrary.CheckFilenameExists(vs);
        checkFilenamesExist(cfe);
              
        doSave(InputFileName);
    }

    private boolean doSaveAsCarryOn() {
        boolean thiscarryon;
        //Save the current input file directory. This is so that filenames that do not currently have an absolute path
        // will be given one if the save directory is different to the current input file directory
        vs.setVar(vs.getVar("InputFileDir"), "OldInputFileDir");
        //Instantiate a new file chooser panel
        gudrunlibrary.FileChooserPanel fcp = new gudrunlibrary.FileChooserPanel();
        //Use the doSaveAS method within this panel
        String[] filetypes = {"txt"};
        thiscarryon = fcp.doSaveAsCarryOn(vs, "InputFileDir", "InputFileName", "Save Gudrun input file", filetypes);
        if (thiscarryon) {
            //Get the new input file directory and file name
            InputFileDir = vs.getVar("InputFileDir");
            INSTRUMENT.setInputFileDir(InputFileDir);
            InputFileName = vs.getVar("InputFileName");
            CurrentInputFileName.setText("Gudrun Input File: " + InputFileName);
            System.out.println(vs.getVar("OldInputFileDir") + " " + vs.getVar("InputFileDir") + " " + InputFileName);
            //Check the files exist, and reset filenames if necessary
            gudrunlibrary.CheckFilenameExists cfe = new gudrunlibrary.CheckFilenameExists(vs);
            checkFilenamesExist(cfe);

            doSave(InputFileName);
        }
        return thiscarryon;
    }

    private void loadStartupFile() {
//        System.out.println(StartupFilename.getText());
        if (!StartupFilename.getText().isEmpty()) {
            String StartupFile = fck.convertToAbsolute(StartupFilename.getText());
            vs.setVar(StartupFilename.getText(), "InputFileName");
            FileInputStream fis = null;
            String str = null;
            try {
                fis = new FileInputStream(StartupFile);
                int size = fis.available();
                byte[] bytes = new byte [size];
                fis.read(bytes);
                str = new String(bytes);
//        System.out.println(str);
            } catch (IOException e) {
            } finally {
                try {
                    fis.close();
                } catch (IOException e2) {
                }
            }   
            if (str != null) {
                ContentsOfCurrentInputFile.setText(str);
                SaveContentsOfCurrentInputFile = str;
                // Attempt to parse the string to update the values in the GUI
                getContentsOfCurrentInputFile();
                CurrentInputFileName.setText("Gudrun Input File: " + StartupFile);
                //Save the startup data file directory as the default data file directory
                if(new File(vs.getVar("DataFileDir")).exists()){
                    DefaultDataFileDir.setText(vs.getVar("DataFileDir"));
                    vs.setVar(vs.getVar("DataFileDir"), "DefaultDataFileDir");
                }
                //Set the correct input file directory
                vs.setVar((new File(StartupFile).getParent()), "InputFileDir");
                INSTRUMENT.setInputFileDir(vs.getVar("InputFileDir"));
                //At the end of the startup file (after the END statement) there may be a list of group numbers for plotting.
                //These will be read into the appropriate window in systemvalues
                //Look for the END statement
                int index1 = str.lastIndexOf("END"+ spc5);
                index1 = str.indexOf("\n", index1) + 1;
                if (index1 < str.length()) {
                    GroupPlotSequence.setText(str.substring(index1));
                }
            }
        }
        if (GroupPlotSequence.getText().isEmpty()) GroupPlotSequence.setText("1");
        //Save the plot sequence to the variable store
        vs.setVar(GroupPlotSequence.getText(), "GroupPlotSequence");
    }

    private void updateContentsOfCurrentInputFile() {
        
        //Zero the error reporter
        while (ErrorReporter.size() > 0) {ErrorReporter.remove(ErrorReporter.size()-1);}
        /* Define the spacing between variables and labels. For input to Fortran we assume a minimum of
         * 1 space between variables
         */
        //Dummy string used to record lines
        String text = "'" + spc2 + "'" + spc2 + "'" + spc5 + "'" + spc2 + "'" + pathSeparator + "'" + "\n" + "\n";
        //String used to record data for DCS input file
        String GINstring = text;
        String GudDCSstring = text;
        String TabTitle = "";

        // Set up counters for the samples and containers arrays
        int icountsamples = -1;
        int icountcontainers = -1;
        int icountsamplebackgrounds = 0;
        int icounttabs=0;
        //Store the tab counter for the current sample
        int istorecurrentsampletab = 0;
        //Store the current sample
        int istorecurrentsample = 0;
        //Store the current container number
        int istorecurrentcontainer = 0;
        //Start the count of the number of containers for each sample. If this exceeds 4, no more will be written to the Gudrun Input File
        int icountNumberOfContainersForThisSample = 0;
        //Flag to indicate whether single file runs are being written
        boolean stillcounting = false;
        //Flag to indicate whether sample contains run files
        boolean SampleContainsRunFiles = false;
        //Step through the tabs and assign tab indices to each sample and any associated containers
        icounttabs = 0;
        int thissampletab = icounttabs;
        int thissamplenoofcontainers = 0;
        int thissamplecontainertab = -1;
        int thissamplecontainerindex = -1;
        while (icounttabs < OPTIONS.getTabCount()) {
            if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE") && !(OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND"))
                && icountsamples < Samples.size()-1) {
                //Sample found. First assign the current parameters to the previous sample if it  exists
                if(icountsamples > -1) {
                    Samples.get(icountsamples).setTabIndices(thissampletab
                            , thissamplenoofcontainers
                            , thissamplecontainertab
                            , thissamplecontainerindex);
                }
                icountsamples++;
                thissampletab = icounttabs;
                thissamplenoofcontainers = 0;
                thissamplecontainertab = icounttabs;
                thissamplecontainerindex = -1;
            } else if (OPTIONS.getTitleAt(icounttabs).contains("CONTAINER") && icountcontainers < Containers.size()-1) {
                icountcontainers++;
                thissamplenoofcontainers++;
                //If this is the first container save the tab and container indices
                if (thissamplenoofcontainers == 1) {
                    thissamplecontainertab = icounttabs;
                    thissamplecontainerindex = icountcontainers;
                }
            }
            icounttabs++;
        }
        //Save the last sample values
        if(icountsamples > -1) {
            Samples.get(icountsamples).setTabIndices(thissampletab
            , thissamplenoofcontainers
            , thissamplecontainertab
            , thissamplecontainerindex);
        }
        
        //Print out the results to make sure it has worked correctly
        for (int s = 0; s < Samples.size(); s++) {
            System.out.println(Samples.get(s).getSampleTab() + " "
                    + Samples.get(s).getNoOfContainers() + " "
                    + Samples.get(s).getFirstContainerTab() + " "
                    + Samples.get(s).getFirstContainerIndex());
        }
        
        icountsamples=0;
        icountcontainers=0;
        
        
        //Step through the tabs and write get contents
        icounttabs = 0;
        while (icounttabs < OPTIONS.getTabCount()) {
//System.out.println(String.valueOf(icounttabs) + " " + String.valueOf(icountsamples));
            
            // INSTRUMENT section
            if (OPTIONS.getTitleAt(icounttabs).contains("INSTRUMENT")) {
                TabTitle = OPTIONS.getTitleAt(icounttabs);
                text = TabTitle + spc5 + "{\n" + "\n";
                text = text + INSTRUMENT.getPanelContents(spc2, spc5, pathSeparator);
                // Indicate the end of section
                text = text + "\n" + "}\n\n";
                GINstring = GINstring + text;
                GudDCSstring = GudDCSstring + text;
                icounttabs++;
            } else
            //BEAM section
            if (OPTIONS.getTitleAt(icounttabs).contains("BEAM")) {
                TabTitle = OPTIONS.getTitleAt(icounttabs);
                text = TabTitle + spc5 + "{\n" + "\n";
                text = text + BEAM.getPanelContents(spc2, spc5, pathSeparator);
                // Indicate the end of section
                text = text + "\n" + "}\n\n";
                GINstring = GINstring + text;
                GudDCSstring = GudDCSstring + text;
                icounttabs++;
            } else
            //NORMALISATION section
            if (OPTIONS.getTitleAt(icounttabs).contains("NORMALISATION")) {
                TabTitle = OPTIONS.getTitleAt(icounttabs);
                text = TabTitle + spc5 + "{\n" + "\n";
                text = text + NORMALISATION.getPanelContents(spc2, spc5, pathSeparator, 
                        OPTIONS.getTitleAt(icounttabs), ErrorReporter);
                // Indicate the end of section
                text = text + "\n" + "}\n\n";
                GINstring = GINstring + text;
                GudDCSstring = GudDCSstring + text;
                icounttabs++;
            } else
            
            //SAMPLE BACKGROUND section
            if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND") && icountsamplebackgrounds < SampleBackgrounds.size()) {
                TabTitle = OPTIONS.getTitleAt(icounttabs);
                text = TabTitle + spc5 + "{\n" + "\n";
                text = text + SampleBackgrounds.get(icountsamplebackgrounds).getPanelContents(spc2, spc5, pathSeparator, 
                        OPTIONS.getTitleAt(icounttabs), ErrorReporter);
                // Indicate the end of section
                text = text + "\n" + "}\n\n";
                GINstring = GINstring + text;
                GudDCSstring = GudDCSstring + text;
                icountsamplebackgrounds++;
                icounttabs++;

            } else

                //SAMPLE and CONTAINER section
            if (OPTIONS.getTitleAt(icounttabs).contains("SAMPLE") && !(OPTIONS.getTitleAt(icounttabs).contains("SAMPLE BACKGROUND"))
                    && icountsamples < Samples.size()) {
                TabTitle = OPTIONS.getTitleAt(icounttabs);
                //Signal whether this sample is to be written to the Gudrun input file
                boolean AnalyseThisSample = Samples.get(icountsamples).AnalyseThisSample.isSelected();
                //Signal whether this sample contains any run files. If not nothing will be written to Gudrun_DCS.dat (including any associated containers)
                //but the output will be written to the output file in the usual way. 
                SampleContainsRunFiles = Samples.get(icountsamples).getNoOfDataFiles() > 0;
                //Start the count of the number of containers for each sample. If this exceeds 4, no more will be written to the Gudrun Input File
                icountNumberOfContainersForThisSample = Samples.get(icountsamples).getNoOfContainers();
                icountcontainers = Samples.get(icountsamples).getFirstContainerIndex();
                if (Samples.get(icountsamples).RunFilesSeparately.isSelected()
                        && SampleContainsRunFiles && AnalyseThisSample) {
                    //Get the text for the Gudrun_DCS run file
                    //Set the counter for the run files
                    int icountrunfiles = 0;
                    while (icountrunfiles < Samples.get(icountsamples).getNoOfDataFiles()) {
                        text = TabTitle + spc5 + "{\n" + "\n";
                        text = text +Samples.get(icountsamples).getPanelContents(spc2, spc5, pathSeparator,
                        OPTIONS.getTitleAt(icounttabs), ErrorReporter, icountrunfiles);
                        // Indicate the end of section
                        text = text + "\n" + "}\n\n";
                        //Add on any containers
                        icounttabs = Samples.get(icountsamples).getFirstContainerTab();
                        int icountcontainersthissample = 0;
                        int noofcontainersthissample = Math.min(3, Samples.get(icountsamples).getNoOfContainers());
                        while (icountcontainersthissample < noofcontainersthissample) {
                            //Increment tab counter
                            text = text + OPTIONS.getTitleAt(icounttabs) + spc5 + "{\n" + "\n";
                            text=text + Containers.get(icountcontainers).getPanelContents(spc2, spc5, pathSeparator,
                                OPTIONS.getTitleAt(icounttabs), ErrorReporter);
                            // Indicate the end of section
                            text = text + "\n" + "}\n\n";
                            icounttabs++;
                            icountcontainers++;
                            icountcontainersthissample++;
                        }
                        //need to insert a GO statement
                        text = text + "GO" + spc5 + "\n\n";
                        GudDCSstring = GudDCSstring + text;
                        icountrunfiles++;
                        //Set the tab and index counters back if not the last run
                        icounttabs = Samples.get(icountsamples).getSampleTab();
                        icountcontainers = Samples.get(icountsamples).getFirstContainerIndex();
                    }
                }
                
                //Now do the bit for the output file and Gudrun_DCS file if separate files are not being processed  
                text = TabTitle + spc5 + "{\n" + "\n";
                text = text +Samples.get(icountsamples).getPanelContents(spc2, spc5, pathSeparator,
                    OPTIONS.getTitleAt(icounttabs), ErrorReporter);
                // Indicate the end of section
                text = text + "\n" + "}\n\n";
                //Add on any containers
                icounttabs = Samples.get(icountsamples).getFirstContainerTab();
                int icountcontainersthissample = 0;
                int noofcontainersthissample = Math.min(3, Samples.get(icountsamples).getNoOfContainers());
                while (icountcontainersthissample < noofcontainersthissample) {
                    //Increment tab counter
                    text = text + OPTIONS.getTitleAt(icounttabs) + spc5 + "{\n" + "\n";
                    text=text + Containers.get(icountcontainers).getPanelContents(spc2, spc5, pathSeparator,
                        OPTIONS.getTitleAt(icounttabs), ErrorReporter);
                    // Indicate the end of section
                    text = text + "\n" + "}\n\n";
                    icounttabs++;
                    icountcontainers++;
                    icountcontainersthissample++;
                }
                if (noofcontainersthissample < 1) icounttabs++;
                //need to insert a GO statement
                text = text + "GO" + spc5 + "\n\n";
                 
                GINstring =  GINstring + text;
                if (SampleContainsRunFiles && !Samples.get(icountsamples).RunFilesSeparately.isSelected() && AnalyseThisSample)
                    GudDCSstring =  GudDCSstring + text;
                icountsamples++;

            } else {

                icounttabs++;

            }
        }
        // Add the  'END' statements
        text ="\n" + "END" + spc5 + "\n";
        GINstring = GINstring + text;
        GudDCSstring = GudDCSstring + text;
 
        // Finally dump it all into the text field if no errors are reported
        
        if (ErrorReporter.size() == 0 ) {
            ContentsOfCurrentInputFile.setText(GINstring);
            // Also write the Gudrun_dcs input file:
            String GudrunDcsDat =INSTRUMENT.getInputFileDir() + pathSeparator + Gudrundcsdat;
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(GudrunDcsDat);
                fos.write(GudDCSstring.getBytes());
            } catch (IOException e) {
            } finally {
                try {
                    fos.close();
                } catch (IOException e2) {
                }
            }
        } else {
            //Report the errors
//            GINstring = GINstring + "\n\n*** WARNING! ***\n";
//            for (int i = 0; i < ErrorReporter.size(); i++) {
//                GINstring = GINstring + ErrorReporter.get(i).toString().trim() + "\n";
//            }
            ContentsOfCurrentInputFile.setText(GINstring);
        }
        // Amen!
    }

    private void getContentsOfCurrentInputFile() {
        
        // Parse the contents of the current input file string and update the GUI
        
        //Initialise file not found counter
        vs.setVar("0", "FileNotFound");
        
        // Get the text to parse
        String str = ContentsOfCurrentInputFile.getText();

        int strindex1 = 0; //records beginning of current sectionname
        int strindex2 = 0; //records end of current sectionname

        // The first line of this includes the path separator from the previous file system. If this occurs anywhere in str
        // replace it with the current path separator
        // First search for the fifth occurrence of "'" in the first line of str:
        // the old path separator is the text between the fifth and sixth "'"
        String oldpathSeparator = ""; //Stores the path separator found in the input file.
        int i = 0;
        strindex1 = 0;
        strindex2 = -1;
        while (i < 6 && strindex2 < str.indexOf("\n")) {
            strindex1 = strindex2+1;
            strindex2 = str.indexOf("'", strindex1);
            i++;
        }
        if (i == 6) oldpathSeparator = str.substring(strindex1, strindex2);
        System.out.println(strindex1 + " " + strindex2 + " " + oldpathSeparator);
        //If oldpathSeparator has a length greater than 0, then replace each occurrence in str with the current path separator
        int oldpathSeparatorLength = oldpathSeparator.length();
        if (oldpathSeparatorLength > 0) {
            String newstr = "";
            strindex1 = 0;
            strindex2 = str.indexOf(oldpathSeparator);
            while (strindex2 > -1) {
                //Replace the old path separator with the new
                newstr = newstr + str.substring(strindex1, strindex2) + pathSeparator;
                strindex1 = strindex2+oldpathSeparatorLength;
                strindex2 = str.indexOf(oldpathSeparator, strindex1);
            }
            //Remember to add on the remainder of str
            newstr = newstr + str.substring(strindex1);
            //Save the newstr back into the original str.
            str = newstr;
        }

        //Initialise Samples and Containers arrays
        while (SampleBackgrounds.size()>0) {SampleBackgrounds.remove(SampleBackgrounds.size()-1);}
        while (Samples.size()>0) {Samples.remove(Samples.size()-1);}
        while (Containers.size()>0) {Containers.remove(Containers.size()-1);}
        nsamplebackgrounds=SampleBackgrounds.size();
        nsamples = Samples.size();
        ncontainers = Containers.size();
        //Remove any tabs other than the first 3
        while (OPTIONS.getTabCount() > 3) {OPTIONS.removeTabAt(OPTIONS.getTabCount()-1); }

        strindex1 = 0; //records beginning of current sectionname
        strindex2 = 0; //records end of current sectionname
        
        // Get the INSTRUMENT section
        // First search for the word "INSTRUMENT". The section name is everything from this word up to, but not including the "{"
        strindex1 = str.indexOf("INSTRUMENT",strindex2);
        strindex1 = str.indexOf(firststr,strindex1)+1;
        strindex2 = str.indexOf(laststr,strindex1);
//        System.out.println(sectionname);
        // Get the variables in this section
        gudrunlibrary.getSectionVariables SectionVariables = new gudrunlibrary.getSectionVariables(spc2, spc5 , str.substring(strindex1,strindex2));
        INSTRUMENT.setPanelContents(pathSeparator,  SectionVariables);
   
        // Get the BEAM section
        strindex1 = str.indexOf("BEAM",strindex2);
        strindex1 = str.indexOf(firststr,strindex1)+1;
        strindex2 = str.indexOf(laststr,strindex1);
//        System.out.println(sectionname);
        // Get the variables in this section
        SectionVariables = new gudrunlibrary.getSectionVariables(spc2, spc5 , str.substring(strindex1, strindex2));
        BEAM.setPanelContents(pathSeparator, SectionVariables);
   
        // Get the NORMALISATION section. Have to allow for older files which contain VANADIUM instead
        int strindext1 = str.indexOf("NORMALISATION",strindex2);
        int strindext2 = str.indexOf("VANADIUM",strindex2);
        if(strindext1 > strindext2) {
            strindex1 = strindext1;
        } else {
            strindex1 = strindext2;
        }
        strindex1 = str.indexOf(firststr,strindex1)+1;
        strindex2 = str.indexOf(laststr,strindex1);
//        System.out.println(sectionname);
        // Get the variables in this section
        SectionVariables = new gudrunlibrary.getSectionVariables(spc2, spc5 ,str.substring(strindex1, strindex2));
        NORMALISATION.setPanelContents(pathSeparator, SectionVariables);

        // For the sample backgrounds, samples and containers we will need to add the tab, as well as creating the objects
        while (strindex1 > 0 ) {

            //Search for the end of the previous section, and the beginning of the next
            strindex1 = str.indexOf(firststr, strindex2);
            if ( strindex1 > strindex2 && str.substring(strindex2,strindex1).contains("SAMPLE BACKGROUND") ) {
                //Next block is a sample background
                strindex1 = str.indexOf("SAMPLE BACKGROUND",strindex2);
                System.out.println(strindex1 + " " + str.substring(strindex1).indexOf(spc5));
                String sname = str.substring(strindex1, strindex1+str.substring(strindex1).indexOf(spc5));
                strindex1 = str.indexOf(firststr,strindex1)+1;
                strindex2 = str.indexOf(laststr,strindex1);
//                System.out.println(sectionname);
                // Get the variables in this section
                SectionVariables = new gudrunlibrary.getSectionVariables(spc2, spc5 ,str.substring(strindex1, strindex2));
                SampleBackgroundPanel sb = new SampleBackgroundPanel(vs);
                sb.setPanelContents(pathSeparator, SectionVariables);
                sb.setName(sname);
                sb.DataFiles.DataFilesLabel.setText(sname + " data files");
                SampleBackgrounds.add(sb);
                nsamplebackgrounds=SampleBackgrounds.size();
                //Add the new tab:
                OPTIONS.addTab(sname, sb);
            }
            if ( strindex1 > strindex2 && str.substring(strindex2,strindex1).contains("SAMPLE") && !str.substring(strindex2,strindex1).contains("SAMPLE BACKGROUND") ) {
                //Next block is a sample
                strindex1 = str.indexOf("SAMPLE",strindex2);
                String sname  = str.substring(strindex1,strindex1+str.substring(strindex1).indexOf(spc5));
                strindex1 = str.indexOf(firststr,strindex1)+1;
                strindex2 = str.indexOf(laststr,strindex1);
                // Get the variables in this section
                SectionVariables = new gudrunlibrary.getSectionVariables(spc2, spc5 ,str.substring(strindex1, strindex2));
                SamplePanel s = new SamplePanel(vs);
                s.setPanelContents(pathSeparator, SectionVariables);
                s.setName(sname);
                s.DataFiles.DataFilesLabel.setText(sname + " data files");
                Samples.add(s);
                nsamples=Samples.size();
                //Add the new tab:
                OPTIONS.addTab(sname, s);
//                System.out.println(sname + " " + s.DataFiles.FilenamesList.getModel().getSize()
//                        +" " + strindex1 
//                        + " " + strindex2);
            }


            if ( strindex1 > strindex2 && str.substring(strindex2,strindex1).contains("CONTAINER") && nsamples > 0) {
                //Next block is a container - can only add a container if the number of samples is > 0
                strindex1 = str.indexOf("CONTAINER",strindex2);
                String sname  = str.substring(strindex1,strindex1+str.substring(strindex1).indexOf(spc5));
                strindex1 = str.indexOf(firststr,strindex1)+1;
                strindex2 = str.indexOf(laststr,strindex1);
//                System.out.println(sectionname);
                // Get the variables in this section
                SectionVariables = new gudrunlibrary.getSectionVariables(spc2, spc5 ,str.substring(strindex1, strindex2));
                ContainerPanel c = new ContainerPanel(vs);
                c.setPanelContents(pathSeparator, SectionVariables);
                c.setName(sname);
                c.DataFiles.DataFilesLabel.setText(sname + " data files");
                Containers.add(c);
                ncontainers=Containers.size();
                //Add the new tab:
                OPTIONS.addTab(sname, c);
                strindex2 = str.indexOf(laststr,strindex2);
            }
        }
        pack();

    }

    private void writePurgeDetDat() {
        
        //Apart from the Instrument and Calibration lines, the order of the files here is not important

        String GINstring = "'" + spc2 + "'" + spc2 + "'" + spc5 + "'" + spc2 + "'" + pathSeparator + "'" + "\n" + "\n";
        GINstring = GINstring + INSTRUMENT.getPurgeDetInfo(spc2, spc5, pathSeparator);
        GINstring = GINstring + NoStd.getText() + spc2 + MaxStd.getText() + spc5 + NoStdLabel.getText() + " " + MaxStdLabel.getText() + "\n";
        if (Ignore.isSelected()) {
            GINstring = GINstring + 1 + spc5 + IgnoreLabel.getText() + "\n";
        } else {
            GINstring = GINstring + 0 + spc5 + IgnoreLabel.getText() + "\n";
        }
        GINstring = GINstring + NORMALISATION.getPurgeDetInfo(spc2, spc5, pathSeparator);
        for (SampleBackgroundPanel s : SampleBackgrounds) {GINstring = GINstring + s.getPurgeDetInfo(spc2, spc5, pathSeparator);}
        for (SamplePanel s : Samples) {GINstring = GINstring + s.getPurgeDetInfo(spc2, spc5, pathSeparator);}
        for (ContainerPanel c : Containers) {GINstring = GINstring + c.getPurgeDetInfo(spc2, spc5, pathSeparator);}
        
        // O.K. so write it out!
        // Setup file name of purge_det.dat
        String purgedetdat = INSTRUMENT.getInputFileDir() + pathSeparator + purgefilename;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(purgedetdat);
            fos.write(GINstring.getBytes());
        } catch (IOException e) {
        } finally {
            try {
                fos.close();
            } catch (IOException e2) {
            }
        }
    }
    
    public void checkFilenamesExist(gudrunlibrary.CheckFilenameExists cfe) {
        INSTRUMENT.checkFilenamesExist(cfe);
        BEAM.checkFilenamesExist(cfe);
        NORMALISATION.checkFilenamesExist(cfe);
        for (SampleBackgroundPanel s : SampleBackgrounds) {s.checkFilenamesExist(cfe);}
        for (SamplePanel s : Samples) {s.checkFilenamesExist(cfe);}
        for (ContainerPanel c : Containers) {c.checkFilenamesExist(cfe);}
    }

    private void exitGUIAction() {
        checkContentsOfCurrentInputFile();
        System.out.println(carryon);
        if (carryon) {
            System.exit(0);
//        } else {
//            ContentsOfCurrentInputFile.setText(SaveContentsOfCurrentInputFile);
        }
    }

    private void checkContentsOfCurrentInputFile() {
        //Set the flag to say whether to continue or not
        carryon = true;
        //Put the current GUI into the editor pane
        updateContentsOfCurrentInputFile();
        //Check that this has not changed since the last time it was saved
        if (!ContentsOfCurrentInputFile.getText().equals(SaveContentsOfCurrentInputFile)) {
            SaveGUIOnExitDialog.setLocationRelativeTo(CurrentInputFileName);
            SaveGUIOnExitDialog.setVisible(true);
        }
    }

    public String InputFileDir = "";
    public String InputFileName = "";
    public String DataFileDir = "";
    public String DataFileType = "";
    public String SampleGeom = "";
    public String spc2 = "  ";  /* Spacing between variables to go into distinct boxes in GUI
                                  * Variables to go into the same box should separated by only 1 space
                                  */
    public String spc5 = "          ";  // Separator between last variable and text describing variable
    private int lenspc2 = spc2.length();
    private int lenspc5 = spc5.length();
    private String pathSeparator = System.getProperty("file.separator");
    private String purgefilename = "purge_det.dat";
    private String Gudrundcsdat = "Gudrun_dcs.dat";
    //Initialise the variable store
    private gudrunlibrary.VariableStore vs = new gudrunlibrary.VariableStore();
    private int nsamplebackgrounds = 0; //Used to count the number of samples defined.
    private int nsamples = 0; //Used to count the number of samples defined.
    private int nsamplesnames = 0; //Used to generate titles for samples - never decremented
    private int ncontainers = 0; //Used to count the total number of containers
    private int ncontainersnames = 0;//Used to generate titles for containers
    private int ncontainerspersamplemax = 4; //Maximum number of containers per sample
    private ArrayList<SampleBackgroundPanel> SampleBackgrounds = new ArrayList<SampleBackgroundPanel>();
    private ArrayList<SamplePanel> Samples = new ArrayList<SamplePanel>();
    private ArrayList<ContainerPanel> Containers = new ArrayList<ContainerPanel>();
    private ArrayList<PlotFilenamePanel> PFPs = new ArrayList<PlotFilenamePanel>();
    private ArrayList<String> ErrorReporter = new ArrayList<String>();
    //Clipboard values
    private boolean isSampleBackgroundClipboard = false;
    private boolean isSampleClipboard = false;
    private boolean isContainerClipboard = false;
    private SampleBackgroundPanel SampleBackgroundClipboard;
    private SamplePanel SampleClipboard;
    private ContainerPanel ContainerClipboard;
    private String firststr = "{";//Beginning of section
    private String laststr = "}";//End of section
    private int clipboardtab = 0;//Used to say which tab is currently copied into the clipboard
    private int clipboardi = 0;//Used to say which element of Samples or Containers arrays are currently stored on the clipboard
    private int ignoretab = -1;//Used to say which tab to ignore when testing for sample names.
    //Initialise the GNUplot write form
    private gudrunlibrary.GNUplotWriteForm gwf = new gudrunlibrary.GNUplotWriteForm(vs);
    private ArrayList<gudrunlibrary.FileNotFoundMessagePanel> FNFMs = new ArrayList<gudrunlibrary.FileNotFoundMessagePanel>();
    private File GudrunStartupFolder; //Will contain name of folder where startup file is stored. Can also be used to store calibration and other common files.
    private gudrunlibrary.FileCheck fck;
    private String SaveContentsOfCurrentInputFile;
    private boolean carryon;


    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AllFilesFound;
    private javax.swing.JDialog AllFilesFoundMessage;
    private javax.swing.JPanel AllFilesFoundMessagePanel;
    private javax.swing.JTextField AnotherSampleName;
    private javax.swing.JLabel AnotherSampleNameHeader;
    private javax.swing.JButton AnotherSampleNameOK;
    private javax.swing.JButton AnotherSampleNameUseDefault;
    private gudrunn.BeamPanel BEAM;
    private javax.swing.JButton BrowseDefaultDataFileDir;
    private javax.swing.JButton BrowseGNUplotPlotCommand;
    private javax.swing.JButton BrowseGnuplotExec;
    private javax.swing.JButton BrowseGudrunDcsExec;
    private javax.swing.JButton BrowsePurge_DetExec;
    private javax.swing.JButton BrowseStartupFilename;
    private javax.swing.JTextArea ContentsOfCurrentInputFile;
    private javax.swing.JScrollPane CurrentInputFile;
    private javax.swing.JTextField CurrentInputFileName;
    private javax.swing.JTextField DefaultDataFileDir;
    private javax.swing.JLabel DefaultDataFileDirLabel;
    private javax.swing.JMenu Edit;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JLabel FileNotFoundLabel;
    private javax.swing.JPanel FileNotFoundMessagePanel;
    private javax.swing.JDialog FileNotFoundMessages;
    private javax.swing.JPanel FileNotFoundPanel;
    private javax.swing.JTextField GNUplotPlotCommand;
    private javax.swing.JLabel GNUplotPlotCommandLabel;
    private javax.swing.JMenuItem GetSystemValues;
    private javax.swing.JTextField GnuplotExe;
    private javax.swing.JLabel GnuplotExeLabel;
    private javax.swing.JTextField GroupPlotSequence;
    private javax.swing.JLabel GroupPlotSequenceLabel;
    private javax.swing.JTextField GudrunExe;
    private javax.swing.JLabel GudrunExeLabel;
    private gudrunn.InstrumentPanel INSTRUMENT;
    private javax.swing.JCheckBox Ignore;
    private javax.swing.JLabel IgnoreLabel;
    private javax.swing.JTextField MaxStd;
    private javax.swing.JLabel MaxStdLabel;
    private gudrunn.NormalisationPanel NORMALISATION;
    private javax.swing.JTextField NoStd;
    private javax.swing.JLabel NoStdLabel;
    private javax.swing.JButton OKAllFilesFound;
    private javax.swing.JButton OKFileNotFound;
    private javax.swing.JTabbedPane OPTIONS;
    private javax.swing.JMenu PlotMenu;
    private javax.swing.JButton PurgeParDone;
    private javax.swing.JPanel PurgeParValues;
    private javax.swing.JDialog PurgeParameters;
    private javax.swing.JTextField Purge_DetExe;
    private javax.swing.JLabel Purge_DetExeLabel;
    private javax.swing.JMenuItem RunGnuplot;
    private javax.swing.JMenuItem RunGudrun;
    private javax.swing.JMenu RunMenu;
    private javax.swing.JMenuItem RunPurge;
    public javax.swing.JTextField SampleName;
    private javax.swing.JLabel SampleNameHeader;
    private javax.swing.JButton SampleNameOK;
    private javax.swing.JButton SampleNameUseDefault;
    private javax.swing.JButton SaveAsGUIOnExitButton;
    private javax.swing.JButton SaveGUIOnExitCancelButton;
    private javax.swing.JDialog SaveGUIOnExitDialog;
    private javax.swing.JLabel SaveGUIOnExitLabel;
    private javax.swing.JButton SaveGUIOnExitNoButton;
    private javax.swing.JPanel SaveGUIOnExitPanel;
    private javax.swing.JButton SaveGUIOnExitYesButton;
    private javax.swing.JButton SaveSystemValues;
    private javax.swing.JTextField StartupFilename;
    private javax.swing.JLabel StartupFilenameLabel;
    private javax.swing.JMenu SystemMenu;
    private javax.swing.JDialog SystemValues;
    private javax.swing.JCheckBoxMenuItem UseDefaultDataFileDir;
    private javax.swing.JLabel UsingDefaultDataFileDirLabel;
    private javax.swing.JLabel WarningLabel;
    private javax.swing.JMenuItem WritePurgeFile;
    private javax.swing.JMenuItem changeSampleName;
    private javax.swing.JMenuItem checkFilenamesExist;
    private javax.swing.JMenuItem copySelection;
    private javax.swing.JMenuItem cutSelection;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenuItem getMenuItem;
    private javax.swing.JMenuItem getPlotDialog;
    private javax.swing.JMenuItem insertContainer;
    private javax.swing.JMenuItem insertSample;
    private javax.swing.JMenuItem insertSampleBackground;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator10;
    private javax.swing.JSeparator jSeparator11;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JSeparator jSeparator13;
    private javax.swing.JSeparator jSeparator14;
    private javax.swing.JSeparator jSeparator15;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem pasteSelection;
    private javax.swing.JMenuItem reloadMenuItem;
    private javax.swing.JMenuItem removeSelection;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JDialog setAnotherSampleName;
    private javax.swing.JDialog setSampleName;
    private javax.swing.JMenuItem updateMenuItem;
    // End of variables declaration//GEN-END:variables
    
}
