From 4e0257ebfbba48d09c59101f28eb06f79866e350 Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Tue, 1 Dec 2015 14:46:30 +0100 Subject: [PATCH] Added connection to records on custom panel. --- plugins/Kollimators.form | 21 ++++++++- plugins/Kollimators.java | 96 ++++++++++++++++++++++++++++++++++++++-- plugins/Marco.form | 41 +++-------------- plugins/Marco.java | 58 +++++++++--------------- 4 files changed, 139 insertions(+), 77 deletions(-) diff --git a/plugins/Kollimators.form b/plugins/Kollimators.form index 5b3d8bd..6689b89 100644 --- a/plugins/Kollimators.form +++ b/plugins/Kollimators.form @@ -17,8 +17,16 @@ - - + + + + + + + + + + @@ -95,6 +103,7 @@ + @@ -188,5 +197,13 @@ + + + + + + + + diff --git a/plugins/Kollimators.java b/plugins/Kollimators.java index f11c17b..5f66f1f 100644 --- a/plugins/Kollimators.java +++ b/plugins/Kollimators.java @@ -1,6 +1,10 @@ import ch.psi.jcae.Channel; import ch.psi.jcae.ChannelException; +import ch.psi.pshell.device.Device; +import ch.psi.pshell.device.DeviceAdapter; +import ch.psi.pshell.epics.ChannelDouble; +import ch.psi.utils.State; import gov.aps.jca.CAException; import gov.aps.jca.Context; import gov.aps.jca.JCALibrary; @@ -8,6 +12,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JTextField; /* * Copyright (c) 2015 Paul Scherrer Institute. All rights reserved. @@ -27,7 +32,70 @@ public class Kollimators extends javax.swing.JPanel { */ public Kollimators(String params) { initComponents(); + //connect(""); + } + + ChannelDouble channel; + String g_deviceName; + + //Overridable callbacks + public void onInitialize(int runCount) { + initComponents(); + //connect(""); } + + public void connect(String device, JTextField textField) { + try { + ChannelDouble channel = new ChannelDouble(device, device, 3); + channel.setMonitored(true); + channel.initialize(); + + channel.addListener(new DeviceAdapter() { + @Override + public void onValueChanged(Device device, Object value, Object former) { + Double val = (Double )value; + textField.setText(String.valueOf(val)); + textField.setToolTipText(device.getName()); + } + }); + //channel.close(); + } catch (Exception ex) { + System.out.println(ex.toString()); + } + } + + private void monitorChannel(ChannelDouble channel, Object textField){ + + } + + public void animate(String deviceName) { + g_deviceName = deviceName; + connect(deviceName+":STA2:1", jTextSta); + connect(deviceName+":IST1:1", jTextDist); + connect(deviceName+":IST1:1", jTextIst1); + connect(deviceName+":IST2:1", jTextIst2); + connect(deviceName+":REF1:1", jTextRef1); + connect(deviceName+":REF2:1", jTextRef2); + connect(deviceName+":IST1:1", jTextDir); + connect(deviceName+":STA2:1", jTextRes); + } + + public void animate() { + animate(g_deviceName); + } + + public void onStateChange(State state, State former) { + + } + + public void onExecutedFile(String fileName, Object result) { + } + + + //Callback to perform update - in event thread + protected void doUpdate() { + } + /** * This method is called from within the constructor to initialize the form. @@ -55,6 +123,7 @@ public class Kollimators extends javax.swing.JPanel { jTextRes = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); jLabelDeviceName = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); jLabel1.setText("STA:"); @@ -91,13 +160,25 @@ public class Kollimators extends javax.swing.JPanel { jLabelDeviceName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabelDeviceName.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); + jButton1.setText("Reconnect"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(3, 3, 3) - .addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(3, 3, 3) + .addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jButton1) + .addGap(0, 0, Short.MAX_VALUE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() @@ -161,18 +242,24 @@ public class Kollimators extends javax.swing.JPanel { .addComponent(jLabel7) .addComponent(jTextDist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel8) - .addComponent(jTextRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jTextRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jButton1)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + animate(); + }//GEN-LAST:event_jButton1ActionPerformed + /** * animate the panel (caget/caset). Called from TestingList. * This function MUST EXISTS in every custom panel callable from TestingList * @param deviceName */ - public void animate(String deviceName) { + public void animateOld(String deviceName) { try { this.jLabelDeviceName.setText(deviceName); @@ -206,6 +293,7 @@ public class Kollimators extends javax.swing.JPanel { } // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; diff --git a/plugins/Marco.form b/plugins/Marco.form index 37b461d..41ac8fa 100644 --- a/plugins/Marco.form +++ b/plugins/Marco.form @@ -18,18 +18,9 @@ - - - - - - - - - - - - + + + @@ -37,37 +28,17 @@ - - - - - - - - - - - + - + - + - - - - - - - - - - diff --git a/plugins/Marco.java b/plugins/Marco.java index f4f82f9..161590b 100644 --- a/plugins/Marco.java +++ b/plugins/Marco.java @@ -19,22 +19,28 @@ import java.util.logging.Logger; /** * */ -public class Marco extends Panel { +public class Marco extends javax.swing.JPanel { public Marco() { initComponents(); } public Marco (String params) { initComponents(); + //connect("XPROLUFT"); + connect(""); } ChannelDouble channel; //Overridable callbacks - @Override public void onInitialize(int runCount) { + initComponents(); + connect(""); + } + + public void connect(String device) { try { - ChannelDouble channel = new ChannelDouble("MyChannel", "SIM-MMAC3:STR:2", 3); + ChannelDouble channel = new ChannelDouble(device+"SIM-MMAC3:STR:2", device+"SIM-MMAC3:STR:2", 3); channel.setMonitored(true); channel.initialize(); @@ -43,42 +49,37 @@ public class Marco extends Panel { public void onValueChanged(Device device, Object value, Object former) { Double val = (Double )value; valueText.setText(String.valueOf(val)); + valueText.setToolTipText(device.getName()); } }); //channel.close(); } catch (Exception ex) { - showException(ex); + System.out.println(ex.toString()); } - } + } - @Override public void onStateChange(State state, State former) { } - @Override public void onExecutedFile(String fileName, Object result) { } //Callback to perform update - in event thread - @Override protected void doUpdate() { } + + public void animate(String deviceName) { + } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { - jLabel1 = new javax.swing.JLabel(); - valuePanel = new ch.psi.pshell.swing.DeviceValuePanel(); jLabel2 = new javax.swing.JLabel(); valueText = new javax.swing.JTextField(); - jLabel1.setText("Value:"); - - valuePanel.setDeviceName("marco"); - jLabel2.setText("Value:"); valueText.setEditable(false); @@ -89,39 +90,24 @@ public class Marco extends Panel { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valuePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueText, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueText, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(226, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(23, 23, 23) - .addComponent(jLabel1)) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(valuePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE) + .addGap(0, 0, 0) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(valueText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(20, 20, 20)) + .addComponent(valueText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addGap(0, 0, 0)) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; - private ch.psi.pshell.swing.DeviceValuePanel valuePanel; private javax.swing.JTextField valueText; // End of variables declaration//GEN-END:variables }