diff --git a/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java
index ed1ec2fa5f26..68699f5054e9 100644
--- a/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java
+++ b/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java
@@ -246,6 +246,11 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
@NotNull
public static JLabel createCommentComponent(@Nullable String commentText, boolean isCommentBelow) {
+ return createCommentComponent(commentText, isCommentBelow, 70);
+ }
+
+ @NotNull
+ public static JLabel createCommentComponent(@Nullable String commentText, boolean isCommentBelow, int maxLineLength) {
// todo why our JBLabel cannot render html if render panel without frame (test only)
boolean isCopyable = SystemProperties.getBooleanProperty("idea.ui.comment.copyable", true);
JLabel component = new JBLabel("").setCopyable(isCopyable).setAllowAutoWrapping(true);
@@ -260,7 +265,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
}
if (isCopyable) {
- setCommentText(component, commentText, isCommentBelow);
+ setCommentText(component, commentText, isCommentBelow, maxLineLength);
}
else {
component.setText(commentText);
@@ -268,7 +273,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
return component;
}
- private static void setCommentText(@NotNull JLabel component, @Nullable String commentText, boolean isCommentBelow) {
+ private static void setCommentText(@NotNull JLabel component, @Nullable String commentText, boolean isCommentBelow, int maxLineLength) {
if (commentText != null) {
String css = "
\n";
- if (commentText.length() > 70 && isCommentBelow) {
+ if (commentText.length() > maxLineLength && isCommentBelow) {
int width = component.getFontMetrics(component.getFont()).stringWidth(commentText.substring(0, 70));
component.setText(String.format("" + css + "%s
", width, commentText));
}
@@ -318,7 +323,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
}
private void setCommentTextImpl(String commentText) {
- ComponentPanelBuilder.setCommentText(comment, commentText, myCommentBelow);
+ ComponentPanelBuilder.setCommentText(comment, commentText, myCommentBelow, 70);
}
private void addToPanel(JPanel panel, GridBagConstraints gc) {
diff --git a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt
index 046bc066d352..ba5a80f65605 100644
--- a/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt
+++ b/platform/platform-impl/src/com/intellij/ui/layout/Cell.kt
@@ -69,6 +69,7 @@ inline fun KMutableProperty0.toBinding(): PropertyBinding {
val component: T
+ fun comment(text: String, maxLineLength: Int = 70): CellBuilder
fun focused(): CellBuilder
fun withValidation(callback: (T) -> ValidationInfo?): CellBuilder
fun onApply(callback: () -> Unit): CellBuilder
diff --git a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt
index 2e124f7e42b6..b97cbc6e19cd 100644
--- a/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt
+++ b/platform/platform-impl/src/com/intellij/ui/layout/migLayout/MigLayoutRow.kt
@@ -29,13 +29,15 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
private val indent: Int /* level number (nested rows) */) : Row() {
companion object {
// as static method to ensure that members of current row are not used
- private fun createCommentRow(parent: MigLayoutRow, comment: String, component: JComponent, indent: Int, isParentRowLabeled: Boolean) {
+ private fun createCommentRow(parent: MigLayoutRow, comment: String, component: JComponent, indent: Int, isParentRowLabeled: Boolean, maxLineLength: Int) {
val cc = CC()
- parent.createChildRow().addComponent(ComponentPanelBuilder.createCommentComponent(comment, true), lazyOf(cc))
- cc.horizontal.gapBefore = gapToBoundSize(getCommentLeftInset(parent.spacing, component) + indent, true)
+ parent.createChildRow().addComponent(ComponentPanelBuilder.createCommentComponent(comment, true, maxLineLength), lazyOf(cc))
if (isParentRowLabeled) {
cc.skip()
}
+ else {
+ cc.horizontal.gapBefore = gapToBoundSize(getCommentLeftInset(component) + indent, true)
+ }
}
// as static method to ensure that members of current row are not used
@@ -211,7 +213,7 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
}
val firstComponent = components.firstOrNull() ?: return 0
if (firstComponent is JRadioButton || firstComponent is JCheckBox) {
- return getCommentLeftInset(spacing, firstComponent)
+ return getCommentLeftInset(firstComponent)
}
else {
return spacing.indentLevel
@@ -220,7 +222,7 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
override operator fun T.invoke(vararg constraints: CCFlags, gapLeft: Int, growPolicy: GrowPolicy?, comment: String?): CellBuilder {
addComponent(this, constraints.create()?.let { lazyOf(it) } ?: lazy { CC() }, gapLeft, growPolicy, comment)
- return CellBuilderImpl(builder, this)
+ return CellBuilderImpl(builder, this@MigLayoutRow, this)
}
// separate method to avoid JComponent as a receiver
@@ -246,11 +248,7 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
}
if (comment != null && comment.isNotEmpty()) {
- gapAfter = "${spacing.commentVerticalTopGap}px!"
-
- val isParentRowLabeled = labeled
- // create comment in a new sibling row (developer is still able to create sub rows because rows is not stored in a flat list)
- createCommentRow(parent!!, comment, component, indent, isParentRowLabeled)
+ addCommentRow(component, comment)
}
if (buttonGroup != null && component is JRadioButton) {
@@ -295,6 +293,14 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
}
}
+ fun addCommentRow(component: JComponent, comment: String, maxLineLength: Int = 70) {
+ gapAfter = "${spacing.commentVerticalTopGap}px!"
+
+ val isParentRowLabeled = labeled
+ // create comment in a new sibling row (developer is still able to create sub rows because rows is not stored in a flat list)
+ createCommentRow(parent!!, comment, component, indent, isParentRowLabeled, maxLineLength)
+ }
+
private fun shareCellWithPreviousComponentIfNeeded(component: JComponent, componentCC: Lazy): Boolean {
if (components.size > 1 && component is JLabel && component.icon === AllIcons.General.GearPlain) {
componentCC.value.horizontal.gapBefore = builder.defaultComponentConstraintCreator.horizontalUnitSizeGap
@@ -369,8 +375,14 @@ internal class MigLayoutRow(private val parent: MigLayoutRow?,
class CellBuilderImpl internal constructor(
private val builder: MigLayoutBuilder,
+ private val row: MigLayoutRow,
override val component: T
) : CellBuilder, CheckboxCellBuilder {
+ override fun comment(text: String, maxLineLength: Int): CellBuilder {
+ row.addCommentRow(component, text, maxLineLength)
+ return this
+ }
+
override fun focused(): CellBuilder {
builder.preferredFocusedComponent = component
return this
@@ -411,7 +423,7 @@ class CellBuilderImpl internal constructor(
}
}
-private fun getCommentLeftInset(spacing: SpacingConfiguration, component: JComponent): Int {
+private fun getCommentLeftInset(component: JComponent): Int {
if (component is JTextField) {
// 1px border, better to indent comment text
return 1