|
|
|
|
@@ -24,15 +24,15 @@
|
|
|
|
|
*/
|
|
|
|
|
package net.runelite.client.plugins.config;
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.MoreObjects;
|
|
|
|
|
import com.google.common.base.Splitter;
|
|
|
|
|
import com.google.common.base.Strings;
|
|
|
|
|
import com.google.common.collect.ComparisonChain;
|
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
|
import com.google.common.primitives.Ints;
|
|
|
|
|
import java.awt.BasicStroke;
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
|
import java.awt.Color;
|
|
|
|
|
import java.awt.Component;
|
|
|
|
|
import java.awt.Container;
|
|
|
|
|
import java.awt.Dimension;
|
|
|
|
|
import java.awt.Font;
|
|
|
|
|
import java.awt.Graphics;
|
|
|
|
|
@@ -46,14 +46,13 @@ import java.awt.event.MouseEvent;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
|
import javax.swing.BoxLayout;
|
|
|
|
|
@@ -63,7 +62,6 @@ import javax.swing.JCheckBox;
|
|
|
|
|
import javax.swing.JComboBox;
|
|
|
|
|
import javax.swing.JFormattedTextField;
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
import javax.swing.JList;
|
|
|
|
|
import javax.swing.JMenuItem;
|
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
@@ -73,16 +71,17 @@ import javax.swing.JSeparator;
|
|
|
|
|
import javax.swing.JSlider;
|
|
|
|
|
import javax.swing.JSpinner;
|
|
|
|
|
import javax.swing.JTextArea;
|
|
|
|
|
import javax.swing.ListCellRenderer;
|
|
|
|
|
import javax.swing.ListSelectionModel;
|
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
import javax.swing.ScrollPaneConstants;
|
|
|
|
|
import javax.swing.SpinnerModel;
|
|
|
|
|
import javax.swing.SpinnerNumberModel;
|
|
|
|
|
import javax.swing.SwingConstants;
|
|
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
|
import javax.swing.border.CompoundBorder;
|
|
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
|
import javax.swing.border.MatteBorder;
|
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
|
import javax.swing.plaf.basic.BasicSpinnerUI;
|
|
|
|
|
import javax.swing.text.JTextComponent;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import net.runelite.api.events.ConfigButtonClicked;
|
|
|
|
|
@@ -120,11 +119,11 @@ import net.runelite.client.ui.components.ToggleButton;
|
|
|
|
|
import net.runelite.client.ui.components.colorpicker.ColorPickerManager;
|
|
|
|
|
import net.runelite.client.ui.components.colorpicker.RuneliteColorPicker;
|
|
|
|
|
import net.runelite.client.util.ColorUtil;
|
|
|
|
|
import net.runelite.client.util.DeferredDocumentChangedListener;
|
|
|
|
|
import net.runelite.client.util.ImageUtil;
|
|
|
|
|
import net.runelite.client.util.LinkBrowser;
|
|
|
|
|
import net.runelite.client.util.SwingUtil;
|
|
|
|
|
import net.runelite.client.util.Text;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
class ConfigPanel extends PluginPanel
|
|
|
|
|
@@ -142,7 +141,6 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
private final FixedWidthPanel mainPanel;
|
|
|
|
|
private final JLabel title;
|
|
|
|
|
private final PluginToggleButton pluginToggle;
|
|
|
|
|
private final ListCellRenderer<Enum<?>> listCellRenderer = new ComboBoxListRenderer<>();
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
private PluginListPanel pluginList;
|
|
|
|
|
@@ -450,7 +448,7 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
|
|
|
|
|
for (ConfigItemDescriptor cid : cd.getItems())
|
|
|
|
|
{
|
|
|
|
|
if (cid.getItem().hidden())
|
|
|
|
|
if (!hideUnhide(cid))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
@@ -469,100 +467,6 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
if (cid.getType() == Button.class)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
item.add(createButton(cd, cid));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.error("Adding action listener failed: {}", ex.getMessage());
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == boolean.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createCheckbox(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == int.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createIntSpinner(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == double.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createDoubleSpinner(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == String.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createTextField(cd, cid), BorderLayout.SOUTH);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == Color.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createColorPicker(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == Dimension.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createDimension(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() instanceof Class && ((Class<?>) cid.getType()).isEnum())
|
|
|
|
|
{
|
|
|
|
|
item.add(createComboBox(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createKeybind(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else if (cid.getType() instanceof ParameterizedType)
|
|
|
|
|
{
|
|
|
|
|
ParameterizedType parameterizedType = (ParameterizedType) cid.getType();
|
|
|
|
|
if (parameterizedType.getRawType() == Set.class)
|
|
|
|
|
{
|
|
|
|
|
item.add(createList(cd, cid), BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JPanel section = sectionWidgets.get(cid.getItem().section());
|
|
|
|
|
if (section == null)
|
|
|
|
|
{
|
|
|
|
|
topLevelPanels.put(cid, item);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
section.add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topLevelPanels.values().forEach(mainPanel::add);
|
|
|
|
|
|
|
|
|
|
JButton resetButton = new JButton("Reset");
|
|
|
|
|
resetButton.addActionListener((e) ->
|
|
|
|
|
{
|
|
|
|
|
final int result = JOptionPane.showOptionDialog(resetButton, "Are you sure you want to reset this plugin's configuration?",
|
|
|
|
|
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
|
|
|
|
|
null, new String[]{"Yes", "No"}, "No");
|
|
|
|
|
|
|
|
|
|
if (result == JOptionPane.YES_OPTION)
|
|
|
|
|
{
|
|
|
|
|
configManager.setDefaultConfiguration(pluginConfig.getConfig(), true);
|
|
|
|
|
|
|
|
|
|
// Reset non-config panel keys
|
|
|
|
|
Plugin plugin = pluginConfig.getPlugin();
|
|
|
|
|
if (plugin != null)
|
|
|
|
|
{
|
|
|
|
|
plugin.resetConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rebuild();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mainPanel.add(resetButton);
|
|
|
|
|
|
|
|
|
|
JButton backButton = new JButton("Back");
|
|
|
|
|
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
|
|
|
|
mainPanel.add(backButton);
|
|
|
|
|
|
|
|
|
|
revalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JButton createButton(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
{
|
|
|
|
|
ConfigItem cidItem = cid.getItem();
|
|
|
|
|
JButton button = new JButton(cidItem.name());
|
|
|
|
|
@@ -573,22 +477,44 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
event.setKey(cid.getItem().keyName());
|
|
|
|
|
eventBus.post(event);
|
|
|
|
|
});
|
|
|
|
|
return button;
|
|
|
|
|
item.add(button);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.error("Adding action listener failed: {}", ex.getMessage());
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JCheckBox createCheckbox(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType() == boolean.class)
|
|
|
|
|
{
|
|
|
|
|
JCheckBox checkbox = new ToggleButton();
|
|
|
|
|
checkbox.setPreferredSize(new Dimension(26, 25));
|
|
|
|
|
checkbox.setSelected(Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName())));
|
|
|
|
|
checkbox.addActionListener(ae -> changeConfiguration(checkbox, cd, cid));
|
|
|
|
|
return checkbox;
|
|
|
|
|
|
|
|
|
|
item.add(checkbox, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSpinner createIntSpinner(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType().isAssignableFrom(Consumer.class))
|
|
|
|
|
{
|
|
|
|
|
item.remove(configEntryName);
|
|
|
|
|
|
|
|
|
|
JButton button = new JButton(cid.getItem().name());
|
|
|
|
|
button.addActionListener((e) ->
|
|
|
|
|
{
|
|
|
|
|
log.debug("Running consumer: {}.{}", cd.getGroup().value(), cid.getItem().keyName());
|
|
|
|
|
configManager.getConsumer(cd.getGroup().value(), cid.getItem().keyName()).accept(pluginConfig.getPlugin());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
item.add(button, BorderLayout.CENTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cid.getType() == int.class)
|
|
|
|
|
{
|
|
|
|
|
int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
|
|
|
|
|
|
|
|
|
|
Units units = cid.getUnits();
|
|
|
|
|
Range range = cid.getRange();
|
|
|
|
|
int min = 0, max = Integer.MAX_VALUE;
|
|
|
|
|
if (range != null)
|
|
|
|
|
@@ -600,6 +526,108 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
// Config may previously have been out of range
|
|
|
|
|
value = Ints.constrainToRange(value, min, max);
|
|
|
|
|
|
|
|
|
|
if (max < Integer.MAX_VALUE)
|
|
|
|
|
{
|
|
|
|
|
JLabel sliderValueLabel = new JLabel();
|
|
|
|
|
JSlider slider = new JSlider(min, max, value);
|
|
|
|
|
slider.setBackground(ColorScheme.DARK_GRAY_COLOR);
|
|
|
|
|
if (units != null)
|
|
|
|
|
{
|
|
|
|
|
sliderValueLabel.setText(slider.getValue() + units.value());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sliderValueLabel.setText(String.valueOf(slider.getValue()));
|
|
|
|
|
}
|
|
|
|
|
slider.setPreferredSize(new Dimension(80, 25));
|
|
|
|
|
slider.addChangeListener((l) ->
|
|
|
|
|
{
|
|
|
|
|
if (units != null)
|
|
|
|
|
{
|
|
|
|
|
sliderValueLabel.setText(slider.getValue() + units.value());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sliderValueLabel.setText(String.valueOf(slider.getValue()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!slider.getValueIsAdjusting())
|
|
|
|
|
{
|
|
|
|
|
changeConfiguration(slider, cd, cid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
SpinnerModel model = new SpinnerNumberModel(value, min, max, 1);
|
|
|
|
|
JSpinner spinner = new JSpinner(model);
|
|
|
|
|
Component editor = spinner.getEditor();
|
|
|
|
|
JFormattedTextField spinnerTextField = ((JSpinner.DefaultEditor) editor).getTextField();
|
|
|
|
|
spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
|
|
|
|
|
spinner.setUI(new BasicSpinnerUI()
|
|
|
|
|
{
|
|
|
|
|
protected Component createNextButton()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Component createPreviousButton()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
JPanel subPanel = new JPanel();
|
|
|
|
|
subPanel.setPreferredSize(new Dimension(110, 25));
|
|
|
|
|
subPanel.setLayout(new BorderLayout());
|
|
|
|
|
|
|
|
|
|
spinner.addChangeListener((ce) ->
|
|
|
|
|
{
|
|
|
|
|
changeConfiguration(spinner, cd, cid);
|
|
|
|
|
|
|
|
|
|
if (units != null)
|
|
|
|
|
{
|
|
|
|
|
sliderValueLabel.setText(spinner.getValue() + units.value());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sliderValueLabel.setText(String.valueOf(spinner.getValue()));
|
|
|
|
|
}
|
|
|
|
|
slider.setValue((Integer) spinner.getValue());
|
|
|
|
|
|
|
|
|
|
subPanel.add(sliderValueLabel, BorderLayout.WEST);
|
|
|
|
|
subPanel.add(slider, BorderLayout.EAST);
|
|
|
|
|
subPanel.remove(spinner);
|
|
|
|
|
|
|
|
|
|
validate();
|
|
|
|
|
repaint();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sliderValueLabel.addMouseListener(new MouseAdapter()
|
|
|
|
|
{
|
|
|
|
|
public void mouseClicked(MouseEvent e)
|
|
|
|
|
{
|
|
|
|
|
spinner.setValue(slider.getValue());
|
|
|
|
|
|
|
|
|
|
subPanel.remove(sliderValueLabel);
|
|
|
|
|
subPanel.remove(slider);
|
|
|
|
|
subPanel.add(spinner, BorderLayout.EAST);
|
|
|
|
|
|
|
|
|
|
validate();
|
|
|
|
|
repaint();
|
|
|
|
|
|
|
|
|
|
final JTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
|
|
|
|
|
tf.requestFocusInWindow();
|
|
|
|
|
SwingUtilities.invokeLater(tf::selectAll);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
subPanel.add(sliderValueLabel, BorderLayout.WEST);
|
|
|
|
|
subPanel.add(slider, BorderLayout.EAST);
|
|
|
|
|
|
|
|
|
|
item.add(subPanel, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SpinnerModel model = new SpinnerNumberModel(value, min, max, 1);
|
|
|
|
|
JSpinner spinner = new JSpinner(model);
|
|
|
|
|
Component editor = spinner.getEditor();
|
|
|
|
|
@@ -607,16 +635,16 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
|
|
|
|
|
spinner.addChangeListener(ce -> changeConfiguration(spinner, cd, cid));
|
|
|
|
|
|
|
|
|
|
Units units = cid.getUnits();
|
|
|
|
|
if (units != null)
|
|
|
|
|
{
|
|
|
|
|
spinnerTextField.setFormatterFactory(new UnitFormatterFactory(units));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return spinner;
|
|
|
|
|
item.add(spinner, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JSpinner createDoubleSpinner(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
else if (cid.getType() == double.class)
|
|
|
|
|
{
|
|
|
|
|
double value = configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName(), double.class);
|
|
|
|
|
|
|
|
|
|
@@ -626,10 +654,11 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
JFormattedTextField spinnerTextField = ((JSpinner.DefaultEditor) editor).getTextField();
|
|
|
|
|
spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
|
|
|
|
|
spinner.addChangeListener(ce -> changeConfiguration(spinner, cd, cid));
|
|
|
|
|
return spinner;
|
|
|
|
|
|
|
|
|
|
item.add(spinner, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JTextComponent createTextField(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType() == String.class)
|
|
|
|
|
{
|
|
|
|
|
JTextComponent textField;
|
|
|
|
|
|
|
|
|
|
@@ -657,10 +686,36 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return textField;
|
|
|
|
|
if (cid.getItem().parse())
|
|
|
|
|
{
|
|
|
|
|
JLabel parsingLabel = new JLabel();
|
|
|
|
|
parsingLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
|
|
parsingLabel.setPreferredSize(new Dimension(PANEL_WIDTH, 15));
|
|
|
|
|
|
|
|
|
|
DeferredDocumentChangedListener listener = new DeferredDocumentChangedListener();
|
|
|
|
|
listener.addChangeListener(e ->
|
|
|
|
|
{
|
|
|
|
|
if (cid.getItem().parse())
|
|
|
|
|
{
|
|
|
|
|
parseLabel(cid.getItem(), parsingLabel, textField.getText());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
textField.getDocument().addDocumentListener(listener);
|
|
|
|
|
|
|
|
|
|
item.add(configEntryName, BorderLayout.NORTH);
|
|
|
|
|
item.add(textField, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseLabel(cid.getItem(), parsingLabel, textField.getText());
|
|
|
|
|
item.add(parsingLabel, BorderLayout.SOUTH);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
item.add(textField, BorderLayout.SOUTH);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ColorJButton createColorPicker(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType() == Color.class)
|
|
|
|
|
{
|
|
|
|
|
Color existing = configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName(), Color.class);
|
|
|
|
|
|
|
|
|
|
@@ -700,10 +755,10 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return colorPickerBtn;
|
|
|
|
|
item.add(colorPickerBtn, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JPanel createDimension(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType() == Dimension.class)
|
|
|
|
|
{
|
|
|
|
|
JPanel dimensionPanel = new JPanel();
|
|
|
|
|
dimensionPanel.setLayout(new BorderLayout());
|
|
|
|
|
@@ -735,10 +790,10 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
dimensionPanel.add(new JLabel(" x "), BorderLayout.CENTER);
|
|
|
|
|
dimensionPanel.add(heightSpinner, BorderLayout.EAST);
|
|
|
|
|
|
|
|
|
|
return dimensionPanel;
|
|
|
|
|
item.add(dimensionPanel, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JComboBox<Enum<?>> createComboBox(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType().isEnum())
|
|
|
|
|
{
|
|
|
|
|
Class<? extends Enum> type = (Class<? extends Enum>) cid.getType();
|
|
|
|
|
|
|
|
|
|
@@ -746,7 +801,7 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
// set renderer prior to calling box.getPreferredSize(), since it will invoke the renderer
|
|
|
|
|
// to build components for each combobox element in order to compute the display size of the
|
|
|
|
|
// combobox
|
|
|
|
|
box.setRenderer(listCellRenderer);
|
|
|
|
|
box.setRenderer(new ComboBoxListRenderer<>());
|
|
|
|
|
box.setPreferredSize(new Dimension(box.getPreferredSize().width, 25));
|
|
|
|
|
box.setForeground(Color.WHITE);
|
|
|
|
|
box.setFocusable(false);
|
|
|
|
|
@@ -759,7 +814,7 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalArgumentException ex)
|
|
|
|
|
{
|
|
|
|
|
log.debug("invalid selected item", ex);
|
|
|
|
|
log.debug("invalid seleced item", ex);
|
|
|
|
|
}
|
|
|
|
|
box.addItemListener(e ->
|
|
|
|
|
{
|
|
|
|
|
@@ -769,11 +824,10 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
box.setToolTipText(Text.titleCase((Enum<?>) box.getSelectedItem()));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return box;
|
|
|
|
|
item.add(box, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private HotkeyButton createKeybind(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class)
|
|
|
|
|
{
|
|
|
|
|
Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(),
|
|
|
|
|
cid.getItem().keyName(),
|
|
|
|
|
@@ -790,35 +844,87 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return button;
|
|
|
|
|
item.add(button, BorderLayout.EAST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JList<Enum<?>> createList(ConfigDescriptor cd, ConfigItemDescriptor cid)
|
|
|
|
|
if (cid.getType() == EnumSet.class)
|
|
|
|
|
{
|
|
|
|
|
ParameterizedType parameterizedType = (ParameterizedType) cid.getType();
|
|
|
|
|
Class<? extends Enum> type = (Class<? extends Enum>) parameterizedType.getActualTypeArguments()[0];
|
|
|
|
|
Set<? extends Enum> set = configManager.getConfiguration(cd.getGroup().value(), null,
|
|
|
|
|
cid.getItem().keyName(), parameterizedType);
|
|
|
|
|
Class enumType = cid.getItem().enumClass();
|
|
|
|
|
|
|
|
|
|
JList<Enum<?>> list = new JList<Enum<?>>(type.getEnumConstants()); // NOPMD: UseDiamondOperator
|
|
|
|
|
list.setCellRenderer(listCellRenderer);
|
|
|
|
|
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
|
|
|
list.setLayoutOrientation(JList.VERTICAL);
|
|
|
|
|
list.setSelectedIndices(
|
|
|
|
|
MoreObjects.firstNonNull(set, Collections.emptySet())
|
|
|
|
|
.stream()
|
|
|
|
|
.mapToInt(e -> ArrayUtils.indexOf(type.getEnumConstants(), e))
|
|
|
|
|
.toArray());
|
|
|
|
|
list.addFocusListener(new FocusAdapter()
|
|
|
|
|
EnumSet enumSet = configManager.getConfiguration(cd.getGroup().value(),
|
|
|
|
|
cid.getItem().keyName(), EnumSet.class);
|
|
|
|
|
if (enumSet == null || enumSet.contains(null))
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void focusLost(FocusEvent e)
|
|
|
|
|
enumSet = EnumSet.noneOf(enumType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JPanel enumsetLayout = new JPanel(new GridLayout(0, 2));
|
|
|
|
|
List<JCheckBox> jcheckboxes = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (Object obj : enumType.getEnumConstants())
|
|
|
|
|
{
|
|
|
|
|
changeConfiguration(list, cd, cid);
|
|
|
|
|
String option = String.valueOf(obj).toLowerCase().replace("_", " ");
|
|
|
|
|
|
|
|
|
|
JCheckBox checkbox = new ToggleButton(option);
|
|
|
|
|
checkbox.setBackground(ColorScheme.DARK_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 section = sectionWidgets.get(cid.getItem().section());
|
|
|
|
|
JPanel title = titleWidgets.get(cid.getItem().title());
|
|
|
|
|
|
|
|
|
|
if (section != null)
|
|
|
|
|
{
|
|
|
|
|
section.add(item);
|
|
|
|
|
}
|
|
|
|
|
else if (title != null)
|
|
|
|
|
{
|
|
|
|
|
title.add(item);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
topLevelPanels.put(cid, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topLevelPanels.values().forEach(mainPanel::add);
|
|
|
|
|
|
|
|
|
|
JButton resetButton = new JButton("Reset");
|
|
|
|
|
resetButton.addActionListener((e) ->
|
|
|
|
|
{
|
|
|
|
|
final int result = JOptionPane.showOptionDialog(resetButton, "Are you sure you want to reset this plugin's configuration?",
|
|
|
|
|
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
|
|
|
|
|
null, new String[]{"Yes", "No"}, "No");
|
|
|
|
|
|
|
|
|
|
if (result == JOptionPane.YES_OPTION)
|
|
|
|
|
{
|
|
|
|
|
configManager.setDefaultConfiguration(pluginConfig.getConfig(), true);
|
|
|
|
|
|
|
|
|
|
// Reset non-config panel keys
|
|
|
|
|
Plugin plugin = pluginConfig.getPlugin();
|
|
|
|
|
if (plugin != null)
|
|
|
|
|
{
|
|
|
|
|
plugin.resetConfiguration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rebuild();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mainPanel.add(resetButton);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
JButton backButton = new JButton("Back");
|
|
|
|
|
backButton.addActionListener(e -> pluginList.getMuxer().popState());
|
|
|
|
|
mainPanel.add(backButton);
|
|
|
|
|
|
|
|
|
|
revalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Boolean parse(ConfigItem item, String value)
|
|
|
|
|
@@ -938,14 +1044,9 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
HotkeyButton hotkeyButton = (HotkeyButton) component;
|
|
|
|
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), hotkeyButton.getValue());
|
|
|
|
|
}
|
|
|
|
|
else if (component instanceof JList)
|
|
|
|
|
{
|
|
|
|
|
JList<?> list = (JList<?>) component;
|
|
|
|
|
List<?> selectedValues = list.getSelectedValuesList();
|
|
|
|
|
|
|
|
|
|
configManager.setConfiguration(cd.getGroup().value(), cid.getItem().keyName(), Sets.newHashSet(selectedValues));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enableDisable(component, cid);
|
|
|
|
|
rebuild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -995,9 +1096,144 @@ class ConfigPanel extends PluginPanel
|
|
|
|
|
return menuItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean hideUnhide(ConfigItemDescriptor cid)
|
|
|
|
|
{
|
|
|
|
|
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
|
|
|
|
|
|
|
|
|
boolean unhide = cid.getItem().hidden();
|
|
|
|
|
boolean hide = !cid.getItem().hide().isEmpty();
|
|
|
|
|
|
|
|
|
|
if (unhide || hide)
|
|
|
|
|
{
|
|
|
|
|
boolean show = false;
|
|
|
|
|
|
|
|
|
|
List<String> itemHide = Splitter
|
|
|
|
|
.onPattern("\\|\\|")
|
|
|
|
|
.trimResults()
|
|
|
|
|
.omitEmptyStrings()
|
|
|
|
|
.splitToList(String.format("%s || %s", cid.getItem().unhide(), cid.getItem().hide()));
|
|
|
|
|
|
|
|
|
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
|
|
|
|
{
|
|
|
|
|
if (itemHide.contains(cid2.getItem().keyName()))
|
|
|
|
|
{
|
|
|
|
|
if (cid2.getType() == boolean.class)
|
|
|
|
|
{
|
|
|
|
|
show = Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
|
|
|
|
|
}
|
|
|
|
|
else if (cid2.getType().isEnum())
|
|
|
|
|
{
|
|
|
|
|
Class<? extends Enum> type = (Class<? extends Enum>) cid2.getType();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().value(), cid2.getItem().keyName()));
|
|
|
|
|
if (!cid.getItem().unhideValue().equals(""))
|
|
|
|
|
{
|
|
|
|
|
List<String> unhideValue = Splitter
|
|
|
|
|
.onPattern("\\|\\|")
|
|
|
|
|
.trimResults()
|
|
|
|
|
.omitEmptyStrings()
|
|
|
|
|
.splitToList(cid.getItem().unhideValue());
|
|
|
|
|
|
|
|
|
|
show = unhideValue.contains(selectedItem.toString());
|
|
|
|
|
}
|
|
|
|
|
else if (!cid.getItem().hideValue().equals(""))
|
|
|
|
|
{
|
|
|
|
|
List<String> hideValue = Splitter
|
|
|
|
|
.onPattern("\\|\\|")
|
|
|
|
|
.trimResults()
|
|
|
|
|
.omitEmptyStrings()
|
|
|
|
|
.splitToList(cid.getItem().hideValue());
|
|
|
|
|
|
|
|
|
|
show = !hideValue.contains(selectedItem.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalArgumentException ignored)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (!unhide || show) && (!hide || !show);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enableDisable(Component component, ConfigItemDescriptor cid)
|
|
|
|
|
{
|
|
|
|
|
ConfigDescriptor cd = pluginConfig.getConfigDescriptor();
|
|
|
|
|
|
|
|
|
|
if (component instanceof JCheckBox)
|
|
|
|
|
{
|
|
|
|
|
JCheckBox checkbox = (JCheckBox) component;
|
|
|
|
|
|
|
|
|
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
|
|
|
|
{
|
|
|
|
|
if (checkbox.isSelected())
|
|
|
|
|
{
|
|
|
|
|
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()))
|
|
|
|
|
{
|
|
|
|
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
|
|
|
|
|
}
|
|
|
|
|
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()))
|
|
|
|
|
{
|
|
|
|
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (component instanceof JComboBox)
|
|
|
|
|
{
|
|
|
|
|
JComboBox jComboBox = (JComboBox) component;
|
|
|
|
|
|
|
|
|
|
for (ConfigItemDescriptor cid2 : cd.getItems())
|
|
|
|
|
{
|
|
|
|
|
String changedVal = ((Enum) jComboBox.getSelectedItem()).name();
|
|
|
|
|
|
|
|
|
|
if (cid2.getItem().enabledBy().contains(cid.getItem().keyName()) && cid2.getItem().enabledByValue().equals(changedVal))
|
|
|
|
|
{
|
|
|
|
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "true");
|
|
|
|
|
}
|
|
|
|
|
else if (cid2.getItem().disabledBy().contains(cid.getItem().keyName()) && cid2.getItem().disabledByValue().equals(changedVal))
|
|
|
|
|
{
|
|
|
|
|
configManager.setConfiguration(cd.getGroup().value(), cid2.getItem().keyName(), "false");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String htmlLabel(String key, String value)
|
|
|
|
|
{
|
|
|
|
|
return "<html><body style = 'color:#a5a5a5'>" + key + ": <span style = 'color:white'>" + value + "</span></body></html>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Component findComponentByName(Component component, String componentName)
|
|
|
|
|
{
|
|
|
|
|
if (component == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (component.getName() != null && component.getName().equalsIgnoreCase(componentName))
|
|
|
|
|
{
|
|
|
|
|
return component;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (component instanceof Container)
|
|
|
|
|
{
|
|
|
|
|
Component[] children = ((Container) component).getComponents();
|
|
|
|
|
for (Component child : children)
|
|
|
|
|
{
|
|
|
|
|
Component found = findComponentByName(child, componentName);
|
|
|
|
|
if (found != null)
|
|
|
|
|
{
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|