Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ackage net.runelite.client.plugins.config;
- import com.google.common.base.Splitter;
- import com.google.common.base.Strings;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.event.FocusAdapter;
- import java.awt.event.FocusEvent;
- import java.awt.event.ItemEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.image.BufferedImage;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.stream.Collectors;
- import javax.swing.BorderFactory;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JColorChooser;
- import javax.swing.JComboBox;
- import javax.swing.JComponent;
- import javax.swing.JFormattedTextField;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JScrollPane;
- import javax.swing.JSpinner;
- import javax.swing.JTextArea;
- import javax.swing.ScrollPaneConstants;
- import javax.swing.SpinnerModel;
- import javax.swing.SpinnerNumberModel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.event.ChangeListener;
- import javax.swing.event.DocumentEvent;
- import javax.swing.event.DocumentListener;
- import javax.swing.text.JTextComponent;
- import lombok.extern.slf4j.Slf4j;
- import net.runelite.client.config.ChatColorConfig;
- import net.runelite.client.config.Config;
- import net.runelite.client.config.ConfigDescriptor;
- import net.runelite.client.config.ConfigGroup;
- import net.runelite.client.config.ConfigItem;
- import net.runelite.client.config.ConfigItemDescriptor;
- import net.runelite.client.config.ConfigManager;
- import net.runelite.client.config.Keybind;
- import net.runelite.client.config.RuneLiteConfig;
- import net.runelite.client.plugins.Plugin;
- import net.runelite.client.plugins.PluginDescriptor;
- import net.runelite.client.plugins.PluginInstantiationException;
- import net.runelite.client.plugins.PluginManager;
- import net.runelite.client.ui.ColorScheme;
- import net.runelite.client.ui.DynamicGridLayout;
- import net.runelite.client.ui.PluginPanel;
- import net.runelite.client.ui.components.ComboBoxListRenderer;
- import net.runelite.client.ui.components.IconButton;
- import net.runelite.client.ui.components.IconTextField;
- import net.runelite.client.util.ImageUtil;
- @Slf4j
- public class ConfigPanel extends PluginPanel
- {
- private static final int SPINNER_FIELD_WIDTH = 6;
- private static final int SCROLLBAR_WIDTH = 17;
- private static final int OFFSET = 6;
- private static final ImageIcon BACK_ICON;
- private static final ImageIcon BACK_ICON_HOVER;
- private static final String RUNELITE_GROUP_NAME = RuneLiteConfig.class.getAnnotation(ConfigGroup.class).value();
- private static final String PINNED_PLUGINS_CONFIG_KEY = "pinnedPlugins";
- private static final String RUNELITE_PLUGIN = "RuneLite";
- private static final String CHAT_COLOR_PLUGIN = "Chat Color";
- private static final Splitter COMMA_SPLITTER = Splitter.on(',');
- private final PluginManager pluginManager;
- private final ConfigManager configManager;
- private final ScheduledExecutorService executorService;
- private final RuneLiteConfig runeLiteConfig;
- private final ChatColorConfig chatColorConfig;
- private final List<PluginListItem> pluginList = new ArrayList<>();
- private final IconTextField searchBar = new IconTextField();
- private final JPanel topPanel;
- private final JPanel mainPanel;
- private final JScrollPane scrollPane;
- private boolean showingPluginList = true;
- private int scrollBarPosition = 0;
- static
- {
- final BufferedImage backIcon = ImageUtil.getResourceStreamFromClass(ConfigPanel.class, "config_back_icon.png");
- BACK_ICON = new ImageIcon(backIcon);
- BACK_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(backIcon, -100));
- }
- ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService,
- RuneLiteConfig runeLiteConfig, ChatColorConfig chatColorConfig)
- {
- super(false);
- this.pluginManager = pluginManager;
- this.configManager = configManager;
- this.executorService = executorService;
- this.runeLiteConfig = runeLiteConfig;
- this.chatColorConfig = chatColorConfig;
- searchBar.setIcon(IconTextField.Icon.SEARCH);
- searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
- searchBar.setBackground(ColorScheme.DARKER_GRAY_COLOR);
- searchBar.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
- searchBar.getDocument().addDocumentListener(new DocumentListener()
- {
- @Override
- public void insertUpdate(DocumentEvent e)
- {
- onSearchBarChanged();
- }
- @Override
- public void removeUpdate(DocumentEvent e)
- {
- onSearchBarChanged();
- }
- @Override
- public void changedUpdate(DocumentEvent e)
- {
- onSearchBarChanged();
- }
- });
- setLayout(new BorderLayout());
- setBackground(ColorScheme.DARK_GRAY_COLOR);
- topPanel = new JPanel();
- topPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- topPanel.setLayout(new BorderLayout(0, OFFSET));
- add(topPanel, BorderLayout.NORTH);
- mainPanel = new FixedWidthPanel();
- mainPanel.setBorder(new EmptyBorder(8, 10, 10, 10));
- mainPanel.setLayout(new DynamicGridLayout(0, 1, 0, 5));
- mainPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
- JPanel northPanel = new FixedWidthPanel();
- northPanel.setLayout(new BorderLayout());
- northPanel.add(mainPanel, BorderLayout.NORTH);
- scrollPane = new JScrollPane(northPanel);
- scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
- add(scrollPane, BorderLayout.CENTER);
- initializePluginList();
- refreshPluginList();
- }
- private void initializePluginList()
- {
- final List<String> pinnedPlugins = getPinnedPluginNames();
- // populate pluginList with all non-hidden plugins
- pluginManager.getPlugins().stream()
- .filter(plugin -> !plugin.getClass().getAnnotation(PluginDescriptor.class).hidden())
- .forEach(plugin ->
- {
- final PluginDescriptor descriptor = plugin.getClass().getAnnotation(PluginDescriptor.class);
- final Config config = pluginManager.getPluginConfigProxy(plugin);
- final ConfigDescriptor configDescriptor = config == null ? null : configManager.getConfigDescriptor(config);
- final PluginListItem listItem = new PluginListItem(this, plugin, descriptor, config, configDescriptor);
- listItem.setPinned(pinnedPlugins.contains(listItem.getName()));
- pluginList.add(listItem);
- });
- // add special entries for core client configurations
- final PluginListItem runeLite = new PluginListItem(this, runeLiteConfig,
- configManager.getConfigDescriptor(runeLiteConfig),
- RUNELITE_PLUGIN, "RuneLite client settings", "client");
- runeLite.setPinned(pinnedPlugins.contains(RUNELITE_PLUGIN));
- pluginList.add(runeLite);
- final PluginListItem chatColor = new PluginListItem(this, chatColorConfig,
- configManager.getConfigDescriptor(chatColorConfig),
- CHAT_COLOR_PLUGIN, "Recolor chat text", "colour", "messages");
- chatColor.setPinned(pinnedPlugins.contains(CHAT_COLOR_PLUGIN));
- pluginList.add(chatColor);
- pluginList.sort(Comparator.comparing(PluginListItem::getName));
- }
- void refreshPluginList()
- {
- // update enabled / disabled status of all items
- pluginList.forEach(listItem ->
- {
- final Plugin plugin = listItem.getPlugin();
- if (plugin != null)
- {
- listItem.setPluginEnabled(pluginManager.isPluginEnabled(plugin));
- }
- });
- if (showingPluginList)
- {
- openConfigList();
- }
- }
- void openConfigList()
- {
- if (showingPluginList)
- {
- scrollBarPosition = scrollPane.getVerticalScrollBar().getValue();
- }
- showingPluginList = true;
- topPanel.removeAll();
- mainPanel.removeAll();
- topPanel.add(searchBar, BorderLayout.CENTER);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement