mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Allow to change max line length for comments, don't indent comments in labeled rows, define comments via CellBuilder
GitOrigin-RevId: f6c123f707ec686608c41426944a9421f68ca319
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1b2f4291db
commit
8186241993
@@ -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 = "<head><style type=\"text/css\">\n" +
|
||||
"a, a:link {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkColor()) + ";}\n" +
|
||||
@@ -277,7 +282,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
|
||||
"a:active {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkPressedColor()) + ";}\n" +
|
||||
//"body {background-color:#" + ColorUtil.toHex(JBColor.YELLOW) + ";}\n" + // Left for visual debugging
|
||||
"</style>\n</head>";
|
||||
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("<html>" + css + "<body><div width=%d>%s</div></body></html>", 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) {
|
||||
|
||||
@@ -69,6 +69,7 @@ inline fun <reified T : Any> KMutableProperty0<T>.toBinding(): PropertyBinding<T
|
||||
interface CellBuilder<T : JComponent> {
|
||||
val component: T
|
||||
|
||||
fun comment(text: String, maxLineLength: Int = 70): CellBuilder<T>
|
||||
fun focused(): CellBuilder<T>
|
||||
fun withValidation(callback: (T) -> ValidationInfo?): CellBuilder<T>
|
||||
fun onApply(callback: () -> Unit): CellBuilder<T>
|
||||
|
||||
@@ -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 : JComponent> T.invoke(vararg constraints: CCFlags, gapLeft: Int, growPolicy: GrowPolicy?, comment: String?): CellBuilder<T> {
|
||||
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<CC>): 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<T : JComponent> internal constructor(
|
||||
private val builder: MigLayoutBuilder,
|
||||
private val row: MigLayoutRow,
|
||||
override val component: T
|
||||
) : CellBuilder<T>, CheckboxCellBuilder {
|
||||
override fun comment(text: String, maxLineLength: Int): CellBuilder<T> {
|
||||
row.addCommentRow(component, text, maxLineLength)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun focused(): CellBuilder<T> {
|
||||
builder.preferredFocusedComponent = component
|
||||
return this
|
||||
@@ -411,7 +423,7 @@ class CellBuilderImpl<T : JComponent> 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
|
||||
|
||||
Reference in New Issue
Block a user