Added connection to records on custom panel.

This commit is contained in:
boccioli_m
2015-12-01 14:46:30 +01:00
parent 66a3660fd2
commit 4e0257ebfb
4 changed files with 139 additions and 77 deletions

View File

@@ -17,8 +17,16 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
<Component id="jLabelDeviceName" pref="100" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
<Component id="jLabelDeviceName" pref="100" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
@@ -95,6 +103,7 @@
<Component id="jTextDist" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jTextRes" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
@@ -188,5 +197,13 @@
<Property name="horizontalTextPosition" type="int" value="2"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="Reconnect"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -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))
);
}// </editor-fold>//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;

View File

@@ -18,18 +18,9 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="valuePanel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="valueText" min="-2" pref="154" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="valueText" min="-2" pref="179" max="-2" attributes="0"/>
<EmptySpace pref="226" max="32767" attributes="0"/>
</Group>
</Group>
@@ -37,37 +28,17 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="valuePanel" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="49" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="valueText" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="20" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Value:"/>
</Properties>
</Component>
<Component class="ch.psi.pshell.swing.DeviceValuePanel" name="valuePanel">
<Properties>
<Property name="deviceName" type="java.lang.String" value="marco"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Value:"/>

View File

@@ -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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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))
);
}// </editor-fold>//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
}