IDEA-161462 Password settings: misaligned button

This commit is contained in:
Vladimir Krivosheev
2016-10-11 16:07:24 +02:00
parent 23167ac5e7
commit 0fc64c2ee3
4 changed files with 26 additions and 15 deletions
@@ -57,15 +57,14 @@ class PasswordSafeConfigurableUi : ConfigurableUi<PasswordSafeSettings> {
row { rememberPasswordsUntilClosing() }
}
if (!passwordSafe.isNativeCredentialStoreUsed)
row {
right {
button("Clear Passwords") { event ->
passwordSafe.clearPasswords()
Messages.showInfoMessage(event.source as Component, "Passwords were cleared", "Clear Passwords")
}
if (!passwordSafe.isNativeCredentialStoreUsed) {
row(separated = true) {
button("Clear Passwords") { event ->
passwordSafe.clearPasswords()
Messages.showInfoMessage(event.source as Component, "Passwords were cleared", "Clear Passwords")
}
}
}
}
private fun getProviderType(): ProviderType {
@@ -21,11 +21,11 @@ import javax.swing.JLabel
class LayoutBuilder(val `$`: LayoutBuilderImpl, val buttonGroup: ButtonGroup? = null) {
inline fun row(label: String, init: Row.() -> Unit) {
row(Label(label), init)
row(label = Label(label), init = init)
}
inline fun row(label: JLabel? = null, init: Row.() -> Unit) {
`$`.newRow(label, buttonGroup).init()
inline fun row(label: JLabel? = null, separated: Boolean = false, init: Row.() -> Unit) {
`$`.newRow(label, buttonGroup, separated).init()
}
/**
@@ -20,6 +20,8 @@ import com.intellij.openapi.actionSystem.ActionToolbar
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.ToggleAction
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.ui.OnePixelDivider
import com.intellij.ui.SeparatorComponent
import com.intellij.ui.components.noteComponent
import com.intellij.util.SmartList
import net.miginfocom.layout.*
@@ -38,7 +40,13 @@ internal class MigLayoutBuilder : LayoutBuilderImpl {
private val componentConstraints: MutableMap<Component, CC> = SmartHashMap()
override fun newRow(label: JLabel?, buttonGroup: ButtonGroup?): Row {
override fun newRow(label: JLabel?, buttonGroup: ButtonGroup?, separated: Boolean): Row {
if (separated) {
val row = MigLayoutRow(componentConstraints, noGrid = true, separated = true)
rows.add(row)
row.apply { SeparatorComponent(0, OnePixelDivider.BACKGROUND, null)() }
}
val row = MigLayoutRow(componentConstraints, label != null, buttonGroup = buttonGroup)
rows.add(row)
@@ -48,7 +56,7 @@ internal class MigLayoutBuilder : LayoutBuilderImpl {
}
override fun noteRow(text: String) {
// add empty row
// add empty row as top gap
newRow()
val row = MigLayoutRow(componentConstraints, noGrid = true)
@@ -106,6 +114,10 @@ internal class MigLayoutBuilder : LayoutBuilderImpl {
if (component === row.components.first()) {
// rowConstraints.noGrid() doesn't work correctly
cc.spanX()
if (row.separated) {
cc.vertical.gapBefore = gapToBoundSize(VERTICAL_GAP * 3, false)
cc.vertical.gapAfter = gapToBoundSize(VERTICAL_GAP * 2, false)
}
}
}
else {
@@ -135,7 +147,7 @@ internal class MigLayoutBuilder : LayoutBuilderImpl {
}
private fun addGrowIfNeed(cc: CC, component: Component) {
if (component is JTextComponent) {
if (component is JTextComponent || component is SeparatorComponent) {
cc.growX()
}
else if (component is JPanel && component.componentCount == 1 &&
@@ -144,7 +156,7 @@ private fun addGrowIfNeed(cc: CC, component: Component) {
}
}
private class MigLayoutRow(private val componentConstraints: MutableMap<Component, CC>, val labeled: Boolean = false, val noGrid: Boolean = false, private val buttonGroup: ButtonGroup? = null) : Row() {
private class MigLayoutRow(private val componentConstraints: MutableMap<Component, CC>, val labeled: Boolean = false, val noGrid: Boolean = false, private val buttonGroup: ButtonGroup? = null, val separated: Boolean = false) : Row() {
val components = SmartList<Component>()
var rightIndex = Int.MAX_VALUE
@@ -32,7 +32,7 @@ fun createLayoutBuilder() = LayoutBuilder(MigLayoutBuilder())
// "When a protected member is accessed from an inline function, a public accessor method is created to provide an access to that protected member from the outside of the class where the function will be inlined to."
// (https://youtrack.jetbrains.com/issue/KT-12215)
interface LayoutBuilderImpl {
fun newRow(label: JLabel? = null, buttonGroup: ButtonGroup? = null): Row
fun newRow(label: JLabel? = null, buttonGroup: ButtonGroup? = null, separated: Boolean = false): Row
fun build(container: Container, layoutConstraints: Array<out LCFlags>)