Commit 5fce9d69 authored by Sergei Vorobyov's avatar Sergei Vorobyov Committed by intellij-monorepo-bot
Browse files

[Gradle|UI] cleanup: added common function for adding comments in Gradle settings

GitOrigin-RevId: f7937b304db45337091a76e80172b440cbb07a7b
parent 6a746407
Branches unavailable Tags unavailable
Showing with 43 additions and 19 deletions
+43 -19
...@@ -15,6 +15,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; ...@@ -15,6 +15,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.ui.GridBag; import com.intellij.util.ui.GridBag;
import com.intellij.util.ui.JBUI; import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -71,6 +72,20 @@ public final class ExternalSystemUiUtil { ...@@ -71,6 +72,20 @@ public final class ExternalSystemUiUtil {
return new GridBag().weightx(1).coverLine().fillCellHorizontally().anchor(GridBagConstraints.WEST).insets(insets); return new GridBag().weightx(1).coverLine().fillCellHorizontally().anchor(GridBagConstraints.WEST).insets(insets);
} }
@NotNull
public static GridBag getCommentConstraints(int indentLevel) {
GridBag constraints = getFillLineConstraints(indentLevel);
constraints.insets.top = 0;
return constraints;
}
@NotNull
public static GridBag getCheckBoxCommentConstraints(int indentLevel, @NotNull JCheckBox checkBox) {
GridBag constraints = getCommentConstraints(indentLevel);
constraints.insets.left += UIUtil.getCheckBoxTextHorizontalOffset(checkBox);
return constraints;
}
public static void fillBottom(@NotNull JComponent component) { public static void fillBottom(@NotNull JComponent component) {
component.add(Box.createVerticalGlue(), new GridBag().weightx(1).weighty(1).fillCell().coverLine()); component.add(Box.createVerticalGlue(), new GridBag().weightx(1).weighty(1).fillCell().coverLine());
} }
......
...@@ -6,6 +6,7 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; ...@@ -6,6 +6,7 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil;
import com.intellij.openapi.externalSystem.util.PaintAwarePanel; import com.intellij.openapi.externalSystem.util.PaintAwarePanel;
import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil;
...@@ -58,15 +59,18 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti ...@@ -58,15 +59,18 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti
@SuppressWarnings("FieldCanBeLocal") // Used by reflection at showUi() and disposeUiResources() @SuppressWarnings("FieldCanBeLocal") // Used by reflection at showUi() and disposeUiResources()
private @Nullable JBLabel myServiceDirectoryLabel; private @Nullable JBLabel myServiceDirectoryLabel;
@SuppressWarnings("FieldCanBeLocal") // Used by reflection at showUi() and disposeUiResources() @SuppressWarnings({"FieldCanBeLocal", "unused"}) // Used by reflection at showUi() and disposeUiResources()
private @Nullable JBLabel myServiceDirectoryHint; private @Nullable JBLabel myServiceDirectoryHint;
private @Nullable TargetPathFieldWithBrowseButton myServiceDirectoryPathField; private @Nullable TargetPathFieldWithBrowseButton myServiceDirectoryPathField;
private @Nullable JBTextField myGradleVmOptionsField; private @Nullable JBTextField myGradleVmOptionsField;
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"}) // Used by reflection at showUi() and disposeUiResources() @SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"}) // Used by reflection at showUi() and disposeUiResources()
private @NotNull List<Component> myGradleVmOptionsComponents = new ArrayList<>(); private @NotNull List<Component> myGradleVmOptionsComponents = new ArrayList<>();
private @Nullable JBCheckBox myGenerateImlFilesCheckBox; private @Nullable JBCheckBox myGenerateImlFilesCheckBox;
@SuppressWarnings("FieldCanBeLocal") // Used by reflection at showUi() and disposeUiResources() @SuppressWarnings({"FieldCanBeLocal", "unused"}) // Used by reflection at showUi() and disposeUiResources()
private @Nullable JBLabel myGenerateImlFilesHint; private @Nullable JBLabel myGenerateImlFilesHint;
private @Nullable JBCheckBox myDownloadSourcesCheckBox; private @Nullable JBCheckBox myDownloadSourcesCheckBox;
private final @NotNull GradleSettingsControl myDefaultProjectSettingsControl = new IdeaGradleDefaultProjectSettingsControl(); private final @NotNull GradleSettingsControl myDefaultProjectSettingsControl = new IdeaGradleDefaultProjectSettingsControl();
...@@ -214,20 +218,17 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti ...@@ -214,20 +218,17 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti
private void addServiceDirectoryControl(PaintAwarePanel canvas, int indentLevel) { private void addServiceDirectoryControl(PaintAwarePanel canvas, int indentLevel) {
myServiceDirectoryLabel = new JBLabel(GradleBundle.message("gradle.settings.text.user.home")); myServiceDirectoryLabel = new JBLabel(GradleBundle.message("gradle.settings.text.user.home"));
myServiceDirectoryHint = new JBLabel(XmlStringUtil.wrapInHtml(GradleBundle.message("gradle.settings.text.user.home.hint")),
UIUtil.ComponentStyle.SMALL);
myServiceDirectoryHint.setForeground(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER));
myServiceDirectoryPathField = GradleRuntimeTargetUI myServiceDirectoryPathField = GradleRuntimeTargetUI
.targetPathFieldWithBrowseButton(myInitialSettings.getProject(), GradleBundle.message("gradle.settings.text.user.home.dialog.title")); .targetPathFieldWithBrowseButton(myInitialSettings.getProject(), GradleBundle.message("gradle.settings.text.user.home.dialog.title"));
myServiceDirectoryLabel.setLabelFor(myServiceDirectoryPathField);
canvas.add(myServiceDirectoryLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel)); canvas.add(myServiceDirectoryLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
canvas.add(myServiceDirectoryPathField, ExternalSystemUiUtil.getFillLineConstraints(indentLevel)); canvas.add(myServiceDirectoryPathField, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
canvas.add(Box.createGlue(), ExternalSystemUiUtil.getLabelConstraints(indentLevel)); myServiceDirectoryHint = addComment(
GridBag constraints = ExternalSystemUiUtil.getFillLineConstraints(indentLevel); canvas,
constraints.insets.top = 0; XmlStringUtil.wrapInHtml(GradleBundle.message("gradle.settings.text.user.home.hint")),
canvas.add(myServiceDirectoryHint, constraints); ExternalSystemUiUtil.getCommentConstraints(indentLevel)
);
myServiceDirectoryLabel.setLabelFor(myServiceDirectoryPathField);
} }
private void addVMOptionsControl(@NotNull PaintAwarePanel canvas, int indentLevel) { private void addVMOptionsControl(@NotNull PaintAwarePanel canvas, int indentLevel) {
...@@ -284,15 +285,11 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti ...@@ -284,15 +285,11 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti
myGenerateImlFilesCheckBox = new JBCheckBox(GradleBundle.message("gradle.settings.text.generate.iml.files")); myGenerateImlFilesCheckBox = new JBCheckBox(GradleBundle.message("gradle.settings.text.generate.iml.files"));
canvas.add(myGenerateImlFilesCheckBox, ExternalSystemUiUtil.getFillLineConstraints(indentLevel)); canvas.add(myGenerateImlFilesCheckBox, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
myGenerateImlFilesHint = new JBLabel( myGenerateImlFilesHint = addComment(
canvas,
XmlStringUtil.wrapInHtml(GradleBundle.message("gradle.settings.text.generate.iml.files.hint", getIDEName())), XmlStringUtil.wrapInHtml(GradleBundle.message("gradle.settings.text.generate.iml.files.hint", getIDEName())),
UIUtil.ComponentStyle.SMALL); ExternalSystemUiUtil.getCheckBoxCommentConstraints(indentLevel, myGenerateImlFilesCheckBox)
myGenerateImlFilesHint.setForeground(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER)); );
GridBag constraints = ExternalSystemUiUtil.getFillLineConstraints(indentLevel);
constraints.insets.left += UIUtil.getCheckBoxTextHorizontalOffset(myGenerateImlFilesCheckBox);
constraints.insets.top = 0;
canvas.add(myGenerateImlFilesHint, constraints);
} }
private void addDownloadSourcesCheckBox(@NotNull PaintAwarePanel canvas, int indentLevel) { private void addDownloadSourcesCheckBox(@NotNull PaintAwarePanel canvas, int indentLevel) {
...@@ -300,6 +297,18 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti ...@@ -300,6 +297,18 @@ public class IdeaGradleSystemSettingsControlBuilder implements GradleSystemSetti
canvas.add(myDownloadSourcesCheckBox, ExternalSystemUiUtil.getFillLineConstraints(indentLevel)); canvas.add(myDownloadSourcesCheckBox, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
} }
private static @NotNull JBLabel addComment(
@NotNull PaintAwarePanel canvas,
@NotNull @NlsContexts.Label String text,
@NotNull GridBag constraints
) {
var label = new JBLabel(text);
label.setComponentStyle(UIUtil.ComponentStyle.SMALL);
label.setForeground(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER));
canvas.add(label, constraints);
return label;
}
@Nullable @Nullable
private static String trimIfPossible(@Nullable String s) { private static String trimIfPossible(@Nullable String s) {
return StringUtil.nullize(StringUtil.trim(s)); return StringUtil.nullize(StringUtil.trim(s));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment