diff --git a/src/main/java/eva2/gui/PropertySheetPanel.java b/src/main/java/eva2/gui/PropertySheetPanel.java index 955f8b01c02fb24e35a9a378986a3f6fe67ab405..f1617e2598469287adcc1c17ffa293a491247cc0 100644 --- a/src/main/java/eva2/gui/PropertySheetPanel.java +++ b/src/main/java/eva2/gui/PropertySheetPanel.java @@ -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 = "" + label + ""; + 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. * diff --git a/src/main/java/eva2/tools/StringTools.java b/src/main/java/eva2/tools/StringTools.java index f13b687ed0a79cbdc9381bb44fe584cfce209e8b..1daddae8ff0ba189b8ebf4e757b3c64a38a46752 100644 --- a/src/main/java/eva2/tools/StringTools.java +++ b/src/main/java/eva2/tools/StringTools.java @@ -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("$1"); + } } diff --git a/src/test/java/eva2/tools/StringToolsTest.java b/src/test/java/eva2/tools/StringToolsTest.java index a6787e600a1e8b2a48d20436c4c1e156f03d66b6..ac6095d0cd8dc4b013de9fa3e94e02690e0f7339 100644 --- a/src/test/java/eva2/tools/StringToolsTest.java +++ b/src/test/java/eva2/tools/StringToolsTest.java @@ -98,4 +98,16 @@ public class StringToolsTest { assertEquals("taur", StringTools.translateGreek("taur")); assertEquals("taur12", StringTools.translateGreek("taur12")); } + + @Test + public void testSubscriptIndices() throws Exception { + // Doesn't alter numbers at the start or mid string + assertEquals("12derp", StringTools.subscriptIndices("12derp")); + assertEquals("der12p", StringTools.subscriptIndices("der12p")); + + // Replaces trailing numbers with a sub html tag + assertEquals("derp12", StringTools.subscriptIndices("derp12")); + assertEquals("This is a string 12", StringTools.subscriptIndices("This is a string 12")); + assertEquals("ϕ10", StringTools.subscriptIndices("ϕ10")); + } }