mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Kotlin UI DSL: easy way to disable sub rows
This commit is contained in:
@@ -145,7 +145,7 @@ internal class PasswordSafeConfigurableUi : ConfigurableUi<PasswordSafeSettings>
|
||||
fun getCurrentDbFile() = keePassDbFile.text.trim().nullize()?.let { Paths.get(it) }
|
||||
|
||||
fun updateEnabledState() {
|
||||
modeToRow[ProviderType.KEEPASS]?.enabled = getProviderType() == ProviderType.KEEPASS
|
||||
modeToRow[ProviderType.KEEPASS]?.subRowsEnabled = getProviderType() == ProviderType.KEEPASS
|
||||
}
|
||||
|
||||
override fun getComponent(): JPanel {
|
||||
@@ -163,7 +163,7 @@ internal class PasswordSafeConfigurableUi : ConfigurableUi<PasswordSafeSettings>
|
||||
}
|
||||
}
|
||||
|
||||
row {
|
||||
modeToRow[ProviderType.KEEPASS] = row {
|
||||
inKeePass()
|
||||
row("Database:") {
|
||||
keePassDbFile = textFieldWithBrowseButton("KeePass Database File",
|
||||
@@ -193,7 +193,7 @@ internal class PasswordSafeConfigurableUi : ConfigurableUi<PasswordSafeSettings>
|
||||
}
|
||||
)
|
||||
}
|
||||
modeToRow[ProviderType.KEEPASS] = row("Master Password:") {
|
||||
row("Master Password:") {
|
||||
keePassMasterPassword(growPolicy = GrowPolicy.SHORT_TEXT)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@ class LayoutBuilder(val `$`: LayoutBuilderImpl, val buttonGroup: ButtonGroup? =
|
||||
row(label = Label(label), init = init)
|
||||
}
|
||||
|
||||
inline fun row(label: JLabel? = null, separated: Boolean = false, init: Row.() -> Unit) {
|
||||
`$`.newRow(label, buttonGroup, separated).init()
|
||||
inline fun row(label: JLabel? = null, separated: Boolean = false, init: Row.() -> Unit): Row {
|
||||
val row = `$`.newRow(label, buttonGroup, separated)
|
||||
row.init()
|
||||
return row
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,7 +182,7 @@ private fun addGrowIfNeed(cc: CC, component: Component) {
|
||||
}
|
||||
|
||||
private class MigLayoutRow(private val componentConstraints: MutableMap<Component, CC>,
|
||||
private val builder: MigLayoutBuilder,
|
||||
override val builder: LayoutBuilderImpl,
|
||||
val labeled: Boolean = false,
|
||||
val noGrid: Boolean = false,
|
||||
private val buttonGroup: ButtonGroup? = null,
|
||||
@@ -191,6 +191,11 @@ private class MigLayoutRow(private val componentConstraints: MutableMap<Componen
|
||||
val components = SmartList<Component>()
|
||||
var rightIndex = Int.MAX_VALUE
|
||||
|
||||
private var _subRows: MutableList<Row>? = null
|
||||
|
||||
override val subRows: List<Row>
|
||||
get() = _subRows ?: emptyList()
|
||||
|
||||
override var enabled: Boolean = true
|
||||
get() = field
|
||||
set(value) {
|
||||
@@ -204,6 +209,17 @@ private class MigLayoutRow(private val componentConstraints: MutableMap<Componen
|
||||
}
|
||||
}
|
||||
|
||||
override var subRowsEnabled: Boolean = true
|
||||
get() = field
|
||||
set(value) {
|
||||
if (field == value) {
|
||||
return
|
||||
}
|
||||
|
||||
field = value
|
||||
_subRows?.forEach { it.enabled = value }
|
||||
}
|
||||
|
||||
override operator fun JComponent.invoke(vararg constraints: CCFlags, gapLeft: Int, growPolicy: GrowPolicy?) {
|
||||
addComponent(this, constraints, gapLeft = gapLeft, growPolicy = growPolicy)
|
||||
}
|
||||
@@ -226,9 +242,12 @@ private class MigLayoutRow(private val componentConstraints: MutableMap<Componen
|
||||
rightIndex = components.size
|
||||
}
|
||||
|
||||
override fun row(label: String, init: Row.() -> Unit): Row {
|
||||
override fun createRow(label: String): Row {
|
||||
val row = builder.newRow(Label(label), indented = true)
|
||||
row.init()
|
||||
if (_subRows == null) {
|
||||
_subRows = SmartList()
|
||||
}
|
||||
_subRows!!.add(row)
|
||||
return row
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ import javax.swing.JLabel
|
||||
abstract class Row() {
|
||||
abstract var enabled: Boolean
|
||||
|
||||
abstract var subRowsEnabled: Boolean
|
||||
|
||||
abstract val subRows: List<Row>
|
||||
|
||||
protected abstract val builder: LayoutBuilderImpl
|
||||
|
||||
fun label(text: String, gapLeft: Int = 0, style: ComponentStyle? = null, fontColor: FontColor? = null, bold: Boolean = false) {
|
||||
Label(text, style, fontColor, bold)(gapLeft = gapLeft)
|
||||
}
|
||||
@@ -113,7 +119,13 @@ abstract class Row() {
|
||||
|
||||
protected abstract fun alignRight()
|
||||
|
||||
abstract fun row(label: String, init: Row.() -> Unit): Row
|
||||
inline fun row(label: String, init: Row.() -> Unit): Row {
|
||||
val row = createRow(label)
|
||||
row.init()
|
||||
return row
|
||||
}
|
||||
|
||||
protected abstract fun createRow(label: String): Row
|
||||
|
||||
@Deprecated(message = "Nested row is prohibited", level = DeprecationLevel.ERROR)
|
||||
fun row(label: JLabel? = null, init: Row.() -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user