Fixes for load Custom Panel

This commit is contained in:
boccioli_m
2015-10-16 15:27:03 +02:00
parent f6fc1337cc
commit 853cb0fdd3
5 changed files with 104 additions and 78 deletions

View File

@@ -17,8 +17,8 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabelDeviceName" pref="150" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
<Component id="jLabelDeviceName" pref="100" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
@@ -188,6 +188,7 @@
<Component class="javax.swing.JLabel" name="jLabelDeviceName">
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="horizontalTextPosition" type="int" value="2"/>
</Properties>
</Component>
</SubComponents>

View File

@@ -82,14 +82,15 @@ public class Kollimators extends javax.swing.JPanel {
jLabel8.setText("Resolution:");
jLabelDeviceName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabelDeviceName.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
.addGap(3, 3, 3)
.addComponent(jLabelDeviceName, javax.swing.GroupLayout.DEFAULT_SIZE, 100, 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()

View File

@@ -476,6 +476,9 @@
<Dimension value="[300, 100]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_LayoutCodePost" type="java.lang.String" value="jPanelCustom.setVisible(false);"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="South"/>
@@ -487,7 +490,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanelCustomHeader" max="32767" attributes="0"/>
<Component id="jPanelCustomHeader" pref="440" max="32767" attributes="0"/>
<Component id="jPanelCustomFrame" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
@@ -524,8 +527,14 @@
<Image iconType="3" name="/icons/x-darker-8px.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Close this custom panel"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[12, 12]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[12, 12]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[10, 10]"/>
<Dimension value="[12, 12]"/>
</Property>
<Property name="rolloverIcon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/x-darker-8px.png"/>
@@ -549,7 +558,7 @@
<Dimension value="[100, 20]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[200, 20]"/>
<Dimension value="[100, 20]"/>
</Property>
</Properties>
<Events>

View File

@@ -324,7 +324,7 @@ public class TestingList extends Panel {
private void loadProperties(){
File configFile = TESTS_PROPERTIES_DEFAULT_DIR.toFile();
if (!configFile.isFile()) return;
boolean error = false;
try {
FileReader reader = new FileReader(configFile);
Properties props = new Properties();
@@ -359,13 +359,19 @@ public class TestingList extends Panel {
} catch (FileNotFoundException ex) {
// file does not exist
System.out.println(ex.toString());
error = true;
} catch (IOException ex) {
// I/O error
System.out.println(ex.toString());
error = true;
} catch (Exception ex){
// Any other exception
System.out.println(ex.toString());
System.out.println(ex.toString());
error = true;
}
if(error){
//load defaults
}
}
@@ -474,6 +480,8 @@ public class TestingList extends Panel {
public void loadCustomPanel(Component panel){
if(panel != null)
loadCustomPanel(panel.getClass().getName() );
else
closeCustomPanel();
}
/**
@@ -489,7 +497,9 @@ public class TestingList extends Panel {
*/
private void loadCustomPanel(String sPanelClassName){
closeCustomPanel();
if (sPanelClassName == null || sPanelClassName.trim() == "" || sPanelClassName.isEmpty()) {
if ( sPanelClassName == null ||
sPanelClassName.trim() == "" ||
sPanelClassName.isEmpty()) {
return;
}
@@ -539,6 +549,7 @@ public class TestingList extends Panel {
//store custom panel in the properties
saveProperties("customPanel", sPanelClassName);
jPanelCustom.setVisible(true);
animateCustomPanel();
} catch (ClassNotFoundException ex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
@@ -556,6 +567,70 @@ public class TestingList extends Panel {
}
}
/**
* Starts animating the custom panel, if present
*
* Note: the custom panel must have the public method "animate(String deviceName)"
*
* @param deviceName name of the device. The panel should then append the epics PV to the device name for caget/caset
*/
public void animateCustomPanel(String deviceName) {
try {
Component customPanel = getCustomPanel();
//if no custom panel: nothing to do
if(customPanel==null) return;
//call the method "animate" of the custom panel (this function must be there)
Class[] cArg = new Class[1];
cArg[0] = String.class;
Method animate = customPanel.getClass().getMethod("animate", cArg);
animate.invoke(customPanel, deviceName);
} catch (NoSuchMethodException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (SecurityException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (IllegalAccessException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (IllegalArgumentException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (InvocationTargetException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (Exception ex){
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
}
}
/**
* Starts animating the custom panel, if present, and only if the whole list of selected tests contains one only device name
*
* Note: the custom panel must have the public method "animate(String deviceName)"
*/
public void animateCustomPanel(){
Component customPanel = getCustomPanel();
//if no custom panel: nothing to do
if(customPanel==null) return;
//scan the table to see if only one device name is present
String sDeviceName = "";
String sRowDeviceName = "";
boolean bRowTestEnabled = false;
for (int row = 0; row < jTable1.getRowCount(); row++) {
sRowDeviceName = String.valueOf(jTable1.getValueAt(row, COL.DEVICENAME.ordinal()));
bRowTestEnabled = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
if(bRowTestEnabled){
if(sDeviceName == ""){
sDeviceName = sRowDeviceName;
} else if(sDeviceName != sRowDeviceName){
//there are at least two devices. Cannot animate the custom panel
return;
}
}
}
//if only one device name is present in the table, then animate the custom panel with the device
if(sDeviceName != ""){
animateCustomPanel(sDeviceName);
}
}
/**
* write info into a log file
@@ -957,7 +1032,9 @@ public class TestingList extends Panel {
jButtonX.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
jButtonX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/x-darker-8px.png"))); // NOI18N
jButtonX.setToolTipText("Close this custom panel");
jButtonX.setPreferredSize(new java.awt.Dimension(10, 10));
jButtonX.setMaximumSize(new java.awt.Dimension(12, 12));
jButtonX.setMinimumSize(new java.awt.Dimension(12, 12));
jButtonX.setPreferredSize(new java.awt.Dimension(12, 12));
jButtonX.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/x-darker-8px.png"))); // NOI18N
jButtonX.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -968,7 +1045,7 @@ public class TestingList extends Panel {
jLabelCustomPanelName.setMaximumSize(new java.awt.Dimension(1000, 20));
jLabelCustomPanelName.setMinimumSize(new java.awt.Dimension(100, 20));
jLabelCustomPanelName.setPreferredSize(new java.awt.Dimension(200, 20));
jLabelCustomPanelName.setPreferredSize(new java.awt.Dimension(100, 20));
jLabelCustomPanelName.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabelCustomPanelNameMouseClicked(evt);
@@ -982,7 +1059,7 @@ public class TestingList extends Panel {
jPanelCustomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCustomLayout.createSequentialGroup()
.addGroup(jPanelCustomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelCustomHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanelCustomHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
.addComponent(jPanelCustomFrame, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
@@ -995,6 +1072,8 @@ public class TestingList extends Panel {
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanelCustom.setVisible(false);
add(jPanelCustom, java.awt.BorderLayout.SOUTH);
}// </editor-fold>//GEN-END:initComponents
@@ -1553,70 +1632,6 @@ public class TestingList extends Panel {
dlg.pack();
dlg.setVisible(true);
}
/**
* Starts animating the custom panel, if present
*
* Note: the custom panel must have the public method "animate(String deviceName)"
*
* @param deviceName name of the device. The panel should then append the epics PV to the device name for caget/caset
*/
public void animateCustomPanel(String deviceName) {
try {
Component customPanel = getCustomPanel();
//if no custom panel: nothing to do
if(customPanel==null) return;
//call the method "animate" of the custom panel (this function must be there)
Class[] cArg = new Class[1];
cArg[0] = String.class;
Method animate = customPanel.getClass().getMethod("animate", cArg);
animate.invoke(customPanel, deviceName);
} catch (NoSuchMethodException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (SecurityException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (IllegalAccessException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (IllegalArgumentException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (InvocationTargetException ex) {
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
} catch (Exception ex){
System.out.println("animateCustomPanel(): "+String.valueOf(ex));
}
}
/**
* Starts animating the custom panel, if present, and only if the whole list of selected tests contains one only device name
*
* Note: the custom panel must have the public method "animate(String deviceName)"
*/
public void animateCustomPanel(){
Component customPanel = getCustomPanel();
//if no custom panel: nothing to do
if(customPanel==null) return;
//scan the table to see if only one device name is present
String sDeviceName = "";
String sRowDeviceName = "";
boolean bRowTestEnabled = false;
for (int row = 0; row < jTable1.getRowCount(); row++) {
sRowDeviceName = String.valueOf(jTable1.getValueAt(row, COL.DEVICENAME.ordinal()));
bRowTestEnabled = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
if(bRowTestEnabled){
if(sDeviceName == ""){
sDeviceName = sRowDeviceName;
} else if(sDeviceName != sRowDeviceName){
//there are at least two devices. Cannot animate the custom panel
return;
}
}
}
//if only one device name is present in the table, then animate the custom panel with the device
if(sDeviceName != ""){
animateCustomPanel(sDeviceName);
}
}
/**

View File

@@ -1,5 +1,5 @@
#TestingList for pshell: configuration properties
#Fri Oct 16 14:53:58 CEST 2015
#Fri Oct 16 15:24:36 CEST 2015
customPanel=Kollimators
showEnabledTestsOnly=true
listFilter=CollimatorTests