com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java Source code

Java tutorial

Introduction

Here is the source code for com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents;

import com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.DelayTableModel;
import com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint;
import com.github.dougkelly88.FLIMPlateReaderGUI.GeneralGUIComponents.SliderControl;
import com.github.dougkelly88.FLIMPlateReaderGUI.GeneralClasses.SeqAcqProps;
import com.github.dougkelly88.FLIMPlateReaderGUI.GeneralClasses.VariableTest;
import com.google.common.eventbus.Subscribe;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import static java.lang.Math.round;
import java.util.ArrayList;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellRenderer;
import mmcorej.CMMCore;
import org.jfree.chart.ChartPanel;
import org.micromanager.MMStudio;
import org.micromanager.api.events.PropertyChangedEvent;

/**
 *
 * @author dk1109
 */
public class FLIMPanel extends javax.swing.JPanel {

    MMStudio gui_;
    CMMCore core_;
    PropertyChangedEvent event_;
    SliderControl mcpSlider_;
    SliderControl gatewidthSlider_;
    SliderControl fastDelaySlider_;
    SliderControl slowDelaySlider_;
    JTable delayTable_;
    DelayTableModel tableModel_;
    FindMaxpoint fm_;
    ChartPanel chartPanel_;
    private SeqAcqProps sap_;
    private VariableTest var_;
    private Object parent_;

    @Subscribe
    public PropertyChangedEvent onPropertyChanged(PropertyChangedEvent event) {
        //        FLIMTestText.setText("google eventbus triggered in device " + event.getDevice() + "\n with property " + event.getProperty() + "\n changed to value " + event.getValue());
        event_ = event;
        return event;
    }

    /**
     * Creates new form FLIMPanel
     */
    public FLIMPanel() {
        initComponents();

        gui_ = MMStudio.getInstance();
        sap_ = SeqAcqProps.getInstance().setUseScanFLIM(false);
        var_ = VariableTest.getInstance();
        try {
            gui_.registerForEvents(this);
            core_ = gui_.getCore();
        } catch (Exception e) {
            //gui_.showMessage("Error in FLIMPanel constructor: " + e.getMessage());
        }

        setControlDefaults();
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        HRIControlsPanel = new javax.swing.JPanel();
        mcpVoltagePanel = new javax.swing.JPanel();
        gatewidthPanel = new javax.swing.JPanel();
        inhibitCheck = new javax.swing.JCheckBox();
        FLIMToolsPanel = new javax.swing.JPanel();
        maxpointGraphPanel = new javax.swing.JPanel();
        autogateButton = new javax.swing.JButton();
        maxpointPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        maxpointButton = new javax.swing.JButton();
        maxpointResolutionField = new javax.swing.JTextField();
        delayBoxTabbedPane = new javax.swing.JTabbedPane();
        fastDelayBoxPanel = new javax.swing.JPanel();
        fastBoxCalibratedCheck = new javax.swing.JCheckBox();
        scanDelCheck = new javax.swing.JCheckBox();
        fastCurrentDelayPanel = new javax.swing.JPanel();
        delaySeqPanel = new javax.swing.JPanel();
        clearDelayButton = new javax.swing.JButton();
        endField = new javax.swing.JTextField();
        incrementField = new javax.swing.JTextField();
        populateDelaysButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        startField = new javax.swing.JFormattedTextField();
        delayTablePanel = new javax.swing.JPanel();
        slowDelayBoxPanel = new javax.swing.JPanel();
        slowBoxCalibrated = new javax.swing.JCheckBox();
        slowCurrentDelayPanel = new javax.swing.JPanel();

        HRIControlsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("HRI controls"));

        mcpVoltagePanel.setToolTipText("Sets the microchannel plate gain voltage on the Kentech HRI. ");

        javax.swing.GroupLayout mcpVoltagePanelLayout = new javax.swing.GroupLayout(mcpVoltagePanel);
        mcpVoltagePanel.setLayout(mcpVoltagePanelLayout);
        mcpVoltagePanelLayout.setHorizontalGroup(mcpVoltagePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 274, Short.MAX_VALUE));
        mcpVoltagePanelLayout.setVerticalGroup(mcpVoltagePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 65, Short.MAX_VALUE));

        gatewidthPanel.setToolTipText("Sets the gate ON time on the Kentech HRI. ");

        javax.swing.GroupLayout gatewidthPanelLayout = new javax.swing.GroupLayout(gatewidthPanel);
        gatewidthPanel.setLayout(gatewidthPanelLayout);
        gatewidthPanelLayout.setHorizontalGroup(gatewidthPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 275, Short.MAX_VALUE));
        gatewidthPanelLayout.setVerticalGroup(gatewidthPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 65, Short.MAX_VALUE));

        inhibitCheck.setSelected(true);
        inhibitCheck.setText("Inhibit?");
        inhibitCheck.setToolTipText("Inhibits the HRI; uncheck to use the HRI for FLIM imaging");
        inhibitCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inhibitCheckActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout HRIControlsPanelLayout = new javax.swing.GroupLayout(HRIControlsPanel);
        HRIControlsPanel.setLayout(HRIControlsPanelLayout);
        HRIControlsPanelLayout.setHorizontalGroup(HRIControlsPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(HRIControlsPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(HRIControlsPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(HRIControlsPanelLayout.createSequentialGroup().addComponent(inhibitCheck)
                                        .addGap(0, 0, Short.MAX_VALUE))
                                .addGroup(HRIControlsPanelLayout.createSequentialGroup()
                                        .addComponent(gatewidthPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(mcpVoltagePanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap()))));
        HRIControlsPanelLayout.setVerticalGroup(
                HRIControlsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(HRIControlsPanelLayout.createSequentialGroup().addContainerGap()
                                .addComponent(inhibitCheck)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(HRIControlsPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(mcpVoltagePanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(gatewidthPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(34, Short.MAX_VALUE)));

        FLIMToolsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("FLIM tools"));

        maxpointGraphPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        maxpointGraphPanel.setMaximumSize(new java.awt.Dimension(630, 204));
        maxpointGraphPanel.setMinimumSize(new java.awt.Dimension(500, 100));
        maxpointGraphPanel.setPreferredSize(new java.awt.Dimension(579, 204));

        javax.swing.GroupLayout maxpointGraphPanelLayout = new javax.swing.GroupLayout(maxpointGraphPanel);
        maxpointGraphPanel.setLayout(maxpointGraphPanelLayout);
        maxpointGraphPanelLayout.setHorizontalGroup(maxpointGraphPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 566, Short.MAX_VALUE));
        maxpointGraphPanelLayout.setVerticalGroup(maxpointGraphPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 199, Short.MAX_VALUE));

        autogateButton.setText("Autogating...");
        autogateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autogateButtonActionPerformed(evt);
            }
        });

        maxpointPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1.setText("\"Find maxpoint\" resolution (ps)");

        maxpointButton.setText("Find maxpoint");
        maxpointButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxpointButtonActionPerformed(evt);
            }
        });

        maxpointResolutionField.setText("200");
        maxpointResolutionField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                maxpointResolutionFieldFocusLost(evt);
            }
        });
        maxpointResolutionField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxpointResolutionFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout maxpointPanelLayout = new javax.swing.GroupLayout(maxpointPanel);
        maxpointPanel.setLayout(maxpointPanelLayout);
        maxpointPanelLayout.setHorizontalGroup(
                maxpointPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(maxpointPanelLayout.createSequentialGroup().addContainerGap()
                                .addComponent(jLabel1).addGap(18, 18, 18)
                                .addComponent(maxpointResolutionField, javax.swing.GroupLayout.PREFERRED_SIZE, 49,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18).addComponent(maxpointButton)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        maxpointPanelLayout.setVerticalGroup(maxpointPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(maxpointPanelLayout.createSequentialGroup().addContainerGap().addGroup(maxpointPanelLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                        .addComponent(maxpointButton).addComponent(maxpointResolutionField,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        javax.swing.GroupLayout FLIMToolsPanelLayout = new javax.swing.GroupLayout(FLIMToolsPanel);
        FLIMToolsPanel.setLayout(FLIMToolsPanelLayout);
        FLIMToolsPanelLayout.setHorizontalGroup(FLIMToolsPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(FLIMToolsPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(FLIMToolsPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(FLIMToolsPanelLayout.createSequentialGroup()
                                        .addComponent(maxpointGraphPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                570, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(172, 172, 172))
                                .addGroup(FLIMToolsPanelLayout.createSequentialGroup()
                                        .addComponent(maxpointPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(autogateButton)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        FLIMToolsPanelLayout.setVerticalGroup(FLIMToolsPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, FLIMToolsPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(maxpointGraphPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addGroup(FLIMToolsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(autogateButton).addComponent(maxpointPanel,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        fastBoxCalibratedCheck.setText("Calibrated?");
        fastBoxCalibratedCheck.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fastBoxCalibratedCheckPropertyChange(evt);
            }
        });

        scanDelCheck.setText("Enable fast delay sequences?");
        scanDelCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                scanDelCheckActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout fastCurrentDelayPanelLayout = new javax.swing.GroupLayout(fastCurrentDelayPanel);
        fastCurrentDelayPanel.setLayout(fastCurrentDelayPanelLayout);
        fastCurrentDelayPanelLayout.setHorizontalGroup(fastCurrentDelayPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 275, Short.MAX_VALUE));
        fastCurrentDelayPanelLayout.setVerticalGroup(fastCurrentDelayPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 65, Short.MAX_VALUE));

        delaySeqPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Delay sequence"));

        clearDelayButton.setText("Clear delays");
        clearDelayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearDelayButtonActionPerformed(evt);
            }
        });

        endField.setText("16000");
        endField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                endFieldFocusLost(evt);
            }
        });
        endField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                endFieldActionPerformed(evt);
            }
        });
        endField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                endFieldPropertyChange(evt);
            }
        });

        incrementField.setText("25");
        incrementField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                incrementFieldFocusLost(evt);
            }
        });
        incrementField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                incrementFieldActionPerformed(evt);
            }
        });

        populateDelaysButton.setText("Populate delays");
        populateDelaysButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                populateDelaysButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Start (ps):");

        jLabel3.setText("End (ps):");

        jLabel4.setText("Increment:");

        startField.setText("0");
        startField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                startFieldFocusLost(evt);
            }
        });
        startField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startFieldActionPerformed(evt);
            }
        });
        startField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                startFieldPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout delayTablePanelLayout = new javax.swing.GroupLayout(delayTablePanel);
        delayTablePanel.setLayout(delayTablePanelLayout);
        delayTablePanelLayout.setHorizontalGroup(delayTablePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 126, Short.MAX_VALUE));
        delayTablePanelLayout.setVerticalGroup(delayTablePanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 130, Short.MAX_VALUE));

        javax.swing.GroupLayout delaySeqPanelLayout = new javax.swing.GroupLayout(delaySeqPanel);
        delaySeqPanel.setLayout(delaySeqPanelLayout);
        delaySeqPanelLayout.setHorizontalGroup(delaySeqPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(delaySeqPanelLayout.createSequentialGroup().addContainerGap()
                        .addComponent(delayTablePanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(delaySeqPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(delaySeqPanelLayout.createSequentialGroup().addGroup(delaySeqPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(populateDelaysButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(clearDelayButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addContainerGap())
                                .addGroup(delaySeqPanelLayout.createSequentialGroup()
                                        .addGroup(delaySeqPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2).addComponent(jLabel3).addComponent(jLabel4))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(delaySeqPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(endField).addComponent(incrementField)
                                                .addComponent(startField))
                                        .addGap(10, 10, 10)))));
        delaySeqPanelLayout
                .setVerticalGroup(delaySeqPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(delaySeqPanelLayout.createSequentialGroup().addComponent(clearDelayButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(delaySeqPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel2).addComponent(startField,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(delaySeqPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(endField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(delaySeqPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(incrementField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(populateDelaysButton).addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(
                                delaySeqPanelLayout.createSequentialGroup()
                                        .addComponent(delayTablePanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap()));

        javax.swing.GroupLayout fastDelayBoxPanelLayout = new javax.swing.GroupLayout(fastDelayBoxPanel);
        fastDelayBoxPanel.setLayout(fastDelayBoxPanelLayout);
        fastDelayBoxPanelLayout.setHorizontalGroup(
                fastDelayBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(fastDelayBoxPanelLayout.createSequentialGroup().addContainerGap()
                                .addGroup(fastDelayBoxPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(fastBoxCalibratedCheck)
                                        .addComponent(fastCurrentDelayPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(scanDelCheck))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(delaySeqPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)));
        fastDelayBoxPanelLayout.setVerticalGroup(fastDelayBoxPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(fastDelayBoxPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(fastDelayBoxPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(fastDelayBoxPanelLayout.createSequentialGroup()
                                        .addComponent(delaySeqPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(fastDelayBoxPanelLayout.createSequentialGroup()
                                        .addComponent(fastBoxCalibratedCheck).addGap(18, 18, Short.MAX_VALUE)
                                        .addComponent(fastCurrentDelayPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(scanDelCheck).addGap(20, 20, 20)))));

        delayBoxTabbedPane.addTab("Fast delay box", fastDelayBoxPanel);

        slowBoxCalibrated.setText("Calibrated?");
        slowBoxCalibrated.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                slowBoxCalibratedStateChanged(evt);
            }
        });

        javax.swing.GroupLayout slowCurrentDelayPanelLayout = new javax.swing.GroupLayout(slowCurrentDelayPanel);
        slowCurrentDelayPanel.setLayout(slowCurrentDelayPanelLayout);
        slowCurrentDelayPanelLayout.setHorizontalGroup(slowCurrentDelayPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 345, Short.MAX_VALUE));
        slowCurrentDelayPanelLayout.setVerticalGroup(slowCurrentDelayPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 65, Short.MAX_VALUE));

        javax.swing.GroupLayout slowDelayBoxPanelLayout = new javax.swing.GroupLayout(slowDelayBoxPanel);
        slowDelayBoxPanel.setLayout(slowDelayBoxPanelLayout);
        slowDelayBoxPanelLayout.setHorizontalGroup(
                slowDelayBoxPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(slowDelayBoxPanelLayout.createSequentialGroup().addContainerGap()
                                .addGroup(slowDelayBoxPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(slowBoxCalibrated).addComponent(slowCurrentDelayPanel,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(235, Short.MAX_VALUE)));
        slowDelayBoxPanelLayout.setVerticalGroup(slowDelayBoxPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(slowDelayBoxPanelLayout.createSequentialGroup().addGap(11, 11, 11)
                        .addComponent(slowBoxCalibrated).addGap(18, 21, Short.MAX_VALUE)
                        .addComponent(slowCurrentDelayPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(59, Short.MAX_VALUE)));

        delayBoxTabbedPane.addTab("Slow delay box", slowDelayBoxPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(HRIControlsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(delayBoxTabbedPane, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(FLIMToolsPanel, javax.swing.GroupLayout.Alignment.LEADING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addGap(26, 26, 26)
                        .addComponent(delayBoxTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 207,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(FLIMToolsPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(HRIControlsPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));
    }// </editor-fold>//GEN-END:initComponents

    private void inhibitCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inhibitCheckActionPerformed
        //        FLIMTestText.setText("Inhibit state = " + inhibitCheck.isSelected());
    }//GEN-LAST:event_inhibitCheckActionPerformed

    private void maxpointResolutionFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxpointResolutionFieldActionPerformed
        int num = Integer.parseInt(maxpointResolutionField.getText());
        fm_.setResolution(num);
    }//GEN-LAST:event_maxpointResolutionFieldActionPerformed

    private void maxpointButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxpointButtonActionPerformed

        fm_.acqMaxpointData();
    }//GEN-LAST:event_maxpointButtonActionPerformed

    private void startFieldPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_startFieldPropertyChange

    }//GEN-LAST:event_startFieldPropertyChange

    private void populateDelaysButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_populateDelaysButtonActionPerformed
        int max;
        int min;
        int incr;
        ArrayList<Integer> dv = new ArrayList<Integer>();

        // deal with case in which start and end have been entered the wrong way round...
        if (Integer.parseInt(startField.getText()) > Integer.parseInt(endField.getText())) {
            max = Integer.parseInt(startField.getText());
            min = Integer.parseInt(endField.getText());
            startField.setText(String.valueOf(min));
            endField.setText(String.valueOf(max));
        } else {
            max = Integer.parseInt(endField.getText());
            min = Integer.parseInt(startField.getText());
        }
        incr = Integer.parseInt(incrementField.getText());

        for (int i = min; i < max + 1; i = i + incr) {
            dv.add(i);
        }

        tableModel_.addWholeData(dv);
        //var_.delays=dv;

    }//GEN-LAST:event_populateDelaysButtonActionPerformed

    private void incrementFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incrementFieldActionPerformed
        updateDelayField(incrementField);
    }//GEN-LAST:event_incrementFieldActionPerformed

    private void endFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endFieldActionPerformed
        updateDelayField(endField);
    }//GEN-LAST:event_endFieldActionPerformed

    private void clearDelayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearDelayButtonActionPerformed
        tableModel_.clearAllData();
    }//GEN-LAST:event_clearDelayButtonActionPerformed

    private void scanDelCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scanDelCheckActionPerformed
        sap_ = sap_.setUseScanFLIM(scanDelCheck.isSelected());
        var_.scanDelCheck = scanDelCheck.isSelected();

    }//GEN-LAST:event_scanDelCheckActionPerformed

    private void startFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startFieldActionPerformed
        updateDelayField(startField);
    }//GEN-LAST:event_startFieldActionPerformed

    private void startFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_startFieldFocusLost
        updateDelayField(startField);
    }//GEN-LAST:event_startFieldFocusLost

    private void endFieldPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_endFieldPropertyChange
        updateDelayField(endField);
    }//GEN-LAST:event_endFieldPropertyChange

    private void endFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_endFieldFocusLost
        updateDelayField(endField);
    }//GEN-LAST:event_endFieldFocusLost

    private void incrementFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_incrementFieldFocusLost
        updateDelayField(incrementField);
    }//GEN-LAST:event_incrementFieldFocusLost

    private void maxpointResolutionFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_maxpointResolutionFieldFocusLost
        int num = Integer.parseInt(maxpointResolutionField.getText());
        fm_.setResolution(num);
    }//GEN-LAST:event_maxpointResolutionFieldFocusLost

    private void autogateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autogateButtonActionPerformed
        tableModel_.addWholeData(fm_.genAutogates());
    }//GEN-LAST:event_autogateButtonActionPerformed

    private void slowBoxCalibratedStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_slowBoxCalibratedStateChanged
        var_.slowBoxCalibratedCheck = slowBoxCalibrated.isSelected();
        // TODO add your handling code here:
    }//GEN-LAST:event_slowBoxCalibratedStateChanged

    private void fastBoxCalibratedCheckPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_fastBoxCalibratedCheckPropertyChange
        var_.fastBoxCalibratedCheck = fastBoxCalibratedCheck.isSelected();
        // TODO add your handling code here:
    }//GEN-LAST:event_fastBoxCalibratedCheckPropertyChange

    private void updateDelayField(JTextField field) {
        int num = 0;
        int min = 0;
        int max = 16666;
        int inc = 25;

        try {
            max = Integer.parseInt(core_.getProperty("Laser", "Frequency"));
        } catch (Exception e) {
        }

        if (!field.getText().isEmpty()) {
            num = Integer.parseInt(field.getText());
            if (num > max)
                num = max;
            else if (num < min)
                num = min;
            num = round(num / inc) * inc;
        } else {
            num = min;
        }
        field.setText(String.valueOf(num));
    }

    private String test(String dev, String prop) {
        String out;
        try {
            out = core_.getProperty(dev, prop);
        } catch (Exception e) {
            out = "Error:" + e.getMessage();
        }
        return out;
    }

    private void setControlDefaults() {

        String[] colName = { "Delays (ps)" };
        int max = 16666;
        try {
            max = Integer.parseInt(core_.getProperty("Laser", "Frequency"));
        } catch (Exception e) {
        }

        tableModel_ = new DelayTableModel(colName, (sap_.getDelaysArray()).get(0), 0, max, 25);
        tableModel_.addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent e) {
                sap_.setDelaysArray(0, tableModel_.getData());
                fm_.setGatingData((sap_.getDelaysArray()).get(0));
                var_.delays = tableModel_.getData();
            }
        });
        delayTable_ = new JTable() {
            @Override
            public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                Component comp = super.prepareRenderer(renderer, row, column);
                int modelRow = convertRowIndexToModel(row);
                int modelColumn = convertColumnIndexToModel(column);
                if (modelColumn != 0 && modelRow != 0) {
                    comp.setBackground(Color.GREEN);
                }

                return comp;
            }
        };
        delayTable_.setModel(tableModel_);
        delayTable_.setSurrendersFocusOnKeystroke(true);
        delayTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

        JScrollPane scroller = new javax.swing.JScrollPane(delayTable_);
        delayTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(60, 100));
        delayTablePanel.setLayout(new BorderLayout());
        delayTablePanel.add(scroller, BorderLayout.CENTER);

        final JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem deleteItem = new JMenuItem("Delete delay");
        deleteItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int r = delayTable_.getSelectedRow();
                tableModel_.removeRow(r);
            }
        });
        JMenuItem addItem = new JMenuItem("Add delay");
        addItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int r = delayTable_.getSelectedRow();
                tableModel_.insertRow(r + 1, 0);
            }
        });
        popupMenu.add(addItem);
        popupMenu.add(deleteItem);
        delayTable_.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                //                System.out.println("pressed");
            }

            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    JTable source = (JTable) e.getSource();
                    int row = source.rowAtPoint(e.getPoint());
                    int column = source.columnAtPoint(e.getPoint());

                    if (!source.isRowSelected(row))
                        source.changeSelection(row, column, false, false);

                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        // Set up slider controls
        mcpSlider_ = new SliderControl("MCP voltage (V)", 300, 850, 750);
        mcpVoltagePanel.setLayout(new BorderLayout());
        mcpVoltagePanel.add(mcpSlider_, BorderLayout.SOUTH);
        mcpSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                mcpSliderPropertyChange(evt);
            }
        });

        gatewidthSlider_ = new SliderControl("Gate width (ps)", 200, 7000, 3000);
        gatewidthPanel.setLayout(new BorderLayout());
        gatewidthPanel.add(gatewidthSlider_, BorderLayout.SOUTH);
        gatewidthSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                gatewidthSliderPropertyChange(evt);
            }
        });

        HRIControlsPanel.revalidate();
        HRIControlsPanel.repaint();

        slowDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0);
        slowCurrentDelayPanel.setLayout(new BorderLayout());
        slowCurrentDelayPanel.add(slowDelaySlider_, BorderLayout.SOUTH);
        slowDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                slowDelaySlider_.setValue(tableModel_.validateData(slowDelaySlider_.getValue().intValue()));
                slowDelaySliderPropertyChange(evt);
            }
        });

        fastDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0);
        fastCurrentDelayPanel.setLayout(new BorderLayout());
        fastCurrentDelayPanel.add(fastDelaySlider_, BorderLayout.SOUTH);
        fastDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                fastDelaySlider_.setValue(tableModel_.validateData(fastDelaySlider_.getValue().intValue()));
                fastDelaySliderPropertyChange(evt);
            }
        });

        delayBoxTabbedPane.revalidate();
        delayBoxTabbedPane.repaint();

        fm_ = new FindMaxpoint();
        maxpointGraphPanel.setLayout(new BorderLayout());
        chartPanel_ = new ChartPanel(fm_.getChart());
        maxpointGraphPanel.add(chartPanel_, BorderLayout.NORTH);
        // for some reason maxpointGraphPanel's height and width are returned 0
        // so hardcode for now...
        chartPanel_.setMaximumDrawWidth(500);
        chartPanel_.setMaximumDrawHeight(200);
        chartPanel_.setPreferredSize(new Dimension(500, 200));

        // Set values for other controls based on underlying data to ensure
        // that all controls are in a consistent state. 
        scanDelCheck.setSelected(sap_.getUseScanFLIM());

    }

    private void mcpSliderPropertyChange(java.beans.PropertyChangeEvent evt) {
        var_.mcpSlider = mcpSlider_.getValue();
        //        FLIMTestText.setText("MCP slider value = " + mcpSlider_.getValue());

    }

    private void gatewidthSliderPropertyChange(java.beans.PropertyChangeEvent evt) {
        var_.gatewidthSlider = gatewidthSlider_.getValue();
        //        FLIMTestText.setText("Gatewidth value = " + gatewidthSlider_.getValue());

    }

    private void fastDelaySliderPropertyChange(java.beans.PropertyChangeEvent evt) {
        var_.fastDelaySlider = fastDelaySlider_.getValue();
        //        FLIMTestText.setText("Fast delay value = " + fastDelaySlider_.getValue());

    }

    private void slowDelaySliderPropertyChange(java.beans.PropertyChangeEvent evt) {
        var_.slowDelaySlider = slowDelaySlider_.getValue();
        //        FLIMTestText.setText("Slow delay value = " + slowDelaySlider_.getValue());
    }

    public void setLoadedSoftwareValues() {
        // searching label of property in SoftwareConfig and set values in FLIMPanle
        scanDelCheck.setSelected(Boolean.parseBoolean(var_.findLabelOfProperty("Fast Current Delay Setting")));
        fastBoxCalibratedCheck.setSelected(Boolean.parseBoolean(var_.findLabelOfProperty("Calibrate? (fastBox)")));
        slowBoxCalibrated.setSelected(Boolean.parseBoolean(var_.findLabelOfProperty("Calibrate? (slowBox)")));
        mcpSlider_.setValue((int) Double.parseDouble(var_.findLabelOfProperty("MCP Voltage")));
        gatewidthSlider_.setValue((int) Double.parseDouble((var_.findLabelOfProperty("Gate Width"))));
        fastDelaySlider_
                .setValue((int) Double.parseDouble((var_.findLabelOfProperty("Fast Current Delay Setting"))));
        slowDelaySlider_
                .setValue((int) Double.parseDouble((var_.findLabelOfProperty("Slow Current Delay Setting"))));
        tableModel_.addWholeData(var_.findLabelOfPropertyForArrayList("Delay Sequence in [ps]"));
    }

    public void setParent(Object o) {
        parent_ = o;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel FLIMToolsPanel;
    private javax.swing.JPanel HRIControlsPanel;
    private javax.swing.JButton autogateButton;
    private javax.swing.JButton clearDelayButton;
    private javax.swing.JTabbedPane delayBoxTabbedPane;
    private javax.swing.JPanel delaySeqPanel;
    private javax.swing.JPanel delayTablePanel;
    private javax.swing.JTextField endField;
    private javax.swing.JCheckBox fastBoxCalibratedCheck;
    private javax.swing.JPanel fastCurrentDelayPanel;
    private javax.swing.JPanel fastDelayBoxPanel;
    private javax.swing.JPanel gatewidthPanel;
    private javax.swing.JTextField incrementField;
    private javax.swing.JCheckBox inhibitCheck;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton maxpointButton;
    private javax.swing.JPanel maxpointGraphPanel;
    private javax.swing.JPanel maxpointPanel;
    private javax.swing.JTextField maxpointResolutionField;
    private javax.swing.JPanel mcpVoltagePanel;
    private javax.swing.JButton populateDelaysButton;
    private javax.swing.JCheckBox scanDelCheck;
    private javax.swing.JCheckBox slowBoxCalibrated;
    private javax.swing.JPanel slowCurrentDelayPanel;
    private javax.swing.JPanel slowDelayBoxPanel;
    private javax.swing.JFormattedTextField startField;
    // End of variables declaration//GEN-END:variables
}