Fix info panel not showing despite @Description annotation being present.

This commit is contained in:
2014-01-21 16:57:27 +01:00
parent 63fe74d2e0
commit e9bd1becf1

View File

@@ -2,6 +2,7 @@ package eva2.gui;
import eva2.gui.editor.GenericObjectEditor;
import eva2.tools.EVAHELP;
import eva2.util.annotation.Description;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
@@ -187,19 +188,13 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
return;
}
int rowHeight = 12;
GridBagConstraints gbConstraints = new GridBagConstraints();
gbConstraints.fill = GridBagConstraints.BOTH;
// Look for a globalInfo method that returns a string
// describing the target
int methsFound = 0; // dont loop too long, so count until all found
for (MethodDescriptor methodDescriptor : methodDescriptors) {
String name = methodDescriptor.getDisplayName();
Method meth = methodDescriptor.getMethod();
if (name.equals("globalInfo")) {
JPanel infoPanel = makeInfoPanel(meth, targ, rowHeight);
Description description = targ.getClass().getAnnotation(Description.class);
if (description != null) {
int rowHeight = 12;
JPanel infoPanel = makeInfoPanel(description.value(), targ, rowHeight);
if (infoPanel != null) {
gbConstraints.gridx = 0;
gbConstraints.gridy = 0;
@@ -207,9 +202,16 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
gbConstraints.anchor = GridBagConstraints.PAGE_START;
add(infoPanel, gbConstraints);
}
methsFound++;
} // end if (name.equals("globalInfo")) {
else if (name.equals("hideHideable")) {
}
// Look for a globalInfo method that returns a string
// describing the target
int methsFound = 0; // dont loop too long, so count until all found
// @ToDo: Replace hideHideable method with annotation
for (MethodDescriptor methodDescriptor : methodDescriptors) {
String name = methodDescriptor.getDisplayName();
Method meth = methodDescriptor.getMethod();
if (name.equals("hideHideable")) {
Object args[] = {};
try {
meth.invoke(targetObject, args);
@@ -220,7 +222,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
methsFound++;
reorderProperties(meth);
}
if (methsFound == 3) {
if (methsFound == 2) {
break; // small speed-up
}
} // end for (int i = 0; i < m_Methods.length; i++) {
@@ -465,7 +467,6 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
/**
* Be sure to give a clone
*
* @param oldProps
* @param meth
* @return
*/
@@ -547,11 +548,8 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
return -1;
}
private JPanel makeInfoPanel(Method meth, Object targ, int rowHeight) {
if (meth.getReturnType().equals(String.class)) {
try {
private JPanel makeInfoPanel(String infoText, Object targ, int rowHeight) {
Object args[] = {};
String globalInfo = (String) (meth.invoke(targetObject, args));
className = targ.getClass().getName();
helpButton = new JButton("Help");
@@ -565,7 +563,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
});
JTextArea infoTextArea = new JTextArea();
infoTextArea.setText(globalInfo);
infoTextArea.setText(infoText);
infoTextArea.setFont(new Font("SansSerif", Font.PLAIN, rowHeight));
infoTextArea.setEditable(false);
infoTextArea.setLineWrap(true);
@@ -585,11 +583,6 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
LOGGER.log(Level.FINE, "Not adding help button because of missing {0}", getHelpFileName());
}
return infoPanel;
} catch (Exception ex) {
LOGGER.severe(ex.getMessage());
}
}
return null;
}
private String translateGreek(String name) {