204 lines
9.5 KiB
Java
204 lines
9.5 KiB
Java
/*
|
|
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
|
*/
|
|
|
|
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")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
|
|
|
|
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.setShowStatus(false);
|
|
motorPanel1.setShowTitle(true);
|
|
|
|
processVariablePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("x"));
|
|
processVariablePanel1.setDecimals(2);
|
|
processVariablePanel1.setDeviceName("x");
|
|
processVariablePanel1.setShowSlider(false);
|
|
processVariablePanel1.setShowTitle(true);
|
|
|
|
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.setShowStatus(false);
|
|
motorPanel2.setShowTitle(true);
|
|
|
|
processVariablePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("omega"));
|
|
processVariablePanel2.setDecimals(2);
|
|
processVariablePanel2.setDeviceName("omega");
|
|
processVariablePanel2.setShowSlider(false);
|
|
processVariablePanel2.setShowTitle(true);
|
|
|
|
checkHighDef.setSelected(true);
|
|
checkHighDef.setText("High definition");
|
|
checkHighDef.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
checkHighDefActionPerformed(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, 330, Short.MAX_VALUE)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.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)))
|
|
.addContainerGap())
|
|
);
|
|
|
|
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {motorPanel1, motorPanel2, processVariablePanel1, processVariablePanel2});
|
|
|
|
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, 68, Short.MAX_VALUE)
|
|
.addComponent(checkHighDef)
|
|
.addGap(18, 18, 18)
|
|
.addComponent(buttonDefineBeam)
|
|
.addGap(26, 26, 26))
|
|
);
|
|
}// </editor-fold>//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
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
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
|
|
}
|