diff --git a/devices/S10MA01-DSCR090.properties b/devices/S10MA01-DSCR090.properties index 52a4453..af1cdab 100644 --- a/devices/S10MA01-DSCR090.properties +++ b/devices/S10MA01-DSCR090.properties @@ -1,4 +1,4 @@ -#Fri Aug 26 12:30:16 CEST 2016 +#Fri Aug 26 15:33:45 CEST 2016 colormap=Grayscale colormapAutomatic=false colormapMax=255.0 @@ -16,7 +16,7 @@ roiWidth=-1 roiX=0 roiY=0 rotation=0.0 -rotationCrop=false +rotationCrop=true scale=1.0 spatialCalOffsetX=NaN spatialCalOffsetY=NaN diff --git a/plugins/Cameras.form b/plugins/Cameras.form index 9348898..bcaae72 100644 --- a/plugins/Cameras.form +++ b/plugins/Cameras.form @@ -23,14 +23,16 @@ - - + + + + - + - + @@ -43,6 +45,7 @@ + @@ -79,5 +82,13 @@ + + + + + + + + diff --git a/plugins/Cameras.java b/plugins/Cameras.java index 57ff2d4..324e6bd 100644 --- a/plugins/Cameras.java +++ b/plugins/Cameras.java @@ -11,15 +11,21 @@ import ch.psi.pshell.imaging.ImageListener; import ch.psi.utils.State; import ch.psi.utils.IO; import ch.psi.utils.swing.SwingUtils; +import ch.psi.utils.swing.ConfigDialog; +import ch.psi.utils.swing.StandardDialog; import ch.psi.pshell.epics.PsiCamera; import ch.psi.pshell.core.JsonSerializer; import ch.psi.pshell.imaging.Data; import java.awt.Dimension; +import java.awt.Frame; import java.awt.image.BufferedImage; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; /** * @@ -28,11 +34,13 @@ public class Cameras extends Panel { public Cameras() { initComponents(); + renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin")); } final String configFolder= "/afs/psi.ch/intranet/SF/Applications/config/camtool"; File[] cameraConfigFiles = new File[0]; PsiCamera camera; + String cameraName; CameraConfig config; //Overridable callbacks @@ -134,8 +142,9 @@ public class Cameras extends Panel { try{ Path configFile= Paths.get(configFolder, cameraName + ".json"); String json = new String(Files.readAllBytes(configFile)); + this.cameraName=cameraName; //SwingUtils.showMessage(null, "", json); - camera = new PsiCamera(cameraName, cameraName); + camera = new PsiCamera("CurrentCamera", cameraName); try{ config = (CameraConfig) JsonSerializer.decode(json, CameraConfig.class); camera.getConfig().flipHorizontally = config.getMirrorX(); @@ -155,9 +164,14 @@ public class Cameras extends Panel { config = null; showException(ex); } - camera.getConfig().save(); + camera.getConfig().save(); + camera.initialize(); + camera.setMonitored(true); + + renderer.setDevice(camera); + renderer.setShowReticle(true); + renderer.setAutoScroll(true); - camera.addListener(renderer); camera.addListener(new ImageListener() { @Override public void onImage(Object o, BufferedImage bi, Data data) { @@ -170,8 +184,7 @@ public class Cameras extends Panel { public void onError(Object o, Exception excptn) { } }); - renderer.setShowReticle(true); - camera.initialize(); + } finally{ onTimer(); @@ -181,6 +194,7 @@ public class Cameras extends Panel { @Override protected void onTimer() { textState.setText((camera==null) ? "" : camera.getState().toString()); + buttonConfig.setEnabled(camera!=null); } @SuppressWarnings("unchecked") @@ -192,6 +206,7 @@ public class Cameras extends Panel { comboCameras = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); textState = new javax.swing.JTextField(); + buttonConfig = new javax.swing.JButton(); jLabel1.setText("Camera:"); @@ -208,6 +223,13 @@ public class Cameras extends Panel { textState.setDisabledTextColor(new java.awt.Color(0, 0, 0)); textState.setEnabled(false); + buttonConfig.setText("Config"); + buttonConfig.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -219,12 +241,14 @@ public class Cameras extends Panel { .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboCameras, 0, 348, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(comboCameras, 0, 290, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonConfig) + .addGap(10, 10, 10) .addComponent(jLabel2) .addGap(4, 4, 4) - .addComponent(textState, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))) - .addGap(26, 26, 26)) + .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -234,7 +258,8 @@ public class Cameras extends Panel { .addComponent(jLabel1) .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) - .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonConfig)) .addGap(18, 18, 18) .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE) .addGap(6, 6, 6)) @@ -246,14 +271,37 @@ public class Cameras extends Panel { private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed try{ - String camera = (String) comboCameras.getSelectedItem(); - setCamera(camera); + setCamera((String) comboCameras.getSelectedItem()); } catch(Exception ex){ showException(ex); } }//GEN-LAST:event_comboCamerasActionPerformed + private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed + try{ + final ConfigDialog dlg = new ConfigDialog((Frame) getTopLevelAncestor(), false); + dlg.setTitle("Device Configuration: " + cameraName); + dlg.setConfig(camera.getConfig()); + dlg.setDefaultCloseOperation(DISPOSE_ON_CLOSE); + dlg.setListener((StandardDialog sd, boolean accepted) -> { + if (sd.getResult()) { + try { + camera.getConfig().save(); + } catch (IOException ex) { + showException(ex); + } + } + }); + dlg.setVisible(true); + SwingUtils.centerComponent(getTopLevelAncestor(), dlg); + dlg.requestFocus(); + } catch(Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonConfigActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonConfig; private javax.swing.JComboBox comboCameras; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2;