Search in sources :

Example 1 with ConfigDescriptor

use of net.runelite.client.config.ConfigDescriptor in project runelite by runelite.

the class ConfigPanel method buildConfigButton.

private JButton buildConfigButton(Config config) {
    // Create edit config button and disable it by default
    final JButton editConfigButton = new JButton(new ImageIcon(CONFIG_ICON));
    editConfigButton.setPreferredSize(new Dimension(32, 0));
    editConfigButton.setEnabled(false);
    // If we have configuration proxy enable the button and add edit config listener
    if (config != null) {
        final ConfigDescriptor configDescriptor = configManager.getConfigDescriptor(config);
        final boolean configEmpty = configDescriptor.getItems().stream().allMatch(item -> item.getItem().hidden());
        if (!configEmpty) {
            editConfigButton.addActionListener(ae -> openGroupConfigPanel(config, configDescriptor, configManager));
            editConfigButton.setEnabled(true);
            editConfigButton.setToolTipText("Edit plugin configuration");
        }
    }
    return editConfigButton;
}
Also used : ImageIcon(javax.swing.ImageIcon) JButton(javax.swing.JButton) ConfigDescriptor(net.runelite.client.config.ConfigDescriptor) Dimension(java.awt.Dimension)

Example 2 with ConfigDescriptor

use of net.runelite.client.config.ConfigDescriptor in project runelite by runelite.

the class ConfigPanel method openGroupConfigPanel.

private void openGroupConfigPanel(Config config, ConfigDescriptor cd, ConfigManager configManager) {
    scrollBarPosition = getScrollPane().getVerticalScrollBar().getValue();
    removeAll();
    String name = cd.getGroup().name() + " Configuration";
    JLabel title = new JLabel(name);
    title.setToolTipText(cd.getGroup().description());
    add(title, SwingConstants.CENTER);
    for (ConfigItemDescriptor cid : cd.getItems()) {
        if (cid.getItem().hidden()) {
            continue;
        }
        JPanel item = new JPanel();
        item.setLayout(new BorderLayout());
        name = cid.getItem().name();
        JLabel configEntryName = new JLabel(name);
        configEntryName.setToolTipText("<html>" + name + ":<br>" + cid.getItem().description() + "</html>");
        item.add(configEntryName, BorderLayout.CENTER);
        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(checkbox, cd, cid));
            item.add(checkbox, BorderLayout.EAST);
        }
        if (cid.getType() == int.class) {
            int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName()));
            SpinnerModel model = new SpinnerNumberModel(value, 0, Integer.MAX_VALUE, 1);
            JSpinner spinner = new JSpinner(model);
            Component editor = spinner.getEditor();
            JFormattedTextField spinnerTextField = ((JSpinner.DefaultEditor) editor).getTextField();
            spinnerTextField.setColumns(SPINNER_FIELD_WIDTH);
            spinner.addChangeListener(ce -> changeConfiguration(spinner, cd, cid));
            item.add(spinner, BorderLayout.EAST);
        }
        if (cid.getType() == String.class) {
            JTextField textField = new JTextField("", TEXT_FIELD_WIDTH);
            textField.setText(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName()));
            textField.addFocusListener(new FocusListener() {

                @Override
                public void focusGained(FocusEvent e) {
                }

                @Override
                public void focusLost(FocusEvent e) {
                    changeConfiguration(textField, cd, cid);
                    textField.setToolTipText(textField.getText());
                }
            });
            textField.setToolTipText(textField.getText());
            item.add(textField, BorderLayout.EAST);
        }
        if (cid.getType() == Color.class) {
            JButton colorPicker = new JButton("Pick a color");
            colorPicker.setFocusable(false);
            colorPicker.setBackground(Color.decode(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
            colorPicker.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    final JFrame parent = new JFrame();
                    JColorChooser jColorChooser = new JColorChooser(Color.decode(configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName())));
                    jColorChooser.getSelectionModel().addChangeListener(e1 -> colorPicker.setBackground(jColorChooser.getColor()));
                    parent.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            changeConfiguration(jColorChooser, cd, cid);
                        }
                    });
                    parent.add(jColorChooser);
                    parent.pack();
                    parent.setVisible(true);
                }
            });
            item.add(colorPicker, BorderLayout.EAST);
        }
        if (cid.getType() == Dimension.class) {
            JPanel dimensionPanel = new JPanel();
            dimensionPanel.setLayout(new BorderLayout());
            String str = configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName());
            String[] splitStr = str.split("x");
            int width = Integer.parseInt(splitStr[0]);
            int height = Integer.parseInt(splitStr[1]);
            SpinnerModel widthModel = new SpinnerNumberModel(width, 0, Integer.MAX_VALUE, 1);
            JSpinner widthSpinner = new JSpinner(widthModel);
            Component widthEditor = widthSpinner.getEditor();
            JFormattedTextField widthSpinnerTextField = ((JSpinner.DefaultEditor) widthEditor).getTextField();
            widthSpinnerTextField.setColumns(4);
            SpinnerModel heightModel = new SpinnerNumberModel(height, 0, Integer.MAX_VALUE, 1);
            JSpinner heightSpinner = new JSpinner(heightModel);
            Component heightEditor = heightSpinner.getEditor();
            JFormattedTextField heightSpinnerTextField = ((JSpinner.DefaultEditor) heightEditor).getTextField();
            heightSpinnerTextField.setColumns(4);
            ChangeListener listener = e -> configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), widthSpinner.getValue() + "x" + heightSpinner.getValue());
            widthSpinner.addChangeListener(listener);
            heightSpinner.addChangeListener(listener);
            dimensionPanel.add(widthSpinner, BorderLayout.WEST);
            dimensionPanel.add(new JLabel(" x "), BorderLayout.CENTER);
            dimensionPanel.add(heightSpinner, BorderLayout.EAST);
            item.add(dimensionPanel, BorderLayout.EAST);
        }
        if (cid.getType().isEnum()) {
            Class<? extends Enum> type = (Class<? extends Enum>) cid.getType();
            JComboBox box = new JComboBox(type.getEnumConstants());
            box.setFocusable(false);
            // sorry but this is the way to keep the size of the combobox in check.
            box.setPrototypeDisplayValue("XXXXXXXX");
            try {
                Enum selectedItem = Enum.valueOf(type, configManager.getConfiguration(cd.getGroup().keyName(), cid.getItem().keyName()));
                box.setSelectedItem(selectedItem);
                box.setToolTipText(selectedItem.toString());
            } catch (IllegalArgumentException ex) {
                log.debug("invalid seleced item", ex);
            }
            box.addItemListener(e -> {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    changeConfiguration(box, cd, cid);
                    box.setToolTipText(box.getSelectedItem().toString());
                }
            });
            item.add(box, BorderLayout.EAST);
        }
        add(item);
    }
    JButton resetButton = new JButton("Reset");
    resetButton.addActionListener((e) -> {
        configManager.setDefaultConfiguration(config, true);
        // Reload configuration panel
        openGroupConfigPanel(config, cd, configManager);
    });
    add(resetButton);
    JButton backButton = new JButton("Back");
    backButton.addActionListener(e -> openConfigList());
    add(backButton);
    revalidate();
    getScrollPane().getVerticalScrollBar().setValue(0);
}
Also used : Color(java.awt.Color) FocusListener(java.awt.event.FocusListener) DocumentListener(javax.swing.event.DocumentListener) YES_NO_OPTION(javax.swing.JOptionPane.YES_NO_OPTION) ConfigManager(net.runelite.client.config.ConfigManager) YES_OPTION(javax.swing.JOptionPane.YES_OPTION) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) ImageIO(javax.imageio.ImageIO) ConfigDescriptor(net.runelite.client.config.ConfigDescriptor) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) WARNING_MESSAGE(javax.swing.JOptionPane.WARNING_MESSAGE) ItemEvent(java.awt.event.ItemEvent) BufferedImage(java.awt.image.BufferedImage) RuneLiteConfig(net.runelite.client.config.RuneLiteConfig) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) WindowEvent(java.awt.event.WindowEvent) Dimension(java.awt.Dimension) Slf4j(lombok.extern.slf4j.Slf4j) Config(net.runelite.client.config.Config) JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) JColorChooser(javax.swing.JColorChooser) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) PluginDescriptor(net.runelite.client.plugins.PluginDescriptor) SwingConstants(javax.swing.SwingConstants) GridLayout(java.awt.GridLayout) ConfigItemDescriptor(net.runelite.client.config.ConfigItemDescriptor) ConfigItem(net.runelite.client.config.ConfigItem) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ImageIcon(javax.swing.ImageIcon) SpinnerModel(javax.swing.SpinnerModel) DocumentEvent(javax.swing.event.DocumentEvent) Plugin(net.runelite.client.plugins.Plugin) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) JSpinner(javax.swing.JSpinner) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) PluginPanel(net.runelite.client.ui.PluginPanel) MouseEvent(java.awt.event.MouseEvent) PluginManager(net.runelite.client.plugins.PluginManager) JScrollPane(javax.swing.JScrollPane) PluginInstantiationException(net.runelite.client.plugins.PluginInstantiationException) TreeMap(java.util.TreeMap) FocusEvent(java.awt.event.FocusEvent) JLabel(javax.swing.JLabel) Comparator(java.util.Comparator) JPanel(javax.swing.JPanel) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) SpinnerModel(javax.swing.SpinnerModel) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) ChangeListener(javax.swing.event.ChangeListener) ConfigItemDescriptor(net.runelite.client.config.ConfigItemDescriptor) Component(java.awt.Component) JComponent(javax.swing.JComponent) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) JFormattedTextField(javax.swing.JFormattedTextField) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) WindowEvent(java.awt.event.WindowEvent) JSpinner(javax.swing.JSpinner) FocusListener(java.awt.event.FocusListener) JColorChooser(javax.swing.JColorChooser)

Aggregations

Dimension (java.awt.Dimension)2 ImageIcon (javax.swing.ImageIcon)2 JButton (javax.swing.JButton)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Component (java.awt.Component)1 GridLayout (java.awt.GridLayout)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 ItemEvent (java.awt.event.ItemEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1