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());
}
}
Aggregations