change config to show buttons, which lead to options rather than all options on one page (#88)
This commit is contained in:
@@ -30,13 +30,8 @@ import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.*;
|
||||
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.config.ConfigDescriptor;
|
||||
import net.runelite.client.config.ConfigItemDescriptor;
|
||||
@@ -53,6 +48,8 @@ public class ConfigPanel extends PluginPanel
|
||||
|
||||
private final RuneLite runelite = RuneLite.getRunelite();
|
||||
|
||||
private JScrollPane scrollPane;
|
||||
|
||||
public ConfigPanel()
|
||||
{
|
||||
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
|
||||
@@ -70,7 +67,7 @@ public class ConfigPanel extends PluginPanel
|
||||
|
||||
public void init()
|
||||
{
|
||||
add(createConfigPanel(), BorderLayout.CENTER);
|
||||
add(createConfigPanel(), BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
private Collection<ConfigDescriptor> getConfig()
|
||||
@@ -90,6 +87,7 @@ public class ConfigPanel extends PluginPanel
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
panel.add(new JLabel("Plugin configuration"), BorderLayout.NORTH);
|
||||
|
||||
ConfigManager configManager = runelite.getConfigManager();
|
||||
Collection<ConfigDescriptor> config = getConfig();
|
||||
@@ -97,39 +95,16 @@ public class ConfigPanel extends PluginPanel
|
||||
{
|
||||
JPanel groupPanel = new JPanel();
|
||||
groupPanel.setLayout(new BorderLayout());
|
||||
|
||||
groupPanel.add(new JLabel(cd.getGroup().name()), BorderLayout.NORTH);
|
||||
|
||||
JPanel itemPanel = new JPanel();
|
||||
itemPanel.setLayout(new BoxLayout(itemPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
for (ConfigItemDescriptor cid : cd.getItems())
|
||||
{
|
||||
JPanel item = new JPanel();
|
||||
item.setLayout(new BoxLayout(item, BoxLayout.X_AXIS));
|
||||
item.add(new JLabel(cid.getItem().name()));
|
||||
|
||||
if (cid.getType() == boolean.class)
|
||||
{
|
||||
JCheckBox checkbox = new JCheckBox();
|
||||
checkbox.setSelected(Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
|
||||
checkbox.addActionListener(ae -> changeConfiguration(ae, checkbox, cd, cid));
|
||||
|
||||
item.add(checkbox);
|
||||
}
|
||||
|
||||
itemPanel.add(item);
|
||||
}
|
||||
|
||||
groupPanel.add(itemPanel, BorderLayout.CENTER);
|
||||
JButton viewGroupItemsButton = new JButton(cd.getGroup().name());
|
||||
viewGroupItemsButton.addActionListener(ae -> openGroupConfigPanel(cd, configManager));
|
||||
groupPanel.add(viewGroupItemsButton, BorderLayout.NORTH);
|
||||
panel.add(groupPanel);
|
||||
}
|
||||
|
||||
//Make the panel scrollable
|
||||
JScrollPane scrollPane = new JScrollPane(panel);
|
||||
scrollPane = new JScrollPane(panel);
|
||||
scrollPane.setBorder(BorderFactory.createEmptyBorder());
|
||||
scrollPane.getVerticalScrollBar().setUnitIncrement(16); //Otherwise scrollspeed is really slow
|
||||
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
@@ -139,4 +114,44 @@ public class ConfigPanel extends PluginPanel
|
||||
configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), "" + checkbox.isSelected());
|
||||
}
|
||||
|
||||
private void openGroupConfigPanel(ConfigDescriptor cd, ConfigManager configManager)
|
||||
{
|
||||
JPanel itemPanel = new JPanel();
|
||||
itemPanel.setLayout(new BoxLayout(itemPanel, BoxLayout.Y_AXIS));
|
||||
itemPanel.add(new JLabel(cd.getGroup().name() + " Configuration"), BorderLayout.NORTH);
|
||||
|
||||
for (ConfigItemDescriptor cid : cd.getItems())
|
||||
{
|
||||
JPanel item = new JPanel();
|
||||
item.setLayout(new BoxLayout(item, BoxLayout.X_AXIS));
|
||||
item.add(new JLabel(cid.getItem().name()));
|
||||
|
||||
if (cid.getType() == boolean.class)
|
||||
{
|
||||
JCheckBox checkbox = new JCheckBox();
|
||||
checkbox.setSelected(Boolean.parseBoolean(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
|
||||
checkbox.addActionListener(ae -> changeConfiguration(ae, checkbox, cd, cid));
|
||||
|
||||
item.add(checkbox);
|
||||
}
|
||||
|
||||
itemPanel.add(item);
|
||||
}
|
||||
|
||||
JButton backButton = new JButton("Back");
|
||||
backButton.addActionListener(this::getBackButtonListener);
|
||||
itemPanel.add(backButton, BorderLayout.NORTH);
|
||||
|
||||
removeAll();
|
||||
updateUI();
|
||||
add(itemPanel, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
public void getBackButtonListener(ActionEvent e)
|
||||
{
|
||||
removeAll();
|
||||
updateUI();
|
||||
|
||||
add(scrollPane, BorderLayout.NORTH);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user