diff --git a/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilder.kt b/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilder.kt index 1d138a321e0e..f474347c6f1f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilder.kt +++ b/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilder.kt @@ -1,149 +1,113 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.openapi.options; +package com.intellij.openapi.options -import com.intellij.ide.ui.search.BooleanOptionDescription; -import com.intellij.ide.ui.search.OptionDescription; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Getter; -import com.intellij.openapi.util.NlsContexts; -import com.intellij.openapi.util.Setter; -import com.intellij.ui.dsl.builder.Panel; -import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.Unmodifiable; +import com.intellij.ide.ui.search.BooleanOptionDescription +import com.intellij.ide.ui.search.OptionDescription +import com.intellij.openapi.util.Comparing +import com.intellij.openapi.util.Getter +import com.intellij.openapi.util.NlsContexts +import com.intellij.openapi.util.Setter +import com.intellij.ui.dsl.builder.Panel +import com.intellij.util.ui.UIUtil +import org.jetbrains.annotations.ApiStatus +import java.util.function.Function +import java.util.function.Supplier +import javax.swing.JCheckBox -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; +@Deprecated("Use identical {@link BeanConfigurable} for replacement") +abstract class ConfigurableBuilder protected constructor() : UiDslUnnamedConfigurable.Simple(), UiDslUnnamedConfigurable, ConfigurableWithOptionDescriptors { -/** - * @deprecated Use identical {@link BeanConfigurable} for replacement - */ -@Deprecated(forRemoval = true) -public abstract class ConfigurableBuilder extends UiDslUnnamedConfigurable.Simple - implements UiDslUnnamedConfigurable, ConfigurableWithOptionDescriptors { + @ApiStatus.Internal + internal class CallbackAccessor(private val myGetter: Supplier, private val mySetter: Setter) { - private static final class CallbackAccessor { - private final @NotNull Supplier myGetter; - private final @NotNull Setter mySetter; - - private CallbackAccessor(@NotNull Supplier getter, @NotNull Setter setter) { - myGetter = getter; - mySetter = setter; - } - - public Boolean getValue() { - return myGetter.get(); - } - - public void setValue(@NotNull Boolean value) { - mySetter.set(value); - } + var value: Boolean + get() = myGetter.get() + set(value) = mySetter.set(value) } @ApiStatus.Internal - static class BeanField { + internal class BeanField( + private val myAccessor: CallbackAccessor, + internal val title: @NlsContexts.Checkbox String, + ) { - private final @NotNull CallbackAccessor myAccessor; - private final @NotNull @NlsContexts.Checkbox String myTitle; - private @Nullable JCheckBox myComponent; + val component: JCheckBox by lazy { JCheckBox(this.title) } - private BeanField(@NotNull CallbackAccessor accessor, @NotNull @NlsContexts.Checkbox String title) { - myAccessor = accessor; - myTitle = title; + fun isModified(): Boolean { + val componentValue = this.componentValue + val beanValue = myAccessor.value + return !Comparing.equal(componentValue, beanValue) } - @NotNull - JCheckBox getComponent() { - if (myComponent == null) { - myComponent = createComponent(); + fun apply() { + myAccessor.value = this.componentValue + } + + fun reset() { + this.componentValue = myAccessor.value + } + + private var componentValue: Boolean + get() = component.isSelected + set(value) = component.setSelected(value) + + internal var accessorValue: Boolean + get() = myAccessor.value + set(value) { + myAccessor.value = value } - return myComponent; - } - - private @NotNull JCheckBox createComponent() { - return new JCheckBox(myTitle); - } - - boolean isModified() { - final Object componentValue = getComponentValue(); - final Object beanValue = myAccessor.getValue(); - return !Comparing.equal(componentValue, beanValue); - } - - void apply() { - myAccessor.setValue(getComponentValue()); - } - - void reset() { - setComponentValue(myAccessor.getValue()); - } - - private Boolean getComponentValue() { - return getComponent().isSelected(); - } - - private void setComponentValue(@NotNull Boolean value) { - getComponent().setSelected(value); - } - - private @NotNull String getTitle() { - return myTitle; - } - - private void setAccessorValue(boolean value) { - myAccessor.setValue(value); - } - - private boolean getAccessorValue() { - return myAccessor.getValue(); - } } - private final List myFields = new ArrayList<>(); - - protected ConfigurableBuilder() { - } + private val myFields = mutableListOf() /** - * Adds check box with given {@code title}. - * Initial checkbox value is obtained from {@code getter}. - * After the apply, the value from the check box is written back to model via {@code setter}. + * Adds check box with given `title`. + * Initial checkbox value is obtained from `getter`. + * After the apply, the value from the check box is written back to model via `setter`. */ - protected void checkBox(@NotNull @NlsContexts.Checkbox String title, @NotNull Getter<@NotNull Boolean> getter, @NotNull Setter setter) { - myFields.add(new BeanField(new CallbackAccessor(getter, setter), title)); + protected open fun checkBox(@NlsContexts.Checkbox title: @NlsContexts.Checkbox String, getter: Getter, setter: Setter) { + myFields.add(BeanField(CallbackAccessor(getter, setter), title)) } - @Override - public @Unmodifiable @NotNull List getOptionDescriptors(@NotNull String configurableId, - @NotNull Function nameConverter) { - return ContainerUtil.map(myFields, box -> new BooleanOptionDescription(nameConverter.apply(box.getTitle()), configurableId) { - @Override - public boolean isOptionEnabled() { - return box.getAccessorValue(); - } + override fun getOptionDescriptors( + configurableId: String, + nameConverter: Function, + ): List { + return myFields.map { box -> + object : BooleanOptionDescription(nameConverter.apply(box.title), configurableId) { + override fun isOptionEnabled(): Boolean { + return box.accessorValue + } - @Override - public void setOptionState(boolean enabled) { - box.setAccessorValue(enabled); + override fun setOptionState(enabled: Boolean) { + box.accessorValue = enabled + } } - }); + } } - @Override - public void createContent(@NotNull Panel builder) { - ConfigurableBuilderHelper.buildFieldsPanel(builder, myFields); + override fun Panel.createContent() { + for (field in myFields) { + row { + cell(field.component) + .onApply { field.apply() } + .onIsModified { field.isModified() } + .onReset { field.reset() } + UIUtil.applyDeprecatedBackground(field.component) + } + } } @ApiStatus.Internal - public static @Nullable String getConfigurableTitle(@NotNull UnnamedConfigurable configurable) { - if (configurable instanceof BeanConfigurable) { - return ((BeanConfigurable)configurable).getTitle(); + companion object { + + @ApiStatus.Internal + @JvmStatic + fun getConfigurableTitle(configurable: UnnamedConfigurable): String? { + if (configurable is BeanConfigurable<*>) { + return configurable.title + } + return null } - return null; } } diff --git a/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilderHelper.kt b/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilderHelper.kt index 523da3510d23..b787efcc49de 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilderHelper.kt +++ b/platform/platform-impl/src/com/intellij/openapi/options/ConfigurableBuilderHelper.kt @@ -4,29 +4,12 @@ package com.intellij.openapi.options import com.intellij.openapi.ui.DialogPanel import com.intellij.ui.dsl.builder.Panel import com.intellij.ui.dsl.builder.panel -import com.intellij.util.ui.UIUtil import org.jetbrains.annotations.ApiStatus import javax.swing.JComponent @ApiStatus.Internal class ConfigurableBuilderHelper { companion object { - @JvmStatic - @ApiStatus.ScheduledForRemoval - @ApiStatus.Internal - @Deprecated("Will be removed") - @JvmName("buildFieldsPanel") - internal fun Panel.buildFieldsPanel(fields: List) { - for (field in fields) { - row { - cell(field.component) - .onApply { field.apply() } - .onIsModified { field.isModified } - .onReset { field.reset() } - UIUtil.applyDeprecatedBackground(field.component) - } - } - } @JvmStatic @ApiStatus.Internal