/* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ import ch.psi.pshell.device.Motor; import ch.psi.pshell.device.Positionable; import ch.psi.pshell.imaging.Overlay; import ch.psi.pshell.imaging.Overlays; import ch.psi.pshell.imaging.Pen; import ch.psi.pshell.imaging.Renderer; import ch.psi.pshell.imaging.RendererListener; import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import java.awt.Color; import java.nio.file.Paths; import java.util.logging.Level; /** * */ public class Microscope extends Panel { public Microscope() { initComponents(); } //Overridable callbacks @Override public void onInitialize(int runCount) { renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "BeamMarker.bin")); } @Override public void onStateChange(State state, State former) { } @Override public void onExecutedFile(String fileName, Object result) { } //Callback to perform update - in event thread @Override protected void doUpdate() { } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { renderer = new ch.psi.pshell.imaging.Renderer(); motorPanel1 = new ch.psi.pshell.swing.MotorPanel(); processVariablePanel1 = new ch.psi.pshell.swing.ProcessVariablePanel(); buttonDefineBeam = new javax.swing.JButton(); motorPanel2 = new ch.psi.pshell.swing.MotorPanel(); processVariablePanel2 = new ch.psi.pshell.swing.ProcessVariablePanel(); checkHighDef = new javax.swing.JCheckBox(); button0 = new javax.swing.JButton(); button90 = new javax.swing.JButton(); button180 = new javax.swing.JButton(); button270 = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); buttonLeft = new javax.swing.JButton(); buttonRight = new javax.swing.JButton(); buttonUp = new javax.swing.JButton(); buttonDown = new javax.swing.JButton(); renderer.setAutoscrolls(true); renderer.setDeviceName("mic-high"); renderer.setMode(ch.psi.pshell.imaging.RendererMode.Fixed); renderer.setShowStatus(false); motorPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("cy")); motorPanel1.setDecimals(2); motorPanel1.setDeviceName("cy"); motorPanel1.setShowHoming(false); motorPanel1.setShowJog(false); motorPanel1.setShowStatus(false); motorPanel1.setShowTitle(true); processVariablePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("x")); processVariablePanel1.setDecimals(2); processVariablePanel1.setDeviceName("x"); processVariablePanel1.setShowLimitButtons(false); processVariablePanel1.setShowSlider(false); processVariablePanel1.setShowTitle(true); processVariablePanel1.setStepIncrement(0.001); processVariablePanel1.setStepSize(0.01); buttonDefineBeam.setText("Define Beam"); buttonDefineBeam.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonDefineBeamActionPerformed(evt); } }); motorPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("cz")); motorPanel2.setDecimals(2); motorPanel2.setDeviceName("cz"); motorPanel2.setShowHoming(false); motorPanel2.setShowJog(false); motorPanel2.setShowStatus(false); motorPanel2.setShowTitle(true); processVariablePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("omega")); processVariablePanel2.setDecimals(2); processVariablePanel2.setDeviceName("omega"); processVariablePanel2.setShowLimitButtons(false); processVariablePanel2.setShowSlider(false); processVariablePanel2.setShowTitle(true); processVariablePanel2.setStepIncrement(10.0); processVariablePanel2.setStepSize(90.0); checkHighDef.setSelected(true); checkHighDef.setText("High definition"); checkHighDef.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { checkHighDefActionPerformed(evt); } }); button0.setText("0"); button0.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { button0ActionPerformed(evt); } }); button90.setText("90"); button90.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { button90ActionPerformed(evt); } }); button180.setText("180"); button180.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { button180ActionPerformed(evt); } }); button270.setText("270"); button270.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { button270ActionPerformed(evt); } }); buttonLeft.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N buttonLeft.setText("<"); buttonLeft.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonLeftActionPerformed(evt); } }); buttonRight.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N buttonRight.setText(">"); buttonRight.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonRightActionPerformed(evt); } }); buttonUp.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N buttonUp.setText("^"); buttonUp.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonUpActionPerformed(evt); } }); buttonDown.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N buttonDown.setText("v"); buttonDown.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonDownActionPerformed(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(96, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(buttonLeft) .addGap(42, 42, 42) .addComponent(buttonRight)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(44, 44, 44) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(buttonDown) .addComponent(buttonUp)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(104, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap(20, Short.MAX_VALUE) .addComponent(buttonUp) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonRight) .addComponent(buttonLeft)) .addGap(18, 18, 18) .addComponent(buttonDown) .addContainerGap(48, Short.MAX_VALUE)) ); 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() .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGap(123, 123, 123) .addComponent(buttonDefineBeam)) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(motorPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(processVariablePanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(processVariablePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addComponent(checkHighDef)) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addComponent(button0) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button90) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button180) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button270))) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {motorPanel1, motorPanel2, processVariablePanel1, processVariablePanel2}); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {button0, button180, button270, button90}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(5, 5, 5)) .addGroup(layout.createSequentialGroup() .addComponent(motorPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(processVariablePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(processVariablePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(button0) .addComponent(button90) .addComponent(button180) .addComponent(button270)) .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(checkHighDef) .addGap(18, 18, 18) .addComponent(buttonDefineBeam) .addGap(26, 26, 26)) ); }// //GEN-END:initComponents Overlay beam; private void buttonDefineBeamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDefineBeamActionPerformed try{ Pen pen = new Pen(Color.RED); final Overlay selection = new Overlays.Rect(pen); renderer.addListener(new RendererListener() { @Override public void onSelectionFinished(Renderer renderer, Overlay overlay) { System.out.println(overlay + " - " + selection + " - " + (overlay == selection)); if (overlay == selection){ try { if (overlay.getLength() > 0) { beam = overlay.copy(); beam.setPen(pen); beam.setSolid(false); beam.setMovable(true); renderer.setMarker(beam); } } catch (Exception ex) { getLogger().log(Level.WARNING, null, ex); } finally { renderer.removeListener(this); } } } @Override public void onSelectionAborted(Renderer renderer, Overlay overlay) { if (overlay == selection){ renderer.removeListener(this); } } }); renderer.removeOverlay(beam); renderer.startSelection(selection); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonDefineBeamActionPerformed private void checkHighDefActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHighDefActionPerformed renderer.setDeviceName(checkHighDef.isSelected() ? "mic-high" : "mic-low"); }//GEN-LAST:event_checkHighDefActionPerformed private void button0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button0ActionPerformed try{ ((Positionable)getDevice("omega")).moveAsync(0.0); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_button0ActionPerformed private void button90ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button90ActionPerformed try{ ((Positionable)getDevice("omega")).moveAsync(90.0); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_button90ActionPerformed private void button180ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button180ActionPerformed try{ ((Positionable)getDevice("omega")).moveAsync(180.0); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_button180ActionPerformed private void button270ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button270ActionPerformed try{ ((Positionable)getDevice("omega")).moveAsync(270.0); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_button270ActionPerformed double step = 0.01; private void buttonLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLeftActionPerformed try{ ((ch.psi.pshell.epics.Positionable)getDevice("x")).moveRelAsync(-step); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonLeftActionPerformed private void buttonRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRightActionPerformed try{ ((ch.psi.pshell.epics.Positionable)getDevice("x")).moveRelAsync(step); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonRightActionPerformed private void buttonUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpActionPerformed try{ doVerticalStep(step); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonUpActionPerformed private void buttonDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDownActionPerformed try{ doVerticalStep(-step); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonDownActionPerformed public void doVerticalStep(double offset) throws Exception { double omega = Math.toRadians((Double) ((Positionable)getDevice("omega")).getPosition()); double z = offset * Math.sin(omega); double y = offset * Math.cos(omega); ((Motor)getDevice("cy")).moveRelAsync(y); ((Motor)getDevice("cz")).moveRelAsync(z); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton button0; private javax.swing.JButton button180; private javax.swing.JButton button270; private javax.swing.JButton button90; private javax.swing.JButton buttonDefineBeam; private javax.swing.JButton buttonDown; private javax.swing.JButton buttonLeft; private javax.swing.JButton buttonRight; private javax.swing.JButton buttonUp; private javax.swing.JCheckBox checkHighDef; private javax.swing.JPanel jPanel1; private ch.psi.pshell.swing.MotorPanel motorPanel1; private ch.psi.pshell.swing.MotorPanel motorPanel2; private ch.psi.pshell.swing.ProcessVariablePanel processVariablePanel1; private ch.psi.pshell.swing.ProcessVariablePanel processVariablePanel2; private ch.psi.pshell.imaging.Renderer renderer; // End of variables declaration//GEN-END:variables }