From 98df31e474731f509c082bfb7929dc332d2c43fe Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 30 Aug 2010 19:51:44 +0400 Subject: [PATCH] typing boolean values is not cool --- .../openapi/util/registry/RegistryUi.java | 36 +++++++++++++------ .../openapi/util/registry/RegistryValue.java | 4 +++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/util/registry/RegistryUi.java b/platform/lang-impl/src/com/intellij/openapi/util/registry/RegistryUi.java index d45b473a824c..168ac023ba80 100644 --- a/platform/lang-impl/src/com/intellij/openapi/util/registry/RegistryUi.java +++ b/platform/lang-impl/src/com/intellij/openapi/util/registry/RegistryUi.java @@ -324,10 +324,15 @@ public class RegistryUi implements Disposable { myLabel.setText(v.getKey()); break; case 2: - if (v.asColor(null) == null) { - myLabel.setText(v.asString()); - } else { + if (v.asColor(null) != null) { myLabel.setIcon(createColoredIcon(v.asColor(null))); + } else if (v.isBoolean()) { + final JCheckBox box = new JCheckBox(); + box.setSelected(v.asBoolean()); + box.setBackground(table.getBackground()); + return box; + } else { + myLabel.setText(v.asString()); } } @@ -361,29 +366,38 @@ public class RegistryUi implements Disposable { private class MyEditor extends AbstractCellEditor implements TableCellEditor { private final JTextField myField = new JTextField(); + private final JCheckBox myCheckBox = new JCheckBox(); private RegistryValue myValue; @Nullable public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { myValue = (RegistryValue) value; - if (myValue.asColor(null) == null) { - myField.setText(myValue.asString()); - myField.selectAll(); - myField.setBorder(null); - return myField; - } else { - final Color color = ColorChooser.chooseColor(table, "Chose color", ((RegistryValue)value).asColor(Color.WHITE)); + if (myValue.asColor(null) != null) { + final Color color = ColorChooser.chooseColor(table, "Choose color", ((RegistryValue)value).asColor(Color.WHITE)); if (color != null) { myValue.setValue(color.getRed() + "," + color.getGreen() + "," + color.getBlue()); } return null; + } else if (myValue.isBoolean()) { + myCheckBox.setSelected(myValue.asBoolean()); + myCheckBox.setBackground(table.getBackground()); + return myCheckBox; + } else { + myField.setText(myValue.asString()); + myField.setBorder(null); + myField.selectAll(); + return myField; } } @Override public boolean stopCellEditing() { if (myValue != null) { - myValue.setValue(myField.getText().trim()); + if (myValue.isBoolean()) { + myValue.setValue(myCheckBox.isSelected()); + } else { + myValue.setValue(myField.getText().trim()); + } } revaliateActions(); return super.stopCellEditing(); diff --git a/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryValue.java b/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryValue.java index 3ed9e587593a..b791891f4b69 100644 --- a/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryValue.java +++ b/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryValue.java @@ -191,4 +191,8 @@ public class RegistryValue { myIntCachedValue = null; myBooleanCachedValue = null; } + + public boolean isBoolean() { + return "true".equals(myStringCachedValue) || "false".equals(myStringCachedValue); + } }