Search in sources :

Example 1 with ConfigItem

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

the class ConfigPanel method changeConfiguration.

private void changeConfiguration(JComponent component, ConfigDescriptor cd, ConfigItemDescriptor cid) {
    ConfigItem configItem = cid.getItem();
    if (component instanceof JCheckBox) {
        JCheckBox checkbox = (JCheckBox) component;
        boolean originalState = !checkbox.isSelected();
        boolean config = originalState ? configItem.warnOnDisable() : configItem.warnOnEnable();
        if (!configItem.confirmationWarining().isEmpty() && config) {
            int value = JOptionPane.showOptionDialog(component, configItem.confirmationWarining(), "Are you sure?", YES_NO_OPTION, WARNING_MESSAGE, null, new String[] { "Yes", "No" }, "No");
            if (value != YES_OPTION) {
                checkbox.setSelected(originalState);
                return;
            }
        }
        configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), "" + checkbox.isSelected());
    }
    if (component instanceof JSpinner) {
        JSpinner spinner = (JSpinner) component;
        configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), "" + spinner.getValue());
    }
    if (component instanceof JTextField) {
        JTextField textField = (JTextField) component;
        configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), textField.getText());
    }
    if (component instanceof JColorChooser) {
        JColorChooser jColorChooser = (JColorChooser) component;
        configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), String.valueOf(jColorChooser.getColor().getRGB()));
    }
    if (component instanceof JComboBox) {
        JComboBox jComboBox = (JComboBox) component;
        configManager.setConfiguration(cd.getGroup().keyName(), cid.getItem().keyName(), ((Enum) jComboBox.getSelectedItem()).name());
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) JComboBox(javax.swing.JComboBox) ConfigItem(net.runelite.client.config.ConfigItem) JSpinner(javax.swing.JSpinner) JTextField(javax.swing.JTextField) JColorChooser(javax.swing.JColorChooser)

Aggregations

JCheckBox (javax.swing.JCheckBox)1 JColorChooser (javax.swing.JColorChooser)1 JComboBox (javax.swing.JComboBox)1 JSpinner (javax.swing.JSpinner)1 JTextField (javax.swing.JTextField)1 ConfigItem (net.runelite.client.config.ConfigItem)1