From aac9dc3603d2f37084ed7afaddfaea245ed2d585 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Mon, 19 Sep 2016 11:26:49 +0200 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 4 +- plugins/ScreenPanel.form | 202 ++--- plugins/ScreenPanel.java | 1206 ++++++++++++++++-------------- 3 files changed, 758 insertions(+), 654 deletions(-) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index e4bd815..fa16cf0 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,5 +1,5 @@ -#Thu Sep 15 15:24:56 CEST 2016 -colormap=Temperature +#Mon Sep 19 11:22:10 CEST 2016 +colormap=Grayscale colormapAutomatic=true colormapMax=0.0 colormapMin=0.0 diff --git a/plugins/ScreenPanel.form b/plugins/ScreenPanel.form index 68ab795..a08cd9f 100644 --- a/plugins/ScreenPanel.form +++ b/plugins/ScreenPanel.form @@ -13,7 +13,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -105,8 +105,8 @@ - - + + @@ -220,25 +220,19 @@ - - - - - - - - - - - + + - + + + + - + @@ -247,14 +241,14 @@ - + - + - - - + + + @@ -276,30 +270,44 @@ - - - - - + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + - - - - - - @@ -343,7 +351,7 @@ - + @@ -354,7 +362,7 @@ - + @@ -376,72 +384,72 @@ - + - - - - - - - - - - - - - - + + - - - - - - + + + + + + + + - - - - - + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + - - - + @@ -504,12 +512,12 @@ - + - + @@ -519,7 +527,7 @@ - + @@ -533,7 +541,7 @@ - + @@ -551,12 +559,12 @@ - + - + @@ -575,10 +583,9 @@ - - - - + + + @@ -587,10 +594,11 @@ - + + + + - - diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index 93f1a95..eb4a759 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -23,6 +23,7 @@ import ch.psi.pshell.epics.ChannelDoubleArray; import ch.psi.pshell.epics.ChannelInteger; import ch.psi.pshell.epics.ChannelIntegerArray; 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; @@ -34,22 +35,25 @@ import ch.psi.pshell.imaging.Overlays; import ch.psi.pshell.imaging.Overlays.Text; import ch.psi.pshell.imaging.Pen; import static ch.psi.pshell.imaging.Renderer.PEN_ERROR_TEXT; -import ch.psi.pshell.imaging.Renderer.Profile; import static ch.psi.pshell.imaging.RendererMenu.PEN_MARKER; import ch.psi.pshell.imaging.RendererMode; import ch.psi.pshell.imaging.Source; +import ch.psi.pshell.imaging.Utils; import ch.psi.pshell.scripting.InterpreterResult; import ch.psi.pshell.scripting.ScriptManager; import ch.psi.utils.Arr; import ch.psi.utils.ArrayProperties; import ch.psi.utils.Convert; import ch.psi.utils.swing.Editor.EditorDialog; +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.image.BufferedImage; +import java.awt.image.DataBufferByte; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -63,6 +67,7 @@ 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; + /** * */ @@ -74,31 +79,31 @@ public class ScreenPanel extends Panel { setPersistedComponents(new Component[]{buttonCamtool, buttonDirect}); comboCameras.setEnabled(false); if (App.hasArgument("poll")) { - try{ + try { polling = Integer.valueOf(App.getArgumentValue("poll")); - } catch (Exception ex){ + } catch (Exception ex) { ex.printStackTrace(); } - } + } if (App.hasArgument("zoom")) { - try{ + try { renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom"))); renderer.resetZoom(); - } catch (Exception ex){ + } catch (Exception ex) { ex.printStackTrace(); } - } - showFit=buttonFit.isSelected(); - } - + } + showFit = buttonFit.isSelected(); + } + @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); + boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false"); + buttonCamtool.setSelected(!direct); buttonDirect.setSelected(direct); - } + } } final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool"; @@ -118,13 +123,13 @@ public class ScreenPanel extends Panel { @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() { + 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) { - if ((bi == null)||(!showFit)) { + public void onImage(Object o, BufferedImage bi, Data data) { + if ((bi == null) || (!showFit)) { fitOv = null; } else { Overlay[] fo = getFitOverlays(data); @@ -132,12 +137,13 @@ public class ScreenPanel extends Panel { fitOv = fo; } } + @Override public void onError(Object o, Exception excptn) { } - } + } ); - + } else { cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"}); Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b)); @@ -160,7 +166,7 @@ public class ScreenPanel extends Panel { } catch (Exception ex) { ex.printStackTrace(); } - } + } } startTimer(1000); } @@ -192,32 +198,31 @@ public class ScreenPanel extends Panel { public ArrayList getCalibration() { return (ArrayList) state.get("calibration"); } - - public double getCalOffsetX(){ - ArrayList calibration = getCalibration(); - double ret = - (calibration.get(0) + calibration.get(2))/2; - return ret; - } - public double getCalOffsetY(){ + public double getCalOffsetX() { ArrayList calibration = getCalibration(); - double ret = - (calibration.get(1) + calibration.get(3))/2; + double ret = -(calibration.get(0) + calibration.get(2)) / 2; return ret; } - public double getScaleX(){ + public double getCalOffsetY() { ArrayList calibration = getCalibration(); - double width = Math.abs( calibration.get(2) - calibration.get(0)); - return getCalibrationWidth()/width; + double ret = -(calibration.get(1) + calibration.get(3)) / 2; + return ret; + } + + public double getScaleX() { + ArrayList calibration = getCalibration(); + double width = Math.abs(calibration.get(2) - calibration.get(0)); + return getCalibrationWidth() / width; //return getCalibrationWidth()/1000; } - public double getScaleY(){ + public double getScaleY() { ArrayList calibration = getCalibration(); - double height = Math.abs( calibration.get(3) - calibration.get(1)); - return getCalibrationHeight()/height; + double height = Math.abs(calibration.get(3) - calibration.get(1)); + return getCalibrationHeight() / height; } - public Double getCalibrationHeight() { return (Double) state.get("calibration_height"); @@ -270,7 +275,7 @@ public class ScreenPanel extends Panel { return (Integer) state.get("run"); } } - + Overlay[] fitOv; void setCamera(String cameraName) throws IOException, InterruptedException { @@ -284,11 +289,11 @@ public class ScreenPanel extends Panel { renderer.clear(); renderer.resetZoom(); } - if (screen!=null){ + if (screen != null) { screen.close(); screen = null; } - if (filter!=null){ + if (filter != null) { filter.close(); filter = null; } @@ -299,7 +304,7 @@ public class ScreenPanel extends Panel { //SwingUtils.showMessage(null, "", json); try { if (buttonCamtool.isSelected()) { - camera = new Camtool("CurrentCamera", cameraName, false); + camera = new Camtool("CurrentCamera", cameraName, false); camera.getConfig().flipHorizontally = false; camera.getConfig().flipVertically = false; camera.getConfig().rotation = 0.0; @@ -318,66 +323,66 @@ public class ScreenPanel extends Panel { 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{ + try { camera.getConfig().spatialCalOffsetX = config.getCalOffsetX(); camera.getConfig().spatialCalOffsetY = config.getCalOffsetY(); camera.getConfig().spatialCalScaleX = config.getScaleX(); camera.getConfig().spatialCalScaleY = config.getScaleY(); - } catch (Exception ex){ + } catch (Exception ex) { camera.getConfig().spatialCalOffsetX = Double.NaN; camera.getConfig().spatialCalOffsetY = Double.NaN; - camera.getConfig().spatialCalScaleX = Double.NaN; - camera.getConfig().spatialCalScaleY = 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(); - camera.getConfig().spatialCalScaleX = ((Camtool)camera).calScaleX.read(); - camera.getConfig().spatialCalScaleY = ((Camtool)camera).calScaleY.read(); - } catch (Exception ex){ - ex.printStackTrace(); - camera.getConfig().spatialCalOffsetX = 0.0; - camera.getConfig().spatialCalOffsetY = 0.0; - camera.getConfig().spatialCalScaleX = 1.0; - camera.getConfig().spatialCalScaleY = 1.0; - } - /* - double[] origin = ((Camtool)camera).origin.read(); - if (origin.length>=2){ - camera.getConfig().spatialCalOffsetX = origin[0]; - camera.getConfig().spatialCalOffsetY = origin[1]; - } - */ + if (camera instanceof Camtool) { + try { + camera.getConfig().spatialCalOffsetX = ((Camtool) camera).calOffX.read(); + camera.getConfig().spatialCalOffsetY = ((Camtool) camera).calOffY.read(); + 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; + } + /* + double[] origin = ((Camtool)camera).origin.read(); + if (origin.length>=2){ + camera.getConfig().spatialCalOffsetX = origin[0]; + camera.getConfig().spatialCalOffsetY = origin[1]; + } + */ } buttonReticle.setEnabled(camera.getConfig().isCalibrated()); buttonGrabBackground.setEnabled(camera instanceof Camtool); camera.getConfig().save(); - - if (polling<=0){ + + if (polling <= 0) { camera.setMonitored(true); } else { camera.setPolling(-polling); - } - renderer.setDevice(camera); + } + renderer.setDevice(camera); renderer.setAutoScroll(true); renderer.setMarker(marker); camera.addListener(new ImageListener() { @Override public void onImage(Object o, BufferedImage bi, Data data) { - if ((bi == null)|| (!showFit)) { + if ((bi == null) || (!showFit)) { renderer.removeOverlays(fitOv); fitOv = null; } else { - if (!renderer.isPaused()){ - Overlay[] fo = getFitOverlays(data); + if (!renderer.isPaused()) { + Overlay[] fo = getFitOverlays(data); renderer.updateOverlays(fo, fitOv); fitOv = fo; } @@ -389,137 +394,141 @@ public class ScreenPanel extends Panel { } }); } catch (Exception ex) { - if (renderer.getDevice()==null){ + if (renderer.getDevice() == null) { renderer.setZoom(1.0); renderer.addOverlay(new Text(PEN_ERROR_TEXT, ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20))); - } - } finally { - checkReticle(); - onTimer(); - } + } + } finally { + checkReticle(); + onTimer(); + } try { - screen = new DiscretePositioner(cameraName+":SET_SCREEN1_POS", cameraName+":GET_SCREEN1_POS"); + screen = new DiscretePositioner(cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); screen.initialize(); DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos: screen.getPositions()){ + for (String pos : screen.getPositions()) { String aux = pos.toLowerCase(); - if (!aux.contains("moving") && !aux.contains("n/a")){ + if (!aux.contains("moving") && !aux.contains("n/a")) { model.addElement(pos); }; } comboScreen.setModel(model); comboScreen.setSelectedItem(screen.read()); - + } catch (Exception ex) { comboScreen.setModel(new DefaultComboBoxModel()); - ex.printStackTrace(); - screen = null; - } - comboScreen.setEnabled(screen!=null); - valueScreen.setDevice(screen); - + //ex.printStackTrace(); + System.err.println(ex.getMessage()); + screen = null; + } + comboScreen.setEnabled(screen != null); + valueScreen.setDevice(screen); + try { - filter = new DiscretePositioner(cameraName+":SET_FILTER", cameraName+":GET_FILTER"); + filter = new DiscretePositioner(cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); filter.initialize(); DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (String pos: filter.getPositions()){ - if (!pos.contains("busy")) model.addElement(pos); + for (String pos : filter.getPositions()) { + if (!pos.contains("busy")) { + model.addElement(pos); + } } comboFilter.setModel(model); comboFilter.setSelectedItem(filter.read()); } catch (Exception ex) { comboFilter.setModel(new DefaultComboBoxModel()); - ex.printStackTrace(); - filter = null; - } - comboFilter.setEnabled(filter!=null); + //ex.printStackTrace(); + System.err.println(ex.getMessage()); + filter = null; + } + comboFilter.setEnabled(filter != null); valueFilter.setDevice(filter); - - + } - - 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); + + 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.setShowReticle(false); + renderer.setCalibration(null); + renderer.setShowReticle(false); } renderer.refresh(); - } - - void updateZoom(){ - try{ + } + + void updateZoom() { + try { buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch); - buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); - if (renderer.getMode() == RendererMode.Fixed){ + buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit); + if (renderer.getMode() == RendererMode.Fixed) { buttonZoomNormal.setSelected(true); - } else if (renderer.getMode() == RendererMode.Zoom){ - if (renderer.getZoom()==1){ + } else if (renderer.getMode() == RendererMode.Zoom) { + if (renderer.getZoom() == 1) { buttonZoomNormal.setSelected(true); - }else if (renderer.getZoom()==0.5){ + } else if (renderer.getZoom() == 0.5) { buttonZoom05.setSelected(true); - }else if (renderer.getZoom()==0.25){ + } else if (renderer.getZoom() == 0.25) { buttonZoom025.setSelected(true); - } else{ + } else { buttonGroup1.clearSelection(); } - } - }catch (Exception ex) { + } + } catch (Exception ex) { ex.printStackTrace(); } } - void updateColormap(){ - try{ - if ((camera!=null) && (camera instanceof ColormapSource)){ - ColormapSourceConfig config = ((ColormapSource)camera).getConfig(); - switch (config.colormap){ - case Grayscale: + 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: + case Rainbow: buttonRainbow.setSelected(true); break; - case Temperature: + case Temperature: buttonTemperature.setSelected(true); break; - default: + default: buttonGroup2.clearSelection(); - + } - if (config.isDefaultColormap()){ + if (config.isDefaultColormap()) { buttonFullRange.setSelected(true); - } else if (config.colormapAutomatic){ + } 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) { + 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){ + 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")){ + if (App.hasArgument("s")) { try { - ((Source)getDevice("image")).initialize(); + ((Source) getDevice("image")).initialize(); } catch (IOException ex) { Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { @@ -529,355 +538,424 @@ public class ScreenPanel extends Panel { updateZoom(); updateColormap(); buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - buttonHistogram.setSelected((histogramDialog!=null)&&(histogramDialog.isShowing())); + checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); } - + Pen fitPen = new Pen(new Color(192, 105, 0), 1); Pen crossPen = new Pen(new Color(192, 105, 0), 1); - Overlay[] getFitOverlays(Data data){ + + Overlay[] getFitOverlays(Data data) { Overlays.Polyline hpoly = null; - Overlays.Polyline vpoly = null; - Double xMean = null; Double xSigma = null; - Double yMean = null; Double ySigma = null; + Overlays.Polyline vpoly = null; + Double xMean = null; + Double xSigma = null; + Double yMean = null; + Double ySigma = null; if (data != null) { //img = Utils.grayscale(img); - double maxPlot = 255.0; - + double maxPlot = 255.0; + try { - double[] sum = (double[]) Convert.toDouble(data.integrateVertically()); - int[] x = Arr.indexesInt(sum.length); + double[] sum = (double[]) Convert.toDouble(data.integrateVertically()); + int[] x = Arr.indexesInt(sum.length); DescriptiveStatistics stats = new DescriptiveStatistics(sum); double min = stats.getMin(); - for (int i=0; i< sum.length; i++){ + for (int i = 0; i < sum.length; i++) { sum[i] = sum[i] - min; } - - maxPlot = 4 * stats.getMax() /data.getHeight() ; + + maxPlot = 4 * stats.getMax() / data.getHeight(); double[] gaussian = fitGaussian(sum, x); - if (gaussian!=null){ - if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){ + if (gaussian != null) { + if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)) { xMean = gaussian[1]; xSigma = gaussian[2]; - gaussian[0]+=min; - double[] fit = getFitFunction(gaussian, x); + gaussian[0] += min; + 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] / maxPlot)); - } + } vpoly = new Overlays.Polyline(fitPen, x, y); } - } + } } catch (Exception ex) { ex.printStackTrace(); - } + } try { double[] sum = (double[]) Convert.toDouble(data.integrateHorizontally()); - int[] x = Arr.indexesInt(sum.length); + int[] x = Arr.indexesInt(sum.length); DescriptiveStatistics stats = new DescriptiveStatistics(sum); double min = stats.getMin(); - for (int i=0; i< sum.length; i++){ + for (int i = 0; i < sum.length; i++) { sum[i] = sum[i] - min; - } - maxPlot = 4 * stats.getMax() /data.getWidth() ; + } + maxPlot = 4 * stats.getMax() / data.getWidth(); double[] gaussian = fitGaussian(sum, x); - if (gaussian!=null){ + if (gaussian != null) { //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){ + if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)) { yMean = gaussian[1]; ySigma = gaussian[2]; - gaussian[0]+=min; - double[] fit = getFitFunction(gaussian, x); + gaussian[0] += min; + double[] fit = getFitFunction(gaussian, x); int[] y = new int[x.length]; for (int i = 0; i < x.length; i++) { y[i] = (int) (fit[i] / maxPlot); - } + } hpoly = new Overlays.Polyline(fitPen, y, x); } } } catch (Exception ex) { ex.printStackTrace(); - } - - Overlays.Crosshairs cross= null; - if ((xMean!=null) && (yMean!=null)){ - cross = new Overlays.Crosshairs(crossPen, - new Point(xMean.intValue(), yMean.intValue()), - new Dimension(2*xSigma.intValue(),2*ySigma.intValue())); } - return new Overlay[]{hpoly, vpoly, cross}; - } + + Overlays.Crosshairs cross = null; + Overlays.Text text = null; + if ((xMean != null) && (yMean != null)) { + cross = new Overlays.Crosshairs(crossPen, + new Point(xMean.intValue(), yMean.intValue()), + new Dimension(2 * xSigma.intValue(), 2 * ySigma.intValue())); + + text = new Overlays.Text(fitPen, + String.format("x = %f \n y = %f" , data.getX((int) Math.round(xMean)), data.getY((int) Math.round(yMean))), + new Font(Font.MONOSPACED, 0, 14), new Point(20,20)); + } + + return new Overlay[]{hpoly, vpoly, cross, text}; + } return null; } - - -double[] fitGaussianScript(int[] y, int[] x){ + + double[] fitGaussianScript(int[] y, int[] x) { ScriptManager sm = Controller.getInstance().getScriptManager(); - ArrayProperties pY = ArrayProperties.get(y); + 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); + 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); - ArrayListvalues = new ArrayList<>(); - for (int i=0; i< y.length; i++){ + 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 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 fitter.fit(values); + } catch (Exception ex) { return null; } - + } - - - double[] getFitFunction(double[] pars, int[] x){ + 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++){ + 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 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 roiShape; - final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain; - final public ChannelDouble calOffX, calOffY, calScaleX, calScaleY; - - 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 ? ".roi.output" : ".image")); - super(name, prefix + (latch ? ":latch" : ":pipeline") + ".roi.output"); - this.prefix = prefix + ":"; - this.latch = latch; - dataPrefix = this.prefix + (latch ? "latch" : "pipeline") + "."; + public class Camtool extends ArraySource { - 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); + final String prefix; + final String dataPrefix; + final boolean latch; + + 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 roiShape; + final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain; + final public ChannelDouble calOffX, calOffY, calScaleX, calScaleY; + + 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 ? ".roi.output" : ".image")); + 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"); - //posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com"); - 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 ? "roi.output.shape" : "image.shape")); - shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("image.shape")); - roiShape = new ChannelIntegerArray(name + " roi shape", dataPrefix + "roi.roi"); - roiEnabled = new ChannelInteger(name + " roi enabled", dataPrefix + "roi.enabled"); - //origin = new ChannelDoubleArray(name + " origin X", roi ? (dataPrefix + "roi.origin_out") : (prefix + "origin")); - 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"); - } + //posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com"); + 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 ? "roi.output.shape" : "image.shape")); + shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("image.shape")); + roiShape = new ChannelIntegerArray(name + " roi shape", dataPrefix + "roi.roi"); + roiEnabled = new ChannelInteger(name + " roi enabled", dataPrefix + "roi.enabled"); + //origin = new ChannelDoubleArray(name + " origin X", roi ? (dataPrefix + "roi.origin_out") : (prefix + "origin")); + 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"); + } - @Override - public void doSetMonitored(boolean value) { - super.doSetMonitored(value); - getDevice().setMonitored(value); - } + @Override + public void doSetMonitored(boolean value) { + super.doSetMonitored(value); + getDevice().setMonitored(value); + } - @Override - public void doUpdate() throws IOException, InterruptedException { - super.doUpdate(); - getDevice().update(); - } + @Override + public void doUpdate() throws IOException, InterruptedException { + super.doUpdate(); + getDevice().update(); + } - 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; + 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); } - 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(); - roiShape.initialize(); - roiEnabled.initialize(); - origin.initialize(); - bgEnable.initialize(); - bgCapture.initialize(); - bgCaptureRemain.initialize(); + @Override + protected void doInitialize() throws IOException, InterruptedException { try { - calOffX.initialize(); - calOffY.initialize(); - calScaleX.initialize(); - calScaleY.initialize(); + channelRun.initialize(); + channelLatch.initialize(); + if (latch) { + start(); + latch(); + } + safeInitialize(channelTimestamp, 2000); + posX.initialize(); + posY.initialize(); + profileX.initialize(); + profileY.initialize(); + shape.initialize(); + roiShape.initialize(); + roiEnabled.initialize(); + origin.initialize(); + bgEnable.initialize(); + bgCapture.initialize(); + bgCaptureRemain.initialize(); + try { + calOffX.initialize(); + calOffY.initialize(); + calScaleX.initialize(); + calScaleY.initialize(); + } catch (Exception ex) { + ex.printStackTrace(); + } + + if (roiEnabled.read() > 0) { + int[] s = roiShape.read(); + //for (int x : s) System.out.println(x); + getConfig().imageHeight = s[3]; + getConfig().imageWidth = s[2]; + } else { + int[] s = shape.read(); + //for (int x : s){ System.out.println(x);} + getConfig().imageHeight = s[0]; + getConfig().imageWidth = s[1]; + } + + getConfig().save(); + getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth); + super.doInitialize(); + //System.out.println(((int[])(getDevice().read())).length); + } catch (InterruptedException ex) { + throw ex; } catch (Exception ex) { ex.printStackTrace(); + throw new IOException(ex); } - - if (roiEnabled.read()>0){ - int[] s = roiShape.read(); - //for (int x : s) System.out.println(x); - getConfig().imageHeight = s[3]; - getConfig().imageWidth = s[2]; - } else { - int[] s = shape.read(); - //for (int x : s){ System.out.println(x);} - getConfig().imageHeight = s[0]; - getConfig().imageWidth = s[1]; - } - - getConfig().save(); - getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth); - super.doInitialize(); - //System.out.println(((int[])(getDevice().read())).length); - } catch (InterruptedException ex) { - throw ex; - } catch (Exception ex) { - ex.printStackTrace(); - throw new IOException(ex); } - } - int numImages = 1; + int numImages = 1; - public int getNumImages() { - return numImages; - } + public int getNumImages() { + return numImages; + } - public void setNumImages(int value) { - numImages = value; - } + public void setNumImages(int value) { + numImages = value; + } - double grabTimeout = 3.0; + double grabTimeout = 3.0; - public double getGrabTimeout() { - return grabTimeout; - } + public double getGrabTimeout() { + return grabTimeout; + } - public void setGrabTimeou(double value) { - grabTimeout = value; - } + 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; + 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); } - if ((System.currentTimeMillis() - start) > grabTimeout) { - throw new IOException("Frame timeout"); + 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; } - 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); + } + } + } - 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(); + } + //////// @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents @@ -919,7 +997,7 @@ public class Camtool extends ArraySource { spinnerMin = new javax.swing.JSpinner(); spinnerMax = new javax.swing.JSpinner(); buttonAutomatic = new javax.swing.JRadioButton(); - buttonHistogram = new javax.swing.JToggleButton(); + checkHistogram = new javax.swing.JCheckBox(); jPanel5 = new javax.swing.JPanel(); buttonCamtool = new javax.swing.JRadioButton(); buttonDirect = new javax.swing.JRadioButton(); @@ -930,7 +1008,7 @@ public class Camtool extends ArraySource { valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); comboFilter = new javax.swing.JComboBox(); - setPreferredSize(new java.awt.Dimension(873, 150)); + setPreferredSize(new java.awt.Dimension(873, 600)); buttonGrabBackground.setText("Grab Background"); buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { @@ -1059,8 +1137,8 @@ public class Camtool extends ArraySource { .addComponent(buttonConfig) .addComponent(buttonSetup)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE) - .addGap(12, 12, 12) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonPause) .addComponent(buttonFit) @@ -1073,8 +1151,6 @@ public class Camtool extends ArraySource { jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState}); - jPanel4.setPreferredSize(new java.awt.Dimension(235, 128)); - jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); buttonGroup1.add(buttonZoomFit); @@ -1102,7 +1178,7 @@ public class Camtool extends ArraySource { }); buttonGroup1.add(buttonZoom025); - buttonZoom025.setText("0.25"); + buttonZoom025.setText("1/4"); buttonZoom025.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonZoom025ActionPerformed(evt); @@ -1110,7 +1186,7 @@ public class Camtool extends ArraySource { }); buttonGroup1.add(buttonZoom05); - buttonZoom05.setText("0.5"); + buttonZoom05.setText("1/2"); buttonZoom05.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonZoom05ActionPerformed(evt); @@ -1124,26 +1200,33 @@ public class Camtool extends ArraySource { .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonZoomFit) - .addComponent(buttonZoomStretch) - .addComponent(buttonZoomNormal) - .addComponent(buttonZoom025) - .addComponent(buttonZoom05)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(buttonZoomFit) + .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)) + .addGap(47, 47, 47)) + .addGroup(jPanel3Layout.createSequentialGroup() + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonZoomNormal) + .addComponent(buttonZoomStretch)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() - .addContainerGap() - .addComponent(buttonZoomFit) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(buttonZoomNormal) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonZoomFit)) + .addGroup(jPanel3Layout.createSequentialGroup() + .addComponent(buttonZoom025) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonZoom05))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonZoomStretch) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonZoom025) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonZoom05) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonZoomNormal) .addContainerGap()) ); @@ -1189,13 +1272,13 @@ public class Camtool extends ArraySource { } }); - jLabel3.setText("min:"); + jLabel3.setText("Min:"); - jLabel4.setText("max:"); + jLabel4.setText("Max:"); spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1)); spinnerMin.setEnabled(false); - spinnerMin.setPreferredSize(new java.awt.Dimension(60, 20)); + 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); @@ -1204,7 +1287,7 @@ public class Camtool extends ArraySource { spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1)); spinnerMax.setEnabled(false); - spinnerMax.setPreferredSize(new java.awt.Dimension(60, 20)); + 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); @@ -1219,10 +1302,10 @@ public class Camtool extends ArraySource { } }); - buttonHistogram.setText("Histogram"); - buttonHistogram.addActionListener(new java.awt.event.ActionListener() { + checkHistogram.setText("Histogram"); + checkHistogram.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonHistogramActionPerformed(evt); + checkHistogramActionPerformed(evt); } }); @@ -1232,58 +1315,59 @@ public class Camtool extends ArraySource { jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonFullRange) - .addComponent(buttonManual)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel4) - .addComponent(jLabel3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel2Layout.createSequentialGroup() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonGrayscale) - .addComponent(buttonRainbow) - .addComponent(buttonTemperature) - .addComponent(buttonAutomatic)) - .addGap(0, 0, Short.MAX_VALUE)))) - .addGroup(jPanel2Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonHistogram) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .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) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonRainbow) + .addComponent(buttonGrayscale) + .addComponent(buttonTemperature)) + .addComponent(checkHistogram, javax.swing.GroupLayout.Alignment.TRAILING)) + .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() - .addContainerGap() - .addComponent(buttonGrayscale) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonRainbow) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonTemperature) - .addGap(18, 18, 18) - .addComponent(buttonAutomatic) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() - .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addContainerGap() + .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))) + .addGroup(jPanel2Layout.createSequentialGroup() + .addGap(77, 77, 77) + .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) - .addComponent(buttonManual)) - .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))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonHistogram) - .addContainerGap()) + .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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source")); @@ -1311,19 +1395,19 @@ public class Camtool extends ArraySource { jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() - .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(buttonCamtool) - .addComponent(buttonDirect)) + .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() .addContainerGap() - .addComponent(buttonCamtool) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDirect) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonCamtool) + .addComponent(buttonDirect)) + .addContainerGap()) ); panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); @@ -1390,29 +1474,28 @@ public class Camtool extends ArraySource { jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(jPanel4Layout.createSequentialGroup() + .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelScreen1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, 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) - .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .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.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(0, 0, Short.MAX_VALUE)) ); jPanel4Layout.setVerticalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(panelScreen1, 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) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -1432,7 +1515,7 @@ public class Camtool extends ArraySource { .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.PREFERRED_SIZE, 0, Short.MAX_VALUE))) + .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) ); }// //GEN-END:initComponents @@ -1442,15 +1525,15 @@ public class Camtool extends ArraySource { new Thread(new Runnable() { @Override public void run() { - try{ + try { setCamera((String) comboCameras.getSelectedItem()); - } catch(Exception ex){ + } catch (Exception ex) { ex.printStackTrace(); - } finally{ + } finally { comboCameras.setEnabled(true); } } - }).start(); + }).start(); } catch (Exception ex) { showException(ex); } @@ -1486,7 +1569,7 @@ public class Camtool extends ArraySource { private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed try { if (camera != null) { - if (buttonPause.isSelected()){ + if (buttonPause.isSelected()) { renderer.pause(); } else { renderer.resume(); @@ -1500,12 +1583,12 @@ public class Camtool extends ArraySource { private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed try { 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(PEN_MARKER, p, new Dimension(100, 100)); - marker.setMovable(true); + 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(PEN_MARKER, p, new Dimension(100, 100)); + marker.setMovable(true); } else { marker = null; } @@ -1513,45 +1596,64 @@ public class Camtool extends ArraySource { } } 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()){ + showFit = buttonFit.isSelected(); + if (!buttonFit.isSelected()) { renderer.removeOverlays(fitOv); - fitOv = null; + fitOv = null; } } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonFitActionPerformed private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed try { - checkReticle(); + checkReticle(); } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonReticleActionPerformed private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed try { - renderer.setSnapshotDialogVisible(buttonSave.isSelected()); + //renderer.setSnapshotDialogVisible(buttonSave.isSelected()); + 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()); + //byte[] arr = (byte[]) (((DataBufferByte)(Utils.grayscale(renderer.getImage()).getRaster().getDataBuffer())).getData()); + //Object image = Convert.toBidimensional(arr, renderer.getImage().getWidth(), renderer.getImage().getHeight()); + //getController().getDataManager().setDataset("/image", image); + elog("ScreenPanel Snapshot", "Data file: " + getController().getExecutionContext().getPath(), new String[]{snapshotFile}); + } 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){ - ((Camtool)camera).captureBackground(5); - } + 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); + } + ((Camtool) camera).captureBackground(5); + if (laserOn){ + setLaserState(true); + } + } + } } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_buttonGrabBackgroundActionPerformed private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed @@ -1559,7 +1661,7 @@ public class Camtool extends ArraySource { 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 @@ -1567,34 +1669,40 @@ public class Camtool extends ArraySource { 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); - renderer.setViewPosition(new Point(0,0)); + renderer.setViewPosition(new Point(0, 0)); } 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; - if (buttonGrayscale.isSelected()) source.getConfig().colormap = Colormap.Grayscale; - if (buttonTemperature.isSelected()) source.getConfig().colormap = Colormap.Temperature; - if (buttonRainbow.isSelected()) source.getConfig().colormap = Colormap.Rainbow; + if ((camera != null) && (camera instanceof ColormapSource)) { + ColormapSource source = (ColormapSource) camera; + if (buttonGrayscale.isSelected()) { + source.getConfig().colormap = Colormap.Grayscale; + } + if (buttonTemperature.isSelected()) { + source.getConfig().colormap = Colormap.Temperature; + } + if (buttonRainbow.isSelected()) { + source.getConfig().colormap = Colormap.Rainbow; + } 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().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMin.getValue(); + source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); source.getConfig().save(); - source.refresh(); - } + source.refresh(); + } } catch (Exception ex) { showException(ex); - } + } }//GEN-LAST:event_onChangeColormap private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange @@ -1604,35 +1712,15 @@ public class Camtool extends ArraySource { private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed renderer.setZoom(0.25); renderer.setMode(RendererMode.Zoom); - renderer.setViewPosition(new Point(0,0)); + renderer.setViewPosition(new Point(0, 0)); }//GEN-LAST:event_buttonZoom025ActionPerformed private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed renderer.setZoom(0.5); - renderer.setMode(RendererMode.Zoom); - renderer.setViewPosition(new Point(0,0)); + renderer.setMode(RendererMode.Zoom); + renderer.setViewPosition(new Point(0, 0)); }//GEN-LAST:event_buttonZoom05ActionPerformed - private void buttonHistogramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonHistogramActionPerformed - try { - if (buttonHistogram.isSelected()){ - 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; - } - } - } catch (Exception ex) { - showException(ex); - } - }//GEN-LAST:event_buttonHistogramActionPerformed - private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed comboCamerasActionPerformed(null); }//GEN-LAST:event_buttonCamtoolActionPerformed @@ -1644,17 +1732,17 @@ public class Camtool extends ArraySource { 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"); + int index = comboScreen.getSelectedIndex(); + setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); setpoint.initialize(); - if (setpoint.read()!=index){ + if (setpoint.read() != index) { setpoint.write(index); } screen.read(); } catch (Exception ex) { showException(ex); - } - if (setpoint!=null){ + } + if (setpoint != null) { setpoint.close(); } }//GEN-LAST:event_comboScreenActionPerformed @@ -1662,15 +1750,23 @@ public class Camtool extends ArraySource { private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed try { String setpoint = (String) comboFilter.getSelectedItem(); - if (!setpoint.equals(filter.read())){ + 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 + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton buttonAutomatic; private javax.swing.JRadioButton buttonCamtool; @@ -1684,7 +1780,6 @@ public class Camtool extends ArraySource { private javax.swing.ButtonGroup buttonGroup2; private javax.swing.ButtonGroup buttonGroup3; private javax.swing.ButtonGroup buttonGroup4; - private javax.swing.JToggleButton buttonHistogram; private javax.swing.JRadioButton buttonManual; private javax.swing.JToggleButton buttonMarker; private javax.swing.JToggleButton buttonPause; @@ -1698,6 +1793,7 @@ public class Camtool extends ArraySource { 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;