Closedown

This commit is contained in:
x07maop
2015-06-17 16:20:37 +02:00
parent 87687d0e34
commit 9190a5a56a
4 changed files with 240 additions and 81 deletions

View File

@@ -28,7 +28,7 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
/**
*
*
*/
public class EnergyScan extends Panel {
@@ -39,6 +39,8 @@ public class EnergyScan extends Panel {
ChannelDoubleArray fdata;
ChannelInteger count;
double[] offsets = new double[4];
@Override
protected JPanel create() {
panel = new PluginPanel();
@@ -54,7 +56,6 @@ public class EnergyScan extends Panel {
edata = (ChannelDoubleArray) getController().getDevicePool().getByName("edata");
idata = (ChannelDoubleArray) getController().getDevicePool().getByName("idata");
fdata = (ChannelDoubleArray) getController().getDevicePool().getByName("fdata");
getController().getDevicePool().getByName("count").addListener(new DeviceListener() {
@Override
@@ -65,7 +66,7 @@ public class EnergyScan extends Panel {
public void onValueChanged(Device device, Object value, Object former) {
update();
}
});
});
update();
//panel.loadConfig();
}
@@ -73,9 +74,9 @@ public class EnergyScan extends Panel {
@Override
protected void onStart() {
super.onStart();
panel.loadConfig();
panel.loadConfig();
}
@Override
protected void onApplicationStateChange(State state, State former) {
getComponent().setEnabled(state == State.Ready);
@@ -85,11 +86,19 @@ public class EnergyScan extends Panel {
protected void doUpdate() {
panel.plot();
}
Path getConfigFile(){
Path getConfigFile() {
return Paths.get(getController().getSetup().getConfigPath(), "energy_scan.properties");
}
enum Mode {
plus,
minus,
lh,
lv
}
public class PluginPanel extends MonitoredPanel {
final LinePlotBase plot;
@@ -124,39 +133,39 @@ public class EnergyScan extends Panel {
Integer c = count.take();
if (c == null) {
series.clear();
} else {
} else {
double[] ydata = null;
if (radioE.isSelected()){
data.setSize(c);
ydata=data.read();
} else if (radioF.isSelected()){
fdata.setSize(c);
ydata=fdata.read();
} else if (radioI0.isSelected()){
idata.setSize(c);
ydata=idata.read();
} else if (radioTEY.isSelected()){
data.setSize(c);
idata.setSize(c);
ydata=data.read();
if (radioE.isSelected()) {
data.setSize(c);
ydata = data.read();
} else if (radioF.isSelected()) {
fdata.setSize(c);
ydata = fdata.read();
} else if (radioI0.isSelected()) {
idata.setSize(c);
ydata = idata.read();
} else if (radioTEY.isSelected()) {
data.setSize(c);
idata.setSize(c);
ydata = data.read();
double[] i0 = idata.read();
for (int i=0;i<c;i++){
for (int i = 0; i < c; i++) {
ydata[i] = (i0[i] == 0.0) ? Double.NaN : ydata[i] / i0[i];
}
} else if (radioTFY.isSelected()){
fdata.setSize(c);
idata.setSize(c);
ydata=fdata.read();
}
} else if (radioTFY.isSelected()) {
fdata.setSize(c);
idata.setSize(c);
ydata = fdata.read();
double[] i0 = idata.read();
for (int i=0;i<c;i++){
for (int i = 0; i < c; i++) {
ydata[i] = (i0[i] == 0.0) ? Double.NaN : ydata[i] / i0[i];
}
}
if (ydata==null){
}
}
if (ydata == null) {
series.clear();
} else {
edata.setSize(c);
double[] xdata = edata.read();
edata.setSize(c);
double[] xdata = edata.read();
series.setData(xdata, ydata);
}
}
@@ -165,20 +174,64 @@ public class EnergyScan extends Panel {
ex.printStackTrace();
}
}
void loadConfig(){
void loadConfig() {
DefaultComboBoxModel model = (DefaultComboBoxModel) comboSetup.getModel();
model.removeAllElements();
try{
try {
for (String line : Files.readAllLines(getConfigFile())) {
if ((line!=null) && (!line.trim().isEmpty())){
if ((line != null) && (!line.trim().isEmpty())) {
String[] tokens = line.split("=");
if (tokens.length>0){
if (tokens.length > 0) {
model.addElement(tokens[0].trim());
}
}
}
} catch (Exception ex){
} catch (Exception ex) {
}
}
String expandPath(String path) {
long time = System.currentTimeMillis();
String mode;
if (comboMode.getSelectedIndex() == 0) {
mode = "plus";
} else if (comboMode.getSelectedIndex() == 1) {
mode = "minus";
} else {
mode = "lin_" + String.format("%1.0f", (Double) spinnerAlpha.getValue());
}
path = path.replaceAll("\\{date\\}", Chrono.getTimeStr(time, "YYYYMMdd"));
path = path.replaceAll("\\{time\\}", Chrono.getTimeStr(time, "HHmmss"));
path = path.replaceAll("\\{year\\}", Chrono.getTimeStr(time, "YYYY"));
path = path.replaceAll("\\{month\\}", Chrono.getTimeStr(time, "MM"));
path = path.replaceAll("\\{day\\}", Chrono.getTimeStr(time, "dd"));
path = path.replaceAll("\\{el\\}", String.valueOf(comboSetup.getSelectedItem()));
path = path.replaceAll("\\{mode\\}", mode);
return path;
}
void setMode(Mode mode) {
switch (mode) {
case plus:
comboMode.setSelectedIndex(0);
spinnerOffset.setValue(offsets[0]);
return;
case minus:
comboMode.setSelectedIndex(1);
spinnerOffset.setValue(offsets[1]);
return;
case lh:
comboMode.setSelectedIndex(2);
spinnerOffset.setValue(offsets[2]);
spinnerAlpha.setValue(0.0);
return;
case lv:
comboMode.setSelectedIndex(3);
spinnerOffset.setValue(offsets[3]);
spinnerAlpha.setValue(90.0);
return;
}
}
@@ -212,6 +265,9 @@ public class EnergyScan extends Panel {
jPanel1 = new javax.swing.JPanel();
comboSetup = new javax.swing.JComboBox();
buttonConfigure = new javax.swing.JButton();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
comboRunType = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
radioTEY = new javax.swing.JRadioButton();
radioTFY = new javax.swing.JRadioButton();
@@ -270,7 +326,7 @@ public class EnergyScan extends Panel {
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel6.setText("File:");
textFile.setText("Unknown");
textFile.setText("{el}_{mode}");
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel7.setText("Folder:");
@@ -366,7 +422,7 @@ public class EnergyScan extends Panel {
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(textFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
.addContainerGap(22, Short.MAX_VALUE))
);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Setup"));
@@ -384,27 +440,49 @@ public class EnergyScan extends Panel {
}
});
jLabel10.setText("Element:");
jLabel11.setText("Run Type:");
comboRunType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Manual", "+", "-", "LH", "LV", "+/-", "+/-/-/+", "LH/LV", "LH/LV/LV/LH" }));
comboRunType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboRunTypeActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()
.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(buttonConfigure))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(comboSetup, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonConfigure, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(comboRunType, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(23, Short.MAX_VALUE))
);
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfigure, comboSetup});
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfigure, comboRunType, comboSetup});
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonConfigure)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
@@ -511,14 +589,14 @@ public class EnergyScan extends Panel {
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(panelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonAbort)
.addComponent(buttonExecute)))
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE))
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
.addComponent(panelParameters, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
@@ -536,15 +614,12 @@ public class EnergyScan extends Panel {
args.put("TIME", (Double) spinnerTime.getValue());
args.put("DELAY", (Double) spinnerDelay.getValue());
args.put("MODE", comboMode.getSelectedItem().toString());
args.put("OFFSET", (Double) spinnerOffset.getValue());
args.put("FILE", textFile.getText());
String folder = textFolder.getText();
long time = System.currentTimeMillis();
folder = folder.replaceAll("\\{date\\}", Chrono.getTimeStr(time, "YYYYMMdd"));
folder = folder.replaceAll("\\{time\\}", Chrono.getTimeStr(time, "HHmmss"));
folder = folder.replaceAll("\\{year\\}", Chrono.getTimeStr(time, "YYYY"));
folder = folder.replaceAll("\\{month\\}", Chrono.getTimeStr(time, "MM"));
folder = folder.replaceAll("\\{day\\}", Chrono.getTimeStr(time, "dd"));
args.put("OFFSET", (Double) spinnerOffset.getValue());
String file = expandPath(textFile.getText());
args.put("FILE", file);
String folder = expandPath(textFolder.getText());
args.put("FOLDER", folder);
runAsync("EnergyScan", args);
plot.getAxis(Plot.AxisId.X).setRange(Math.min(e1, e2), Math.max(e1, e2));
@@ -559,32 +634,35 @@ public class EnergyScan extends Panel {
private void comboSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSetupActionPerformed
try {
Properties prop = new Properties();
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){
if (tokens.length != 8) {
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) {
offsets[0] = Double.valueOf(tokens[4].trim());
offsets[1] = Double.valueOf(tokens[5].trim());
offsets[2] = Double.valueOf(tokens[6].trim());
offsets[3] = Double.valueOf(tokens[7].trim());
comboRunTypeActionPerformed(null);
} 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) {
} catch (Exception ex) {
SwingUtils.showException(this, ex);
}
}
}//GEN-LAST:event_buttonConfigureActionPerformed
private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed
@@ -595,14 +673,52 @@ public class EnergyScan extends Panel {
panel.plot();
}//GEN-LAST:event_radioPlotActionPerformed
private void comboRunTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboRunTypeActionPerformed
try {
switch (comboRunType.getSelectedIndex()) {
case 0: //Manual
return;
case 1: //+
setMode(Mode.plus);
return;
case 2: //-
setMode(Mode.minus);
return;
case 3: //LH
setMode(Mode.lh);
return;
case 4: //LV
setMode(Mode.lv);
return;
case 5: //+/-
setMode(Mode.plus);
return;
case 6: //+/-/-/+
setMode(Mode.plus);
return;
case 7: //LH/LV
setMode(Mode.lh);
return;
case 8: //LH/LV/LV/LH
setMode(Mode.lh);
return;
}
} catch (Exception ex) {
SwingUtils.showException(this, ex);
}
}//GEN-LAST:event_comboRunTypeActionPerformed
// 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.ButtonGroup buttonGroupPlot;
private javax.swing.JComboBox comboMode;
private javax.swing.JComboBox comboRunType;
private javax.swing.JComboBox comboSetup;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;