mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[Java] Improve adhesion to the right border for compilation charts
IDEA-356480 GitOrigin-RevId: 5ea82d24ca31e8bb3a185b27f5424728405497b0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d1ccea5333
commit
5c3080b5d5
@@ -17,6 +17,7 @@ class CompilationChartsView(project: Project, private val vm: CompilationChartsV
|
||||
init {
|
||||
val zoom = Zoom()
|
||||
|
||||
|
||||
val scroll = object : JBScrollPane() {
|
||||
override fun createViewport(): JViewport = CompilationChartsViewport(zoom)
|
||||
}.apply {
|
||||
@@ -24,13 +25,13 @@ class CompilationChartsView(project: Project, private val vm: CompilationChartsV
|
||||
verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
|
||||
border = JBUI.Borders.empty()
|
||||
viewport.scrollMode = JViewport.SIMPLE_SCROLL_MODE
|
||||
horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
|
||||
name = "compilation-charts-scroll-pane"
|
||||
|
||||
val rightAdhesionScrollBarListener = RightAdhesionScrollBarListener(viewport)
|
||||
addMouseWheelListener(rightAdhesionScrollBarListener)
|
||||
horizontalScrollBar.addAdjustmentListener(rightAdhesionScrollBarListener)
|
||||
}
|
||||
val rightAdhesionScrollBarListener = RightAdhesionScrollBarListener(scroll.viewport)
|
||||
scroll.horizontalScrollBar.addAdjustmentListener(rightAdhesionScrollBarListener)
|
||||
val diagrams = CompilationChartsDiagramsComponent(vm, zoom, scroll.viewport).apply {
|
||||
addMouseWheelListener(rightAdhesionScrollBarListener)
|
||||
name = "compilation-charts-diagrams-component"
|
||||
isFocusable = true
|
||||
}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.compiler.charts.ui
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.util.concurrency.AppExecutorUtil
|
||||
import java.awt.Point
|
||||
import java.awt.event.AdjustmentEvent
|
||||
import java.awt.event.AdjustmentListener
|
||||
import java.awt.event.MouseWheelEvent
|
||||
import java.awt.event.MouseWheelListener
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.swing.JViewport
|
||||
|
||||
internal class RightAdhesionScrollBarListener(private val viewport: JViewport) : AdjustmentListener, MouseWheelListener {
|
||||
private var shouldScroll = true
|
||||
|
||||
private val executor = AppExecutorUtil.createBoundedScheduledExecutorService("Compilation charts adjust value listener", 1)
|
||||
private var updateShouldScrollTask: ScheduledFuture<*>? = null
|
||||
override fun adjustmentValueChanged(e: AdjustmentEvent) {
|
||||
if (e.valueIsAdjusting) {
|
||||
updateShouldScroll()
|
||||
@@ -19,7 +24,17 @@ internal class RightAdhesionScrollBarListener(private val viewport: JViewport) :
|
||||
}
|
||||
|
||||
override fun mouseWheelMoved(e: MouseWheelEvent) {
|
||||
updateShouldScroll(e.unitsToScroll)
|
||||
if (e.isControlDown) {
|
||||
shouldScroll = false
|
||||
scheduleUpdateShouldScroll()
|
||||
} else {
|
||||
updateShouldScroll(e.unitsToScroll)
|
||||
}
|
||||
}
|
||||
|
||||
private fun scheduleUpdateShouldScroll() {
|
||||
updateShouldScrollTask?.cancel(false)
|
||||
updateShouldScrollTask = executor.schedule(::updateShouldScroll, 100, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
|
||||
private fun adjustHorizontalScrollToRightIfNeeded() {
|
||||
@@ -31,4 +46,8 @@ internal class RightAdhesionScrollBarListener(private val viewport: JViewport) :
|
||||
private fun updateShouldScroll(additionalValue: Int = 0) {
|
||||
shouldScroll = viewport.viewPosition.x + viewport.width + additionalValue >= viewport.viewSize.width
|
||||
}
|
||||
|
||||
companion object {
|
||||
val LOG = Logger.getInstance(RightAdhesionScrollBarListener::class.java)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user