From 376de05a573496ee36d8510d827f94a48237ab9d Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Fri, 23 Jun 2023 18:26:21 +0200 Subject: [PATCH] fixed vertical gap btw title & comment, indented settings controls Signed-off-by: Andre Dietisheim --- .../lsp4ij/settings/LanguageServerView.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/settings/LanguageServerView.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/settings/LanguageServerView.java index d9ff96ef6..4d1bb5771 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/settings/LanguageServerView.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/settings/LanguageServerView.java @@ -18,7 +18,6 @@ import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.PortField; import com.intellij.ui.components.JBCheckBox; -import com.intellij.ui.components.JBTextField; import com.intellij.util.ui.FormBuilder; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UI; @@ -26,6 +25,7 @@ import com.redhat.devtools.intellij.lsp4ij.LanguageServersRegistry; import javax.swing.*; +import javax.swing.border.TitledBorder; import java.awt.*; /** @@ -44,31 +44,40 @@ public class LanguageServerView implements Disposable { private final ComboBox serverTraceComboBox = new ComboBox<>(new DefaultComboBoxModel<>(ServerTrace.values())); public LanguageServerView(LanguageServersRegistry.LanguageServerDefinition languageServerDefinition) { - this.myMainPanel = FormBuilder.createFormBuilder() - .setFormLeftIndent(5) - .addComponent(createTitleComponent(languageServerDefinition), 1) + JComponent descriptionPanel = createDescription(languageServerDefinition.description.trim()); + JPanel settingsPanel = createSettings(descriptionPanel); + TitledBorder title = IdeBorderFactory.createTitledBorder(languageServerDefinition.getDisplayName()); + settingsPanel.setBorder(title); + JPanel wrapper = JBUI.Panels.simplePanel(settingsPanel); + wrapper.setBorder(JBUI.Borders.emptyLeft(10)); + this.myMainPanel = wrapper; + } + + private JPanel createSettings(JComponent description) { + return FormBuilder.createFormBuilder() + .addComponent(description, 0) .addLabeledComponent(LanguageServerBundle.message("language.server.debug.port"), debugPortField, 5) .addComponent(debugSuspendCheckBox, 5) .addLabeledComponent(LanguageServerBundle.message("language.server.trace"), serverTraceComboBox, 5) .addComponentFillVertically(new JPanel(), 0) .getPanel(); - this.myMainPanel.setBorder(JBUI.Borders.empty(5, 10)); } - private JComponent createTitleComponent(LanguageServersRegistry.LanguageServerDefinition languageServerDefinition) { + private JComponent createDescription(String description) { + /** + * Normally comments are below the controls. + * Here we want the comments to precede the controls, we therefore create an empty, 0-sized panel. + */ JPanel titledComponent = UI.PanelFactory.grid().createPanel(); - String description = languageServerDefinition.description; + titledComponent.setMinimumSize(JBUI.emptySize()); + titledComponent.setPreferredSize(JBUI.emptySize()); if (description != null && !description.isBlank()) { titledComponent = UI.PanelFactory.panel(titledComponent) - //FIXME I can't figure out how to reduce the margin between the title and the comment - // https://jetbrains.github.io/ui/controls/inline_help_text/#group-of-controls example - // doesn't show as big of a margin - .withComment(description.trim()) + .withComment(description) .resizeX(true) .resizeY(true) .createPanel(); } - titledComponent.setBorder(IdeBorderFactory.createTitledBorder(languageServerDefinition.getDisplayName())); return titledComponent; }