Sprint 12/21

This commit is contained in:
gac-x11ma
2020-12-09 15:06:55 +01:00
parent 13352381ed
commit b0718601c2
19 changed files with 1717 additions and 682 deletions

View File

@@ -19,6 +19,8 @@ import javax.swing.SwingConstants;
*/
public class Beamline extends Panel {
boolean updatingControls;
public enum ID {
ID1,
ID2,
@@ -44,7 +46,7 @@ public class Beamline extends Panel {
SwingUtils.setEnumCombo(comboPol1, Beamline.Polarization.class, true);
SwingUtils.setEnumCombo(comboPol2, Beamline.Polarization.class, true);
Component[] parameterControls = new Component[0];
Component[] parameterControls = new Component[]{};
for (JPanel panel : new JPanel[]{panelBeamline}) {
for (Class cls : new Class[]{JComboBox.class, JSpinner.class, JToggleButton.class}) {
parameterControls = Arr.append(parameterControls, SwingUtils.getComponentsByType(panel, cls));
@@ -71,6 +73,38 @@ public class Beamline extends Panel {
@Override
public void onInitialize(int runCount) {
try {
updateBeamlineSetup();
} catch (IOException ex) {
showException(ex);
}
}
@Override
public void onStateChange(State state, State former) {
try{
updatingControls = true;
checkDryMode.setSelected((boolean) this.eval("get_dry_run()", true));
//updateBeamlineSetup();
} catch (Exception ex){
checkDryMode.setSelected(false);
} finally{
updatingControls = false;
}
updateControls();
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
//Callback to perform update - in event thread
@Override
protected void doUpdate() {
}
void updateBeamlineSetup() throws IOException{
String id = getSetting("ID");
Double en = Double.valueOf(getSetting("ENERGY"));
String pol1 = getSetting("POL_ID_1");
@@ -90,48 +124,34 @@ public class Beamline extends Panel {
comboPol2.setSelectedItem(pol2);
spinnerAlp2.setValue(alp2);
spinnerHar2.setValue(har2);
spinnerOff2.setValue(off2);
checkAutoValve.setSelected(String.valueOf(getSetting("AUTO_SWITCH_VALVE")).equalsIgnoreCase("true"));
} catch (IOException ex) {
showException(ex);
}
}
@Override
public void onStateChange(State state, State former) {
updateControls();
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
//Callback to perform update - in event thread
@Override
protected void doUpdate() {
spinnerOff2.setValue(off2);
checkAutoValve.setSelected(String.valueOf(getSetting("AUTO_SWITCH_VALVE")).equalsIgnoreCase("true"));
}
void updateControls() {
boolean editable = getState().isInitialized() && !getState().isProcessing();
boolean is_id1 = comboID.getSelectedIndex() != 1;
boolean is_id2 = comboID.getSelectedIndex() != 0;
buttonApply.setEnabled(editable);
for (Component c : parameterControls) {
c.setEnabled(editable);
}
updatingControls = true;
try{
boolean editable = getState().isInitialized() && !getState().isProcessing();
boolean is_id1 = comboID.getSelectedIndex() != 1;
boolean is_id2 = comboID.getSelectedIndex() != 0;
buttonApply.setEnabled(editable);
if (editable) {
spinnerAlp1.setEnabled(is_id1 && (comboPol1.getSelectedItem() == Beamline.Polarization.Lin.toString()));
spinnerAlp2.setEnabled(is_id2 & (comboPol2.getSelectedItem() == Beamline.Polarization.Lin.toString()));
spinnerHar1.setEnabled(is_id1 );
spinnerHar2.setEnabled(is_id2 );
spinnerOff1.setEnabled(is_id1 );
spinnerOff2.setEnabled(is_id2 );
comboPol1.setEnabled(is_id1 );
comboPol2.setEnabled(is_id2 );
for (Component c : parameterControls) {
c.setEnabled(editable);
}
if (editable) {
spinnerAlp1.setEnabled(is_id1 && (comboPol1.getSelectedItem() == Beamline.Polarization.Lin.toString()));
spinnerAlp2.setEnabled(is_id2 & (comboPol2.getSelectedItem() == Beamline.Polarization.Lin.toString()));
spinnerHar1.setEnabled(is_id1 );
spinnerHar2.setEnabled(is_id2 );
spinnerOff1.setEnabled(is_id1 );
spinnerOff2.setEnabled(is_id2 );
comboPol1.setEnabled(is_id1 );
comboPol2.setEnabled(is_id2 );
}
} finally {
updatingControls = false;
}
}
@@ -201,6 +221,11 @@ public class Beamline extends Panel {
checkAutoValve = new javax.swing.JCheckBox();
deviceValuePanel1 = new ch.psi.pshell.swing.DeviceValuePanel();
deviceValuePanel10 = new ch.psi.pshell.swing.DeviceValuePanel();
buttonUndo = new javax.swing.JButton();
checkDryMode = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
panelBeamline.setBorder(javax.swing.BorderFactory.createTitledBorder("Setup"));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel3.setText("ID:");
@@ -419,6 +444,13 @@ public class Beamline extends Panel {
deviceValuePanel10.setDeviceName("energy_opt_desc");
buttonUndo.setText("Undo");
buttonUndo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUndoActionPerformed(evt);
}
});
javax.swing.GroupLayout panelBeamlineLayout = new javax.swing.GroupLayout(panelBeamline);
panelBeamline.setLayout(panelBeamlineLayout);
panelBeamlineLayout.setHorizontalGroup(
@@ -445,6 +477,8 @@ public class Beamline extends Panel {
.addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(panelBeamlineLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonUndo, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
@@ -477,25 +511,46 @@ public class Beamline extends Panel {
.addComponent(deviceValuePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(checkAutoValve)))
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(buttonApply)
.addGap(18, 18, 18)
.addGroup(panelBeamlineLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonApply)
.addComponent(buttonUndo))
.addContainerGap())
);
panelBeamlineLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboID, deviceValuePanel1, deviceValuePanel10, spinnerImgEng});
checkDryMode.setEnabled(false);
checkDryMode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkDryModeActionPerformed(evt);
}
});
jLabel1.setText("Dry Mode");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panelBeamline, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(checkDryMode)
.addGap(2, 2, 2)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGap(0, 0, 0)
.addComponent(panelBeamline, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap(24, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(checkDryMode)
.addComponent(jLabel1))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
@@ -520,16 +575,38 @@ public class Beamline extends Panel {
}//GEN-LAST:event_buttonApplyActionPerformed
private void checkAutoValveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkAutoValveActionPerformed
try{
setSetting("AUTO_SWITCH_VALVE", checkAutoValve.isSelected());
} catch (Exception ex){
showException (ex);
if (!updatingControls){
try{
setSetting("AUTO_SWITCH_VALVE", checkAutoValve.isSelected());
} catch (Exception ex){
showException (ex);
}
}
}//GEN-LAST:event_checkAutoValveActionPerformed
private void checkDryModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkDryModeActionPerformed
if (!updatingControls){
try{
this.eval("set_dry_run("+ (checkDryMode.isSelected() ? "True" : "False") + ")", true);
} catch (Exception ex){
showException (ex);
}
}
}//GEN-LAST:event_checkDryModeActionPerformed
private void buttonUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUndoActionPerformed
try{
updateBeamlineSetup();
} catch (Exception ex){
showException (ex);
}
}//GEN-LAST:event_buttonUndoActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonApply;
private javax.swing.JButton buttonUndo;
private javax.swing.JCheckBox checkAutoValve;
private javax.swing.JCheckBox checkDryMode;
private javax.swing.JComboBox<String> comboID;
private javax.swing.JComboBox<String> comboPol1;
private javax.swing.JComboBox<String> comboPol2;
@@ -543,6 +620,7 @@ public class Beamline extends Panel {
private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel7;
private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel8;
private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel9;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;