From 42aa3e02fc4a646701fb20fda35cfd248f1ec80f Mon Sep 17 00:00:00 2001 From: gac-x03da Date: Tue, 29 Sep 2020 11:01:36 +0200 Subject: [PATCH] Startup --- plugins/XPSSpectrum.form | 870 ++++++++++----------- plugins/XPSSpectrum.java | 1582 +++++++++++++++++++------------------- 2 files changed, 1246 insertions(+), 1206 deletions(-) diff --git a/plugins/XPSSpectrum.form b/plugins/XPSSpectrum.form index e25d4422..d7e015be 100644 --- a/plugins/XPSSpectrum.form +++ b/plugins/XPSSpectrum.form @@ -1,435 +1,435 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/XPSSpectrum.java b/plugins/XPSSpectrum.java index 07572bc7..bf86ebaf 100644 --- a/plugins/XPSSpectrum.java +++ b/plugins/XPSSpectrum.java @@ -1,771 +1,811 @@ -/* - * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. - */ - -import ch.psi.pshell.core.Context; -import ch.psi.pshell.device.Device; -import ch.psi.pshell.device.DeviceAdapter; -import ch.psi.pshell.device.DeviceListener; -import ch.psi.pshell.epics.Scienta; -import ch.psi.pshell.plot.LinePlotSeries; -import ch.psi.pshell.plot.RangeSelectionPlot.RangeSelection; -import ch.psi.pshell.ui.Panel; -import ch.psi.utils.IO; -import ch.psi.utils.Serializer; -import ch.psi.utils.State; -import ch.psi.utils.swing.SwingUtils; -import ch.psi.pshell.swing.ValueSelection; -import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; -import java.awt.Component; -import java.io.File; -import java.nio.file.Files; -import java.time.LocalTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.logging.Level; -import javax.swing.JComboBox; -import javax.swing.JFileChooser; -import javax.swing.JToggleButton; -import javax.swing.SwingUtilities; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.DefaultTableModel; - -/** - * - */ -public class XPSSpectrum extends Panel { - - boolean detailedScan; - boolean running; - Scienta scienta; - - public XPSSpectrum() { - initComponents(); - buttonSkip.setVisible(false); - rangeSelectionPanel.setAditionalColumns(new String[]{"Time", "Size", "Iter", "Eph"}, new Class[]{Double.class, Double.class, Integer.class, Double.class}); - final DefaultTableModel model = (DefaultTableModel) rangeSelectionPanel.getTable().getModel(); - model.addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - if (e.getType() == TableModelEvent.INSERT) { - final int row = e.getFirstRow(); - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - if (row > 0) { - for (int col = 3; col < 7; col++) { - model.setValueAt(model.getValueAt(row - 1, col), row, col); - } - } else { - model.setValueAt(valueTime.getValue(), row, 3); - model.setValueAt(valueSize.getValue(), row, 4); - model.setValueAt((int) valueIterations.getValue(), row, 5); - model.setValueAt(Double.NaN, row, 6); - } - } - }); - } - } - }); - - - //Component persistence - ArrayList persistedComponents = new ArrayList<>(); - persistedComponents.addAll(Arrays.asList(SwingUtils.getComponentsByType(this, JToggleButton.class))); - persistedComponents.addAll(Arrays.asList(SwingUtils.getComponentsByType(this, ValueSelection.class))); - persistedComponents.addAll(Arrays.asList(SwingUtils.getComponentsByType(this, JComboBox.class))); - setPersistedComponents(persistedComponents.toArray(new Component[0])); - - ValueSelectionListener listener = new ValueSelectionListener() { - @Override - public void onValueChanged(ValueSelection origin, double value, boolean editing) { - try{ - if (editing){ - scienta = (Scienta) getDevice("Scienta"); - if (origin == valueLow){ - scienta.getLowEnergy().write(value); - } else if (origin == valueHigh){ - scienta.getHighEnergy().write(value); - } else if (origin == valueTime){ - scienta.getStepTime().write(value); - } else if (origin == valueSize){ - scienta.getStepSize().write(value); - } - } - } catch (Exception ex){ - getLogger().log(Level.WARNING, null, ex); - } - } - }; - - valueLow.addListener(listener); - valueHigh.addListener(listener); - valueTime.addListener(listener); - valueSize.addListener(listener); - - } - - @Override - public void onInitialize(int runCount) { - scienta = (Scienta) getDevice("Scienta"); - scienta.getTotalChannels().addListener(progressListener); - scienta.getCurrentChannel().addListener(progressListener); - dvpAcqTime.setDevice(scienta.getAcquisitionTime()); - startTimer(500, 100); - manualInitPlotData(); - } - - void manualInitPlotData(){ - //Setting data so cam define ranges for detailed without initial - LinePlotSeries series = new LinePlotSeries("Data"); - rangeSelectionPanel.setSeries(series); - series.setData(new double[]{valueLow.getValue(), valueHigh.getValue()}, new double[]{Double.NaN,Double.NaN}); - } - - @Override - public void onStateChange(State state, State former) { - setEnabled(state == State.Ready); - if (!state.isProcessing()) { - buttonSkip.setVisible(false); - if (running) { - //stopTimer(); - running = false; - getView().getStatusBar().setProgress(-1); - } - } - } - - @Override - public void onExecutedFile(String fileName, Object result) { - String script = IO.getPrefix(fileName); - if (script != null) { - switch (script) { - case "XPSSpectrum": - if (result instanceof Exception) { - //SwingUtils.showMessage(getComponent(), "Error in " + fileName, exception.getMessage()); - if (detailedScan) { - - } else { - manualInitPlotData(); - } - } else { - if (detailedScan) { - - } else { - Object[] ret = (Object[]) ((Object[]) result)[0]; - if (ret.length > 0) { - //double[] data = (double[]) Convert.wrapperArrayToPrimitiveArray(ret[0], Double.class); - double[] xdata = (double[]) ret[0]; - double[] ydata = (double[]) ret[1]; - - //double[] data = new double[]{1.0,1.0,1.0,1.0,1.0}; - LinePlotSeries series = new LinePlotSeries("Data"); - rangeSelectionPanel.setSeries(series); - series.setData(xdata, ydata); - } - } - } - break; - } - } - detailedScan = false; - updateButtons(); - } - - @Override - public void setEnabled(boolean value) { - super.setEnabled(value); - rangeSelectionPanel.setEnabled(value); - valueLow.setEnabled(value); - valueHigh.setEnabled(value); - valueTime.setEnabled(value); - valueSize.setEnabled(value); - valueIterations.setEnabled(value); - comboPass.setEnabled(value); - checkEndScan.setEnabled(value); - checkSaveImage.setEnabled(value); - updateButtons(); - } - - void updateButtons() { - buttonInitialScan.setEnabled(isEnabled()); - buttonDetailedScan.setEnabled(isEnabled() && rangeSelectionPanel.getPlot().getSelectedRanges().length > 0); - btLoad.setEnabled(isEnabled()); - btSave.setEnabled(buttonDetailedScan.isEnabled()); - } - - DeviceListener progressListener = new DeviceAdapter() { - - @Override - public void onValueChanged(Device device, Object o, Object o1) { - if (running) { - getView().getStatusBar().setProgress(scienta.getProgress()); - } - } - }; - public final String CURRERNT_RANGE_VAR = "cur_range"; - public final String CURRERNT_ITERATION_VAR = "cur_iteration"; - int currentScanIndex; - RangeSelection[] scanRanges; - - @Override - protected void onTimer() { - try { - if (running) { - Object index = XPSSpectrum.this.eval(CURRERNT_RANGE_VAR, true); - if ((index != null) && (index instanceof Integer) && ((Integer) index >= 0)) { - int scanIndex = (Integer) index; - if (scanIndex != currentScanIndex) { - buttonSkip.setEnabled(true); - } - currentScanIndex = scanIndex; - - int current_iteration = (Integer) XPSSpectrum.this.eval(CURRERNT_ITERATION_VAR, true); - int iterations = (Integer) scanRanges[currentScanIndex].getVars()[2]; - - buttonSkip.setVisible((iterations > 1) && (current_iteration < (iterations - 1))); - - if (detailedScan) { - RangeSelection range = rangeSelectionPanel.getRangesOrdered()[scanIndex]; - for (int row = 0; row < rangeSelectionPanel.getTable().getRowCount(); row++) { - if (range.equals((Double) rangeSelectionPanel.getTable().getValueAt(row, 0), (Double) rangeSelectionPanel.getTable().getValueAt(row, 2))) { - rangeSelectionPanel.getTable().setRowSelectionInterval(row, row); - break; - } - if (row == (rangeSelectionPanel.getTable().getRowCount() - 1)) { - rangeSelectionPanel.getTable().clearSelection(); - } - } - } - } else { - rangeSelectionPanel.getTable().clearSelection(); - } - } else { - try{ - int steps = 0; - RangeSelection[] r = rangeSelectionPanel.getRanges(); - if ((buttonDetailedScan.isEnabled()) && (r.length > 0)) { - for (int i = 0; i < r.length; i++) { - int iterations = (Integer) r[i].getVars()[2]; - steps += iterations; - } - } else { - steps = Math.max(1, (int) valueIterations.getValue()); - } - int seconds = (int) (Double.valueOf(dvpAcqTime.getLabel().getText()) * steps); - int hours = seconds / (60 * 60); - textTotalTime.setText(hours >= 24 ? hours + "h" : LocalTime.ofSecondOfDay(seconds).toString()); - } catch (Exception ex) { - textTotalTime.setText(""); - } - } - } catch (Exception ex) { - getLogger().log(Level.FINE, null, ex); - } - } - - void start() throws Context.ContextStateException { - HashMap args = new HashMap<>(); - args.put("ranges", scanRanges); - args.put("pass_energy", Integer.valueOf(comboPass.getSelectedItem().toString())); - args.put("save_scienta_image", checkSaveImage.isSelected()); - args.put("ENDSCAN", checkEndScan.isSelected()); - currentScanIndex = -1; - runAsync("XPSSpectrum", args); - //startTimer(500,10); - running = true; - } - - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - panelArguments = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - valueIterations = new ch.psi.pshell.swing.ValueSelection(); - jLabel9 = new javax.swing.JLabel(); - valueTime = new ch.psi.pshell.swing.ValueSelection(); - comboPass = new javax.swing.JComboBox(); - valueSize = new ch.psi.pshell.swing.ValueSelection(); - jLabel11 = new javax.swing.JLabel(); - valueLow = new ch.psi.pshell.swing.ValueSelection(); - jLabel2 = new javax.swing.JLabel(); - valueHigh = new ch.psi.pshell.swing.ValueSelection(); - jLabel8 = new javax.swing.JLabel(); - jLabel17 = new javax.swing.JLabel(); - buttonScientaSetup = new javax.swing.JButton(); - checkEndScan = new javax.swing.JCheckBox(); - checkSaveImage = new javax.swing.JCheckBox(); - textTotalTime = new javax.swing.JLabel(); - dvpAcqTime = new ch.psi.pshell.swing.DeviceValuePanel(); - labelAcqTime = new javax.swing.JLabel(); - labelTotalTime = new javax.swing.JLabel(); - jPanel2 = new javax.swing.JPanel(); - btLoad = new javax.swing.JButton(); - btSave = new javax.swing.JButton(); - buttonInitialScan = new javax.swing.JButton(); - buttonDetailedScan = new javax.swing.JButton(); - rangeSelectionPanel = new ch.psi.pshell.swing.RangeSelectionPanel() { - protected void onSeriesChanged() { - updateButtons(); - } - protected void onSelectionChanged() { - updateButtons(); - } - } - ; - buttonAbort = new javax.swing.JButton(); - buttonSkip = new javax.swing.JButton(); - - panelArguments.setBorder(javax.swing.BorderFactory.createTitledBorder("Arguments")); - - jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel1.setText("Low:"); - - valueIterations.setDecimals(0); - valueIterations.setMaxValue(1000.0); - valueIterations.setMinValue(0.0); - valueIterations.setShowButtons(false); - valueIterations.setValue(1.0); - - jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel9.setText("Size:"); - - valueTime.setDecimals(3); - valueTime.setMaxValue(1000.0); - valueTime.setMinValue(0.0); - valueTime.setShowButtons(false); - valueTime.setValue(1.0); - - comboPass.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2", "5", "10", "20", "50", "100", "200" })); - comboPass.setSelectedIndex(4); - comboPass.setToolTipText(""); - comboPass.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboPassActionPerformed(evt); - } - }); - - valueSize.setDecimals(3); - valueSize.setMaxValue(1000.0); - valueSize.setMinValue(0.0); - valueSize.setShowButtons(false); - valueSize.setValue(1.0); - - jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel11.setText("Pass:"); - - valueLow.setDecimals(3); - valueLow.setMaxValue(2000.0); - valueLow.setMinValue(0.0); - valueLow.setShowButtons(false); - valueLow.setValue(0.0); - - jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel2.setText("High:"); - - valueHigh.setDecimals(3); - valueHigh.setMaxValue(2000.0); - valueHigh.setMinValue(0.0); - valueHigh.setShowButtons(false); - valueHigh.setValue(100.0); - - jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel8.setText("Time:"); - - jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - jLabel17.setText("Iter:"); - - buttonScientaSetup.setText("Scienta Setup"); - buttonScientaSetup.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonScientaSetupActionPerformed(evt); - } - }); - - checkEndScan.setText("Turn off beam at end"); - - checkSaveImage.setText("Save Scienta image"); - - textTotalTime.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - textTotalTime.setBorder(javax.swing.BorderFactory.createTitledBorder("")); - - labelAcqTime.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelAcqTime.setText("Acquisition time(s):"); - - labelTotalTime.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - labelTotalTime.setText("Total time:"); - - javax.swing.GroupLayout panelArgumentsLayout = new javax.swing.GroupLayout(panelArguments); - panelArguments.setLayout(panelArgumentsLayout); - panelArgumentsLayout.setHorizontalGroup( - panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelArgumentsLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonScientaSetup, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelArgumentsLayout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelAcqTime) - .addComponent(labelTotalTime)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(textTotalTime, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(dvpAcqTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGroup(panelArgumentsLayout.createSequentialGroup() - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(checkEndScan) - .addComponent(checkSaveImage) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() - .addComponent(jLabel11) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboPass, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() - .addComponent(jLabel17) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueIterations, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() - .addComponent(jLabel9) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueSize, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() - .addComponent(jLabel8) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueHigh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueLow, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - - panelArgumentsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel11, jLabel17, jLabel2, jLabel8, jLabel9}); - - panelArgumentsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {dvpAcqTime, textTotalTime}); - - panelArgumentsLayout.setVerticalGroup( - panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelArgumentsLayout.createSequentialGroup() - .addContainerGap() - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(valueLow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel2) - .addComponent(valueHigh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel8) - .addComponent(valueTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel9) - .addComponent(valueSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel17) - .addComponent(valueIterations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(jLabel11) - .addComponent(comboPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(labelAcqTime) - .addComponent(dvpAcqTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) - .addComponent(textTotalTime) - .addComponent(labelTotalTime)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE) - .addComponent(checkEndScan) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(checkSaveImage) - .addGap(18, 18, 18) - .addComponent(buttonScientaSetup) - .addGap(26, 26, 26)) - ); - - panelArgumentsLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {dvpAcqTime, textTotalTime}); - - jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Scan Control")); - - btLoad.setText("Load"); - btLoad.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btLoadActionPerformed(evt); - } - }); - - btSave.setText("Save"); - btSave.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btSaveActionPerformed(evt); - } - }); - - buttonInitialScan.setText("Initial Scan"); - buttonInitialScan.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonInitialScanActionPerformed(evt); - } - }); - - buttonDetailedScan.setText("Detailed Scan"); - buttonDetailedScan.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonDetailedScanActionPerformed(evt); - } - }); - - rangeSelectionPanel.setTablePosition(ch.psi.pshell.swing.RangeSelectionPanel.TablePosition.bottom); - - buttonAbort.setText("Abort"); - buttonAbort.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonAbortActionPerformed(evt); - } - }); - - buttonSkip.setText("Skip"); - buttonSkip.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonSkipActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(btLoad) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(btSave)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() - .addGap(20, 20, 20) - .addComponent(buttonInitialScan) - .addGap(18, 18, 18) - .addComponent(buttonDetailedScan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE) - .addComponent(buttonSkip) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonAbort)) - .addComponent(rangeSelectionPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - - jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btLoad, btSave, buttonAbort, buttonDetailedScan, buttonInitialScan, buttonSkip}); - - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonInitialScan) - .addComponent(buttonDetailedScan) - .addComponent(buttonAbort) - .addComponent(buttonSkip)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(rangeSelectionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(btLoad, javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(btSave, javax.swing.GroupLayout.Alignment.TRAILING)) - .addContainerGap()) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(panelArguments, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 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) - .addComponent(panelArguments, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - }// //GEN-END:initComponents - - private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed - try { - abort(); - scienta.stop(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonAbortActionPerformed - - private void buttonInitialScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInitialScanActionPerformed - try { - rangeSelectionPanel.clear(); - detailedScan = false; - - RangeSelection initialRange = new RangeSelection(valueLow.getValue(), valueHigh.getValue()); - int iterations = (int) valueIterations.getValue(); - initialRange.setVars(new Object[]{valueTime.getValue(), valueSize.getValue(), iterations, Double.NaN}); - scanRanges = new RangeSelection[]{initialRange}; - - start(); - } catch (Exception ex) { - showException(ex); - } - - }//GEN-LAST:event_buttonInitialScanActionPerformed - - private void buttonDetailedScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetailedScanActionPerformed - try { - detailedScan = true; - scanRanges = rangeSelectionPanel.getRangesOrdered(); - - start(); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonDetailedScanActionPerformed - - private void btSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSaveActionPerformed - try { - JFileChooser chooser = new JFileChooser(getContext().getSetup().getContextPath()); - FileNameExtensionFilter filter = new FileNameExtensionFilter("XPS Spectrum scan definition file", "xps"); - chooser.setFileFilter(filter); - int rVal = chooser.showSaveDialog(this); - if (rVal == JFileChooser.APPROVE_OPTION) { - File f = chooser.getSelectedFile(); - if (IO.getExtension(f).isEmpty()) { - f = new File(f.getPath() + ".xps"); - } - Object[] obj = new Object[]{SwingUtils.getTableData(rangeSelectionPanel.getTable()), - rangeSelectionPanel.getPlot().getSeries(0).getX(), - rangeSelectionPanel.getPlot().getSeries(0).getY()}; - Files.write(f.toPath(), Serializer.encode(obj, Serializer.EncoderType.bin)); - - } - } catch (Exception ex) { - showException(ex); - } - - }//GEN-LAST:event_btSaveActionPerformed - - private void btLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLoadActionPerformed - try { - JFileChooser chooser = new JFileChooser(getContext().getSetup().getContextPath()); - FileNameExtensionFilter filter = new FileNameExtensionFilter("XPS Spectrum scan definition file", "xps"); - chooser.setFileFilter(filter); - int rVal = chooser.showOpenDialog(this); - if (rVal == JFileChooser.APPROVE_OPTION) { - rangeSelectionPanel.removeAllRanges(); - Object[] obj = (Object[]) Serializer.decode(Files.readAllBytes(chooser.getSelectedFile().toPath()), Serializer.EncoderType.bin); - Object[][] table = (Object[][]) obj[0]; - if (!rangeSelectionPanel.getPlot().hasData()) { - double[] x = (double[]) obj[1]; - double[] y = (double[]) obj[2]; - LinePlotSeries series = new LinePlotSeries("Data"); - rangeSelectionPanel.setSeries(series); - series.setData(x, y); - } - for (Object[] row : table) { - rangeSelectionPanel.getPlot().addRange((Double) row[0], (Double) row[2]); - } - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - for (int row = 0; row < table.length; row++) { - for (int col = 3; col < 7; col++) { - rangeSelectionPanel.getTable().setValueAt(table[row][col], row, col); - } - } - } - }); - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_btLoadActionPerformed - - private void buttonSkipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSkipActionPerformed - try { - this.eval("skip_iteration = True", true); - buttonSkip.setEnabled(false); - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonSkipActionPerformed - - private void buttonScientaSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScientaSetupActionPerformed - try { - showDevicePanel("Scienta"); - } catch (Exception ex) { - SwingUtils.showException(this, ex); - } - }//GEN-LAST:event_buttonScientaSetupActionPerformed - - private void comboPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboPassActionPerformed - try { - scienta = (Scienta) getDevice("Scienta"); - int energy = Integer.valueOf(comboPass.getSelectedItem().toString()); - if (energy != scienta.getPassEnergy()){ - scienta.setPassEnergy(energy); - } - } catch (Exception ex) { - getLogger().log(Level.WARNING, null, ex); - } - }//GEN-LAST:event_comboPassActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btLoad; - private javax.swing.JButton btSave; - private javax.swing.JButton buttonAbort; - private javax.swing.JButton buttonDetailedScan; - private javax.swing.JButton buttonInitialScan; - private javax.swing.JButton buttonScientaSetup; - private javax.swing.JButton buttonSkip; - private javax.swing.JCheckBox checkEndScan; - private javax.swing.JCheckBox checkSaveImage; - private javax.swing.JComboBox comboPass; - private ch.psi.pshell.swing.DeviceValuePanel dvpAcqTime; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel11; - private javax.swing.JLabel jLabel17; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel8; - private javax.swing.JLabel jLabel9; - private javax.swing.JPanel jPanel2; - private javax.swing.JLabel labelAcqTime; - private javax.swing.JLabel labelTotalTime; - private javax.swing.JPanel panelArguments; - private ch.psi.pshell.swing.RangeSelectionPanel rangeSelectionPanel; - private javax.swing.JLabel textTotalTime; - private ch.psi.pshell.swing.ValueSelection valueHigh; - private ch.psi.pshell.swing.ValueSelection valueIterations; - private ch.psi.pshell.swing.ValueSelection valueLow; - private ch.psi.pshell.swing.ValueSelection valueSize; - private ch.psi.pshell.swing.ValueSelection valueTime; - // End of variables declaration//GEN-END:variables -} +/* + * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. + */ + +import ch.psi.pshell.core.Context; +import ch.psi.pshell.device.Device; +import ch.psi.pshell.device.DeviceAdapter; +import ch.psi.pshell.device.DeviceListener; +import ch.psi.pshell.epics.Scienta; +import ch.psi.pshell.plot.LinePlotSeries; +import ch.psi.pshell.plot.RangeSelectionPlot.RangeSelection; +import ch.psi.pshell.ui.Panel; +import ch.psi.utils.IO; +import ch.psi.utils.Serializer; +import ch.psi.utils.State; +import ch.psi.utils.swing.SwingUtils; +import ch.psi.pshell.swing.ValueSelection; +import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; +import java.awt.Component; +import java.io.File; +import java.nio.file.Files; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.logging.Level; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JToggleButton; +import javax.swing.SwingUtilities; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.DefaultTableModel; + +/** + * + */ +public class XPSSpectrum extends Panel { + + boolean detailedScan; + boolean running; + Scienta scienta; + SwingUtils.TableChangeListener tableChangeListener; + + boolean showMiddle = false; + int indexTime = showMiddle? 3 :2; + int indexSize = showMiddle? 4 :3; + int indexIter = showMiddle? 5 :4; + int indexEph = showMiddle? 6 :5; + + public XPSSpectrum() { + initComponents(); + rangeSelectionPanel.setOverlapAllowed(true); + rangeSelectionPanel.setShowMiddle(showMiddle); + buttonSkip.setVisible(false); + rangeSelectionPanel.setAditionalColumns(new String[]{"Time", "Size", "Iter", "Eph"}, new Class[]{Double.class, Double.class, Integer.class, Double.class}); + final DefaultTableModel model = (DefaultTableModel) rangeSelectionPanel.getTable().getModel(); + model.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + if (e.getType() == TableModelEvent.INSERT) { + final int row = e.getFirstRow(); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + if (row > 0) { + for (int col = indexTime; col <=indexEph; col++) { + model.setValueAt(model.getValueAt(row - 1, col), row, col); + } + } else { + model.setValueAt(valueTime.getValue(), row, indexTime); + model.setValueAt(valueSize.getValue(), row, indexSize); + model.setValueAt((int) valueIterations.getValue(), row, indexIter); + model.setValueAt(Double.NaN, row, indexEph); + } + } + }); + } + } + }); + + + //Component persistence + ArrayList persistedComponents = new ArrayList<>(); + persistedComponents.addAll(Arrays.asList(SwingUtils.getComponentsByType(this, JToggleButton.class))); + persistedComponents.addAll(Arrays.asList(SwingUtils.getComponentsByType(this, ValueSelection.class))); + persistedComponents.addAll(Arrays.asList(SwingUtils.getComponentsByType(this, JComboBox.class))); + setPersistedComponents(persistedComponents.toArray(new Component[0])); + + ValueSelectionListener listener = new ValueSelectionListener() { + @Override + public void onValueChanged(ValueSelection origin, double value, boolean editing) { + try{ + if (editing){ + scienta = (Scienta) getDevice("Scienta"); + if (origin == valueLow){ + scienta.getLowEnergy().write(value); + } else if (origin == valueHigh){ + scienta.getHighEnergy().write(value); + } else if (origin == valueTime){ + scienta.getStepTime().write(value); + } else if (origin == valueSize){ + scienta.getStepSize().write(value); + } + } + } catch (Exception ex){ + getLogger().log(Level.WARNING, null, ex); + } + } + }; + + valueLow.addListener(listener); + valueHigh.addListener(listener); + valueTime.addListener(listener); + valueSize.addListener(listener); + + + tableChangeListener = new SwingUtils.TableChangeListener(rangeSelectionPanel.getTable()) { + @Override + protected void onTableChange(int row, int column, Object value, Object former) { + if ((column == indexEph) && isDefined (value) && isDefined (former)){ + try{ + double offset = ((Double)value) - ((Double)former); + Double lower = (Double) model.getValueAt(row, 0); + Double upper = (Double) model.getValueAt(row, indexTime-1); + if ( isDefined (lower) && isDefined (upper)){ + model.setValueAt(lower + offset, row, 0); + model.setValueAt(upper + offset, row, indexTime-1); + RangeSelection range = rangeSelectionPanel.getPlotRange(lower, null, upper); + if (range!=null){ + rangeSelectionPanel.getPlot().updateRange(range, lower + offset, upper + offset); + } + } + } catch (Exception ex) { + showException(ex); + } + } + } + }; + + } + + boolean isDefined(Object value){ + return (value != null) && (value instanceof Double) && !(((Double)value).isNaN()); + } + + @Override + public void onInitialize(int runCount) { + scienta = (Scienta) getDevice("Scienta"); + scienta.getTotalChannels().addListener(progressListener); + scienta.getCurrentChannel().addListener(progressListener); + dvpAcqTime.setDevice(scienta.getAcquisitionTime()); + startTimer(500, 100); + manualInitPlotData(); + } + + void manualInitPlotData(){ + //Setting data so cam define ranges for detailed without initial + LinePlotSeries series = new LinePlotSeries("Data"); + rangeSelectionPanel.setSeries(series); + series.setData(new double[]{valueLow.getValue(), valueHigh.getValue()}, new double[]{Double.NaN,Double.NaN}); + } + + @Override + public void onStateChange(State state, State former) { + setEnabled(state == State.Ready); + if (!state.isProcessing()) { + buttonSkip.setVisible(false); + if (running) { + //stopTimer(); + running = false; + getView().getStatusBar().setProgress(-1); + } + } + } + + @Override + public void onExecutedFile(String fileName, Object result) { + String script = IO.getPrefix(fileName); + if (script != null) { + switch (script) { + case "XPSSpectrum": + if (result instanceof Exception) { + //SwingUtils.showMessage(getComponent(), "Error in " + fileName, exception.getMessage()); + if (detailedScan) { + + } else { + manualInitPlotData(); + } + } else { + if (detailedScan) { + + } else { + Object[] ret = (Object[]) ((Object[]) result)[0]; + if (ret.length > 0) { + //double[] data = (double[]) Convert.wrapperArrayToPrimitiveArray(ret[0], Double.class); + double[] xdata = (double[]) ret[0]; + double[] ydata = (double[]) ret[1]; + + //double[] data = new double[]{1.0,1.0,1.0,1.0,1.0}; + LinePlotSeries series = new LinePlotSeries("Data"); + rangeSelectionPanel.setSeries(series); + series.setData(xdata, ydata); + } + } + } + break; + } + } + detailedScan = false; + updateButtons(); + } + + @Override + public void setEnabled(boolean value) { + super.setEnabled(value); + rangeSelectionPanel.setEnabled(value); + valueLow.setEnabled(value); + valueHigh.setEnabled(value); + valueTime.setEnabled(value); + valueSize.setEnabled(value); + valueIterations.setEnabled(value); + comboPass.setEnabled(value); + checkEndScan.setEnabled(value); + checkSaveImage.setEnabled(value); + updateButtons(); + } + + void updateButtons() { + buttonInitialScan.setEnabled(isEnabled()); + buttonDetailedScan.setEnabled(isEnabled() && rangeSelectionPanel.getPlot().getSelectedRanges().length > 0); + btLoad.setEnabled(isEnabled()); + btSave.setEnabled(buttonDetailedScan.isEnabled()); + } + + DeviceListener progressListener = new DeviceAdapter() { + + @Override + public void onValueChanged(Device device, Object o, Object o1) { + if (running) { + getView().getStatusBar().setProgress(scienta.getProgress()); + } + } + }; + public final String CURRERNT_RANGE_VAR = "cur_range"; + public final String CURRERNT_ITERATION_VAR = "cur_iteration"; + int currentScanIndex; + RangeSelection[] scanRanges; + + @Override + protected void onTimer() { + try { + if (running) { + Object index = XPSSpectrum.this.eval(CURRERNT_RANGE_VAR, true); + if ((index != null) && (index instanceof Integer) && ((Integer) index >= 0)) { + int scanIndex = (Integer) index; + if (scanIndex != currentScanIndex) { + buttonSkip.setEnabled(true); + } + currentScanIndex = scanIndex; + + int current_iteration = (Integer) XPSSpectrum.this.eval(CURRERNT_ITERATION_VAR, true); + int iterations = (Integer) scanRanges[currentScanIndex].getVars()[2]; + + buttonSkip.setVisible((iterations > 1) && (current_iteration < (iterations - 1))); + + if (detailedScan) { + RangeSelection range = rangeSelectionPanel.getRangesOrdered()[scanIndex]; + for (int row = 0; row < rangeSelectionPanel.getTable().getRowCount(); row++) { + if (range.equals((Double) rangeSelectionPanel.getTable().getValueAt(row, 0), (Double) rangeSelectionPanel.getTable().getValueAt(row, 2))) { + rangeSelectionPanel.getTable().setRowSelectionInterval(row, row); + break; + } + if (row == (rangeSelectionPanel.getTable().getRowCount() - 1)) { + rangeSelectionPanel.getTable().clearSelection(); + } + } + } + } else { + rangeSelectionPanel.getTable().clearSelection(); + } + } else { + try{ + int steps = 0; + RangeSelection[] r = rangeSelectionPanel.getRanges(); + if ((buttonDetailedScan.isEnabled()) && (r.length > 0)) { + for (int i = 0; i < r.length; i++) { + int iterations = (Integer) r[i].getVars()[2]; + steps += iterations; + } + } else { + steps = Math.max(1, (int) valueIterations.getValue()); + } + int seconds = (int) (Double.valueOf(dvpAcqTime.getLabel().getText()) * steps); + int hours = seconds / (60 * 60); + textTotalTime.setText(hours >= 24 ? hours + "h" : LocalTime.ofSecondOfDay(seconds).toString()); + } catch (Exception ex) { + textTotalTime.setText(""); + } + } + } catch (Exception ex) { + getLogger().log(Level.FINE, null, ex); + } + } + + void start() throws Context.ContextStateException { + HashMap args = new HashMap<>(); + args.put("ranges", scanRanges); + args.put("pass_energy", Integer.valueOf(comboPass.getSelectedItem().toString())); + args.put("save_scienta_image", checkSaveImage.isSelected()); + args.put("ENDSCAN", checkEndScan.isSelected()); + currentScanIndex = -1; + runAsync("XPSSpectrum", args); + //startTimer(500,10); + running = true; + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + panelArguments = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + valueIterations = new ch.psi.pshell.swing.ValueSelection(); + jLabel9 = new javax.swing.JLabel(); + valueTime = new ch.psi.pshell.swing.ValueSelection(); + comboPass = new javax.swing.JComboBox(); + valueSize = new ch.psi.pshell.swing.ValueSelection(); + jLabel11 = new javax.swing.JLabel(); + valueLow = new ch.psi.pshell.swing.ValueSelection(); + jLabel2 = new javax.swing.JLabel(); + valueHigh = new ch.psi.pshell.swing.ValueSelection(); + jLabel8 = new javax.swing.JLabel(); + jLabel17 = new javax.swing.JLabel(); + buttonScientaSetup = new javax.swing.JButton(); + checkEndScan = new javax.swing.JCheckBox(); + checkSaveImage = new javax.swing.JCheckBox(); + textTotalTime = new javax.swing.JLabel(); + dvpAcqTime = new ch.psi.pshell.swing.DeviceValuePanel(); + labelAcqTime = new javax.swing.JLabel(); + labelTotalTime = new javax.swing.JLabel(); + jPanel2 = new javax.swing.JPanel(); + btLoad = new javax.swing.JButton(); + btSave = new javax.swing.JButton(); + buttonInitialScan = new javax.swing.JButton(); + buttonDetailedScan = new javax.swing.JButton(); + rangeSelectionPanel = new ch.psi.pshell.swing.RangeSelectionPanel() { + protected void onSeriesChanged() { + updateButtons(); + } + protected void onSelectionChanged() { + updateButtons(); + } + } + ; + buttonAbort = new javax.swing.JButton(); + buttonSkip = new javax.swing.JButton(); + + panelArguments.setBorder(javax.swing.BorderFactory.createTitledBorder("Arguments")); + + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel1.setText("Low:"); + + valueIterations.setDecimals(0); + valueIterations.setMaxValue(1000.0); + valueIterations.setMinValue(0.0); + valueIterations.setShowButtons(false); + valueIterations.setValue(1.0); + + jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel9.setText("Size:"); + + valueTime.setDecimals(3); + valueTime.setMaxValue(1000.0); + valueTime.setMinValue(0.0); + valueTime.setShowButtons(false); + valueTime.setValue(1.0); + + comboPass.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2", "5", "10", "20", "50", "100", "200" })); + comboPass.setSelectedIndex(4); + comboPass.setToolTipText(""); + comboPass.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboPassActionPerformed(evt); + } + }); + + valueSize.setDecimals(3); + valueSize.setMaxValue(1000.0); + valueSize.setMinValue(0.0); + valueSize.setShowButtons(false); + valueSize.setValue(1.0); + + jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel11.setText("Pass:"); + + valueLow.setDecimals(3); + valueLow.setMaxValue(2000.0); + valueLow.setMinValue(0.0); + valueLow.setShowButtons(false); + valueLow.setValue(0.0); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel2.setText("High:"); + + valueHigh.setDecimals(3); + valueHigh.setMaxValue(2000.0); + valueHigh.setMinValue(0.0); + valueHigh.setShowButtons(false); + valueHigh.setValue(100.0); + + jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel8.setText("Time:"); + + jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel17.setText("Iter:"); + + buttonScientaSetup.setText("Scienta Setup"); + buttonScientaSetup.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonScientaSetupActionPerformed(evt); + } + }); + + checkEndScan.setText("Turn off beam at end"); + + checkSaveImage.setText("Save Scienta image"); + + textTotalTime.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + textTotalTime.setBorder(javax.swing.BorderFactory.createTitledBorder("")); + + labelAcqTime.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + labelAcqTime.setText("Acquisition time(s):"); + + labelTotalTime.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + labelTotalTime.setText("Total time:"); + + javax.swing.GroupLayout panelArgumentsLayout = new javax.swing.GroupLayout(panelArguments); + panelArguments.setLayout(panelArgumentsLayout); + panelArgumentsLayout.setHorizontalGroup( + panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelArgumentsLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonScientaSetup, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelArgumentsLayout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(labelAcqTime) + .addComponent(labelTotalTime)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(textTotalTime, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(dvpAcqTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(panelArgumentsLayout.createSequentialGroup() + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(checkEndScan) + .addComponent(checkSaveImage) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() + .addComponent(jLabel11) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(comboPass, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() + .addComponent(jLabel17) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueIterations, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() + .addComponent(jLabel9) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueSize, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() + .addComponent(jLabel8) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueHigh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelArgumentsLayout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueLow, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + + panelArgumentsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel11, jLabel17, jLabel2, jLabel8, jLabel9}); + + panelArgumentsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {dvpAcqTime, textTotalTime}); + + panelArgumentsLayout.setVerticalGroup( + panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelArgumentsLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(valueLow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel2) + .addComponent(valueHigh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel8) + .addComponent(valueTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel9) + .addComponent(valueSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel17) + .addComponent(valueIterations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel11) + .addComponent(comboPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(labelAcqTime) + .addComponent(dvpAcqTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelArgumentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(textTotalTime) + .addComponent(labelTotalTime)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE) + .addComponent(checkEndScan) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(checkSaveImage) + .addGap(18, 18, 18) + .addComponent(buttonScientaSetup) + .addGap(26, 26, 26)) + ); + + panelArgumentsLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {dvpAcqTime, textTotalTime}); + + jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Scan Control")); + + btLoad.setText("Load"); + btLoad.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btLoadActionPerformed(evt); + } + }); + + btSave.setText("Save"); + btSave.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btSaveActionPerformed(evt); + } + }); + + buttonInitialScan.setText("Initial Scan"); + buttonInitialScan.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonInitialScanActionPerformed(evt); + } + }); + + buttonDetailedScan.setText("Detailed Scan"); + buttonDetailedScan.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDetailedScanActionPerformed(evt); + } + }); + + rangeSelectionPanel.setTablePosition(ch.psi.pshell.swing.RangeSelectionPanel.TablePosition.bottom); + + buttonAbort.setText("Abort"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + buttonSkip.setText("Skip"); + buttonSkip.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonSkipActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(btLoad) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(btSave)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() + .addGap(20, 20, 20) + .addComponent(buttonInitialScan) + .addGap(18, 18, 18) + .addComponent(buttonDetailedScan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE) + .addComponent(buttonSkip) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonAbort)) + .addComponent(rangeSelectionPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + + jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btLoad, btSave, buttonAbort, buttonDetailedScan, buttonInitialScan, buttonSkip}); + + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonInitialScan) + .addComponent(buttonDetailedScan) + .addComponent(buttonAbort) + .addComponent(buttonSkip)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(rangeSelectionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(btLoad, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(btSave, javax.swing.GroupLayout.Alignment.TRAILING)) + .addContainerGap()) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(panelArguments, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 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) + .addComponent(panelArguments, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + try { + abort(); + scienta.stop(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonAbortActionPerformed + + private void buttonInitialScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInitialScanActionPerformed + try { + rangeSelectionPanel.clear(); + detailedScan = false; + + RangeSelection initialRange = new RangeSelection(valueLow.getValue(), valueHigh.getValue()); + int iterations = (int) valueIterations.getValue(); + initialRange.setVars(new Object[]{valueTime.getValue(), valueSize.getValue(), iterations, Double.NaN}); + scanRanges = new RangeSelection[]{initialRange}; + + start(); + } catch (Exception ex) { + showException(ex); + } + + }//GEN-LAST:event_buttonInitialScanActionPerformed + + private void buttonDetailedScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDetailedScanActionPerformed + try { + detailedScan = true; + scanRanges = rangeSelectionPanel.getRangesOrdered(); + + start(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonDetailedScanActionPerformed + + private void btSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSaveActionPerformed + try { + JFileChooser chooser = new JFileChooser(getContext().getSetup().getContextPath()); + FileNameExtensionFilter filter = new FileNameExtensionFilter("XPS Spectrum scan definition file", "xps"); + chooser.setFileFilter(filter); + int rVal = chooser.showSaveDialog(this); + if (rVal == JFileChooser.APPROVE_OPTION) { + File f = chooser.getSelectedFile(); + if (IO.getExtension(f).isEmpty()) { + f = new File(f.getPath() + ".xps"); + } + Object[] obj = new Object[]{SwingUtils.getTableData(rangeSelectionPanel.getTable()), + rangeSelectionPanel.getPlot().getSeries(0).getX(), + rangeSelectionPanel.getPlot().getSeries(0).getY()}; + Files.write(f.toPath(), Serializer.encode(obj, Serializer.EncoderType.bin)); + + } + } catch (Exception ex) { + showException(ex); + } + + }//GEN-LAST:event_btSaveActionPerformed + + private void btLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLoadActionPerformed + try { + JFileChooser chooser = new JFileChooser(getContext().getSetup().getContextPath()); + FileNameExtensionFilter filter = new FileNameExtensionFilter("XPS Spectrum scan definition file", "xps"); + chooser.setFileFilter(filter); + int rVal = chooser.showOpenDialog(this); + if (rVal == JFileChooser.APPROVE_OPTION) { + rangeSelectionPanel.removeAllRanges(); + Object[] obj = (Object[]) Serializer.decode(Files.readAllBytes(chooser.getSelectedFile().toPath()), Serializer.EncoderType.bin); + Object[][] table = (Object[][]) obj[0]; + if (!rangeSelectionPanel.getPlot().hasData()) { + double[] x = (double[]) obj[1]; + double[] y = (double[]) obj[2]; + LinePlotSeries series = new LinePlotSeries("Data"); + rangeSelectionPanel.setSeries(series); + series.setData(x, y); + } + int indexUpper = ((table.length>0) && (table[0].length == 6)) ? 1 : 2; + System.out.println(indexUpper); + for (Object[] row : table) { + rangeSelectionPanel.getPlot().addRange((Double) row[0], (Double) row[indexUpper]); + } + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + for (int row = 0; row < table.length; row++) { + for (int col = 0; col < 4; col++) { + rangeSelectionPanel.getTable().setValueAt(table[row][col + indexUpper + 1], row, col + indexTime); + } + } + } + }); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_btLoadActionPerformed + + private void buttonSkipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSkipActionPerformed + try { + this.eval("skip_iteration = True", true); + buttonSkip.setEnabled(false); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonSkipActionPerformed + + private void buttonScientaSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScientaSetupActionPerformed + try { + showDevicePanel("Scienta"); + } catch (Exception ex) { + SwingUtils.showException(this, ex); + } + }//GEN-LAST:event_buttonScientaSetupActionPerformed + + private void comboPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboPassActionPerformed + try { + scienta = (Scienta) getDevice("Scienta"); + int energy = Integer.valueOf(comboPass.getSelectedItem().toString()); + if (energy != scienta.getPassEnergy()){ + scienta.setPassEnergy(energy); + } + } catch (Exception ex) { + getLogger().log(Level.WARNING, null, ex); + } + }//GEN-LAST:event_comboPassActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btLoad; + private javax.swing.JButton btSave; + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonDetailedScan; + private javax.swing.JButton buttonInitialScan; + private javax.swing.JButton buttonScientaSetup; + private javax.swing.JButton buttonSkip; + private javax.swing.JCheckBox checkEndScan; + private javax.swing.JCheckBox checkSaveImage; + private javax.swing.JComboBox comboPass; + private ch.psi.pshell.swing.DeviceValuePanel dvpAcqTime; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel11; + private javax.swing.JLabel jLabel17; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JPanel jPanel2; + private javax.swing.JLabel labelAcqTime; + private javax.swing.JLabel labelTotalTime; + private javax.swing.JPanel panelArguments; + private ch.psi.pshell.swing.RangeSelectionPanel rangeSelectionPanel; + private javax.swing.JLabel textTotalTime; + private ch.psi.pshell.swing.ValueSelection valueHigh; + private ch.psi.pshell.swing.ValueSelection valueIterations; + private ch.psi.pshell.swing.ValueSelection valueLow; + private ch.psi.pshell.swing.ValueSelection valueSize; + private ch.psi.pshell.swing.ValueSelection valueTime; + // End of variables declaration//GEN-END:variables +}