diff --git a/lib/miglayout-core-5.0.jar b/lib/miglayout-core-5.0.jar index 1211b7016818..1089b5101719 100644 Binary files a/lib/miglayout-core-5.0.jar and b/lib/miglayout-core-5.0.jar differ diff --git a/lib/src/miglayout-core-5.0-sources.jar b/lib/src/miglayout-core-5.0-sources.jar index 004faae6f54e..6b11f6eee233 100644 Binary files a/lib/src/miglayout-core-5.0-sources.jar and b/lib/src/miglayout-core-5.0-sources.jar differ diff --git a/platform/platform-api/src/com/intellij/openapi/ui/dialogBuilder.kt b/platform/platform-api/src/com/intellij/openapi/ui/dialogBuilder.kt new file mode 100644 index 000000000000..8f9ef15229d3 --- /dev/null +++ b/platform/platform-api/src/com/intellij/openapi/ui/dialogBuilder.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.ui + +import javax.swing.JComponent + +fun dialog(title: String, centerPanel: JComponent, resizable: Boolean = true): DialogBuilder { + val builder = DialogBuilder() + builder + .title(title) + .centerPanel(centerPanel) + if (!resizable) { + builder.resizable(false) + } + return builder +} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ui/migLayout.kt b/platform/platform-impl/src/com/intellij/ui/migLayout.kt index bd5687b464b3..032c30bb707f 100644 --- a/platform/platform-impl/src/com/intellij/ui/migLayout.kt +++ b/platform/platform-impl/src/com/intellij/ui/migLayout.kt @@ -19,16 +19,17 @@ import com.intellij.BundleBase import com.intellij.ui.IdeBorderFactory import com.intellij.ui.components.JBLabel import com.intellij.util.ui.UIUtil -import net.miginfocom.layout.CC -import net.miginfocom.layout.ConstraintParser -import net.miginfocom.layout.LC +import net.miginfocom.layout.* import net.miginfocom.swing.MigLayout import java.awt.BorderLayout import java.awt.Component +import java.awt.Font import java.awt.LayoutManager import java.awt.event.ActionEvent import javax.swing.* +// http://www.migcalendar.com/miglayout/mavensite/docs/cheatsheet.pdf + enum class LCFlags { /** * Puts the layout in a flow-only mode. @@ -52,7 +53,17 @@ enum class LCFlags { } enum class CCFlags { - wrap, grow, push, pushY, pushX, right + /** + * Wrap to the next line/column **after** the component that this constraint belongs to. + */ + wrap, + + /** + * Span cells in both x and y. + */ + span, + + grow, push, pushY, pushX, right } inline fun panel(vararg layoutConstraints: LCFlags, init: Panel.() -> Unit): JPanel { @@ -75,7 +86,7 @@ fun JPanel.titledPanel(title: String, wrappedComponent: Component, vararg constr add(panel, *constraints) } -fun JPanel.label(text: String, constraints: CC? = null, componentStyle: UIUtil.ComponentStyle? = null, fontColor: UIUtil.FontColor? = null) { +fun JPanel.label(text: String, vararg constraints: CCFlags, componentStyle: UIUtil.ComponentStyle? = null, fontColor: UIUtil.FontColor? = null, bold: Boolean = false, gapLeft: Int = 0, gapBottom: Int = 0, gapAfter: Int = 0) { val finalText = BundleBase.replaceMnemonicAmpersand(text) val label = if (componentStyle == null && fontColor == null) { JLabel(finalText) @@ -84,15 +95,38 @@ fun JPanel.label(text: String, constraints: CC? = null, componentStyle: UIUtil.C JBLabel(finalText, componentStyle ?: UIUtil.ComponentStyle.REGULAR, fontColor ?: UIUtil.FontColor.NORMAL) } - add(label, constraints) + if (bold) { + label.font = label.font.deriveFont(Font.BOLD) + } + + var _cc = constraints.create() + fun cc(): CC { + if (_cc == null) { + _cc = CC() + } + return _cc!! + } + + if (gapLeft != 0) { + cc().horizontal.gapBefore = gapToBoundSize(gapLeft, true) + } + if (gapAfter != 0) { + cc().horizontal.gapAfter = gapToBoundSize(gapAfter, true) + } + if (gapBottom != 0) { + cc().vertical.gapAfter = gapToBoundSize(gapBottom, false) + } + add(label, _cc) } -fun JPanel.hint(text: String, constraints: CC = CC()) { - if (constraints.horizontal.gapBefore == null) { - // default gap 10 * indent 3 - constraints.gapLeft("30") - } - label(text, constraints, componentStyle = UIUtil.ComponentStyle.SMALL, fontColor = UIUtil.FontColor.BRIGHTER) +private fun gapToBoundSize(value: Int, isHorizontal: Boolean): BoundSize { + val unitValue = UnitValue(value.toFloat(), "", isHorizontal, UnitValue.STATIC, null) + return BoundSize(unitValue, unitValue, null, false, null) +} + +fun JPanel.hint(text: String, vararg constraints: CCFlags) { + // default gap 10 * indent 3 + label(text, componentStyle = UIUtil.ComponentStyle.SMALL, fontColor = UIUtil.FontColor.BRIGHTER, constraints = *constraints, gapLeft = 30) } fun RadioButton(text: String) = JRadioButton(BundleBase.replaceMnemonicAmpersand(text)) @@ -173,6 +207,8 @@ fun CC.apply(flags: Array): CC { CCFlags.push -> push() CCFlags.pushX -> pushX() CCFlags.pushY -> pushY() + + CCFlags.span -> span() } } return this diff --git a/platform/platform-impl/src/com/intellij/util/string.kt b/platform/platform-impl/src/com/intellij/util/string.kt new file mode 100644 index 000000000000..042084d4e4ad --- /dev/null +++ b/platform/platform-impl/src/com/intellij/util/string.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util + +import com.intellij.openapi.util.text.StringUtil + +fun String?.nullize(): String? = StringUtil.nullize(this) + +fun String.trimMiddle(maxLength: Int): String? = StringUtil.trimMiddle(this, maxLength) \ No newline at end of file