From 64c45126367095d2071940cba9b3229a7b2bfc48 Mon Sep 17 00:00:00 2001 From: x07maop Date: Tue, 16 Jun 2015 15:01:35 +0200 Subject: [PATCH] Closedown --- config/energy_scan.properties | 2 +- plugins/EnergyScan.form | 12 ++++-- plugins/EnergyScan.java | 79 ++++++++++++++++++++++++++++------- 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/config/energy_scan.properties b/config/energy_scan.properties index 3b03520..7fd1b48 100644 --- a/config/energy_scan.properties +++ b/config/energy_scan.properties @@ -1,2 +1,2 @@ Fe_plus=690 755 3 10 0 -9 -Fe_plus_2=693 756 2 8 0 -8 + diff --git a/plugins/EnergyScan.form b/plugins/EnergyScan.form index c3fad8e..5d13a6c 100644 --- a/plugins/EnergyScan.form +++ b/plugins/EnergyScan.form @@ -291,7 +291,7 @@ - + @@ -303,7 +303,7 @@ - + @@ -316,11 +316,17 @@ + + + - + + + + diff --git a/plugins/EnergyScan.java b/plugins/EnergyScan.java index fb9dff8..b1ef25f 100644 --- a/plugins/EnergyScan.java +++ b/plugins/EnergyScan.java @@ -16,12 +16,13 @@ import ch.psi.utils.Chrono; import ch.psi.utils.State; import ch.psi.utils.swing.SwingUtils; import java.awt.Component; -import java.io.File; -import java.io.IOException; +import java.awt.Desktop; +import java.io.FileInputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; +import java.util.Properties; import javax.swing.DefaultComboBoxModel; import javax.swing.JLabel; import javax.swing.JPanel; @@ -59,11 +60,17 @@ public class EnergyScan extends Panel { public void onValueChanged(Device device, Object value, Object former) { update(); } - }); - panel.loadConfig(); + }); update(); + panel.loadConfig(); } + @Override + protected void onStart() { + super.onStart(); + panel.loadConfig(); + } + @Override protected void onApplicationStateChange(State state, State former) { getComponent().setEnabled(state == State.Ready); @@ -119,16 +126,15 @@ public class EnergyScan extends Panel { } void loadConfig(){ - System.out.println("Init"); DefaultComboBoxModel model = (DefaultComboBoxModel) comboSetup.getModel(); model.removeAllElements(); try{ for (String line : Files.readAllLines(getConfigFile())) { - System.out.println(line); - String[] tokens = line.split("="); - if (tokens.length>0){ - model.addElement(tokens[0].trim()); - System.out.println(tokens[0].trim()); + if (line!=null && !line.trim().isEmpty()){ + String[] tokens = line.split("="); + if (tokens.length>0){ + model.addElement(tokens[0].trim()); + } } } } catch (Exception ex){ @@ -161,7 +167,7 @@ public class EnergyScan extends Panel { spinnerOffset = new javax.swing.JSpinner(); jPanel1 = new javax.swing.JPanel(); comboSetup = new javax.swing.JComboBox(); - jButton1 = new javax.swing.JButton(); + buttonConfigure = new javax.swing.JButton(); buttonExecute.setText("Start"); buttonExecute.addActionListener(new java.awt.event.ActionListener() { @@ -299,7 +305,18 @@ public class EnergyScan extends Panel { jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Setup")); - jButton1.setText("Configure"); + comboSetup.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboSetupActionPerformed(evt); + } + }); + + buttonConfigure.setText("Configure"); + buttonConfigure.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigureActionPerformed(evt); + } + }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); @@ -309,11 +326,11 @@ public class EnergyScan extends Panel { .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton1)) + .addComponent(buttonConfigure)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboSetup, jButton1}); + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfigure, comboSetup}); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -321,7 +338,7 @@ public class EnergyScan extends Panel { .addContainerGap() .addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) - .addComponent(jButton1) + .addComponent(buttonConfigure) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -394,12 +411,42 @@ public class EnergyScan extends Panel { abort(); }//GEN-LAST:event_buttonAbortActionPerformed + private void comboSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSetupActionPerformed + try { + Properties prop = new Properties(); + prop.load(new FileInputStream(getConfigFile().toFile())); + String selection = comboSetup.getSelectedItem().toString(); + String val = prop.getProperty(selection); + String[] tokens = val.split(" "); + if (tokens.length!=6){ + throw new Exception("Invalid file format"); + } + textFile.setText(selection); + spinnerE1.setValue(Double.valueOf(tokens[0].trim())); + spinnerE2.setValue(Double.valueOf(tokens[1].trim())); + spinnerTime.setValue(Double.valueOf(tokens[2].trim())); + spinnerDelay.setValue(Double.valueOf(tokens[3].trim())); + comboMode.setSelectedIndex(Integer.valueOf(tokens[4].trim())); + spinnerOffset.setValue(Double.valueOf(tokens[5].trim())); + } catch (Exception ex) { + SwingUtils.showException(this, ex); + } + }//GEN-LAST:event_comboSetupActionPerformed + + private void buttonConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigureActionPerformed + try { + Desktop.getDesktop().open(getConfigFile().toFile()); + } catch (Exception ex) { + SwingUtils.showException(this, ex); + } + }//GEN-LAST:event_buttonConfigureActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonConfigure; private javax.swing.JButton buttonExecute; private javax.swing.JComboBox comboMode; private javax.swing.JComboBox comboSetup; - private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3;