Closedown
This commit is contained in:
125
plugins/Microscope.java
Normal file
125
plugins/Microscope.java
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.imaging.Source;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.State;
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Microscope extends Panel {
|
||||
public Microscope() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
//Overridable callbacks
|
||||
@Override
|
||||
public void onInitialize(int runCount) {
|
||||
|
||||
final Overlay overlay = new Overlays.Rect(new Pen(Color.RED), new Point(10,10), new Point(50,50));
|
||||
renderer.addOverlay(overlay);
|
||||
overlay.setMovable(true);
|
||||
overlay.setSolid(false);
|
||||
|
||||
renderer.addListener(new RendererListener() {
|
||||
public void onMouseDragged(Renderer renderer, Point p) {
|
||||
//sendOutput(p.toString());
|
||||
System.out.println((p.x - renderer.getImageSize().width/2) + " - " + (p.y - renderer.getImageSize().height/2));
|
||||
}
|
||||
|
||||
public void onMoveFinished(Renderer renderer, Overlay ov) {
|
||||
if (ov == overlay){
|
||||
System.out.println(ov.getPosition().toString());
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
|
||||
renderer.setAutoscrolls(true);
|
||||
renderer.setDeviceName("mic-low");
|
||||
renderer.setMode(ch.psi.pshell.imaging.RendererMode.Fixed);
|
||||
renderer.setShowStatus(false);
|
||||
|
||||
jButton1.setText("Wait click");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(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, 392, Short.MAX_VALUE)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
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()
|
||||
.addContainerGap()
|
||||
.addComponent(jButton1)
|
||||
.addContainerGap(307, Short.MAX_VALUE))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
try{
|
||||
new Thread(()->{
|
||||
try {
|
||||
Point p = renderer.waitClick(10000);
|
||||
System.out.println(p);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
jButton1.setEnabled(true);
|
||||
|
||||
}).start();
|
||||
jButton1.setEnabled(false);
|
||||
} catch (Exception ex){
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
private ch.psi.pshell.imaging.Renderer renderer;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
Reference in New Issue
Block a user