forked from paul-griffith/kindling
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ListFilterPanel to avoid repetitive class impls.
- Loading branch information
Showing
5 changed files
with
66 additions
and
124 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/io/github/inductiveautomation/kindling/core/LIstFilterPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.github.inductiveautomation.kindling.core | ||
|
||
import io.github.inductiveautomation.kindling.utils.Column | ||
import io.github.inductiveautomation.kindling.utils.FilterList | ||
import io.github.inductiveautomation.kindling.utils.FlatScrollPane | ||
import io.github.inductiveautomation.kindling.utils.Stringifier | ||
import io.github.inductiveautomation.kindling.utils.getAll | ||
import net.miginfocom.swing.MigLayout | ||
import javax.swing.JPanel | ||
import javax.swing.JPopupMenu | ||
|
||
abstract class LIstFilterPanel<T>( | ||
override val tabName: String, | ||
toStringFn: Stringifier = { it?.toString() }, | ||
) : FilterPanel<T>() { | ||
val filterList = FilterList(toStringFn = toStringFn) | ||
|
||
private val sortButtons = filterList.createSortButtons() | ||
|
||
override val component = JPanel(MigLayout("fill, gap 5")).apply { | ||
val sortGroupEnumeration = sortButtons.elements | ||
add(sortGroupEnumeration.nextElement(), "split ${sortButtons.buttonCount}, flowx") | ||
for (element in sortGroupEnumeration) { | ||
add(element, "gapx 2") | ||
} | ||
add(FlatScrollPane(filterList), "newline, push, grow") | ||
} | ||
|
||
init { | ||
filterList.checkBoxListSelectionModel.addListSelectionListener { e -> | ||
if (!e.valueIsAdjusting) { | ||
listeners.getAll<FilterChangeListener>().forEach(FilterChangeListener::filterChanged) | ||
} | ||
} | ||
} | ||
|
||
override fun isFilterApplied() = filterList.checkBoxListSelectedValues.size != filterList.model.size - 1 | ||
|
||
override fun reset() = filterList.selectAll() | ||
|
||
override fun customizePopupMenu(menu: JPopupMenu, column: Column<out T, *>, event: T) = Unit | ||
} |
42 changes: 6 additions & 36 deletions
42
src/main/kotlin/io/github/inductiveautomation/kindling/log/ThreadPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 6 additions & 40 deletions
46
src/main/kotlin/io/github/inductiveautomation/kindling/thread/PoolPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,11 @@ | ||
package io.github.inductiveautomation.kindling.thread | ||
|
||
import io.github.inductiveautomation.kindling.core.FilterChangeListener | ||
import io.github.inductiveautomation.kindling.core.FilterPanel | ||
import io.github.inductiveautomation.kindling.core.LIstFilterPanel | ||
import io.github.inductiveautomation.kindling.thread.model.Thread | ||
import io.github.inductiveautomation.kindling.utils.Column | ||
import io.github.inductiveautomation.kindling.utils.FilterList | ||
import io.github.inductiveautomation.kindling.utils.FlatScrollPane | ||
import io.github.inductiveautomation.kindling.utils.getAll | ||
import net.miginfocom.swing.MigLayout | ||
import javax.swing.JPanel | ||
import javax.swing.JPopupMenu | ||
|
||
class PoolPanel : FilterPanel<Thread?>() { | ||
override val tabName = "Pool" | ||
|
||
val poolList = FilterList { it?.toString() ?: "(No Pool)" } | ||
|
||
private val sortButtons = poolList.createSortButtons() | ||
|
||
override val component = JPanel(MigLayout("fill, gap 5")).apply { | ||
val sortGroupEnumeration = sortButtons.elements | ||
add(sortGroupEnumeration.nextElement(), "split ${sortButtons.buttonCount}, flowx") | ||
for (element in sortGroupEnumeration) { | ||
add(element, "gapx 2") | ||
} | ||
add(FlatScrollPane(poolList), "newline, push, grow") | ||
} | ||
|
||
init { | ||
poolList.checkBoxListSelectionModel.addListSelectionListener { e -> | ||
if (!e.valueIsAdjusting) { | ||
listeners.getAll<FilterChangeListener>().forEach(FilterChangeListener::filterChanged) | ||
} | ||
} | ||
} | ||
|
||
override fun isFilterApplied(): Boolean = poolList.checkBoxListSelectedValues.size != poolList.model.size - 1 | ||
|
||
override fun reset() = poolList.selectAll() | ||
|
||
override fun filter(item: Thread?): Boolean = item?.pool in poolList.checkBoxListSelectedValues | ||
|
||
override fun customizePopupMenu(menu: JPopupMenu, column: Column<out Thread?, *>, event: Thread?) = Unit | ||
class PoolPanel : LIstFilterPanel<Thread?>( | ||
tabName = "Pool", | ||
toStringFn = { it?.toString() ?: "(No Pool)" }, | ||
) { | ||
override fun filter(item: Thread?) = item?.pool in filterList.checkBoxListSelectedValues | ||
} |
48 changes: 6 additions & 42 deletions
48
src/main/kotlin/io/github/inductiveautomation/kindling/thread/SystemPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,11 @@ | ||
package io.github.inductiveautomation.kindling.thread | ||
|
||
import io.github.inductiveautomation.kindling.core.FilterChangeListener | ||
import io.github.inductiveautomation.kindling.core.FilterPanel | ||
import io.github.inductiveautomation.kindling.core.LIstFilterPanel | ||
import io.github.inductiveautomation.kindling.thread.model.Thread | ||
import io.github.inductiveautomation.kindling.utils.Column | ||
import io.github.inductiveautomation.kindling.utils.FilterList | ||
import io.github.inductiveautomation.kindling.utils.FlatScrollPane | ||
import io.github.inductiveautomation.kindling.utils.getAll | ||
import net.miginfocom.swing.MigLayout | ||
import javax.swing.JPanel | ||
import javax.swing.JPopupMenu | ||
|
||
class SystemPanel : FilterPanel<Thread?>() { | ||
override val tabName = "System" | ||
|
||
val systemList = FilterList { it?.toString() ?: "Unassigned" } | ||
|
||
private val sortButtons = systemList.createSortButtons() | ||
|
||
override val component = JPanel(MigLayout("fill, gap 5")).apply { | ||
val sortGroupEnumeration = sortButtons.elements | ||
add(sortGroupEnumeration.nextElement(), "split ${sortButtons.buttonCount}, flowx") | ||
for (element in sortGroupEnumeration) { | ||
add(element, "gapx 2") | ||
} | ||
add(FlatScrollPane(systemList), "newline, push, grow") | ||
} | ||
|
||
init { | ||
systemList.selectAll() | ||
|
||
systemList.checkBoxListSelectionModel.addListSelectionListener { e -> | ||
if (!e.valueIsAdjusting) { | ||
listeners.getAll<FilterChangeListener>().forEach(FilterChangeListener::filterChanged) | ||
} | ||
} | ||
} | ||
|
||
override fun isFilterApplied(): Boolean = systemList.checkBoxListSelectedValues.size != systemList.model.size - 1 | ||
|
||
override fun reset() = systemList.selectAll() | ||
|
||
override fun filter(item: Thread?): Boolean = item?.system in systemList.checkBoxListSelectedValues | ||
|
||
override fun customizePopupMenu(menu: JPopupMenu, column: Column<out Thread?, *>, event: Thread?) = Unit | ||
class SystemPanel : LIstFilterPanel<Thread?>( | ||
tabName = "System", | ||
toStringFn = { it?.toString() ?: "Unassigned" }, | ||
) { | ||
override fun filter(item: Thread?): Boolean = item?.system in filterList.checkBoxListSelectedValues | ||
} |