Subscript indices in PropertySheetPanel

- add subscriptIndices to StringTools
- add tests
This commit is contained in:
2015-12-15 11:02:21 +01:00
parent b58a589b24
commit 965049c4cb
3 changed files with 48 additions and 6 deletions

View File

@@ -300,10 +300,7 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
continue;
} // end try
// Add some specific display for some greeks here
name = StringTools.translateGreek(name);
name = StringTools.humaniseCamelCase(name);
propertyTableModel.addRow(new Object[]{name, newView});
propertyTableModel.addRow(new Object[]{prepareLabel(name), newView});
}
propertyTable.setToolTips(toolTips);
@@ -327,6 +324,15 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
setVisible(true);
}
private String prepareLabel(String label) {
// Add some specific display for some greeks here
label = StringTools.translateGreek(label);
label = StringTools.humaniseCamelCase(label);
label = StringTools.subscriptIndices(label);
label = "<html>" + label + "</html>";
return label;
}
private static JPanel buildTitledSeperator(String title) {
JPanel titledSeperator = new JPanel(new GridBagLayout());
@@ -558,8 +564,6 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
return infoPanel;
}
/**
* Get the html help file name.
*

View File

@@ -479,6 +479,9 @@ public final class StringTools {
}
/**
* Takes a full package name and returns the string
* after the last period (usually the class name).
*
* @param value The string to cut
* @return Returns the class Name without package.
*/
@@ -491,6 +494,13 @@ public final class StringTools {
return className; // now is shortName
}
/**
* Takes a string and looks for greek letter names. If found,
* replaces them by their greek unicode counterparts.
*
* @param name A string
* @return String with greek letter names replaced
*/
public static String translateGreek(String name) {
// Add some specific display for some greeks here
final String[][] mapping = {
@@ -549,5 +559,21 @@ public final class StringTools {
return name;
}
/**
* Takes a string and looks for trailing numbers. If present those numbers will
* be replaced by a HTML subscript. Make sure to wrap inside a html block when
* displaying as part of a JLabel.
*
* @param label
* @return
*/
public static String subscriptIndices(String label) {
// Trailing numbers
Pattern p = Pattern.compile("(\\d+)$");
Matcher m = p.matcher(label);
return m.replaceFirst("<sub>$1</sub>");
}
}