diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index dadaa913..13433e18 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -267,7 +267,7 @@ public class EvAClient implements RemoteStateListener, Serializable { final SplashScreen splashScreen = new SplashScreen(EvAInfo.splashLocation); // preload some classes (into system cache) in a parallel thread - preloadClasses(); + preloadClasses(); withGUI = !noGui; @@ -1195,7 +1195,7 @@ public class EvAClient implements RemoteStateListener, Serializable { final class SplashScreen extends Frame { private static final long serialVersionUID = 1281793825850423095L; - String imgLocation; + private String imgLocation; public SplashScreen(String imgLoc) { imgLocation = imgLoc; diff --git a/src/eva2/gui/PropertySheetPanel.java b/src/eva2/gui/PropertySheetPanel.java index fda8e822..e571f5a3 100644 --- a/src/eva2/gui/PropertySheetPanel.java +++ b/src/eva2/gui/PropertySheetPanel.java @@ -268,7 +268,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener // Add some specific display for some greeks here name = translateGreek(name); - + name = eva2.tools.StringTools.humaniseCamelCase(name); addLabelView(componentOffset, gbLayout, i, name, newView); m_NumEditable++; if (m_Properties[i].isHidden()) { @@ -397,6 +397,7 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener private void addLabelView(int componentOffset, GridBagLayout gbLayout, int i, String name, JComponent newView) { + m_Labels[i] = makeLabel(name); m_Views[i] = newView; m_ViewWrapper[i] = new JPanel(); diff --git a/src/eva2/tools/StringTools.java b/src/eva2/tools/StringTools.java index 81bd3306..82ce3a80 100644 --- a/src/eva2/tools/StringTools.java +++ b/src/eva2/tools/StringTools.java @@ -1,14 +1,22 @@ package eva2.tools; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - import eva2.gui.BeanInspector; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -public class StringTools { +/** + * Utility class to provide simplification functions + * for working with Strings. + * + * @author Fabian Becker, Marcel Kronfeld + */ +public final class StringTools { + + /** + * Private constructor to prevent instantiation. + */ + private StringTools() { } /** * Returns a HTML formated String, in which each line is at most lineBreak @@ -19,23 +27,27 @@ public class StringTools { * @return */ public static String toHTML(String string, int lineBreak) { - StringTokenizer st = new StringTokenizer(string, " "); - if (!st.hasMoreTokens()) return ""; - StringBuffer sbuf = new StringBuffer(st.nextToken()); - - int length = sbuf.length(); - while (st.hasMoreElements()) { - if (length >= lineBreak) { - sbuf.append("
"); - length = 0; - } else sbuf.append(" "); - String tmp = st.nextToken(); - length += tmp.length() + 1; - sbuf.append(tmp); + StringTokenizer sTok = new StringTokenizer(string, " "); + if (!sTok.hasMoreTokens()) { + return ""; } - sbuf.insert(0, ""); - sbuf.append(""); - return sbuf.toString(); + StringBuilder sBuf = new StringBuilder(sTok.nextToken()); + + int length = sBuf.length(); + while (sTok.hasMoreElements()) { + if (length >= lineBreak) { + sBuf.append("
"); + length = 0; + } else { + sBuf.append(" "); + } + String tmp = sTok.nextToken(); + length += tmp.length() + 1; + sBuf.append(tmp); + } + sBuf.insert(0, ""); + sBuf.append(""); + return sBuf.toString(); } public static boolean arrayContains(String[] arr, String key, boolean ignoreCase) { @@ -251,20 +263,22 @@ public class StringTools { /** * Concatenate a list of Strings using a given delimiter string. * - * @param headlineFields - * @param delim - * @return + * @param strings List of Strings to concatenate + * @param delim Delimiter for concatenation + * @return String representation */ - public static String concatFields(List strings, - String delim) { - StringBuffer sb = new StringBuffer(); - int cnt=0; + public static String concatFields(final List strings, + final String delim) { + StringBuilder sBuilder = new StringBuilder(); + int cnt = 0; for (String field : strings) { - if (cnt>0) sb.append(delim); - sb.append(field); + if (cnt > 0) { + sBuilder.append(delim); + } + sBuilder.append(field); cnt++; } - return sb.toString(); + return sBuilder.toString(); } /** @@ -276,11 +290,13 @@ public class StringTools { * @return */ public static String concatValues(List objects, - String delim) { - StringBuffer sb = new StringBuffer(); - int cnt=0; + final String delim) { + StringBuilder sb = new StringBuilder(); + int cnt = 0; for (Object v : objects) { - if (cnt>0) sb.append(delim); + if (cnt > 0) { + sb.append(delim); + } sb.append(BeanInspector.toString(v)); cnt++; } @@ -289,10 +305,12 @@ public class StringTools { public static String concatFields(String[] strs, String delim) { - StringBuffer sb = new StringBuffer(); - int cnt=0; + StringBuilder sb = new StringBuilder(); + int cnt = 0; for (String str : strs) { - if (cnt>0) sb.append(delim); + if (cnt > 0) { + sb.append(delim); + } sb.append(str); cnt++; } @@ -329,16 +347,18 @@ public class StringTools { /** * Delete a certain character from a string. * - * @param c - * @param str - * @return + * @param c Character to delete + * @param str String to remove c from. + * @return String with character c removed. */ - public static String deleteChar(char c, String str) { - StringBuffer sb = new StringBuffer(); - for (int i=0; i tokens = new ArrayList(); + Matcher matcher = pattern.matcher(word); + String acronym = ""; + while (matcher.find()) { + String found = matcher.group(); + if (found.matches("^[A-Z]$")) { + acronym += found; + } else { + if (acronym.length() > 0) { + //we have an acronym to add before we continue + tokens.add(acronym); + acronym = ""; + } + tokens.add(upcaseFirst(found)); + } + } + + if (acronym.length() > 0) { + tokens.add(acronym); + } + + if (!tokens.isEmpty()) { + return concatFields(tokens, " "); + } + + return upcaseFirst(word); + } + + /** + * Takes a string and returns it with the first character + * converted to uppercase. + * + * @param word Word to modify + * @return Parameter with its first character converted to uppercase + */ + public static String upcaseFirst(final String word) { + return word.substring(0, 1).toUpperCase() + word.substring(1); + } }