[Kotlin UI DSL] Port GuiDesignerConfigurable to Kotlin UI DSL

GitOrigin-RevId: 0e0f046aaf80a9e6d7eac2cfdae9c8d9453a6ab1
This commit is contained in:
Pavel Porvatov
2025-06-26 20:06:27 +00:00
committed by intellij-monorepo-bot
parent 7f61d8724c
commit 79561628d0
3 changed files with 97 additions and 222 deletions
@@ -1,138 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.uiDesigner.GuiDesignerConfigurable.MyGeneralUI">
<grid id="4a770" binding="myPanel" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="62" y="47" width="493" height="295"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="d5f77">
<constraints>
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="b77c5" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="0">
<margin top="0" left="0" bottom="4" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2add1" class="javax.swing.JRadioButton" binding="myRbInstrumentSourcesOnCompilation">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="2" left="0" bottom="2" right="2"/>
<text resource-bundle="messages/UIDesignerBundle" key="radio.generate.into.java.on.compilation"/>
</properties>
</component>
<component id="e8471" class="javax.swing.JRadioButton" binding="myRbInstrumentClasses">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="2" left="0" bottom="2" right="2"/>
<text resource-bundle="messages/UIDesignerBundle" key="radio.generate.into.class"/>
</properties>
</component>
<component id="e8472" class="javax.swing.JRadioButton" binding="myRbInstrumentSourcesOnSave">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="2" left="0" bottom="2" right="2"/>
<text resource-bundle="messages/UIDesignerBundle" key="radio.generate.into.java.on.save"/>
</properties>
</component>
<component id="2eed8" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIDesignerBundle" key="label.generate.gui.into"/>
</properties>
</component>
</children>
</grid>
<hspacer id="cdabe">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="e8ed8" class="javax.swing.JCheckBox" binding="myChkCopyFormsRuntime">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/UIDesignerBundle" key="chk.copy.form.runtime"/>
</properties>
</component>
<component id="3c31d" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="4c65a"/>
<text resource-bundle="messages/UIDesignerBundle" key="default.layout.manager"/>
</properties>
</component>
<component id="117bd" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="baaa0"/>
<text resource-bundle="messages/UIDesignerBundle" key="default.field.accessibility"/>
</properties>
</component>
<component id="4c65a" class="javax.swing.JComboBox" binding="myLayoutManagerCombo">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="baaa0" class="javax.swing.JComboBox" binding="myDefaultFieldAccessibilityCombo" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="private"/>
<item value="package-private"/>
<item value="protected"/>
<item value="public"/>
</model>
</properties>
</component>
<component id="b9ad7" class="javax.swing.JCheckBox" binding="myResizeHeaders">
<constraints>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="10" left="0" bottom="2" right="2"/>
<text resource-bundle="messages/UIDesignerBundle" key="ui.designer.general.settings.resize.column.and.row.headers"/>
</properties>
</component>
<component id="12840" class="javax.swing.JCheckBox" binding="myChkUseDynamicBundles">
<constraints>
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="10" left="0" bottom="2" right="2"/>
<text resource-bundle="messages/UIDesignerBundle" key="ui.designer.general.settings.use.dynamic.bundles"/>
</properties>
</component>
</children>
</grid>
<buttonGroups>
<group name="buttonGroup1">
<member id="e8471"/>
<member id="e8472"/>
<member id="2add1"/>
</group>
</buttonGroups>
</form>
@@ -10,7 +10,6 @@ import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.util.DispatchThreadProgressWindow;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDocumentManager;
@@ -18,10 +17,8 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.ui.SimpleListCellRenderer;
import com.intellij.uiDesigner.compiler.AsmCodeGenerator;
import com.intellij.uiDesigner.make.FormSourceCodeGenerator;
import com.intellij.uiDesigner.radComponents.LayoutManagerRegistry;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -30,7 +27,7 @@ import javax.swing.*;
public final class GuiDesignerConfigurable implements SearchableConfigurable, Configurable.NoScroll {
private static final Logger LOG = Logger.getInstance(GuiDesignerConfigurable.class);
private final Project myProject;
private MyGeneralUI myGeneralUI;
private GuiDesignerUI myGuiDesignerUI;
/**
* Invoked by reflection
@@ -51,62 +48,22 @@ public final class GuiDesignerConfigurable implements SearchableConfigurable, Co
@Override
public JComponent createComponent() {
if (myGeneralUI == null) {
myGeneralUI = new MyGeneralUI();
if (myGuiDesignerUI == null) {
myGuiDesignerUI = new GuiDesignerUI(myProject);
}
return myGeneralUI.myPanel;
return myGuiDesignerUI.content;
}
@Override
public boolean isModified() {
final GuiDesignerConfiguration configuration = GuiDesignerConfiguration.getInstance(myProject);
if (myGeneralUI == null) {
return false;
}
if (myGeneralUI.myChkCopyFormsRuntime.isSelected() != configuration.COPY_FORMS_RUNTIME_TO_OUTPUT) {
return true;
}
if (myGeneralUI.myChkUseDynamicBundles.isSelected() != configuration.USE_DYNAMIC_BUNDLES) {
return true;
}
if (!Comparing.equal(configuration.DEFAULT_LAYOUT_MANAGER, myGeneralUI.myLayoutManagerCombo.getSelectedItem())) {
return true;
}
if (!Comparing.equal(configuration.DEFAULT_FIELD_ACCESSIBILITY, myGeneralUI.myDefaultFieldAccessibilityCombo.getSelectedItem())) {
return true;
}
if (configuration.INSTRUMENT_CLASSES != myGeneralUI.myRbInstrumentClasses.isSelected()) {
return true;
}
if (configuration.GENERATE_SOURCES_ON_SAVE != myGeneralUI.myRbInstrumentSourcesOnSave.isSelected()) {
return true;
}
if (configuration.RESIZE_HEADERS != myGeneralUI.myResizeHeaders.isSelected()) {
return true;
}
return false;
return myGuiDesignerUI != null && myGuiDesignerUI.content.isModified();
}
@Override
public void apply() {
myGuiDesignerUI.content.apply();
final GuiDesignerConfiguration configuration = GuiDesignerConfiguration.getInstance(myProject);
configuration.COPY_FORMS_RUNTIME_TO_OUTPUT = myGeneralUI.myChkCopyFormsRuntime.isSelected();
configuration.DEFAULT_LAYOUT_MANAGER = (String)myGeneralUI.myLayoutManagerCombo.getSelectedItem();
configuration.INSTRUMENT_CLASSES = myGeneralUI.myRbInstrumentClasses.isSelected();
configuration.DEFAULT_FIELD_ACCESSIBILITY = (String)myGeneralUI .myDefaultFieldAccessibilityCombo.getSelectedItem();
configuration.RESIZE_HEADERS = myGeneralUI.myResizeHeaders.isSelected();
configuration.USE_DYNAMIC_BUNDLES = myGeneralUI.myChkUseDynamicBundles.isSelected();
configuration.GENERATE_SOURCES_ON_SAVE = myGeneralUI.myRbInstrumentSourcesOnSave.isSelected();
if (configuration.INSTRUMENT_CLASSES && !myProject.isDefault()) {
final DispatchThreadProgressWindow progressWindow = new DispatchThreadProgressWindow(false, myProject);
@@ -118,47 +75,14 @@ public final class GuiDesignerConfigurable implements SearchableConfigurable, Co
@Override
public void reset() {
final GuiDesignerConfiguration configuration = GuiDesignerConfiguration.getInstance(myProject);
/*general*/
if (configuration.INSTRUMENT_CLASSES) {
myGeneralUI.myRbInstrumentClasses.setSelected(true);
}
else if (configuration.GENERATE_SOURCES_ON_SAVE) {
myGeneralUI.myRbInstrumentSourcesOnSave.setSelected(true);
}
else {
myGeneralUI.myRbInstrumentSourcesOnCompilation.setSelected(true);
}
myGeneralUI.myChkCopyFormsRuntime.setSelected(configuration.COPY_FORMS_RUNTIME_TO_OUTPUT);
myGeneralUI.myChkUseDynamicBundles.setSelected(configuration.USE_DYNAMIC_BUNDLES);
myGeneralUI.myLayoutManagerCombo.setModel(new DefaultComboBoxModel<>(LayoutManagerRegistry.getNonDeprecatedLayoutManagerNames()));
myGeneralUI.myLayoutManagerCombo.setRenderer(SimpleListCellRenderer.create("", LayoutManagerRegistry::getLayoutManagerDisplayName));
myGeneralUI.myLayoutManagerCombo.setSelectedItem(configuration.DEFAULT_LAYOUT_MANAGER);
myGeneralUI.myDefaultFieldAccessibilityCombo.setSelectedItem(configuration.DEFAULT_FIELD_ACCESSIBILITY);
myGeneralUI.myResizeHeaders.setSelected(configuration.RESIZE_HEADERS);
myGuiDesignerUI.content.reset();
}
@Override
public void disposeUIResources() {
myGeneralUI = null;
myGuiDesignerUI = null;
} /*UI for "General" tab*/
private static final class MyGeneralUI {
public JPanel myPanel;
public JRadioButton myRbInstrumentClasses;
public JRadioButton myRbInstrumentSourcesOnCompilation;
public JRadioButton myRbInstrumentSourcesOnSave;
public JCheckBox myChkCopyFormsRuntime;
public JCheckBox myChkUseDynamicBundles;
private JComboBox<String> myLayoutManagerCombo;
private JComboBox<String> myDefaultFieldAccessibilityCombo;
private JCheckBox myResizeHeaders;
}
private final class MyApplyRunnable implements Runnable {
private final DispatchThreadProgressWindow myProgressWindow;
@@ -0,0 +1,89 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.uiDesigner
import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBRadioButton
import com.intellij.ui.dsl.builder.AlignY
import com.intellij.ui.dsl.builder.bindItem
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.listCellRenderer.textListCellRenderer
import com.intellij.uiDesigner.radComponents.LayoutManagerRegistry
import org.jetbrains.annotations.ApiStatus
@ApiStatus.Internal
internal class GuiDesignerUI(project: Project) {
@JvmField
val content = panel {
val configuration = GuiDesignerConfiguration.getInstance(project)
row {
label(UIDesignerBundle.message("label.generate.gui.into"))
.align(AlignY.TOP)
lateinit var rbInstrumentClasses: JBRadioButton
lateinit var rbInstrumentSourcesOnCompilation: JBRadioButton
lateinit var rbInstrumentSourcesOnSave: JBRadioButton
panel {
buttonsGroup {
row {
rbInstrumentClasses = radioButton(UIDesignerBundle.message("radio.generate.into.class"))
.component
}
row {
rbInstrumentSourcesOnCompilation = radioButton(UIDesignerBundle.message("radio.generate.into.java.on.compilation"))
.component
}
row {
rbInstrumentSourcesOnSave = radioButton(UIDesignerBundle.message("radio.generate.into.java.on.save"))
.component
}
}
}.onApply {
configuration.INSTRUMENT_CLASSES = rbInstrumentClasses.isSelected
configuration.GENERATE_SOURCES_ON_SAVE = rbInstrumentSourcesOnSave.isSelected
}.onIsModified {
configuration.INSTRUMENT_CLASSES != rbInstrumentClasses.isSelected ||
configuration.GENERATE_SOURCES_ON_SAVE != rbInstrumentSourcesOnSave.isSelected
}.onReset {
if (configuration.INSTRUMENT_CLASSES) {
rbInstrumentClasses.setSelected(true)
}
else if (configuration.GENERATE_SOURCES_ON_SAVE) {
rbInstrumentSourcesOnSave.setSelected(true)
}
else {
rbInstrumentSourcesOnCompilation.setSelected(true)
}
}
}
row {
checkBox(UIDesignerBundle.message("chk.copy.form.runtime"))
.bindSelected(configuration::COPY_FORMS_RUNTIME_TO_OUTPUT)
}
row(UIDesignerBundle.message("default.layout.manager")) {
comboBox(LayoutManagerRegistry.getNonDeprecatedLayoutManagerNames().toList(),
textListCellRenderer("", LayoutManagerRegistry::getLayoutManagerDisplayName))
.bindItem(configuration::DEFAULT_LAYOUT_MANAGER)
}
row(UIDesignerBundle.message("default.field.accessibility")) {
comboBox(listOf("private", "package-private", "protected", "public"))
.bindItem(configuration::DEFAULT_FIELD_ACCESSIBILITY)
}
row {
checkBox(UIDesignerBundle.message("ui.designer.general.settings.resize.column.and.row.headers"))
.bindSelected(configuration::RESIZE_HEADERS)
}
row {
checkBox(UIDesignerBundle.message("ui.designer.general.settings.use.dynamic.bundles"))
.bindSelected(configuration::USE_DYNAMIC_BUNDLES)
}
}
}