client: format enum config options as "Config Opt" instead of CONFIG_OPT

This commit is contained in:
Lotto
2019-05-12 16:08:14 +02:00
parent 869fa9d93d
commit 69e57c9a61
3 changed files with 38 additions and 3 deletions

View File

@@ -492,7 +492,7 @@ public class ConfigPanel extends PluginPanel
{
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)
{
@@ -503,7 +503,7 @@ public class ConfigPanel extends PluginPanel
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);

View File

@@ -31,6 +31,7 @@ import javax.swing.JList;
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.
@@ -57,7 +58,16 @@ public final class ComboBoxListRenderer extends JLabel implements ListCellRender
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;

View File

@@ -31,6 +31,7 @@ import com.google.common.base.Splitter;
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.
@@ -159,4 +160,28 @@ public class Text
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;
}
}