Skip to content

Commit

Permalink
client: format enum config options as "Config Opt" instead of CONFIG_OPT
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderhenne committed May 14, 2019
1 parent 869fa9d commit 69e57c9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Expand Up @@ -492,7 +492,7 @@ public void windowClosing(WindowEvent e)
{
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
box.setSelectedItem(selectedItem);
box.setToolTipText(selectedItem.toString());
box.setToolTipText(Text.titleCase(selectedItem));
}
catch (IllegalArgumentException ex)
{
Expand All @@ -503,7 +503,7 @@ public void windowClosing(WindowEvent e)
if (e.getStateChange() == ItemEvent.SELECTED)
{
changeConfiguration(listItem, config, box, cd, cid);
box.setToolTipText(box.getSelectedItem().toString());
box.setToolTipText(Text.titleCase((Enum) box.getSelectedItem()));
}
});
item.add(box, BorderLayout.EAST);
Expand Down
Expand Up @@ -31,6 +31,7 @@
import javax.swing.ListCellRenderer;
import javax.swing.border.EmptyBorder;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.util.Text;

/**
* A custom list renderer to avoid substance's weird coloring.
Expand All @@ -57,7 +58,16 @@ public Component getListCellRendererComponent(JList list, Object o, int index, b

setBorder(new EmptyBorder(5, 5, 5, 0));

String text = o.toString();
String text;
if (o instanceof Enum)
{
text = Text.titleCase((Enum) o);
}
else
{
text = o.toString();
}

setText(text);

return this;
Expand Down
25 changes: 25 additions & 0 deletions runelite-client/src/main/java/net/runelite/client/util/Text.java
Expand Up @@ -31,6 +31,7 @@
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.text.WordUtils;

/**
* A set of utilities to use when dealing with text.
Expand Down Expand Up @@ -159,4 +160,28 @@ public static String sanitize(String name)
String cleaned = name.contains("<img") ? name.substring(name.lastIndexOf('>') + 1) : name;
return cleaned.replace('\u00A0', ' ');
}

/**
* If passed in enum doesn't implement its own toString,
* converts enum name format from THIS_FORMAT to This Format.
*
* @param o an enum
* @return the enum's name in title case,
* or if it overrides toString,
* the value returned by toString
*/
public static String titleCase(Enum o)
{
String toString = o.toString();

// .toString() returns the value of .name() if not overridden
if (o.name().equals(toString))
{
return WordUtils
.capitalize(toString.toLowerCase(), '_')
.replace("_", " ");
}

return toString;
}
}

0 comments on commit 69e57c9

Please sign in to comment.