Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding of Swing component painting behavior #722

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions jvm-package/jvm-publish-batik/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ task jarLetsPlotJvmBatikClasses(type: ShadowJar) {
exclude 'svgMapper/**/*'

// Fix for "META-INF/services files specify xalan" https://github.com/JetBrains/lets-plot/issues/576
// Get rid of "services" altogether.
exclude 'META-INF/services/**/*'
// Get rid only of harmful services.
exclude 'META-INF/services/org.apache.*'
exclude 'META-INF/services/javax.*'
}

task jarLetsPlotJvmBatikSources(type: ShadowJar) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023. 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.vis.swing

import org.apache.batik.gvt.GraphicsNode
import java.awt.Dimension
import java.awt.Graphics2D
import java.util.*

interface BatikGraphicsNodeRenderer {
val priority: Int
fun paint(node: GraphicsNode, g: Graphics2D, size: Dimension)

object Default : BatikGraphicsNodeRenderer {
override val priority: Int
get() = 0

override fun paint(node: GraphicsNode, g: Graphics2D, size: Dimension) {
node.paint(g)
}
}

companion object {
fun getInstance(): BatikGraphicsNodeRenderer {
val serviceClass = BatikGraphicsNodeRenderer::class.java
val loader = ServiceLoader.load(serviceClass, serviceClass.classLoader)
return loader.maxByOrNull { it.priority } ?: Default
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BatikMapperComponentHelper private constructor(
private val myMapper: SvgRootDocumentMapper
private val myUserAgent: UserAgent
private val myBridgeContext: BridgeContext
private val myRenderer: BatikGraphicsNodeRenderer

val preferredSize: Dimension
get() {
Expand Down Expand Up @@ -75,6 +76,8 @@ class BatikMapperComponentHelper private constructor(
myGraphicsNode = builder.build(myBridgeContext, myMapper.target)

myUserAgent.eventDispatcher.rootNode = myGraphicsNode

myRenderer = BatikGraphicsNodeRenderer.getInstance()
}

internal fun addSvgNodeContainerListener(l: SvgNodeContainerListener) {
Expand All @@ -99,7 +102,7 @@ class BatikMapperComponentHelper private constructor(
}

fun paint(g: Graphics2D) {
myGraphicsNode.paint(g)
myRenderer.paint(myGraphicsNode, g, preferredSize)
}

// fun handleMouseEvent(e: MouseEvent) {
Expand Down