Included RegisterStats to provide URLDevice operations on waveforms

This commit is contained in:
2018-03-06 08:28:38 +01:00
parent 858d02c061
commit 8ac127c272

View File

@@ -18,6 +18,10 @@ import ch.psi.pshell.bs.StreamValue;
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.data.DataManager;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.Readable.ReadableArray;
import ch.psi.pshell.device.Readable.ReadableNumber;
import ch.psi.pshell.device.ReadableRegister.ReadableRegisterArray;
import ch.psi.pshell.device.ReadableRegister.ReadableRegisterNumber;
import ch.psi.pshell.epics.ChannelInteger;
import ch.psi.pshell.epics.DiscretePositioner;
import ch.psi.pshell.epics.Epics;
@@ -40,11 +44,13 @@ 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.DeviceValueChart;
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.StandardDialog;
@@ -52,14 +58,19 @@ import ch.psi.utils.swing.StandardDialog.StandardDialogListener;
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.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
@@ -77,7 +88,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
@@ -133,6 +143,9 @@ public class ScreenPanel2 extends Panel {
String serverUrl;
String camServerUrl;
String instanceName;
Overlay titleOv = null;
String pipelineSuffix = "_sp";
Double getServerDouble(String name) {
return (Double) Convert.toDouble(server.getValue(name));
@@ -241,7 +254,7 @@ public class ScreenPanel2 extends Panel {
((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.RIGHT);
}
renderer.setPersistenceFile(Paths.get(getContext().getSetup().getContextPath(), "Renderer_Cameras.bin"));
setPersistedComponents(new Component[]{buttonServer, buttonDirect});
//setPersistedComponents(new Component[]{buttonServer, buttonDirect});
comboCameras.setEnabled(false);
comboType.setEnabled(false);
@@ -288,6 +301,9 @@ public class ScreenPanel2 extends Panel {
if (App.hasArgument("calc")) {
useServerStats = false;
}
if (App.hasArgument("suffix")) {
pipelineSuffix = App.getArgumentValue("suffix");
}
renderer.setProfileNormalized(true);
renderer.setShowProfileLimits(false);
@@ -301,8 +317,8 @@ public class ScreenPanel2 extends Panel {
}
});
JMenuItem menuCameraConfig = new JMenuItem("Renderer Config");
menuCameraConfig.addActionListener((ActionEvent e) -> {
JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters");
menuRendererConfig.addActionListener((ActionEvent e) -> {
try {
if (camera != null) {
this.showDeviceConfigDialog(camera, false);
@@ -312,6 +328,52 @@ public class ScreenPanel2 extends Panel {
}
});
JMenuItem menuCameraConfig = new JMenuItem("Camera Configurarion");
menuCameraConfig.addActionListener((ActionEvent e) -> {
try {
if (camera != null) {
String cameraConfigJson = null;
if (usingServer) {
String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl;
try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) {
srv.initialize();
//TODO: replace into encodeMultiline
cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true);
}
} else {
String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null);
Path configFile = Paths.get(configFolder, cameraName + ".json");
cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null;
}
TextEditor configEditor = new TextEditor();
configEditor.setText(cameraConfigJson);
configEditor.setReadOnly(true);
configEditor.setTitle(cameraName);
EditorDialog dlg = configEditor.getDialog(getTopLevel(), false);
dlg.setSize(480, 640);
dlg.setVisible(true);
SwingUtils.centerComponent(getTopLevel(), dlg);
}
} catch (Exception ex) {
showException(ex);
}
});
JMenuItem menuSetImageBufferSize = new JMenuItem("Set Stack Size...");
menuSetImageBufferSize.addActionListener((ActionEvent e) -> {
try {
String ret = SwingUtils.getString(getTopLevel(), "Enter size of image buffer: ", String.valueOf(imageBufferLenght));
if (ret!=null){
this.setImageBufferSize(Integer.valueOf(ret));
}
} catch (Exception ex) {
showException(ex);
}
});
JMenuItem menuSaveStack = new JMenuItem("Save Stack");
menuSaveStack.addActionListener((ActionEvent e) -> {
try {
@@ -319,8 +381,8 @@ public class ScreenPanel2 extends Panel {
} catch (Exception ex) {
showException(ex);
}
});
menuSaveStack.setEnabled(imageBufferLenght > 0);
});
JMenuItem menuSetROI = new JMenuItem("Set ROI...");
menuSetROI.addActionListener((ActionEvent e) -> {
@@ -369,10 +431,13 @@ public class ScreenPanel2 extends Panel {
});
renderer.getPopupMenu().addSeparator();
renderer.getPopupMenu().add(menuRendererConfig);
renderer.getPopupMenu().add(menuCameraConfig);
renderer.getPopupMenu().add(menuCalibrate);
renderer.getPopupMenu().add(menuSetImageBufferSize);
renderer.getPopupMenu().add(menuSaveStack);
renderer.getPopupMenu().addSeparator();
renderer.getPopupMenu().add(menuCalibrate);
renderer.getPopupMenu().addSeparator();
renderer.getPopupMenu().add(menuSetROI);
renderer.getPopupMenu().add(menuResetROI);
renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {
@@ -382,6 +447,8 @@ public class ScreenPanel2 extends Panel {
menuSetROI.setEnabled(server != null);
menuCalibrate.setVisible(server != null);
menuCalibrate.setEnabled((calibrationDialolg == null) || (!calibrationDialolg.isShowing()));
menuSaveStack.setEnabled(imageBufferLenght > 0);
menuSetImageBufferSize.setEnabled(!renderer.isPaused());
}
@Override
@@ -407,9 +474,9 @@ public class ScreenPanel2 extends Panel {
}
}
});
imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20));
imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 42));
imageBufferOverlay.setFixed(true);
imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT);
imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT);
if (MainFrame.isDark()) {
textState.setDisabledTextColor(textState.getForeground());
}
@@ -603,6 +670,21 @@ public class ScreenPanel2 extends Panel {
}
}
void manageTitleOverlay() {
Overlay to = null;
if ((buttonTitle.isSelected()) && (cameraName != null)) {
Font font = new Font("Arial", Font.PLAIN, 28);
to = new Text(renderer.getPenErrorText(), cameraName, font, new Point(-SwingUtils.getTextSize(cameraName, renderer.getGraphics().getFontMetrics(font)).width - 14, 26));
to.setFixed(true);
to.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT);
}
synchronized (lockOverlays) {
renderer.updateOverlays(to, titleOv);
titleOv = to;
}
}
@Override
public void onStateChange(State state, State former) {
@@ -680,16 +762,21 @@ public class ScreenPanel2 extends Panel {
filter.close();
filter = null;
}
if (renderer.isPaused()){
if (renderer.isPaused()) {
renderer.resume();
renderer.removeOverlay(imageBufferOverlay);
pauseSelection.setVisible(false);
panelCameraSelection.setVisible(true);
}
}
}
manageTitleOverlay();
if (App.isDetached()) {
getTopLevel().setTitle(cameraName == null ? "ScreenPanel" : cameraName);
}
if (cameraName == null) {
return;
}
System.out.println("Setting camera: " + cameraName + " [" + (buttonServer.isSelected() ? "server" : "direct") + "]");
try {
if (buttonServer.isSelected()) {
@@ -710,8 +797,8 @@ public class ScreenPanel2 extends Panel {
System.out.println("Camera initialization OK");
if (server != null) {
//server.start(cameraName, false);
String pipelineName = cameraName + "_sp";
instanceName = cameraName + "_sp1";
String pipelineName = cameraName + pipelineSuffix;
instanceName = cameraName + pipelineSuffix +"1";
if (!server.getPipelines().contains(pipelineName)) {
System.out.println("Creating pipeline: " + pipelineName);
HashMap<String, Object> config = new HashMap<>();
@@ -734,7 +821,7 @@ public class ScreenPanel2 extends Panel {
}
camera.setBackgroundEnabled(checkBackground.isSelected());
}
updateButtons();
updateButtons();
camera.getConfig().save();
renderer.setDevice(camera);
renderer.setAutoScroll(true);
@@ -1001,31 +1088,31 @@ public class ScreenPanel2 extends Panel {
}
boolean isCameraStopped() {
if ((server != null) && !server.isStarted()){
if ((server != null) && !server.isStarted()) {
return true;
}
return ((camera == null) || camera.isClosed());
}
boolean updatingButtons;
void updateButtons(){
void updateButtons() {
updatingButtons = true;
try{
boolean active = !isCameraStopped() ;//(camera != null);
buttonArgs.setEnabled(active);
try {
boolean active = !isCameraStopped();//(camera != null);
buttonSave.setEnabled(active);
buttonGrabBackground.setEnabled(active);
buttonMarker.setEnabled(active);
buttonProfile.setEnabled(active);
buttonFit.setEnabled(active);
buttonReticle.setEnabled(active && camera.getConfig().isCalibrated());
buttonStreamData.setEnabled(active && (server!=null));
buttonPause.setEnabled(active);
buttonReticle.setEnabled(active && camera.getConfig().isCalibrated());
buttonStreamData.setEnabled(active && (server != null));
buttonPause.setEnabled(active);
//buttonPause.setIcon(getIcon("Play"));
//buttonPause.setToolTipText("Resume");
//buttonPause.setIcon(getIcon("Pause"));
//buttonPause.setToolTipText("Pause");
if (renderer.isPaused() != buttonPause.isSelected()) {
buttonPause.setSelected(renderer.isPaused());
buttonPauseActionPerformed(null);
@@ -1037,8 +1124,8 @@ public class ScreenPanel2 extends Panel {
buttonMarker.setSelected(false);
}
buttonSave.setSelected(renderer.isSnapshotDialogVisible());
} finally{
} finally {
updatingButtons = false;
}
}
@@ -1051,7 +1138,7 @@ public class ScreenPanel2 extends Panel {
}
}
textState.setText((camera == null) ? "" : camera.getState().toString());
textState.setText((camera == null) ? "" : camera.getState().toString());
if (App.hasArgument("s")) {
try {
((Source) getDevice("image")).initialize();
@@ -1066,7 +1153,7 @@ public class ScreenPanel2 extends Panel {
}
updateZoom();
updateColormap();
updateButtons();
updateButtons();
checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing()));
}
@@ -1095,6 +1182,17 @@ public class ScreenPanel2 extends Panel {
return null;
}
void setImageBufferSize(int size) {
if (renderer.isPaused()) {
throw new RuntimeException("Cannot change buffer size whn paused");
}
synchronized (imageBuffer) {
imageBufferLenght = size;
imageBuffer.clear();
}
}
Overlay[][] getFitOverlays(Data data) {
Overlays.Polyline hgaussian = null;
Overlays.Polyline vgaussian = null;
@@ -1103,11 +1201,11 @@ public class ScreenPanel2 extends Panel {
Double xMean = null, xSigma = null, xNorm = null, xCom = null, xRms = null;
Double yMean = null, ySigma = null, yNorm = null, yCom = null, yRms = null;
double[] pX = null, pY = null, gX = null, gY = null;
int height = data.getHeight();
int width = data.getWidth();
PointDouble[] sliceCenters = null;
//Double xCom=null, yCom=null;
if (data != null) {
int height = data.getHeight();
int width = data.getWidth();
int profileSize = renderer.getProfileSize();
if ((useServerStats) && (server != null)) {
try {
@@ -1692,6 +1790,9 @@ public class ScreenPanel2 extends Panel {
manageUserOverlays(image, data);
}
}
if ((dataTableDialog != null) && (dataTableDialog.isShowing())) {
updateStreamData();
}
}
void saveSnapshot() throws Exception {
@@ -1936,7 +2037,6 @@ public class ScreenPanel2 extends Panel {
scrollPane.setPreferredSize(new Dimension(300, 400));
dataTableDialog.setContentPane(scrollPane);
dataTableDialog.pack();
SwingUtils.centerComponent(getTopLevel(), dataTableDialog);
dataTableDialog.setVisible(true);
dataTableDialog.addWindowListener(new WindowAdapter() {
@Override
@@ -1944,6 +2044,62 @@ public class ScreenPanel2 extends Panel {
dataTableModel = null;
}
});
dataTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
int index = dataTable.getSelectedRow();
dataTable.setToolTipText(null);
if (index>1){
String id = String.valueOf(dataTable.getModel().getValueAt(index, 0));
String locator = String.valueOf(dataTable.getModel().getValueAt(0, 1));
dataTable.setToolTipText(locator + " " + id);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(locator+ " " + id), (Clipboard clipboard1, Transferable contents) -> {});
if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) {
Object obj = getCurrentFrame().cache.getValue(id);
if (id.equals("image")) {
} else if (id.equals("processing_parameters")) {
Map<String, Object> pars = getProcessingParameters(getCurrentFrame().cache);
StringBuilder sb = new StringBuilder();
for (String key : pars.keySet()) {
sb.append(key).append(" = ").append(Str.toString(pars.get(key), 10)).append("\n");
}
SwingUtils.showMessage(dataTableDialog, "Processing Parameters", sb.toString());
} else if ((obj!=null) && (obj.getClass().isArray() || (obj instanceof Number))) {
DeviceValueChart chart = new DeviceValueChart();
Device dev = null;
if (obj.getClass().isArray()){
dev = new ReadableRegisterArray(new ReadableArray() {
@Override
public Object read() throws IOException, InterruptedException {
return Convert.toDouble(getCurrentFrame().cache.getValue(id));
}
@Override
public int getSize() {
return Array.getLength(getCurrentFrame().cache.getValue(id));
}
});
} else {
dev = new ReadableRegisterNumber(new ReadableNumber() {
@Override
public Object read() throws IOException, InterruptedException {
return Convert.toDouble(getCurrentFrame().cache.getValue(id));
}
});
}
dev.setPolling(1000);
chart.setDevice(dev);
JDialog dlg = SwingUtils.showDialog(dataTableDialog, cameraName +" " + id, null, chart);
}
}
}
} catch (Exception ex) {
showException(ex);
}
}
});
SwingUtils.centerComponent(getTopLevel(), dataTableDialog);
}
}
@@ -1969,30 +2125,34 @@ public class ScreenPanel2 extends Panel {
dataTableModel.addRow(new Object[]{id, ""});
}
}
for (int i = 2; i < dataTableModel.getRowCount(); i++) {
String id = String.valueOf(dataTableModel.getValueAt(i, 0));
Object obj = server.getValue(id);
if (obj != null) {
if (obj.getClass().isArray()) {
obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]";
} else if (obj instanceof Double) {
obj = Convert.roundDouble((Double) obj, 1);
} else if (obj instanceof Float) {
obj = Convert.roundDouble((Float) obj, 1);
Frame frame = getCurrentFrame();
if ((frame != null) && (frame.cache!=null)){
for (int i = 2; i < dataTableModel.getRowCount(); i++) {
String id = String.valueOf(dataTableModel.getValueAt(i, 0));
//Object obj = server.getValue(id);
Object obj = frame.cache.getValue(id);
if (obj != null) {
if (obj.getClass().isArray()) {
obj = obj.getClass().getComponentType().getSimpleName() + "[" + Array.getLength(obj) + "]";
} else if (obj instanceof Double) {
obj = Convert.roundDouble((Double) obj, 1);
} else if (obj instanceof Float) {
obj = Convert.roundDouble((Float) obj, 1);
}
}
dataTableModel.setValueAt(String.valueOf(obj), i, 1);
}
dataTableModel.setValueAt(String.valueOf(obj), i, 1);
}
}
}
ImageIcon getIcon(String name) {
ImageIcon getIcon(String name) {
ImageIcon ret = null;
try {
//Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(),"resources", name + ".png");
String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/";
if (new File(dir + name + ".png").exists()){
ret =new javax.swing.ImageIcon(dir + name + ".png");
String dir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "resources/";
if (new File(dir + name + ".png").exists()) {
ret = new javax.swing.ImageIcon(dir + name + ".png");
} else {
ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + name + ".png"));
if (MainFrame.isDark()) {
@@ -2000,7 +2160,7 @@ public class ScreenPanel2 extends Panel {
ret = new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/dark/" + name + ".png"));
} catch (Exception e) {
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -2051,6 +2211,7 @@ public class ScreenPanel2 extends Panel {
buttonServer = new javax.swing.JRadioButton();
buttonDirect = new javax.swing.JRadioButton();
textState = new javax.swing.JTextField();
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767));
panelScreen = new javax.swing.JPanel();
valueScreen = new ch.psi.pshell.swing.DeviceValuePanel();
comboScreen = new javax.swing.JComboBox();
@@ -2075,15 +2236,9 @@ public class ScreenPanel2 extends Panel {
labelSlOrientation = new javax.swing.JLabel();
spinnerSlOrientation = new javax.swing.JSpinner();
topPanel = new javax.swing.JPanel();
comboCameras = new javax.swing.JComboBox();
jLabel1 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
comboType = new javax.swing.JComboBox();
toolBar = new javax.swing.JToolBar();
buttonSidePanel = new javax.swing.JToggleButton();
buttonStreamData = new javax.swing.JButton();
buttonArgs = new javax.swing.JButton();
jSeparator5 = new javax.swing.JToolBar.Separator();
buttonSave = new javax.swing.JToggleButton();
buttonGrabBackground = new javax.swing.JButton();
buttonPause = new javax.swing.JToggleButton();
@@ -2092,7 +2247,13 @@ public class ScreenPanel2 extends Panel {
buttonProfile = new javax.swing.JToggleButton();
buttonFit = new javax.swing.JToggleButton();
buttonReticle = new javax.swing.JToggleButton();
buttonTitle = new javax.swing.JToggleButton();
pauseSelection = new ch.psi.pshell.swing.ValueSelection();
panelCameraSelection = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
comboCameras = new javax.swing.JComboBox();
jLabel5 = new javax.swing.JLabel();
comboType = new javax.swing.JComboBox();
renderer = new ch.psi.pshell.imaging.Renderer();
setPreferredSize(new java.awt.Dimension(873, 600));
@@ -2352,15 +2513,23 @@ public class ScreenPanel2 extends Panel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(56, 56, 56))
);
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(buttonServer)
.addComponent(buttonDirect)
.addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(textState, 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(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonServer)
.addComponent(buttonDirect)))
.addContainerGap())
);
@@ -2627,7 +2796,7 @@ public class ScreenPanel2 extends Panel {
.addComponent(panelScreen2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
sidePanelLayout.setVerticalGroup(
sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -2643,30 +2812,10 @@ public class ScreenPanel2 extends Panel {
.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.RELATED)
.addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
comboCameras.setMaximumRowCount(30);
comboCameras.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboCamerasActionPerformed(evt);
}
});
jLabel1.setText("Camera:");
jLabel5.setText("Type:");
comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
comboType.setMaximumRowCount(30);
comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" }));
comboType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboTypeActionPerformed(evt);
}
});
toolBar.setFloatable(false);
toolBar.setRollover(true);
@@ -2695,22 +2844,6 @@ public class ScreenPanel2 extends Panel {
});
toolBar.add(buttonStreamData);
buttonArgs.setIcon(getIcon("Data"));
buttonArgs.setText(" ");
buttonArgs.setToolTipText("Camera Setup");
buttonArgs.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
buttonArgs.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonArgsActionPerformed(evt);
}
});
toolBar.add(buttonArgs);
jSeparator5.setMaximumSize(new java.awt.Dimension(20, 32767));
jSeparator5.setPreferredSize(new java.awt.Dimension(20, 0));
jSeparator5.setRequestFocusEnabled(false);
toolBar.add(jSeparator5);
buttonSave.setIcon(getIcon("Save"));
buttonSave.setText(" ");
buttonSave.setToolTipText("Save Snapshot");
@@ -2797,42 +2930,90 @@ public class ScreenPanel2 extends Panel {
});
toolBar.add(buttonReticle);
buttonTitle.setIcon(getIcon("Title"));
buttonTitle.setText(" ");
buttonTitle.setToolTipText("Show Camera Name");
buttonTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
buttonTitle.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonTitleActionPerformed(evt);
}
});
toolBar.add(buttonTitle);
pauseSelection.setDecimals(0);
jLabel1.setText("Camera:");
comboCameras.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
comboCameras.setMaximumRowCount(30);
comboCameras.setMinimumSize(new java.awt.Dimension(127, 27));
comboCameras.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboCamerasActionPerformed(evt);
}
});
jLabel5.setText("Type:");
comboType.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
comboType.setMaximumRowCount(30);
comboType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Laser", "Electrons", "Photonics" }));
comboType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboTypeActionPerformed(evt);
}
});
javax.swing.GroupLayout panelCameraSelectionLayout = new javax.swing.GroupLayout(panelCameraSelection);
panelCameraSelection.setLayout(panelCameraSelectionLayout);
panelCameraSelectionLayout.setHorizontalGroup(
panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCameraSelectionLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(0, 0, 0)
.addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0))
);
panelCameraSelectionLayout.setVerticalGroup(
panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCameraSelectionLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(panelCameraSelectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jLabel1)
.addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, 0))
);
javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
topPanel.setLayout(topPanelLayout);
topPanelLayout.setHorizontalGroup(
topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(topPanelLayout.createSequentialGroup()
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup()
.addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.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(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0))
.addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
topPanelLayout.setVerticalGroup(
topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(topPanelLayout.createSequentialGroup()
.addGap(1, 1, 1)
.addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(topPanelLayout.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(jLabel5)
.addComponent(comboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addComponent(pauseSelection, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(panelCameraSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
topPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, comboType, toolBar});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
@@ -2842,7 +3023,7 @@ public class ScreenPanel2 extends Panel {
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(sidePanel, 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, 578, Short.MAX_VALUE))
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(topPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
@@ -3205,24 +3386,32 @@ public class ScreenPanel2 extends Panel {
private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed
try {
renderer.removeOverlay(imageBufferOverlay);
if (camera != null) {
boolean pause = !renderer.isPaused();
synchronized (imageBuffer) {
if (pause) {
renderer.pause();
} else {
imageBuffer.clear();
renderer.resume();
}
pauseSelection.setVisible(pause && (imageBuffer.size() > 1));
if (pauseSelection.isVisible()) {
renderer.addOverlay(imageBufferOverlay);
pauseSelection.setMaxValue(imageBuffer.size());
pauseSelection.setValue(imageBuffer.size());;
if (!updatingButtons){
renderer.removeOverlay(imageBufferOverlay);
if (camera != null) {
boolean pause = !renderer.isPaused();
synchronized (imageBuffer) {
if (pause) {
renderer.pause();
} else {
imageBuffer.clear();
renderer.resume();
}
if (pause && (imageBuffer.size() > 1)) {
panelCameraSelection.setVisible(false);
pauseSelection.setVisible(true);
renderer.addOverlay(imageBufferOverlay);
pauseSelection.setMaxValue(imageBuffer.size());
pauseSelection.setValue(imageBuffer.size());;
updatePause();
} else {
pauseSelection.setVisible(false);
panelCameraSelection.setVisible(true);
}
}
updateStreamData();
}
updateStreamData();
}
} catch (Exception ex) {
showException(ex);
@@ -3273,41 +3462,11 @@ public class ScreenPanel2 extends Panel {
try {
saveSnapshot();
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, null, ex);
showException(ex);
}
}//GEN-LAST:event_buttonSaveActionPerformed
private void buttonArgsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonArgsActionPerformed
try {
if (camera != null) {
String cameraConfigJson = null;
if (usingServer) {
String cameraServerUrl = (camServerUrl == null) ? server.getUrl().substring(0, server.getUrl().length() - 1) + "8" : camServerUrl;
try (CameraServer srv = new CameraServer("CamServer", cameraServerUrl)) {
srv.initialize();
//TODO: replace into encodeMultiline
cameraConfigJson = JsonSerializer.encode(srv.getConfig(cameraName), true);
}
} else {
String configFolder = (String) getContext().getClassByName("SfCamera").getMethod("getConfigFolder", new Class[]{}).invoke(null);
Path configFile = Paths.get(configFolder, cameraName + ".json");
cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : 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(getTopLevel(), dlg);
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonArgsActionPerformed
private void buttonStreamDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStreamDataActionPerformed
try {
showStreamData();
@@ -3331,7 +3490,7 @@ public class ScreenPanel2 extends Panel {
} catch (Exception ex) {
ex.printStackTrace();
} finally{
} finally {
updateButtons();
}
}//GEN-LAST:event_comboTypeActionPerformed
@@ -3377,9 +3536,17 @@ public class ScreenPanel2 extends Panel {
}
}//GEN-LAST:event_comboCamerasActionPerformed
private void buttonTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTitleActionPerformed
try {
manageTitleOverlay();
} catch (Exception ex) {
showException(ex);
} finally {
}
}//GEN-LAST:event_buttonTitleActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btFixColormapRange;
private javax.swing.JButton buttonArgs;
private javax.swing.JRadioButton buttonAutomatic;
private javax.swing.JRadioButton buttonDirect;
private javax.swing.JToggleButton buttonFit;
@@ -3398,6 +3565,7 @@ public class ScreenPanel2 extends Panel {
private javax.swing.JRadioButton buttonServer;
private javax.swing.JToggleButton buttonSidePanel;
private javax.swing.JButton buttonStreamData;
private javax.swing.JToggleButton buttonTitle;
private javax.swing.JRadioButton buttonZoom025;
private javax.swing.JRadioButton buttonZoom05;
private javax.swing.JRadioButton buttonZoom2;
@@ -3414,6 +3582,7 @@ public class ScreenPanel2 extends Panel {
private javax.swing.JComboBox comboFilter;
private javax.swing.JComboBox comboScreen;
private javax.swing.JComboBox comboType;
private javax.swing.Box.Filler filler1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
@@ -3422,7 +3591,6 @@ public class ScreenPanel2 extends Panel {
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel5;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JToolBar.Separator jSeparator5;
private javax.swing.JToolBar.Separator jSeparator6;
private javax.swing.JLabel labelGrScale;
private javax.swing.JLabel labelGrThreshold;
@@ -3431,6 +3599,7 @@ public class ScreenPanel2 extends Panel {
private javax.swing.JLabel labelSlNumber;
private javax.swing.JLabel labelSlOrientation;
private javax.swing.JLabel labelSlScale;
private javax.swing.JPanel panelCameraSelection;
private javax.swing.JPanel panelFilter;
private javax.swing.JPanel panelScreen;
private javax.swing.JPanel panelScreen2;