Files
sf-op/plugins/ScreenPanel.java
2016-11-04 11:42:56 +01:00

2262 lines
104 KiB
Java

/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.pshell.core.Controller;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import javax.swing.DefaultComboBoxModel;
import ch.psi.pshell.ui.Panel;
import ch.psi.pshell.imaging.ImageListener;
import ch.psi.utils.State;
import ch.psi.utils.IO;
import ch.psi.utils.Chrono;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.utils.swing.TextEditor;
import ch.psi.pshell.epics.PsiCamera;
import ch.psi.pshell.epics.Camtool;
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceAdapter;
import ch.psi.pshell.epics.ArraySource;
import ch.psi.pshell.epics.ChannelInteger;
import ch.psi.pshell.epics.DiscretePositioner;
import ch.psi.pshell.epics.Epics;
import ch.psi.pshell.imaging.Colormap;
import ch.psi.pshell.imaging.ColormapSource;
import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.Histogram;
import ch.psi.pshell.imaging.Overlay;
import ch.psi.pshell.imaging.Overlays;
import ch.psi.pshell.imaging.Overlays.Text;
import ch.psi.pshell.imaging.Pen;
import ch.psi.pshell.imaging.PointDouble;
import ch.psi.pshell.imaging.Renderer;
import ch.psi.pshell.imaging.RendererListener;
import ch.psi.pshell.imaging.RendererMode;
import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.scripting.InterpreterResult;
import ch.psi.pshell.scripting.ScriptManager;
import ch.psi.pshell.swing.ValueSelection;
import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener;
import ch.psi.utils.Arr;
import ch.psi.utils.ArrayProperties;
import ch.psi.utils.Convert;
import ch.psi.utils.Str;
import ch.psi.utils.swing.Editor.EditorDialog;
import ch.psi.utils.swing.MainFrame;
import ch.psi.utils.swing.SwingUtils.OptionResult;
import ch.psi.utils.swing.SwingUtils.OptionType;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import org.apache.commons.math3.analysis.function.Gaussian;
import org.apache.commons.math3.fitting.GaussianCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoint;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
/**
*
*/
public class ScreenPanel extends Panel {
boolean useCamtoolStats = true;
final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool";
File[] cameraConfigFiles = new File[0];
ArraySource camera;
String cameraName;
String cameraConfigJson;
CameraConfig config;
int polling = 1000;
Overlay marker = null;
JDialog histogramDialog;
DiscretePositioner screen;
DiscretePositioner filter;
boolean showFit;
final ArrayList<Data> imageBuffer = new ArrayList();
int imageBufferLenght = 0;
Text imageBufferOverlay;
public ScreenPanel() {
initComponents();
renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin"));
setPersistedComponents(new Component[]{buttonCamtool, buttonDirect});
comboCameras.setEnabled(false);
if (App.hasArgument("poll")) {
try {
polling = Integer.valueOf(App.getArgumentValue("poll"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (App.hasArgument("zoom")) {
try {
renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom")));
renderer.resetZoom();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (App.hasArgument("buf")) {
try {
imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (App.hasArgument("calc")) {
useCamtoolStats = false;
}
renderer.setProfileNormalized(true);
renderer.setShowProfileLimits(false);
JMenuItem menuSetROI = new JMenuItem("Set ROI...");
menuSetROI.addActionListener((ActionEvent e) -> {
renderer.abortSelection();
if (camera instanceof Camtool) {
final Overlays.Rect selection = new Overlays.Rect(renderer.getPenMovingOverlay());
renderer.addListener(new RendererListener() {
@Override
public void onSelectionFinished(Renderer renderer, Overlay overlay) {
try {
Rectangle roi = overlay.isFixed() ? renderer.toImageCoord(overlay.getBounds()) : overlay.getBounds();
if (((Camtool)camera).roiEnabled.read() >0){
int[] cur = ((Camtool)camera).roi.read();
((Camtool)camera).roi.writeAsync(new int[]{roi.x + cur[0] , roi.y + cur[1], roi.width, roi.height});
}
else {
((Camtool)camera).roi.writeAsync(new int[]{roi.x, roi.y, roi.width, roi.height});
((Camtool)camera).roiEnabled.writeAsync(1);
}
} catch (Exception ex) {
} finally {
renderer.removeListener(this);
}
}
@Override
public void onSelectionAborted(Renderer renderer, Overlay overlay) {
renderer.removeListener(this);
}
});
selection.setFixed(true);
renderer.startSelection(selection);
}
});
JMenuItem menuResetROI = new JMenuItem("Reset ROI");
menuResetROI.addActionListener((ActionEvent e) -> {
renderer.abortSelection();
if (camera instanceof Camtool) {
((Camtool)camera).roiEnabled.writeAsync(0);
}
});
renderer.getPopupMenu().addSeparator();
renderer.getPopupMenu().add(menuSetROI);
renderer.getPopupMenu().add(menuResetROI);
renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
menuResetROI.setEnabled (camera instanceof Camtool);
menuSetROI.setEnabled (camera instanceof Camtool);
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
renderer.getPopupMenu().setVisible(false);
showFit = buttonFit.isSelected();
if (imageBufferLenght > 1) {
renderer.addListener(new RendererListener() {
@Override
public void onImage(Renderer renderer, Object origin, BufferedImage image, Data data) {
if (data != null) {
synchronized (imageBuffer) {
imageBuffer.add(data);
if (imageBuffer.size() > imageBufferLenght) {
imageBuffer.remove(0);
}
}
}
}
});
}
pauseSelection.setVisible(false);
pauseSelection.setMinValue(1);
pauseSelection.addListener(new ValueSelectionListener() {
@Override
public void onValueChanged(ValueSelection origin, double value, boolean editing) {
if (editing && (value >= 1) && (value <= imageBuffer.size())) {
updatePause();
}
}
});
imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20));
imageBufferOverlay.setFixed(true);
imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT);
if (MainFrame.isDark()) {
textState.setEnabled(true);
}
}
@Override
public void onStart() {
super.onStart();
if (App.hasArgument("ct")) {
boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false");
buttonCamtool.setSelected(!direct);
buttonDirect.setSelected(direct);
}
}
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
comboCameras.setEnabled(false);
if (App.hasArgument("s")) {
renderer.setDevice((Source) getDevice("image"));
renderer.setAutoScroll(true);
((Source) getDevice("image")).addListener(new ImageListener() {
@Override
public void onImage(Object o, BufferedImage bi, Data data) {
manageFit(bi, data);
}
@Override
public void onError(Object o, Exception excptn) {
}
}
);
} else {
cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"});
Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b));
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (File file : cameraConfigFiles) {
String prefix = IO.getPrefix(file);
if (!prefix.startsWith("#")) {
model.addElement(prefix);
}
}
comboCameras.setModel(model);
comboCameras.setEnabled(true);
comboCameras.setSelectedItem(-1);
if (model.getSize() > 0) {
try {
if (App.hasArgument("cam")) {
comboCameras.setSelectedItem(App.getArgumentValue("cam"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
startTimer(1000);
}
void manageFit(BufferedImage bi, Data data) {
Overlay[] fo = ((bi == null) || (!showFit)) ? null : getFitOverlays(data);
renderer.updateOverlays(fo, fitOv);
fitOv = fo;
}
@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() {
}
public static class CameraConfig {
public HashMap kwargs;
public ArrayList args;
public ArrayList links;
public String type;
public HashMap<String, Object> state;
public CameraConfig image_source;
public HashMap<String, CameraConfig> subcomponents;
public ArrayList<Integer> getCalibration() {
return (ArrayList<Integer>) state.get("calibration");
}
public double getCalOffsetX() {
ArrayList<Integer> calibration = getCalibration();
double ret = -(calibration.get(0) + calibration.get(2)) / 2;
return ret;
}
public double getCalOffsetY() {
ArrayList<Integer> calibration = getCalibration();
double ret = -(calibration.get(1) + calibration.get(3)) / 2;
return ret;
}
public double getScaleX() {
ArrayList<Integer> calibration = getCalibration();
double width = Math.abs(calibration.get(2) - calibration.get(0));
return getCalibrationWidth() / width;
}
public double getScaleY() {
ArrayList<Integer> calibration = getCalibration();
double height = Math.abs(calibration.get(3) - calibration.get(1));
return getCalibrationHeight() / height;
}
public Double getCalibrationHeight() {
return (Double) state.get("calibration_height");
}
public Double getCalibrationWidth() {
return (Double) state.get("calibration_width");
}
public Double getCalibrationHorizontalAngle() {
return (Double) state.get("calibration_horizontal_angle");
}
public Double getCalibrationVerticalAngle() {
return (Double) state.get("calibration_vertical_angle");
}
public Boolean getMirrorX() {
return (Boolean) state.get("mirror_x");
}
public Boolean getMirrorY() {
return (Boolean) state.get("mirror_y");
}
public Integer getRotate() {
return (Integer) state.get("rotate");
}
public ArrayList<Integer> getOrigin() {
return (ArrayList<Integer>) state.get("origin");
}
public ArrayList<Integer> getRoi() {
return (ArrayList<Integer>) state.get("roi");
}
public Boolean getRoiEnable() {
if ((state.get("roi_enable") == null) || (state.get("roi") == null)) {
return false;
}
return (Boolean) state.get("roi_enable");
}
public ArrayList<Double> getUnitSize() {
return (ArrayList<Double>) state.get("unit_size");
}
public Integer getRun() {
return (Integer) state.get("run");
}
}
Overlay[] fitOv;
void setCamera(String cameraName) throws IOException, InterruptedException {
System.out.println("Setting camera: " + cameraName + " [" + (buttonCamtool.isSelected() ? "camtool" : "direct") + "]");
if (camera != null) {
camera.close();
camera = null;
renderer.setDevice(null);
renderer.setShowReticle(false);
renderer.removeOverlays(fitOv);
renderer.clear();
renderer.resetZoom();
}
if (screen != null) {
screen.close();
screen = null;
}
if (filter != null) {
filter.close();
filter = null;
}
try {
Path configFile = Paths.get(configFolder, cameraName + ".json");
cameraConfigJson = new String(Files.readAllBytes(configFile));
this.cameraName = cameraName;
try {
if (buttonCamtool.isSelected()) {
camera = new Camtool("CurrentCamera", cameraName, false);
camera.getConfig().flipHorizontally = false;
camera.getConfig().flipVertically = false;
camera.getConfig().rotation = 0.0;
camera.getConfig().roiX = 0;
camera.getConfig().roiY = 0;
camera.getConfig().roiWidth = -1;
camera.getConfig().roiHeight = -1;
} else {
camera = new PsiCamera("CurrentCamera", cameraName);
config = (CameraConfig) JsonSerializer.decode(cameraConfigJson, CameraConfig.class);
camera.getConfig().flipHorizontally = config.getMirrorX();
camera.getConfig().flipVertically = config.getMirrorY();
//camera.getConfig().rotation = config.getRotate();
//camera.getConfig().rotationCrop = true;
switch (config.getRotate()){
case 1: camera.getConfig().rotation = 270; break;
case 2: camera.getConfig().rotation = 180; break;
case 3: camera.getConfig().rotation = 90; break;
}
camera.getConfig().rotationCrop = false;
camera.getConfig().roiX = config.getRoiEnable() ? config.getRoi().get(0) : 0;
camera.getConfig().roiY = config.getRoiEnable() ? config.getRoi().get(1) : 0;
camera.getConfig().roiWidth = config.getRoiEnable() ? config.getRoi().get(2) : -1;
camera.getConfig().roiHeight = config.getRoiEnable() ? config.getRoi().get(3) : -1;
try {
camera.getConfig().spatialCalOffsetX = config.getCalOffsetX();
camera.getConfig().spatialCalOffsetY = config.getCalOffsetY();
camera.getConfig().spatialCalScaleX = -config.getScaleX();
camera.getConfig().spatialCalScaleY = -config.getScaleY();
} catch (Exception ex) {
camera.getConfig().spatialCalOffsetX = Double.NaN;
camera.getConfig().spatialCalOffsetY = Double.NaN;
camera.getConfig().spatialCalScaleX = Double.NaN;
camera.getConfig().spatialCalScaleY = Double.NaN;
}
}
} catch (Exception ex) {
config = null;
showException(ex);
}
camera.initialize();
if (camera instanceof Camtool) {
try {
camera.getConfig().spatialCalOffsetX = ((Camtool) camera).calOffX.read();
camera.getConfig().spatialCalOffsetY = ((Camtool) camera).calOffY.read();
double[] origin = ((Camtool) camera).origin.read();
//TODO: not working on camtool
//camera.getConfig().spatialCalScaleX = -origin[0];
//camera.getConfig().spatialCalScaleY = -origin[1];
camera.getConfig().spatialCalScaleX = ((Camtool) camera).calScaleX.read();
camera.getConfig().spatialCalScaleY = ((Camtool) camera).calScaleY.read();
} catch (Exception ex) {
System.err.println(ex.getMessage());
camera.getConfig().spatialCalOffsetX = 0.0;
camera.getConfig().spatialCalOffsetY = 0.0;
camera.getConfig().spatialCalScaleX = 1.0;
camera.getConfig().spatialCalScaleY = 1.0;
}
((Camtool)camera).shape.addListener(new DeviceAdapter(){
@Override
public void onValueChanged(Device device, Object value, Object former) {
if ((camera instanceof Camtool) &&(device==((Camtool)camera).shape) && (camera.getState().isInitialized())) {
try {
if ((value != null) && (value.getClass() == int[].class)) {
final int[] s = (int[]) value;
if ((s.length > 1) && (s[0] * s[1] > 0) &&
((s[0] != camera.getConfig().imageHeight) || (s[1] != camera.getConfig().imageWidth))) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
comboCamerasActionPerformed(null);
}
});
}
}
} catch (Exception ex) {
System.err.println(ex);
}
}
}
});
((Camtool)camera).shape.setMonitored(true);
}
buttonReticle.setEnabled(camera.getConfig().isCalibrated());
buttonGrabBackground.setEnabled(camera instanceof Camtool);
camera.getConfig().save();
if (polling <= 0) {
camera.setMonitored(true);
} else {
camera.setPolling(-polling);
}
renderer.setDevice(camera);
renderer.setAutoScroll(true);
renderer.setMarker(marker);
firstImage = true;
camera.addListener(new ImageListener() {
@Override
public void onImage(Object o, BufferedImage bi, Data data) {
if (bi != null) {
if (firstImage) {
if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
centralizeRenderer();
}
});
}
firstImage = false;
}
renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight()));
}
if ((bi == null) || (!showFit)) {
renderer.removeOverlays(fitOv);
fitOv = null;
} else {
if (!renderer.isPaused()) {
Overlay[] fo = getFitOverlays(data);
renderer.updateOverlays(fo, fitOv);
fitOv = fo;
}
}
}
@Override
public void onError(Object o, Exception excptn) {
}
});
} catch (Exception ex) {
if (renderer.getDevice() == null) {
renderer.setZoom(1.0);
renderer.setMode(RendererMode.Zoom);
renderer.addOverlay(new Text(renderer.getPenErrorText(), ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)));
}
} finally {
checkReticle();
onTimer();
}
try {
screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS");
screen.initialize();
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (String pos : screen.getPositions()) {
model.addElement(pos);
}
comboScreen.setModel(model);
comboScreen.setSelectedItem(screen.read());
} catch (Exception ex) {
comboScreen.setModel(new DefaultComboBoxModel());
System.err.println(ex.getMessage());
screen = null;
}
comboScreen.setEnabled(screen != null);
valueScreen.setDevice(screen);
try {
filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER");
filter.initialize();
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (String pos : filter.getPositions()) {
model.addElement(pos);
}
comboFilter.setModel(model);
comboFilter.setSelectedItem(filter.read());
} catch (Exception ex) {
comboFilter.setModel(new DefaultComboBoxModel());
System.err.println(ex.getMessage());
filter = null;
}
comboFilter.setEnabled(filter != null);
valueFilter.setDevice(filter);
}
volatile Boolean firstImage;
void checkReticle() {
if ((renderer.getDevice() != null) && (camera != null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()) {
renderer.setCalibration(camera.getCalibration());
renderer.configureReticle(new Dimension(800, 800), 200);
renderer.setShowReticle(true);
} else {
renderer.setCalibration(null);
renderer.setShowReticle(false);
}
renderer.refresh();
}
void checkMarker() {
if (camera != null) {
if (buttonMarker.isSelected()) {
Dimension d = renderer.getImageSize();
Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2);
Overlay ov = null;
marker = new Overlays.Crosshairs(renderer.getPenMarker(), p, new Dimension(100, 100));
marker.setMovable(true);
marker.setPassive(false);
} else {
marker = null;
}
renderer.setMarker(marker);
}
}
void updateZoom() {
try {
buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch);
buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit);
if (renderer.getMode() == RendererMode.Fixed) {
buttonZoomNormal.setSelected(true);
} else if (renderer.getMode() == RendererMode.Zoom) {
if (renderer.getZoom() == 1) {
buttonZoomNormal.setSelected(true);
} else if (renderer.getZoom() == 0.5) {
buttonZoom05.setSelected(true);
} else if (renderer.getZoom() == 0.25) {
buttonZoom025.setSelected(true);
} else if (renderer.getZoom() == 2.0) {
buttonZoom2.setSelected(true);
} else {
buttonGroup1.clearSelection();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
void updateColormap() {
try {
if ((camera != null) && (camera instanceof ColormapSource)) {
ColormapSourceConfig config = ((ColormapSource) camera).getConfig();
switch (config.colormap) {
case Grayscale:
buttonGrayscale.setSelected(true);
break;
case Rainbow:
buttonRainbow.setSelected(true);
break;
case Temperature:
buttonTemperature.setSelected(true);
break;
default:
buttonGroup2.clearSelection();
}
if (config.isDefaultColormap()) {
buttonFullRange.setSelected(true);
} else if (config.colormapAutomatic) {
buttonAutomatic.setSelected(true);
} else {
buttonManual.setSelected(true);
}
spinnerMin.setEnabled(buttonManual.isSelected());
spinnerMax.setEnabled(buttonManual.isSelected());
spinnerMin.setValue(Double.isNaN(config.colormapMin) ? 0 : Math.min(Math.max((int) config.colormapMin, 0), 65535));
spinnerMax.setValue(Double.isNaN(config.colormapMax) ? 0 : Math.min(Math.max((int) config.colormapMax, 0), 65535));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
protected void onTimer() {
for (Device dev : new Device[]{screen, filter}) {
if (dev != null) {
dev.request();
}
}
textState.setText((camera == null) ? "" : camera.getState().toString());
buttonConfig.setEnabled(camera != null);
if (App.hasArgument("s")) {
try {
((Source) getDevice("image")).initialize();
} catch (IOException ex) {
Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (renderer.isPaused() != buttonPause.isSelected()) {
buttonPause.setSelected(renderer.isPaused());
buttonPauseActionPerformed(null);
}
if (renderer.getShowReticle() != buttonReticle.isSelected()) {
//buttonReticle.setSelected(renderer.getShowReticle());
}
if ((renderer.getMarker() == null) && buttonMarker.isSelected()) {
buttonMarker.setSelected(false);
}
updateZoom();
updateColormap();
buttonSave.setSelected(renderer.isSnapshotDialogVisible());
checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing()));
}
Pen penFit = new Pen(new Color(192, 105, 0), 1);
Pen penCross = new Pen(new Color(192, 105, 0), 1);
Overlay[] getFitOverlays(Data data) {
Overlays.Polyline hgaussian = null;
Overlays.Polyline vgaussian = null;
Overlays.Polyline hprofile = null;
Overlays.Polyline vprofile = null;
Double xMean = null, xSigma = null, xNorm = null;
Double yMean = null, ySigma = null, yNorm = null;
Double xCom=null, yCom=null;
if (data != null) {
int profileSize = renderer.getProfileSize();
if ((useCamtoolStats) &&(camera instanceof Camtool)){
try{
profileSize/=4;
double[] gX = ((Camtool)camera).gaussX.read();
double[] pX = ((Camtool)camera).profileX.read();
int[] x = Arr.indexesInt(gX.length);
int[] y = new int[gX.length];
int[] p = new int[gX.length];
List<Double> l = Arrays.asList((Double[]) Convert.toWrapperArray(pX));
Double min = Collections.min(l);
Double max = Collections.max(l);
double minPlot = min;
double rangePlot = max- min;
for (int i = 0; i < x.length; i++) {
y[i] = (int) (data.getHeight() - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize));
p[i] = (int) (data.getHeight() - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize));
}
vgaussian = new Overlays.Polyline(penFit, x, y);
vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p);
double[] gY = ((Camtool)camera).gaussY.read();
double[] pY = ((Camtool)camera).profileY.read();
y = Arr.indexesInt(gY.length);
x = new int[gY.length];
p = new int[gY.length];
l = Arrays.asList((Double[]) Convert.toWrapperArray(pY));
min = Collections.min(l);
max = Collections.max(l);
minPlot = min;
rangePlot = max- min;
for (int i = 0; i < x.length; i++) {
x[i] = (int) (((gY[i] - minPlot) / rangePlot) * profileSize);
p[i] = (int) (((pY[i] - minPlot) / rangePlot) * profileSize);
}
hgaussian = new Overlays.Polyline(penFit, x, y);
hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, y);
xMean = ((Camtool)camera).gaussCenterX.read();
yMean = ((Camtool)camera).gaussCenterY.read();
xSigma = ((Camtool)camera).gaussStdDivX.read();
ySigma = ((Camtool)camera).gaussStdDivY.read();
xCom = ((Camtool)camera).posX.read();
yCom = ((Camtool)camera).posY.read();
} catch (Exception ex){
System.err.println(ex.getMessage());
return null;
}
}else {
ArrayProperties properties = data.getProperties();
double maxPlot = properties.max;
double minPlot = properties.min;
double rangePlot = maxPlot - minPlot;
if (rangePlot <= 0) {
return null;
}
try {
double[] sum = (double[]) Convert.toDouble(data.integrateVertically(true));
double[] saux = new double[sum.length];
int[] p = new int[sum.length];
xCom = getCom(sum);
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
for (int i = 0; i < sum.length; i++) {
saux[i] = sum[i] - min;
}
double[] gaussian = fitGaussian(saux, x);
if (gaussian != null) {
if ((gaussian[2] < sum.length * 0.45)
&& (gaussian[2] > 2)
&& (gaussian[0] > min * 0.03)) {
xNorm = gaussian[0];
xMean = gaussian[1];
xSigma = gaussian[2];
double[] fit = getFitFunction(gaussian, x);
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) (data.getHeight() - 1 - ((((fit[i] + min) / data.getHeight() - minPlot) / rangePlot) * profileSize));
p[i] = (int) (data.getHeight() - 1 - (((sum[i] / data.getHeight() - minPlot) / rangePlot) * profileSize));
}
vgaussian = new Overlays.Polyline(penFit, x, y);
vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
try {
double[] sum = (double[]) Convert.toDouble(data.integrateHorizontally(true));
double[] saux = new double[sum.length];
int[] p = new int[sum.length];
yCom = getCom(sum);
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
for (int i = 0; i < sum.length; i++) {
saux[i] = sum[i] - min;
}
double[] gaussian = fitGaussian(saux, x);
if (gaussian != null) {
//Only aknowledge beam fully inside the image and peak over 3% of min
if ((gaussian[2] < sum.length * 0.45)
&& (gaussian[2] > 2)
&& (gaussian[0] > min * 0.03)) {
yNorm = gaussian[0];
yMean = gaussian[1];
ySigma = gaussian[2];
double[] fit = getFitFunction(gaussian, x);
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) ((((fit[i] + min) / data.getWidth() - minPlot) / rangePlot) * profileSize);
p[i] = (int) (((sum[i] / data.getWidth() - minPlot) / rangePlot) * profileSize);
}
hgaussian = new Overlays.Polyline(penFit, y, x);
hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
if (renderer.getCalibration() != null) {
if (xSigma!=null) xSigma *= renderer.getCalibration().getScaleX();
if (ySigma!=null) ySigma *= renderer.getCalibration().getScaleY();
if (xMean!=null) xMean = data.getX((int) Math.round(xMean));
if (yMean!=null) yMean = data.getY((int) Math.round(yMean));
if (xCom!=null) xCom = data.getX((int) Math.round(xCom));
if (yCom!=null) yCom = data.getY((int) Math.round(yCom));
}
}
Overlays.Crosshairs cross = null;
Overlays.Text text = null;
if ((xMean != null) && (yMean != null)) {
text = new Overlays.Text(penFit,
String.format("x: m=%1.3f \u03C3=%1.3f c=%1.3f\ny: m=%1.3f \u03C3=%1.3f c=%1.3f",
xMean, xSigma, xCom,
yMean, ySigma, yCom),
new Font(Font.MONOSPACED, 0, 14), new Point(20, 20));
text.setFixed(true);
text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
Point center = new Point(xMean.intValue(), yMean.intValue());
if (renderer.getCalibration() != null) {
center = renderer.getCalibration().convertToImagePosition(new PointDouble(xMean, yMean));
xSigma /= renderer.getCalibration().getScaleX();
ySigma /= renderer.getCalibration().getScaleY();
}
cross = new Overlays.Crosshairs(penCross,center, new Dimension(Math.abs(2 * xSigma.intValue()), 2 * Math.abs(ySigma.intValue())));
}
return new Overlay[]{hprofile, vprofile, hgaussian, vgaussian, cross, text};
}
return null;
}
double getCom(double[] arr){
if (arr==null) {
return Double.NaN;
}
int index = 0;
double ret = 0;
double total=0;
for (double v: arr){
ret += (v * index++);
total +=v;
}
if (total==0){
return Double.NaN;
}
return ret/total;
}
double[] fitGaussianScript(int[] y, int[] x) {
ScriptManager sm = Controller.getInstance().getScriptManager();
ArrayProperties pY = ArrayProperties.get(y);
sm.setVar("y", y);
sm.setVar("x", x);
InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex + ",])");
if (r.exception != null) {
r.exception.printStackTrace();
} else {
List ret = (List) sm.getVar("r");
if ((ret != null) && (ret.size() == 1) && (ret.get(0) instanceof List) && (((List) (ret.get(0))).size() == 3)) {
double norm = (Double) ((List) ret.get(0)).get(0);
double mean = (Double) ((List) ret.get(0)).get(1);
double sigma = (Double) ((List) ret.get(0)).get(2);
return new double[]{norm, mean, sigma};
}
}
return null;
}
double[] fitGaussian(double[] y, int[] x) {
try {
ArrayProperties pY = ArrayProperties.get(y);
GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max - pY.min) / 2, x[pY.maxIndex], 1.0}).withMaxIterations(1000);
ArrayList<WeightedObservedPoint> values = new ArrayList<>();
for (int i = 0; i < y.length; i++) {
values.add(new WeightedObservedPoint(1.0, x[i], y[i]));
}
return fitter.fit(values);
} catch (Exception ex) {
return null;
}
}
double[] getFitFunction(double[] pars, int[] x) {
double[] fit = new double[x.length];
Gaussian g = new Gaussian(pars[0], pars[1], pars[2]);
for (int i = 0; i < x.length; i++) {
fit[i] = g.value(x[i]);
}
return fit;
}
/*
public class Camtool extends ArraySource {
final String prefix;
final String dataPrefix;
final boolean latch;
final Object lock = new Object();
final public ChannelInteger channelRun;
final public ChannelInteger channelLatch;
final public ChannelDouble channelTimestamp;
final public ChannelDoubleArray origin;
final public ChannelDouble posX, posY;
final public ChannelDoubleArray profileX, profileY;
final public ChannelIntegerArray shape;
final public ChannelInteger roiEnabled;
final public ChannelIntegerArray roi;
final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain;
final public ChannelDouble calOffX, calOffY, calScaleX, calScaleY;
final public ChannelDoubleArray gaussX, gaussY;
final public ChannelDouble gaussCenterX, gaussCenterY;
final public ChannelDouble gaussStdDivX, gaussStdDivY;
public Camtool(String name, String prefix) {
this(name, prefix, false);
}
public Camtool(String name, String prefix, boolean latch) {
super(name, prefix + (latch ? ":latch" : ":pipeline") + ".roi.output");
this.prefix = prefix + ":";
this.latch = latch;
dataPrefix = this.prefix + (latch ? "latch" : "pipeline") + ".";
channelRun = new ChannelInteger(name + " run", this.prefix + "camera.run");
channelLatch = new ChannelInteger(name + " latch", this.prefix + "latch.capture");
channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp");
channelTimestamp.setMonitored(true);
posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com_egu");
posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu");
profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x");
profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y");
shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("roi.output.shape"));
roiEnabled = new ChannelInteger(name + " roi enable", dataPrefix + ("roi.enabled"));
roi = new ChannelIntegerArray(name + " roi", dataPrefix + ("roi.roi"));
origin = new ChannelDoubleArray(name + " origin X", dataPrefix + "roi.origin_out");
bgEnable = new ChannelInteger(name + " bg enable", this.prefix + "pipeline.bg.enabled");
bgCapture = new ChannelInteger(name + " bg capture", this.prefix + "pipeline.bg.capture");
bgCaptureRemain = new ChannelInteger(name + " bg capture remain", this.prefix + "pipeline.bg.capture_remain");
calOffX = new ChannelDouble(name + " cal off x", this.prefix + "pipeline.egu.eoff_x");
calOffY = new ChannelDouble(name + " cal off y", this.prefix + "pipeline.egu.eoff_y");
calScaleX = new ChannelDouble(name + " cal scale x", this.prefix + "pipeline.egu.eslo_x");
calScaleY = new ChannelDouble(name + " cal scale y", this.prefix + "pipeline.egu.eslo_y");
gaussX = new ChannelDoubleArray(name + " gauss x", dataPrefix + ("x_stats.gauss"));
gaussY = new ChannelDoubleArray(name + " gauss y", dataPrefix + ("y_stats.gauss"));
gaussCenterX = new ChannelDouble(name + "gauss center x", dataPrefix + "x_stats.g_center_egu");
gaussCenterY = new ChannelDouble(name + "gauss center y", dataPrefix + "y_stats.g_center_egu");
gaussStdDivX = new ChannelDouble(name + "gauss stddiv x", dataPrefix + "x_stats.g_stddiv_egu");
gaussStdDivY = new ChannelDouble(name + "gauss stddiv t", dataPrefix + "y_stats.g_stddiv_egu");
}
@Override
public void doSetMonitored(boolean value) {
super.doSetMonitored(value);
getDevice().setMonitored(value);
}
void safeInitialize(Device dev, int timeout) throws IOException, InterruptedException {
for (int retries = 0; retries < 10; retries++) {
try {
dev.initialize();
break;
} catch (IOException ex) {
if (retries == 9) {
throw ex;
}
Thread.sleep(timeout / 10);
}
}
}
@Override
protected void doInitialize() throws IOException, InterruptedException {
try {
channelRun.initialize();
channelLatch.initialize();
if (latch) {
start();
latch();
}
safeInitialize(channelTimestamp, 2000);
posX.initialize();
posY.initialize();
profileX.initialize();
profileY.initialize();
shape.initialize();
roiEnabled.initialize();
roi.initialize();
origin.initialize();
bgEnable.initialize();
bgCapture.initialize();
bgCaptureRemain.initialize();
try {
calOffX.initialize();
calOffY.initialize();
calScaleX.initialize();
calScaleY.initialize();
} catch (Exception ex) {
ex.printStackTrace();
}
gaussX.initialize();
gaussY.initialize();
gaussCenterX.initialize();
gaussCenterY.initialize();
gaussStdDivX.initialize();
gaussStdDivY.initialize();
int[] s = shape.read();
getConfig().imageHeight = s[0];
getConfig().imageWidth = s[1];
getConfig().save();
getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth);
super.doInitialize();
} catch (InterruptedException ex) {
throw ex;
} catch (Exception ex) {
ex.printStackTrace();
throw new IOException(ex);
}
}
@Override
public void doClose() throws IOException {
super.doClose();
channelRun.close();
channelLatch.close();
channelTimestamp.close();
posX.close();
posY.close();
profileX.close();
profileY.close();
shape.close();
roiEnabled.close();
roi.close();
origin.close();
bgEnable.close();
bgCapture.close();
bgCaptureRemain.close();
calOffX.close();
calOffY.close();
calScaleX.close();
calScaleY.close();
gaussX.close();
gaussY.close();
gaussCenterX.close();
gaussCenterY.close();
gaussStdDivX.close();
gaussStdDivY.close();
gaussX.close();
gaussY.close();
gaussCenterX.close();
gaussCenterY.close();
gaussStdDivX.close();
gaussStdDivY.close();
}
int numImages = 1;
public int getNumImages() {
return numImages;
}
public void setNumImages(int value) {
numImages = value;
}
double grabTimeout = 3.0;
public double getGrabTimeout() {
return grabTimeout;
}
public void setGrabTimeou(double value) {
grabTimeout = value;
}
public void capture() throws IOException, InterruptedException {
int retries = 3;
while (true) {
try {
double timestamp = channelTimestamp.read();
if (latch) {
channelLatch.write(1);
} else {
channelRun.write(1);
}
long start = System.currentTimeMillis();
while (true) {
double val = channelTimestamp.read();
if (timestamp != val) {
return;
}
if ((System.currentTimeMillis() - start) > grabTimeout) {
throw new IOException("Frame timeout");
}
Thread.sleep(5);
}
} catch (IOException ex) {
retries--;
if (--retries <= 0) {
throw ex;
}
}
}
}
public void start() throws IOException, InterruptedException {
channelRun.write(-1);
}
public void stop() throws IOException, InterruptedException {
channelRun.write(0);
}
public void grabSingle() throws IOException, InterruptedException {
channelRun.write(1);
}
public void latch() throws IOException, InterruptedException {
channelLatch.write(1);
}
public void enableBackground(boolean value) throws IOException, InterruptedException {
bgEnable.write(value ? 1 : 0);
}
public void captureBackground(int images) throws IOException, InterruptedException {
start();
bgCapture.write(images);
Thread.sleep(200);
while (bgCaptureRemain.read() > 0) {
Thread.sleep(10);
}
}
}
*/
void setHistogramVisible(boolean value) {
if (value) {
if ((histogramDialog == null) || (!histogramDialog.isShowing())) {
Histogram histogram = new Histogram(true);
histogram.setRenderer(renderer);
histogramDialog = SwingUtils.showDialog(SwingUtils.getWindow(renderer), "Histogram", null, histogram);
renderer.refresh();
}
} else {
if (histogramDialog != null) {
histogramDialog.setVisible(false);
histogramDialog = null;
}
}
}
void setLaserState(boolean value) throws Exception {
Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1);
Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1);
Thread.sleep(3000);
}
boolean getLaserState() throws Exception {
return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0);
}
void elog(String title, String message, String[] attachments) throws Exception {
String domain = "";
String logbook = "SwissFEL commissioning data";
String category = "Info";
String entry = "";
StringBuffer cmd = new StringBuffer();
cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" ");
cmd.append("-a \"Author=ScreenPanel\" ");
cmd.append("-a \"Type=pshell\" ");
cmd.append("-a \"Entry=").append(entry).append("\" ");
cmd.append("-a \"Title=").append(title).append("\" ");
cmd.append("-a \"Category=").append(category).append("\" ");
cmd.append("-a \"Domain=").append(domain).append("\" ");
for (String attachment : attachments) {
cmd.append("-f \"").append(attachment).append("\" ");
}
cmd.append("-n 1 ");
cmd.append("\"").append(message).append("\" ");
System.out.println(cmd.toString());
final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()});
new Thread(() -> {
try {
process.waitFor();
int bytes = process.getInputStream().available();
byte[] arr = new byte[bytes];
process.getInputStream().read(arr, 0, bytes);
System.out.println(new String(arr));
bytes = process.getErrorStream().available();
arr = new byte[bytes];
process.getErrorStream().read(arr, 0, bytes);
System.err.println(new String(arr));
} catch (Exception ex) {
System.err.println(ex);
}
}).start();
}
void centralizeRenderer() {
Point center = null;
Dimension size = renderer.getImageSize();
double zoom = (renderer.getMode() == RendererMode.Fixed) ? 1.0 : renderer.getZoom();
if (renderer.getCalibration() != null) {
center = renderer.getCalibration().getCenter();
} else if (size != null) {
center = new Point(size.width / 2, size.height / 2);
}
if (center != null) {
Point topleft = new Point(Math.max((int) (center.x - renderer.getWidth() / 2 / zoom), 0),
Math.max((int) (center.y - renderer.getHeight() / 2 / zoom), 0));
renderer.setViewPosition(topleft);
}
}
void updatePause() {
int index = ((int) pauseSelection.getValue()) - 1;
synchronized (imageBuffer) {
if (index < imageBuffer.size()) {
Data data = imageBuffer.get(index);
BufferedImage image = camera.generateImage(data);
renderer.setImage(renderer.getOrigin(), image, data);
imageBufferOverlay.update(Chrono.getTimeStr(data.getTimestamp(), "HH:mm:ss.SSS"));
manageFit(image, data);
}
}
}
////////
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
buttonGroup3 = new javax.swing.ButtonGroup();
buttonGroup4 = new javax.swing.ButtonGroup();
jProgressBar1 = new javax.swing.JProgressBar();
jPanel1 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
buttonMarker = new javax.swing.JToggleButton();
buttonGrabBackground = new javax.swing.JButton();
buttonSave = new javax.swing.JToggleButton();
buttonFit = new javax.swing.JToggleButton();
buttonReticle = new javax.swing.JToggleButton();
buttonPause = new javax.swing.JToggleButton();
jPanel6 = new javax.swing.JPanel();
textState = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
comboCameras = new javax.swing.JComboBox();
buttonSetup = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
buttonConfig = new javax.swing.JButton();
renderer = new ch.psi.pshell.imaging.Renderer();
jPanel4 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
buttonZoomFit = new javax.swing.JRadioButton();
buttonZoomStretch = new javax.swing.JRadioButton();
buttonZoomNormal = new javax.swing.JRadioButton();
buttonZoom025 = new javax.swing.JRadioButton();
buttonZoom05 = new javax.swing.JRadioButton();
buttonZoom2 = new javax.swing.JRadioButton();
jPanel2 = new javax.swing.JPanel();
buttonGrayscale = new javax.swing.JRadioButton();
buttonRainbow = new javax.swing.JRadioButton();
buttonTemperature = new javax.swing.JRadioButton();
buttonFullRange = new javax.swing.JRadioButton();
buttonManual = new javax.swing.JRadioButton();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
spinnerMin = new javax.swing.JSpinner();
spinnerMax = new javax.swing.JSpinner();
buttonAutomatic = new javax.swing.JRadioButton();
checkHistogram = new javax.swing.JCheckBox();
jPanel5 = new javax.swing.JPanel();
buttonCamtool = new javax.swing.JRadioButton();
buttonDirect = new javax.swing.JRadioButton();
panelScreen = new javax.swing.JPanel();
valueScreen = new ch.psi.pshell.swing.DeviceValuePanel();
comboScreen = new javax.swing.JComboBox();
panelScreen1 = new javax.swing.JPanel();
valueFilter = new ch.psi.pshell.swing.DeviceValuePanel();
comboFilter = new javax.swing.JComboBox();
pauseSelection = new ch.psi.pshell.swing.ValueSelection();
setPreferredSize(new java.awt.Dimension(873, 600));
buttonMarker.setText("Marker");
buttonMarker.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonMarkerActionPerformed(evt);
}
});
buttonGrabBackground.setText("Grab Background");
buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonGrabBackgroundActionPerformed(evt);
}
});
buttonSave.setText("Save Snapshot");
buttonSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSaveActionPerformed(evt);
}
});
buttonFit.setSelected(true);
buttonFit.setText("Fit");
buttonFit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonFitActionPerformed(evt);
}
});
buttonReticle.setSelected(true);
buttonReticle.setText("Reticle");
buttonReticle.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonReticleActionPerformed(evt);
}
});
buttonPause.setText("Pause");
buttonPause.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonPauseActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(buttonPause)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonMarker)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonFit)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonReticle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonGrabBackground)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSave)
.addGap(0, 0, 0))
);
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle});
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave});
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonPause)
.addComponent(buttonFit)
.addComponent(buttonMarker)
.addComponent(buttonSave)
.addComponent(buttonReticle)
.addComponent(buttonGrabBackground))
.addGap(0, 0, 0))
);
textState.setEditable(false);
textState.setHorizontalAlignment(javax.swing.JTextField.CENTER);
textState.setDisabledTextColor(new java.awt.Color(0, 0, 0));
textState.setEnabled(false);
jLabel2.setText("State:");
comboCameras.setMaximumRowCount(30);
comboCameras.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboCamerasActionPerformed(evt);
}
});
buttonSetup.setText("Setup");
buttonSetup.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSetupActionPerformed(evt);
}
});
jLabel1.setText("Camera:");
buttonConfig.setText("Config");
buttonConfig.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonConfigActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGap(0, 0, 0)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboCameras, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonConfig)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSetup)
.addGap(50, 50, 50)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0))
);
jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonSetup});
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonConfig)
.addComponent(buttonSetup))
.addGap(0, 0, 0))
);
jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom"));
buttonGroup1.add(buttonZoomFit);
buttonZoomFit.setText("Fit");
buttonZoomFit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonZoomFitActionPerformed(evt);
}
});
buttonGroup1.add(buttonZoomStretch);
buttonZoomStretch.setText("Stretch");
buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonZoomStretchActionPerformed(evt);
}
});
buttonGroup1.add(buttonZoomNormal);
buttonZoomNormal.setText("Normal");
buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonZoomNormalActionPerformed(evt);
}
});
buttonGroup1.add(buttonZoom025);
buttonZoom025.setText("1/4");
buttonZoom025.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonZoom025ActionPerformed(evt);
}
});
buttonGroup1.add(buttonZoom05);
buttonZoom05.setText("1/2");
buttonZoom05.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonZoom05ActionPerformed(evt);
}
});
buttonGroup1.add(buttonZoom2);
buttonZoom2.setText("2");
buttonZoom2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonZoom2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(buttonZoomFit)
.addComponent(buttonZoomNormal)
.addComponent(buttonZoomStretch))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(buttonZoom025)
.addComponent(buttonZoom05)
.addComponent(buttonZoom2))
.addGap(47, 47, 47))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(4, 4, 4)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonZoomNormal)
.addComponent(buttonZoom025))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonZoomFit)
.addComponent(buttonZoom05))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonZoomStretch)
.addComponent(buttonZoom2))
.addContainerGap())
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap"));
buttonGroup2.add(buttonGrayscale);
buttonGrayscale.setText("Grayscale");
buttonGrayscale.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onChangeColormap(evt);
}
});
buttonGroup2.add(buttonRainbow);
buttonRainbow.setText("Rainbow");
buttonRainbow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onChangeColormap(evt);
}
});
buttonGroup2.add(buttonTemperature);
buttonTemperature.setText("Temperature");
buttonTemperature.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onChangeColormap(evt);
}
});
buttonGroup3.add(buttonFullRange);
buttonFullRange.setText("Full range");
buttonFullRange.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onChangeColormap(evt);
}
});
buttonGroup3.add(buttonManual);
buttonManual.setText("Manual");
buttonManual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onChangeColormap(evt);
}
});
jLabel3.setText("Min:");
jLabel4.setText("Max:");
spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1));
spinnerMin.setEnabled(false);
spinnerMin.setPreferredSize(new java.awt.Dimension(77, 20));
spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
onChangeColormapRange(evt);
}
});
spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1));
spinnerMax.setEnabled(false);
spinnerMax.setPreferredSize(new java.awt.Dimension(77, 20));
spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
onChangeColormapRange(evt);
}
});
buttonGroup3.add(buttonAutomatic);
buttonAutomatic.setText("Automatic");
buttonAutomatic.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onChangeColormap(evt);
}
});
checkHistogram.setText("Histogram");
checkHistogram.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
checkHistogramActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(buttonAutomatic)
.addComponent(buttonFullRange)
.addComponent(buttonManual)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(checkHistogram)
.addComponent(buttonTemperature)
.addComponent(buttonRainbow)
.addComponent(buttonGrayscale))
.addContainerGap())
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerMax, spinnerMin});
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(4, 4, 4)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonAutomatic)
.addComponent(buttonGrayscale))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonFullRange)
.addComponent(buttonRainbow))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(buttonManual)
.addComponent(buttonTemperature))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(checkHistogram))
.addContainerGap())
);
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source"));
buttonGroup4.add(buttonCamtool);
buttonCamtool.setText("Camtool");
buttonCamtool.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonCamtoolActionPerformed(evt);
}
});
buttonGroup4.add(buttonDirect);
buttonDirect.setText("Direct");
buttonDirect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonDirectActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addComponent(buttonCamtool)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonDirect)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(4, 4, 4)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonCamtool)
.addComponent(buttonDirect))
.addContainerGap())
);
panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen"));
comboScreen.setEnabled(false);
comboScreen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboScreenActionPerformed(evt);
}
});
javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen);
panelScreen.setLayout(panelScreenLayout);
panelScreenLayout.setHorizontalGroup(
panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelScreenLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
panelScreenLayout.setVerticalGroup(
panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
panelScreen1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter"));
comboFilter.setEnabled(false);
comboFilter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboFilterActionPerformed(evt);
}
});
javax.swing.GroupLayout panelScreen1Layout = new javax.swing.GroupLayout(panelScreen1);
panelScreen1.setLayout(panelScreen1Layout);
panelScreen1Layout.setHorizontalGroup(
panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelScreen1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
panelScreen1Layout.setVerticalGroup(
panelScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreen1Layout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pauseSelection.setDecimals(0);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(panelScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelScreen1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel4Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(panelScreen1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
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()
.addGap(0, 0, 0)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
);
}// </editor-fold>//GEN-END:initComponents
private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed
try {
comboCameras.setEnabled(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
setCamera((String) comboCameras.getSelectedItem());
} catch (Exception ex) {
ex.printStackTrace();
} finally {
comboCameras.setEnabled(true);
}
}
}).start();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_comboCamerasActionPerformed
private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed
try {
if (camera != null) {
TextEditor editor = new TextEditor();
editor.setText(cameraConfigJson);
editor.setReadOnly(true);
editor.setTitle(cameraName);
EditorDialog dlg = editor.getDialog(getTopLevel(), false);
dlg.setSize(480, 640);
dlg.setVisible(true);
SwingUtils.centerComponent(this, dlg);
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonConfigActionPerformed
private void buttonSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetupActionPerformed
try {
if (camera != null) {
this.showDeviceConfigDialog(camera, false);
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonSetupActionPerformed
private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed
try {
renderer.removeOverlay(imageBufferOverlay);
if (camera != null) {
synchronized (imageBuffer) {
if (buttonPause.isSelected()) {
renderer.pause();
} else {
imageBuffer.clear();
renderer.resume();
}
pauseSelection.setVisible(buttonPause.isSelected() && (imageBuffer.size() > 0));
if (pauseSelection.isVisible()) {
renderer.addOverlay(imageBufferOverlay);
pauseSelection.setMaxValue(imageBuffer.size());
pauseSelection.setValue(imageBuffer.size());;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
showException(ex);
}
}//GEN-LAST:event_buttonPauseActionPerformed
private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed
try {
checkMarker();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonMarkerActionPerformed
private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed
try {
showFit = buttonFit.isSelected();
if (!buttonFit.isSelected()) {
renderer.removeOverlays(fitOv);
fitOv = null;
} else {
renderer.setProfile(Renderer.Profile.None);
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonFitActionPerformed
private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed
try {
checkReticle();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonReticleActionPerformed
private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
try {
String snapshotFile = getController().getSetup().expandPath("{images}/snapshot.png");
renderer.saveSnapshot(snapshotFile, "png", true);
getController().setExecutionContext("snapshot", null, null, null, null, null, null, null);
getController().getDataManager().setDataset("/data", renderer.getData().getMatrix(), renderer.getData().isUnsigned());
getController().getDataManager().closeOutput();
StringBuilder message = new StringBuilder();
message.append("Camera: ").append(cameraName).append(" (").
append((camera instanceof Camtool) ? "camtool" : "direct").append(")").append("\n");
message.append("Data file: ").append(getController().getExecutionContext().getPath()).append("\n");
if ((fitOv != null) && (fitOv.length > 3)) {
Overlays.Text text = (Overlays.Text) fitOv[3];
message.append(text.getText()).append("\n");
}
elog("ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile});
SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getController().getExecutionContext().getPath(), 5000);
} catch (Exception ex) {
ex.printStackTrace();
showException(ex);
}
}//GEN-LAST:event_buttonSaveActionPerformed
private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed
try {
if (camera instanceof Camtool) {
if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) {
boolean laserOn = getLaserState();
if (laserOn) {
setLaserState(false);
}
try {
((Camtool) camera).captureBackground(5);
} finally {
if (laserOn) {
setLaserState(true);
}
}
SwingUtils.showMessage(getTopLevel(), "Success", "Success capturing background", 5000);
}
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonGrabBackgroundActionPerformed
private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed
try {
renderer.setMode(RendererMode.Fit);
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonZoomFitActionPerformed
private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed
try {
renderer.setMode(RendererMode.Stretch);
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonZoomStretchActionPerformed
private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed
try {
renderer.setMode(RendererMode.Fixed);
centralizeRenderer();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonZoomNormalActionPerformed
private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap
try {
if ((camera != null) && (camera instanceof ColormapSource)) {
ColormapSource source = (ColormapSource) camera;
Color colorReticule = new Color(16, 16, 16);
Color colorMarker = new Color(128, 128, 128);
if (buttonGrayscale.isSelected()) {
colorReticule = new Color(0, 192, 0);
colorMarker = new Color(64, 255, 64);
source.getConfig().colormap = Colormap.Grayscale;
}
if (buttonTemperature.isSelected()) {
source.getConfig().colormap = Colormap.Temperature;
}
if (buttonRainbow.isSelected()) {
source.getConfig().colormap = Colormap.Rainbow;
}
renderer.setPenReticle(new Pen(colorReticule));
renderer.setPenProfile(new Pen(colorReticule,0));
renderer.setPenMarker(new Pen(colorMarker, 2));
renderer.setShowReticle(false);
checkReticle();
source.getConfig().colormapAutomatic = buttonAutomatic.isSelected();
source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue();
source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue();
source.getConfig().save();
source.refresh();
if (buttonPause.isSelected()) {
updatePause();
}
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_onChangeColormap
private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange
onChangeColormap(null);
}//GEN-LAST:event_onChangeColormapRange
private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed
renderer.setZoom(0.25);
renderer.setMode(RendererMode.Zoom);
centralizeRenderer();
}//GEN-LAST:event_buttonZoom025ActionPerformed
private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed
renderer.setZoom(0.5);
renderer.setMode(RendererMode.Zoom);
centralizeRenderer();
}//GEN-LAST:event_buttonZoom05ActionPerformed
private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed
comboCamerasActionPerformed(null);
}//GEN-LAST:event_buttonCamtoolActionPerformed
private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed
comboCamerasActionPerformed(null);
}//GEN-LAST:event_buttonDirectActionPerformed
private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed
ChannelInteger setpoint = null;
try {
int index = comboScreen.getSelectedIndex();
setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS");
setpoint.initialize();
if (setpoint.read() != index) {
boolean laserOn = getLaserState();
if (laserOn) {
setLaserState(false);
}
try {
setpoint.write(index);
} finally {
if (laserOn) {
setLaserState(true);
}
}
}
screen.read();
} catch (Exception ex) {
showException(ex);
}
if (setpoint != null) {
setpoint.close();
}
}//GEN-LAST:event_comboScreenActionPerformed
private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed
try {
String setpoint = (String) comboFilter.getSelectedItem();
if (!setpoint.equals(filter.read())) {
filter.write(setpoint);
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_comboFilterActionPerformed
private void checkHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkHistogramActionPerformed
try {
setHistogramVisible(checkHistogram.isSelected());
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_checkHistogramActionPerformed
private void buttonZoom2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom2ActionPerformed
renderer.setZoom(2.0);
renderer.setMode(RendererMode.Zoom);
centralizeRenderer();
}//GEN-LAST:event_buttonZoom2ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JRadioButton buttonAutomatic;
private javax.swing.JRadioButton buttonCamtool;
private javax.swing.JButton buttonConfig;
private javax.swing.JRadioButton buttonDirect;
private javax.swing.JToggleButton buttonFit;
private javax.swing.JRadioButton buttonFullRange;
private javax.swing.JButton buttonGrabBackground;
private javax.swing.JRadioButton buttonGrayscale;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.ButtonGroup buttonGroup3;
private javax.swing.ButtonGroup buttonGroup4;
private javax.swing.JRadioButton buttonManual;
private javax.swing.JToggleButton buttonMarker;
private javax.swing.JToggleButton buttonPause;
private javax.swing.JRadioButton buttonRainbow;
private javax.swing.JToggleButton buttonReticle;
private javax.swing.JToggleButton buttonSave;
private javax.swing.JButton buttonSetup;
private javax.swing.JRadioButton buttonTemperature;
private javax.swing.JRadioButton buttonZoom025;
private javax.swing.JRadioButton buttonZoom05;
private javax.swing.JRadioButton buttonZoom2;
private javax.swing.JRadioButton buttonZoomFit;
private javax.swing.JRadioButton buttonZoomNormal;
private javax.swing.JRadioButton buttonZoomStretch;
private javax.swing.JCheckBox checkHistogram;
private javax.swing.JComboBox comboCameras;
private javax.swing.JComboBox comboFilter;
private javax.swing.JComboBox comboScreen;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JPanel panelScreen;
private javax.swing.JPanel panelScreen1;
private ch.psi.pshell.swing.ValueSelection pauseSelection;
private ch.psi.pshell.imaging.Renderer renderer;
private javax.swing.JSpinner spinnerMax;
private javax.swing.JSpinner spinnerMin;
private javax.swing.JTextField textState;
private ch.psi.pshell.swing.DeviceValuePanel valueFilter;
private ch.psi.pshell.swing.DeviceValuePanel valueScreen;
// End of variables declaration//GEN-END:variables
}