Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f3ea6e9
feat(swing-ui): mark the component-library bridge with an opt-in warning
MatkovIvan Nov 13, 2026
0a8da4f
feat(swing-ui-test): find content composed in nested compositions
MatkovIvan Nov 17, 2026
ee5d1f5
feat: report Swing components in composable signatures
MatkovIvan Nov 3, 2026
0ceb30b
feat(swing-ui-detekt): report a composable with more than one modifie…
MatkovIvan Nov 3, 2026
7cefaf7
feat(swing-ui-detekt): report a SwingNode factory that reuses a compo…
MatkovIvan Nov 3, 2026
b44bc12
feat(swing-ui-detekt): report a SwingNode factory that reads a value …
MatkovIvan Nov 3, 2026
d91ca20
fix(swing-ui-detekt): treat a class property named SwingModifier as s…
MatkovIvan Nov 11, 2026
95b390d
fix(swing-ui-detekt): report fully qualified calls and references, no…
MatkovIvan Nov 17, 2026
84e7f1d
feat(swing-ui-detekt): report a composable that calls SwingNode more …
MatkovIvan Nov 12, 2026
3927265
feat(swing-ui-detekt): report a SwingNode update that writes a part o…
MatkovIvan Nov 13, 2026
72da799
feat(swing-ui-detekt): report a SwingNode update that repeats a reque…
MatkovIvan Nov 13, 2026
0809c6e
feat(swing-ui-detekt): report a SwingNode update that stores a callba…
MatkovIvan Nov 13, 2026
6eb5b2e
feat(swing-ui-detekt): report a SwingNode updater call that is not a …
MatkovIvan Nov 13, 2026
926fe1c
fix(swing-ui-detekt): explain why each modifier, table and animation …
MatkovIvan Nov 13, 2026
1b8fc6a
test: compose stock components through the library composables
MatkovIvan Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmarks/benchmark-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ kotlin {
sourceSets.configureEach {
languageSettings.optIn("org.jetbrains.compose.swing.annotations.InternalSwingUiApi")
}
sourceSets.named("test") {
languageSettings.optIn("org.jetbrains.compose.swing.annotations.SwingComponentLibraryApi")
}
target.compilations.named("memoryTest") {
associateWith(target.compilations.getByName("main"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
package org.jetbrains.compose.swing.benchmark

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCompositionContext
import androidx.compose.runtime.setValue
import androidx.compose.testutils.ComposeTestCase
import kotlinx.coroutines.yield
import org.jetbrains.compose.swing.NestedContentHost
import org.jetbrains.compose.swing.components.Label
import org.jetbrains.compose.swing.node.SwingNode
import org.jetbrains.compose.swing.runSwingTest
import org.jetbrains.compose.swing.setContent
import org.junit.jupiter.api.Test
import java.awt.Component
import java.awt.Rectangle
import java.awt.event.FocusAdapter
import java.awt.event.KeyAdapter
Expand Down Expand Up @@ -174,24 +174,13 @@ class ComponentTreeTest {
@Test
fun `dirty region excludes hidden children and children clipped by an ancestor`() =
runSwingTest {
val hidden = JLabel("Hidden").apply { setBounds(0, 0, 10, 10) }
val clipped = JLabel("Clipped").apply { setBounds(0, 0, 10, 10) }
val clip =
JPanel(null).apply {
setBounds(20, 0, 10, 10)
add(clipped)
}
val panel =
JPanel(null).apply {
add(hidden)
add(clip)
}
val subject = VisibilityCase(panel, hidden, clipped)
val subject = VisibilityCase()
SwingExecutionControl(listOf(subject), coroutineContext).use { control ->
control.compose()
control.settle()
val panel = control.hosted<VisibilityPanel>()
val visible = control.measure { panel.repaint(0, 0, 100, 100) }
val excluded = control.measure { subject.toggle() }
val excluded = control.measure { panel.toggle() }
assertEquals(
visible.getValue("componentsInDirtyRegion") - 2,
excluded.getValue("componentsInDirtyRegion"),
Expand All @@ -202,13 +191,18 @@ class ComponentTreeTest {
@Test
fun `replacing a child counts additions only in the measured host`() =
runSwingTest {
val panel = JPanel().apply { add(JLabel("Before")) }
val unrelated = JPanel().apply { add(JLabel("Unrelated")) }
val subject = ReplaceCase(panel, unrelated)
val subject = ReplaceCase()
SwingExecutionControl(listOf(subject), coroutineContext).use { control ->
control.compose()
control.settle()
val metrics = control.measure { subject.toggle() }
val panel = control.hosted<ReplacePanel>()
val metrics =
control.measure {
panel.replace()
unrelated.remove(0)
unrelated.add(JLabel("Other"))
}
assertEquals(1L, metrics.getValue("componentsAdded"))
panel.add(JLabel("Outside measurement"))
assertEquals(0L, control.measure {}.getValue("componentsAdded"))
Expand All @@ -223,20 +217,13 @@ class ComponentTreeTest {
object : ComposeTestCase {
@Composable
override fun Content() {
val panel = remember { JPanel() }
val parent = rememberCompositionContext()
SwingNode(factory = { panel })
DisposableEffect(parent) {
val handle =
panel.setContent(parent) {
if (grow) {
key("nested") {
val text = remember { "Nested remembered content" }
SwingNode(factory = { JLabel(text) })
}
}
NestedContentHost {
if (grow) {
key("nested") {
val text = remember { "Nested remembered content" }
Label(text)
}
onDispose { handle.dispose() }
}
}
}
}
Expand Down Expand Up @@ -273,37 +260,52 @@ class ComponentTreeTest {
}
}

private class VisibilityCase(
private val panel: JPanel,
private val hidden: JLabel,
private val clipped: JLabel,
) : ComposeTestCase {
private class VisibilityCase : ComposeTestCase {
@Composable
override fun Content() {
SwingNode(factory = { VisibilityPanel() })
}
}

private class VisibilityPanel : JPanel(null) {
private val hidden = JLabel("Hidden").apply { setBounds(0, 0, 10, 10) }
private val clipped = JLabel("Clipped").apply { setBounds(0, 0, 10, 10) }

init {
add(hidden)
add(
JPanel(null).apply {
setBounds(20, 0, 10, 10)
add(clipped)
},
)
}

fun toggle() {
hidden.isVisible = !hidden.isVisible
clipped.setLocation(if (hidden.isVisible) 0 else 20, 0)
panel.repaint(0, 0, 100, 100)
repaint(0, 0, 100, 100)
}
}

private class ReplaceCase : ComposeTestCase {
@Composable
override fun Content() {
SwingNode(factory = { panel })
SwingNode(factory = { ReplacePanel() })
}
}

private class ReplaceCase(
private val panel: JPanel,
private val unrelated: JPanel,
) : ComposeTestCase {
fun toggle() {
panel.remove(0)
panel.add(JLabel("After"))
unrelated.remove(0)
unrelated.add(JLabel("Other"))
private class ReplacePanel : JPanel() {
init {
add(JLabel("Before"))
}

@Composable
override fun Content() {
SwingNode(factory = { panel })
fun replace() {
remove(0)
add(JLabel("After"))
}
}
}

private inline fun <reified T : Component> SwingExecutionControl.hosted(): T =
componentTree(host.panel).filterIsInstance<T>().single()
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.testutils.ComposeTestCase
import org.jetbrains.compose.swing.node.SwingNode
import org.jetbrains.compose.swing.runSwingTest
import java.awt.Color
import java.awt.Component
import java.awt.Dimension
import java.awt.Graphics
import javax.swing.JPanel
Expand All @@ -23,22 +24,21 @@ class SwingExecutionControlDrawTest {
SwingExecutionControl(listOf(subject), coroutineContext).use { control ->
control.compose()
control.recompose()
assertEquals(0, subject.panel.width)
val panel = control.hosted<PaintPanel>()
assertEquals(0, panel.width)
control.host.drawToBitmap()
assertNotEquals(Color.RED.rgb, control.host.image.getRGB(1, 1))
control.host.layout()
assertTrue(subject.panel.width > 0)
assertTrue(panel.width > 0)
control.host.drawToBitmap()
assertEquals(Color.RED.rgb, control.host.image.getRGB(1, 1))
}
}

private class PaintCase : ComposeTestCase {
val panel = PaintPanel()

@Composable
override fun Content() {
SwingNode(factory = { panel })
SwingNode(factory = { PaintPanel() })
}
}

Expand All @@ -54,3 +54,6 @@ class SwingExecutionControlDrawTest {
}
}
}

private inline fun <reified T : Component> SwingExecutionControl.hosted(): T =
componentTree(host.panel).filterIsInstance<T>().single()
Loading
Loading