diff --git a/java/compiler/charts/resources/messages/CompilationChartsBundle.properties b/java/compiler/charts/resources/messages/CompilationChartsBundle.properties index abe6439846fa..7fd847b02b3f 100644 --- a/java/compiler/charts/resources/messages/CompilationChartsBundle.properties +++ b/java/compiler/charts/resources/messages/CompilationChartsBundle.properties @@ -6,4 +6,6 @@ charts.production.type=Production charts.test.type=Test charts.memory.type=Memory charts.cpu.type=CPU -charts.search.results={0} results \ No newline at end of file +charts.search.results={0} results +charts.scroll.to.end.action.title = Scroll to End +charts.scroll.to.end.action.description = Scrolls to end in compilation charts \ No newline at end of file diff --git a/java/compiler/charts/src/com/intellij/java/compiler/charts/CompilationChartsViewModel.kt b/java/compiler/charts/src/com/intellij/java/compiler/charts/CompilationChartsViewModel.kt index ab9a8198c455..c0167c72513e 100644 --- a/java/compiler/charts/src/com/intellij/java/compiler/charts/CompilationChartsViewModel.kt +++ b/java/compiler/charts/src/com/intellij/java/compiler/charts/CompilationChartsViewModel.kt @@ -18,8 +18,12 @@ class CompilationChartsViewModel(val lifetime: Lifetime) { val statistics: Statistics = Statistics() val cpuMemory: RdProperty = RdProperty(CpuMemoryStatisticsType.MEMORY) val filter: RdProperty = RdProperty(Filter()) + val scrollToEndEvent: RdProperty = RdProperty(ScrollToEndEvent()) private val threadIndexes: MutableMap = ConcurrentHashMap() + + fun requestScrollToEnd() = scrollToEndEvent.set(ScrollToEndEvent()) + fun started(values: List) { values.forEach { value -> modules.add(Modules.StartEvent(value, index(value.thread))) @@ -118,6 +122,8 @@ class CompilationChartsViewModel(val lifetime: Lifetime) { } } + class ScrollToEndEvent + enum class CpuMemoryStatisticsType { CPU, MEMORY } diff --git a/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/ActionPanel.kt b/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/ActionPanel.kt index 0c8cd940cc1b..72eb3b27fc17 100644 --- a/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/ActionPanel.kt +++ b/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/ActionPanel.kt @@ -4,8 +4,8 @@ package com.intellij.java.compiler.charts.ui import com.intellij.icons.AllIcons import com.intellij.java.compiler.charts.CompilationChartsBundle import com.intellij.java.compiler.charts.CompilationChartsViewModel -import com.intellij.openapi.actionSystem.ActionManager -import com.intellij.openapi.actionSystem.IdeActions +import com.intellij.openapi.actionSystem.* +import com.intellij.openapi.actionSystem.ex.CustomComponentAction import com.intellij.openapi.project.DumbAwareAction import com.intellij.openapi.project.Project import com.intellij.openapi.ui.popup.IconButton @@ -104,10 +104,42 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart }) // legend - addToRight(JPanel().apply { + val actionGroup = DefaultActionGroup({"Some action group"}, listOf(CompilationChartsStatsActionHolder(vm), Separator(), ScrollToEndAction(vm))) + addToRight(ActionManager.getInstance().createActionToolbar("Some toolbar", actionGroup, true).component) + + DumbAwareAction.create { + val focusManager = IdeFocusManager.getInstance(project) + if (focusManager.getFocusedDescendantFor(this@ActionPanel.component) != null) { + focusManager.requestFocus(searchField, true) + } + }.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_FIND).shortcutSet, this@ActionPanel.component) + } + + fun updateLabel(set: Set?, filter: CompilationChartsViewModel.Filter?) { + if (set == null || filter == null) { + countLabel.text = "" + } else { + val count = set.count { filter.test(it) } + if (count == set.count()) { + countLabel.text = "" + } else { + countLabel.text = CompilationChartsBundle.message("charts.search.results", count) + } + } + } + + private class ScrollToEndAction(private val vm : CompilationChartsViewModel): DumbAwareAction( + CompilationChartsBundle.message("charts.scroll.to.end.action.title"), + CompilationChartsBundle.message("charts.scroll.to.end.action.description"), + AllIcons.Actions.Forward) { + override fun actionPerformed(e: AnActionEvent) = vm.requestScrollToEnd() + } + + private class CompilationChartsStatsActionHolder(private val vm: CompilationChartsViewModel) : DumbAwareAction(), CustomComponentAction { + + override fun createCustomComponent(presentation: Presentation, place: String): JComponent = JPanel().apply { layout = BoxLayout(this, BoxLayout.LINE_AXIS) border = JBUI.Borders.empty(2) - add(JBPanel>(FlowLayout(FlowLayout.LEFT)).apply { val block = JBLabel().apply { preferredSize = Dimension(10, 10) @@ -173,7 +205,6 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart background = COLOR_MEMORY_BORDER } val label = JBLabel(CompilationChartsBundle.message("charts.memory.type")) - add(block) add(label) @@ -194,26 +225,7 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart } }) }) - }) - - DumbAwareAction.create { - val focusManager = IdeFocusManager.getInstance(project) - if (focusManager.getFocusedDescendantFor(this@ActionPanel.component) != null) { - focusManager.requestFocus(searchField, true) - } - }.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_FIND).shortcutSet, this@ActionPanel.component) - } - - fun updateLabel(set: Set?, filter: CompilationChartsViewModel.Filter?) { - if (set == null || filter == null) { - countLabel.text = "" - } else { - val count = set.count { filter.test(it) } - if (count == set.count()) { - countLabel.text = "" - } else { - countLabel.text = CompilationChartsBundle.message("charts.search.results", count) - } } + override fun actionPerformed(e: AnActionEvent) = Unit } } \ No newline at end of file diff --git a/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/CompilationChartsView.kt b/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/CompilationChartsView.kt index 640666030a1b..02049826d68a 100644 --- a/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/CompilationChartsView.kt +++ b/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/CompilationChartsView.kt @@ -84,6 +84,10 @@ class CompilationChartsView(project: Project, private val vm: CompilationChartsV diagrams.cpuMemory = filter diagrams.forceRepaint() } + + vm.scrollToEndEvent.advise(vm.lifetime) { _ -> + rightAdhesionScrollBarListener.scrollToEnd() + } } companion object { diff --git a/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/RightAdhesionScrollBarListener.kt b/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/RightAdhesionScrollBarListener.kt index 40fbe6218e1d..62680a58d844 100644 --- a/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/RightAdhesionScrollBarListener.kt +++ b/java/compiler/charts/src/com/intellij/java/compiler/charts/ui/RightAdhesionScrollBarListener.kt @@ -47,6 +47,11 @@ internal class RightAdhesionScrollBarListener(private val viewport: JViewport) : shouldScroll = viewport.viewPosition.x + viewport.width + additionalValue >= viewport.viewSize.width } + fun scrollToEnd() { + shouldScroll = true + adjustHorizontalScrollToRightIfNeeded() + } + companion object { val LOG = Logger.getInstance(RightAdhesionScrollBarListener::class.java) }