Skip to content

Commit

Permalink
Fix graphical glitches in IDEA
Browse files Browse the repository at this point in the history
  • Loading branch information
IKupriyanov-HORIS committed May 26, 2021
1 parent fc908bd commit 3ae1fec
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
24 changes: 24 additions & 0 deletions plot-config/src/jvmMain/kotlin/plot/AwtContainerDisposer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2021. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/

package jetbrains.datalore.plot

import jetbrains.datalore.base.registration.Disposable
import java.awt.Container

class AwtContainerDisposer(
private val container: Container
) : Disposable {
private var isDisposed: Boolean = false

override fun dispose() {
require(!isDisposed) { "Already disposed." }
isDisposed = true
container.components.forEach {
// We expect all children are disposable
(it as Disposable).dispose()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal object AwtLiveMapFactoryUtil {
preferredSize: ReadableProperty<DoubleVector>,
svgComponentFactory: (svg: SvgSvgElement) -> JComponent,
executor: (() -> Unit) -> Unit
): DisposableJPanel {
): JComponent {
val cursorServiceConfig = CursorServiceConfig()
injectLiveMapProvider(assembler, processedSpec, cursorServiceConfig)

Expand Down
13 changes: 8 additions & 5 deletions plot-config/src/jvmMain/kotlin/plot/AwtLiveMapPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ import java.awt.event.ComponentEvent
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.JComponent
import javax.swing.JLayeredPane
import javax.swing.JPanel


class AwtLiveMapPanel(
private val plotContainer: PlotContainer,
private val plotComponent: JComponent,
private val executor: (() -> Unit) -> Unit,
private val cursorServiceConfig: CursorServiceConfig
) : DisposableJPanel(null) {
) : JLayeredPane(), Disposable {
private val awtContainerDisposer = AwtContainerDisposer(this)
private val mappers: MutableList<() -> Unit> = ArrayList()
private val livemaps: MutableList<Registration> = ArrayList()
private val registrations: MutableList<Registration> = ArrayList()
private val mouseMoutionListener = object : MouseAdapter() {
override fun mouseDragged(e: MouseEvent) {
super.mouseDragged(e)
Expand Down Expand Up @@ -93,7 +96,7 @@ class AwtLiveMapPanel(
timer
).let {
mappers.add {
livemaps.add(canvasFigure.mapToCanvas(it))
registrations.add(canvasFigure.mapToCanvas(it))
}
}
}
Expand All @@ -111,8 +114,8 @@ class AwtLiveMapPanel(
}

override fun dispose() {
super.dispose()
livemaps.forEach(Disposable::dispose)
awtContainerDisposer.dispose()
registrations.forEach(Disposable::dispose)
plotComponent.removeMouseMotionListener(mouseMoutionListener)
plotContainer.clearContent()
cursorServiceConfig.defaultSetter { }
Expand Down
10 changes: 3 additions & 7 deletions plot-config/src/jvmMain/kotlin/plot/DisposableJPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ import java.awt.LayoutManager
import javax.swing.JPanel

open class DisposableJPanel(layout: LayoutManager?) : JPanel(layout), Disposable {
private var isDisposed: Boolean = false
private val disposer = AwtContainerDisposer(this)

override fun dispose() {
require(!isDisposed) { "Already disposed." }
isDisposed = true
components.forEach {
// We a expect all children are disposable
(it as Disposable).dispose()
}
disposer.dispose()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ class AwtRepaintTimer(
) : Disposable {
private val myHandlers = ArrayList<(Long) -> Unit>()

init {
myHandlers.add { repaint() }
}

private var actionListener = ActionListener {
myHandlers.forEach {
executor {
it(System.currentTimeMillis())
}
}
repaint()
}

private val myTimer: Timer = Timer(1000 / 60, actionListener)
Expand Down Expand Up @@ -54,6 +51,7 @@ class AwtRepaintTimer(

override fun dispose() {
myTimer.stop()
myTimer.removeActionListener(actionListener)
actionListener = ActionListener {}
myHandlers.clear()
}
Expand Down

0 comments on commit 3ae1fec

Please sign in to comment.