/* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ import ch.psi.pshell.device.Motor; 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(); 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); } }); 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, 342, Short.MAX_VALUE) .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))) .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)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 158, Short.MAX_VALUE) .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{ ((Motor)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{ ((Motor)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{ ((Motor)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{ ((Motor)getDevice("omega")).moveAsync(270.0); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_button270ActionPerformed // 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.JCheckBox checkHighDef; 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 }