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

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