config: render EnumSet as checkboxes
This commit is contained in:
@@ -69,13 +69,6 @@ public @interface ConfigItem
|
|||||||
|
|
||||||
boolean parse() default false;
|
boolean parse() default false;
|
||||||
|
|
||||||
/**
|
|
||||||
* For Config items that have a value of multiple enums,
|
|
||||||
*
|
|
||||||
* @return the number of rows that are display in the item without having to scroll.
|
|
||||||
*/
|
|
||||||
int displayRows() default 2;
|
|
||||||
|
|
||||||
Class<?> clazz() default void.class;
|
Class<?> clazz() default void.class;
|
||||||
|
|
||||||
String method() default "";
|
String method() default "";
|
||||||
|
|||||||
@@ -534,7 +534,14 @@ public class ConfigManager
|
|||||||
EnumSet enumSet = EnumSet.noneOf(enumClass);
|
EnumSet enumSet = EnumSet.noneOf(enumClass);
|
||||||
for (String s : splitStr)
|
for (String s : splitStr)
|
||||||
{
|
{
|
||||||
enumSet.add(Enum.valueOf(enumClass, s.replace("[", "").replace("]", "")));
|
try
|
||||||
|
{
|
||||||
|
enumSet.add(Enum.valueOf(enumClass, s.replace("[", "").replace("]", "")));
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException ignore)
|
||||||
|
{
|
||||||
|
return EnumSet.noneOf(enumClass);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return enumSet;
|
return enumSet;
|
||||||
}
|
}
|
||||||
@@ -617,6 +624,11 @@ public class ConfigManager
|
|||||||
}
|
}
|
||||||
if (object instanceof EnumSet)
|
if (object instanceof EnumSet)
|
||||||
{
|
{
|
||||||
|
if (((EnumSet) object).size() == 0)
|
||||||
|
{
|
||||||
|
return getElementType((EnumSet) object).getCanonicalName() + "{}";
|
||||||
|
}
|
||||||
|
|
||||||
return ((EnumSet) object).toArray()[0].getClass().getCanonicalName() + "{" + object.toString() + "}";
|
return ((EnumSet) object).toArray()[0].getClass().getCanonicalName() + "{" + object.toString() + "}";
|
||||||
}
|
}
|
||||||
if (object instanceof Number)
|
if (object instanceof Number)
|
||||||
@@ -626,6 +638,15 @@ public class ConfigManager
|
|||||||
return object.toString();
|
return object.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends Enum<T>> Class<T> getElementType(EnumSet<T> enumSet)
|
||||||
|
{
|
||||||
|
if (enumSet.isEmpty())
|
||||||
|
{
|
||||||
|
enumSet = EnumSet.complementOf(enumSet);
|
||||||
|
}
|
||||||
|
return enumSet.iterator().next().getDeclaringClass();
|
||||||
|
}
|
||||||
|
|
||||||
public void sendConfig()
|
public void sendConfig()
|
||||||
{
|
{
|
||||||
boolean changed;
|
boolean changed;
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ package net.runelite.client.plugins.config;
|
|||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.FocusAdapter;
|
import java.awt.event.FocusAdapter;
|
||||||
@@ -65,7 +65,6 @@ import javax.swing.JSpinner;
|
|||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.ListSelectionModel;
|
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.SpinnerModel;
|
import javax.swing.SpinnerModel;
|
||||||
import javax.swing.SpinnerNumberModel;
|
import javax.swing.SpinnerNumberModel;
|
||||||
@@ -361,7 +360,6 @@ class ConfigPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Boolean parse(ConfigItem item, String value)
|
private Boolean parse(ConfigItem item, String value)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -843,9 +841,6 @@ class ConfigPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
else if (cid.getType() == EnumSet.class)
|
else if (cid.getType() == EnumSet.class)
|
||||||
{
|
{
|
||||||
|
|
||||||
int displayRows = cid.getItem().displayRows();
|
|
||||||
|
|
||||||
Class enumType = cid.getItem().enumClass();
|
Class enumType = cid.getItem().enumClass();
|
||||||
|
|
||||||
EnumSet enumSet = configManager.getConfiguration(cd.getGroup().value(),
|
EnumSet enumSet = configManager.getConfiguration(cd.getGroup().value(),
|
||||||
@@ -854,37 +849,25 @@ class ConfigPanel extends PluginPanel
|
|||||||
{
|
{
|
||||||
enumSet = EnumSet.noneOf(enumType);
|
enumSet = EnumSet.noneOf(enumType);
|
||||||
}
|
}
|
||||||
JList jList = new JList(enumType.getEnumConstants());
|
|
||||||
jList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
||||||
|
|
||||||
if (!enumSet.isEmpty() && enumSet.size() > 1)
|
JPanel enumsetLayout = new JPanel(new GridLayout(0, 2));
|
||||||
|
List<JCheckBox> jcheckboxes = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object obj : enumType.getEnumConstants())
|
||||||
{
|
{
|
||||||
int[] selected = new int[enumSet.size()];
|
String option = String.valueOf(obj).toLowerCase().replace("_", " ");
|
||||||
for (int i = 0; i < enumSet.size(); i++)
|
|
||||||
{
|
|
||||||
if (enumSet.contains(EnumSet.allOf(enumType).toArray()[i]))
|
|
||||||
{
|
|
||||||
selected[i] = Lists.newArrayList(EnumSet.allOf(enumType)).indexOf(enumSet.toArray()[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jList.setSelectedIndices(selected);
|
|
||||||
}
|
|
||||||
if (enumSet.size() == 1)
|
|
||||||
{
|
|
||||||
enumSet.forEach(anObject -> jList.setSelectedValue(anObject, true));
|
|
||||||
}
|
|
||||||
jList.setVisibleRowCount(displayRows);
|
|
||||||
jList.setPrototypeCellValue("XXXXXXXXXX");
|
|
||||||
jList.setCellRenderer(new ComboBoxListRenderer());
|
|
||||||
jList.setLayoutOrientation(JList.VERTICAL);
|
|
||||||
jList.setSelectionBackground(Color.decode("708090"));
|
|
||||||
jList.addListSelectionListener(e -> changeConfiguration(jList, cd, cid));
|
|
||||||
JScrollPane jScrollPane = new JScrollPane();
|
|
||||||
jScrollPane.setViewportView(jList);
|
|
||||||
jScrollPane.setViewportBorder(BorderFactory.createLoweredSoftBevelBorder());
|
|
||||||
|
|
||||||
item.add(jScrollPane, BorderLayout.SOUTH);
|
JCheckBox checkbox = new JCheckBox(option);
|
||||||
|
checkbox.setBackground(ColorScheme.LIGHT_GRAY_COLOR);
|
||||||
|
checkbox.setSelected(enumSet.contains(obj));
|
||||||
|
jcheckboxes.add(checkbox);
|
||||||
|
|
||||||
|
enumsetLayout.add(checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
jcheckboxes.forEach(checkbox -> checkbox.addActionListener(ae -> changeConfiguration(jcheckboxes, cd, cid)));
|
||||||
|
|
||||||
|
item.add(enumsetLayout, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
JPanel titleSection = titleSectionWidgets.get(cid.getItem().titleSection());
|
JPanel titleSection = titleSectionWidgets.get(cid.getItem().titleSection());
|
||||||
@@ -938,6 +921,32 @@ class ConfigPanel extends PluginPanel
|
|||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void changeConfiguration(List<JCheckBox> components, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
||||||
|
{
|
||||||
|
Class<? extends Enum> enumType = cid.getItem().enumClass();
|
||||||
|
EnumSet enumSet = configManager.getConfiguration(cd.getGroup().value(),
|
||||||
|
cid.getItem().keyName(), EnumSet.class);
|
||||||
|
if (enumSet == null)
|
||||||
|
{
|
||||||
|
//noinspection unchecked
|
||||||
|
enumSet = EnumSet.noneOf(enumType);
|
||||||
|
}
|
||||||
|
enumSet.clear();
|
||||||
|
|
||||||
|
EnumSet finalEnumSet = enumSet;
|
||||||
|
|
||||||
|
//noinspection unchecked
|
||||||
|
components.forEach(value ->
|
||||||
|
{
|
||||||
|
if (value.isSelected())
|
||||||
|
{
|
||||||
|
finalEnumSet.add(Enum.valueOf(cid.getItem().enumClass(), String.valueOf(value.getText()).toUpperCase().replace(" ", "_")));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
||||||
|
}
|
||||||
|
|
||||||
private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
private void changeConfiguration(Component component, ConfigDescriptor cd, ConfigItemDescriptor cid)
|
||||||
{
|
{
|
||||||
final ConfigItem configItem = cid.getItem();
|
final ConfigItem configItem = cid.getItem();
|
||||||
@@ -985,27 +994,6 @@ class ConfigPanel extends PluginPanel
|
|||||||
JComboBox jComboBox = (JComboBox) component;
|
JComboBox jComboBox = (JComboBox) component;
|
||||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), ((Enum) jComboBox.getSelectedItem()).name());
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), ((Enum) jComboBox.getSelectedItem()).name());
|
||||||
}
|
}
|
||||||
else if (component instanceof JList)
|
|
||||||
{
|
|
||||||
JList jList = (JList) component;
|
|
||||||
|
|
||||||
Class<? extends Enum> enumType = cid.getItem().enumClass();
|
|
||||||
EnumSet enumSet = configManager.getConfiguration(cd.getGroup().value(),
|
|
||||||
cid.getItem().keyName(), EnumSet.class);
|
|
||||||
if (enumSet == null)
|
|
||||||
{
|
|
||||||
//noinspection unchecked
|
|
||||||
enumSet = EnumSet.noneOf(enumType);
|
|
||||||
}
|
|
||||||
enumSet.clear();
|
|
||||||
|
|
||||||
EnumSet finalEnumSet = enumSet;
|
|
||||||
//noinspection unchecked
|
|
||||||
jList.getSelectedValuesList().forEach(value ->
|
|
||||||
finalEnumSet.add(Enum.valueOf(cid.getItem().enumClass(), value.toString())));
|
|
||||||
|
|
||||||
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), finalEnumSet);
|
|
||||||
}
|
|
||||||
else if (component instanceof HotkeyButton)
|
else if (component instanceof HotkeyButton)
|
||||||
{
|
{
|
||||||
HotkeyButton hotkeyButton = (HotkeyButton) component;
|
HotkeyButton hotkeyButton = (HotkeyButton) component;
|
||||||
|
|||||||
@@ -482,42 +482,60 @@ public class PlayerIndicatorsPlugin extends Plugin
|
|||||||
if (this.highlightOwnPlayer)
|
if (this.highlightOwnPlayer)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.SELF, config.getOwnPlayerColor());
|
relationColorHashMap.put(PlayerRelation.SELF, config.getOwnPlayerColor());
|
||||||
locationHashMap.put(PlayerRelation.SELF, EnumSet.copyOf(config.selfIndicatorModes()).toArray());
|
if (config.selfIndicatorModes() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.SELF, EnumSet.copyOf(config.selfIndicatorModes()).toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.highlightFriends = config.highlightFriends();
|
this.highlightFriends = config.highlightFriends();
|
||||||
if (this.highlightFriends)
|
if (this.highlightFriends)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.FRIEND, config.getFriendColor());
|
relationColorHashMap.put(PlayerRelation.FRIEND, config.getFriendColor());
|
||||||
locationHashMap.put(PlayerRelation.FRIEND, config.friendIndicatorMode().toArray());
|
if (config.friendIndicatorMode() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.FRIEND, config.friendIndicatorMode().toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.highlightClan = config.highlightClan();
|
this.highlightClan = config.highlightClan();
|
||||||
if (this.highlightClan)
|
if (this.highlightClan)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.CLAN, config.getClanColor());
|
relationColorHashMap.put(PlayerRelation.CLAN, config.getClanColor());
|
||||||
locationHashMap.put(PlayerRelation.CLAN, config.clanIndicatorModes().toArray());
|
if (config.clanIndicatorModes() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.CLAN, config.clanIndicatorModes().toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.highlightTeam = config.highlightTeamMembers();
|
this.highlightTeam = config.highlightTeamMembers();
|
||||||
if (this.highlightTeam)
|
if (this.highlightTeam)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.TEAM, config.getTeamcolor());
|
relationColorHashMap.put(PlayerRelation.TEAM, config.getTeamcolor());
|
||||||
locationHashMap.put(PlayerRelation.TEAM, config.teamIndicatorModes().toArray());
|
if (config.teamIndicatorModes() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.TEAM, config.teamIndicatorModes().toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.highlightOther = config.highlightOtherPlayers();
|
this.highlightOther = config.highlightOtherPlayers();
|
||||||
if (this.highlightOther)
|
if (this.highlightOther)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.OTHER, config.getOtherColor());
|
relationColorHashMap.put(PlayerRelation.OTHER, config.getOtherColor());
|
||||||
locationHashMap.put(PlayerRelation.OTHER, EnumSet.copyOf(config.otherIndicatorModes()).toArray());
|
if (config.otherIndicatorModes() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.OTHER, EnumSet.copyOf(config.otherIndicatorModes()).toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.highlightTargets = config.highlightTargets();
|
this.highlightTargets = config.highlightTargets();
|
||||||
if (this.highlightTargets)
|
if (this.highlightTargets)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.TARGET, config.getTargetsColor());
|
relationColorHashMap.put(PlayerRelation.TARGET, config.getTargetsColor());
|
||||||
locationHashMap.put(PlayerRelation.TARGET, config.targetsIndicatorModes().toArray());
|
if (config.targetsIndicatorModes() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.TARGET, config.targetsIndicatorModes().toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.highlightCallers = config.highlightCallers();
|
this.highlightCallers = config.highlightCallers();
|
||||||
@@ -527,7 +545,10 @@ public class PlayerIndicatorsPlugin extends Plugin
|
|||||||
|
|
||||||
this.configCallers = config.callers();
|
this.configCallers = config.callers();
|
||||||
relationColorHashMap.put(PlayerRelation.CALLER, config.callerColor());
|
relationColorHashMap.put(PlayerRelation.CALLER, config.callerColor());
|
||||||
locationHashMap.put(PlayerRelation.CALLER, config.callerHighlightOptions().toArray());
|
if (config.callerHighlightOptions() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.CALLER, config.callerHighlightOptions().toArray());
|
||||||
|
}
|
||||||
getCallerList();
|
getCallerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +556,10 @@ public class PlayerIndicatorsPlugin extends Plugin
|
|||||||
if (this.highlightCallerTargets)
|
if (this.highlightCallerTargets)
|
||||||
{
|
{
|
||||||
relationColorHashMap.put(PlayerRelation.CALLER_TARGET, config.callerTargetColor());
|
relationColorHashMap.put(PlayerRelation.CALLER_TARGET, config.callerTargetColor());
|
||||||
locationHashMap.put(PlayerRelation.CALLER_TARGET, config.callerTargetHighlightOptions().toArray());
|
if (config.callerTargetHighlightOptions() != null)
|
||||||
|
{
|
||||||
|
locationHashMap.put(PlayerRelation.CALLER_TARGET, config.callerTargetHighlightOptions().toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.showClanRanks = config.showClanRanks();
|
this.showClanRanks = config.showClanRanks();
|
||||||
|
|||||||
Reference in New Issue
Block a user