diff --git a/plugins/ScreenPanel2.form b/plugins/ScreenPanel2.form index 6596174..bc4a4f3 100755 --- a/plugins/ScreenPanel2.form +++ b/plugins/ScreenPanel2.form @@ -445,14 +445,16 @@ - - - - + + + + + + diff --git a/plugins/ScreenPanel2.java b/plugins/ScreenPanel2.java index 7e5efd3..20f2fd2 100644 --- a/plugins/ScreenPanel2.java +++ b/plugins/ScreenPanel2.java @@ -18,10 +18,6 @@ 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; @@ -44,13 +40,11 @@ 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; @@ -58,19 +52,14 @@ 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; @@ -88,6 +77,7 @@ 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; @@ -143,7 +133,6 @@ public class ScreenPanel2 extends Panel { String serverUrl; String camServerUrl; String instanceName; - Overlay titleOv = null; Double getServerDouble(String name) { return (Double) Convert.toDouble(server.getValue(name)); @@ -252,7 +241,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); @@ -312,8 +301,8 @@ public class ScreenPanel2 extends Panel { } }); - JMenuItem menuRendererConfig = new JMenuItem("Renderer Parameters"); - menuRendererConfig.addActionListener((ActionEvent e) -> { + JMenuItem menuCameraConfig = new JMenuItem("Renderer Config"); + menuCameraConfig.addActionListener((ActionEvent e) -> { try { if (camera != null) { this.showDeviceConfigDialog(camera, false); @@ -323,52 +312,6 @@ 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 { @@ -376,8 +319,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) -> { @@ -426,12 +369,9 @@ public class ScreenPanel2 extends Panel { }); renderer.getPopupMenu().addSeparator(); - renderer.getPopupMenu().add(menuRendererConfig); renderer.getPopupMenu().add(menuCameraConfig); - renderer.getPopupMenu().add(menuSetImageBufferSize); - renderer.getPopupMenu().add(menuSaveStack); - renderer.getPopupMenu().addSeparator(); renderer.getPopupMenu().add(menuCalibrate); + renderer.getPopupMenu().add(menuSaveStack); renderer.getPopupMenu().addSeparator(); renderer.getPopupMenu().add(menuSetROI); renderer.getPopupMenu().add(menuResetROI); @@ -442,8 +382,6 @@ 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 @@ -469,9 +407,9 @@ public class ScreenPanel2 extends Panel { } } }); - imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 42)); + imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20)); imageBufferOverlay.setFixed(true); - imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_OR_IMAGE_TOP_RIGHT); + imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT); if (MainFrame.isDark()) { textState.setDisabledTextColor(textState.getForeground()); } @@ -665,21 +603,6 @@ 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) { @@ -757,21 +680,16 @@ 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()) { @@ -816,7 +734,7 @@ public class ScreenPanel2 extends Panel { } camera.setBackgroundEnabled(checkBackground.isSelected()); } - updateButtons(); + updateButtons(); camera.getConfig().save(); renderer.setDevice(camera); renderer.setAutoScroll(true); @@ -1083,31 +1001,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); + try{ + boolean active = !isCameraStopped() ;//(camera != null); + buttonArgs.setEnabled(active); 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); @@ -1119,8 +1037,8 @@ public class ScreenPanel2 extends Panel { buttonMarker.setSelected(false); } buttonSave.setSelected(renderer.isSnapshotDialogVisible()); - - } finally { + + } finally{ updatingButtons = false; } } @@ -1133,7 +1051,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(); @@ -1148,7 +1066,7 @@ public class ScreenPanel2 extends Panel { } updateZoom(); updateColormap(); - updateButtons(); + updateButtons(); checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing())); } @@ -1177,17 +1095,6 @@ 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; @@ -1785,9 +1692,6 @@ public class ScreenPanel2 extends Panel { manageUserOverlays(image, data); } } - if ((dataTableDialog != null) && (dataTableDialog.isShowing())) { - updateStreamData(); - } } void saveSnapshot() throws Exception { @@ -2032,6 +1936,7 @@ 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 @@ -2039,62 +1944,6 @@ 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 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); } } @@ -2120,34 +1969,30 @@ public class ScreenPanel2 extends Panel { dataTableModel.addRow(new Object[]{id, ""}); } } - 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); - } + 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); } - 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()) { @@ -2155,7 +2000,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(); @@ -2206,7 +2051,6 @@ 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(); @@ -2231,9 +2075,15 @@ 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(); @@ -2242,13 +2092,7 @@ 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)); @@ -2508,10 +2352,6 @@ 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) @@ -2520,10 +2360,7 @@ public class ScreenPanel2 extends Panel { .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonServer) .addComponent(buttonDirect) - .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))) + .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); @@ -2790,7 +2627,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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) ); sidePanelLayout.setVerticalGroup( sidePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -2806,10 +2643,30 @@ 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) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); + 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); @@ -2838,6 +2695,22 @@ 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"); @@ -2924,91 +2797,42 @@ public class ScreenPanel2 extends Panel { }); toolBar.add(buttonReticle); - buttonTitle.setIcon(getIcon("Title")); - buttonTitle.setText(" "); - buttonTitle.setToolTipText("Show Camera Name"); - buttonTitle.setFocusable(false); - 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(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup() + .addGroup(topPanelLayout.createSequentialGroup() .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) - .addComponent(panelCameraSelection, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .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) .addGap(18, 18, 18) - .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addComponent(pauseSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0)) ); topPanelLayout.setVerticalGroup( topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(topPanelLayout.createSequentialGroup() .addGap(1, 1, 1) - .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))) + .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) ); + 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( @@ -3018,7 +2842,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, 594, Short.MAX_VALUE)) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 578, 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))) @@ -3031,7 +2855,7 @@ public class ScreenPanel2 extends Panel { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(sidePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE))) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) ); }// //GEN-END:initComponents @@ -3381,32 +3205,24 @@ public class ScreenPanel2 extends Panel { private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed try { - 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); - } + 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());; } - updateStreamData(); } + updateStreamData(); } } catch (Exception ex) { showException(ex); @@ -3461,6 +3277,37 @@ public class ScreenPanel2 extends Panel { } }//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(); @@ -3484,7 +3331,7 @@ public class ScreenPanel2 extends Panel { } catch (Exception ex) { ex.printStackTrace(); - } finally { + } finally{ updateButtons(); } }//GEN-LAST:event_comboTypeActionPerformed @@ -3530,17 +3377,9 @@ 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; @@ -3559,7 +3398,6 @@ 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; @@ -3576,7 +3414,6 @@ 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; @@ -3585,6 +3422,7 @@ 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; @@ -3593,7 +3431,6 @@ 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;