mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Java] Extract zoom actions of compilation charts into the intellij.java.compiler.charts.xml
IDEA-353070 GitOrigin-RevId: 60cb62d5e21810a2ef189d7dc9947d10621e6a21
This commit is contained in:
committed by
intellij-monorepo-bot
parent
00bf390eb6
commit
cc61ed361e
@@ -8,4 +8,18 @@
|
||||
<registryKey key="compilation.charts" defaultValue="false"
|
||||
description="Show compilation charts" restartRequired="false"/>
|
||||
</extensions>
|
||||
<actions resource-bundle="messages.CompilationChartsBundle">
|
||||
<group id="CompilationChartsActionGroup" class="com.intellij.openapi.actionSystem.DefaultActionGroup">
|
||||
<separator/>
|
||||
<action id="CompilationChartsZoomResetAction" class="com.intellij.java.compiler.charts.ui.ActionPanel$ZoomResetAction"
|
||||
icon="AllIcons.Graph.ActualZoom">
|
||||
<keyboard-shortcut first-keystroke="meta 0" keymap="Mac OS X"/>
|
||||
<keyboard-shortcut first-keystroke="ctrl shift 0" keymap="$default"/>
|
||||
</action>
|
||||
<action id="CompilationChartsZoomOutAction" class="com.intellij.java.compiler.charts.ui.ActionPanel$ZoomOutAction"
|
||||
icon="AllIcons.Graph.ZoomOut" use-shortcut-of="CollapseAll"/>
|
||||
<action id="CompilationChartsZoomInAction" class="com.intellij.java.compiler.charts.ui.ActionPanel$ZoomInAction"
|
||||
icon="AllIcons.Graph.ZoomIn" use-shortcut-of="ExpandAll"/>
|
||||
</group>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -9,9 +9,9 @@ charts.cpu.type=CPU
|
||||
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
|
||||
charts.zoom.in.action.title=Zoom In
|
||||
charts.zoom.in.action.description=Increases zoom of compilation charts
|
||||
charts.zoom.out.action.title=Zoom Out
|
||||
charts.zoom.out.action.description=Decreases zoom of compilation charts
|
||||
charts.zoom.reset.action.title=Reset
|
||||
charts.zoom.reset.action.description=Resets zoom of compilation charts
|
||||
action.CompilationChartsZoomInAction.text=Zoom In Compilation Charts
|
||||
action.CompilationChartsZoomInAction.description=Increases zoom of compilation charts
|
||||
action.CompilationChartsZoomOutAction.text=Zoom Out Compilation Charts
|
||||
action.CompilationChartsZoomOutAction.description=Decreases zoom of compilation charts
|
||||
action.CompilationChartsZoomResetAction.text=Reset Zoom In Compilation Charts
|
||||
action.CompilationChartsZoomResetAction.description=Resets zoom in compilation charts
|
||||
|
||||
-9
@@ -20,12 +20,9 @@ class CompilationChartsViewModel(val lifetime: Lifetime) {
|
||||
val cpuMemory: RdProperty<CpuMemoryStatisticsType> = RdProperty(CpuMemoryStatisticsType.MEMORY)
|
||||
val filter: RdProperty<Filter> = RdProperty(Filter())
|
||||
val scrollToEndEvent: RdProperty<ScrollToEndEvent> = RdProperty(ScrollToEndEvent())
|
||||
val zoomEvent: RdProperty<ZoomEvent> = RdProperty(ZoomEvent.Reset)
|
||||
|
||||
fun requestScrollToEnd() = scrollToEndEvent.set(ScrollToEndEvent())
|
||||
|
||||
fun requestZoomChange(event: ZoomEvent) = zoomEvent.set(event)
|
||||
|
||||
fun started(values: List<StartTarget>) {
|
||||
values.forEach { value ->
|
||||
modules.add(Modules.StartEvent(value))
|
||||
@@ -117,12 +114,6 @@ class CompilationChartsViewModel(val lifetime: Lifetime) {
|
||||
|
||||
class ScrollToEndEvent
|
||||
|
||||
sealed class ZoomEvent {
|
||||
class In : ZoomEvent()
|
||||
class Out : ZoomEvent()
|
||||
data object Reset: ZoomEvent()
|
||||
}
|
||||
|
||||
enum class CpuMemoryStatisticsType {
|
||||
CPU {
|
||||
override fun max(statistics: Statistics): Long = 100
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.intellij.java.compiler.charts.CompilationChartsBundle
|
||||
import com.intellij.java.compiler.charts.CompilationChartsViewModel
|
||||
import com.intellij.openapi.actionSystem.*
|
||||
import com.intellij.openapi.actionSystem.ex.CustomComponentAction
|
||||
import com.intellij.openapi.client.ClientSystemInfo
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.popup.IconButton
|
||||
@@ -23,13 +22,14 @@ import com.intellij.util.ui.components.BorderLayoutPanel
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Dimension
|
||||
import java.awt.FlowLayout
|
||||
import java.awt.event.InputEvent.CTRL_DOWN_MASK
|
||||
import java.awt.event.InputEvent.META_DOWN_MASK
|
||||
import java.awt.event.KeyAdapter
|
||||
import java.awt.event.KeyEvent
|
||||
import java.awt.event.MouseAdapter
|
||||
import java.awt.event.MouseEvent
|
||||
import javax.swing.*
|
||||
import javax.swing.BorderFactory
|
||||
import javax.swing.BoxLayout
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.event.DocumentEvent
|
||||
import javax.swing.event.DocumentListener
|
||||
|
||||
@@ -106,18 +106,15 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart
|
||||
})
|
||||
|
||||
// legend
|
||||
val actionGroup = DefaultActionGroup(listOf(
|
||||
CompilationChartsStatsActionHolder(vm),
|
||||
Separator(),
|
||||
ZoomResetAction(vm, component),
|
||||
ZoomOutAction(vm, component),
|
||||
ZoomInAction(vm, component),
|
||||
ScrollToEndAction(vm))
|
||||
)
|
||||
val toolbar = ActionManager.getInstance().createActionToolbar(COMPILATION_CHARTS_TOOLBAR_NAME, actionGroup, true).apply {
|
||||
targetComponent = this@ActionPanel
|
||||
val actionGroup = ActionManager.getInstance().getAction("CompilationChartsActionGroup") as? DefaultActionGroup
|
||||
if (actionGroup != null) {
|
||||
actionGroup.addAction(CompilationChartsStatsActionHolder(vm), Constraints.FIRST)
|
||||
actionGroup.addAction(ScrollToEndAction(vm), Constraints.LAST)
|
||||
val toolbar = ActionManager.getInstance().createActionToolbar(COMPILATION_CHARTS_TOOLBAR_NAME, actionGroup, true).apply {
|
||||
targetComponent = this@ActionPanel
|
||||
}
|
||||
addToRight(toolbar.component)
|
||||
}
|
||||
addToRight(toolbar.component)
|
||||
|
||||
DumbAwareAction.create {
|
||||
val focusManager = IdeFocusManager.getInstance(project)
|
||||
@@ -149,42 +146,25 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart
|
||||
override fun actionPerformed(e: AnActionEvent) = vm.requestScrollToEnd()
|
||||
}
|
||||
|
||||
private class ZoomInAction(private val vm: CompilationChartsViewModel, component: JComponent) : DumbAwareAction(
|
||||
CompilationChartsBundle.message("charts.zoom.in.action.title"),
|
||||
CompilationChartsBundle.message("charts.zoom.in.action.description"),
|
||||
AllIcons.Graph.ZoomIn
|
||||
) {
|
||||
init {
|
||||
registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_EXPAND_ALL).shortcutSet, component)
|
||||
internal abstract class CompilationChartsActionBase: DumbAwareAction() {
|
||||
override fun update(e: AnActionEvent) {
|
||||
e.presentation.isEnabledAndVisible = e.getData(COMPILATION_CHARTS_VIEW_KEY) != null
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) = vm.requestZoomChange(CompilationChartsViewModel.ZoomEvent.In())
|
||||
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
|
||||
}
|
||||
|
||||
private class ZoomOutAction(private val vm: CompilationChartsViewModel, component: JComponent) : DumbAwareAction(
|
||||
CompilationChartsBundle.message("charts.zoom.out.action.title"),
|
||||
CompilationChartsBundle.message("charts.zoom.out.action.description"),
|
||||
AllIcons.Graph.ZoomOut
|
||||
) {
|
||||
init {
|
||||
registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.ACTION_COLLAPSE_ALL).shortcutSet, component)
|
||||
internal abstract class ZoomActionBase(private val zoomEvent: ZoomEvent): CompilationChartsActionBase() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
e.getData(COMPILATION_CHARTS_VIEW_KEY)?.zoom(zoomEvent)
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) = vm.requestZoomChange(CompilationChartsViewModel.ZoomEvent.Out())
|
||||
}
|
||||
|
||||
internal class ZoomInAction : ZoomActionBase(ZoomEvent.IN)
|
||||
|
||||
private class ZoomResetAction(private val vm: CompilationChartsViewModel, component: JComponent) : DumbAwareAction(
|
||||
CompilationChartsBundle.message("charts.zoom.reset.action.title"),
|
||||
CompilationChartsBundle.message("charts.zoom.reset.action.description"),
|
||||
AllIcons.Graph.ActualZoom
|
||||
) {
|
||||
init {
|
||||
registerCustomShortcutSet(CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_0, SHORTCUT_MODIFIER_MASK_NUMBER)), component)
|
||||
}
|
||||
internal class ZoomOutAction : ZoomActionBase(ZoomEvent.OUT)
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) = vm.requestZoomChange(CompilationChartsViewModel.ZoomEvent.Reset)
|
||||
}
|
||||
internal class ZoomResetAction : ZoomActionBase(ZoomEvent.RESET)
|
||||
|
||||
private class CompilationChartsStatsActionHolder(private val vm: CompilationChartsViewModel) : DumbAwareAction(), CustomComponentAction {
|
||||
|
||||
@@ -281,8 +261,6 @@ class ActionPanel(private val project: Project, private val vm: CompilationChart
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SHORTCUT_MODIFIER_MASK_NUMBER
|
||||
get() = if (ClientSystemInfo.isMac()) META_DOWN_MASK else CTRL_DOWN_MASK
|
||||
private const val COMPILATION_CHARTS_TOOLBAR_NAME = "Compilation charts toolbar"
|
||||
}
|
||||
}
|
||||
+29
-10
@@ -4,6 +4,9 @@ package com.intellij.java.compiler.charts.ui
|
||||
import com.intellij.java.compiler.charts.CompilationChartsViewModel
|
||||
import com.intellij.java.compiler.charts.CompilationChartsViewModel.CpuMemoryStatisticsType.CPU
|
||||
import com.intellij.java.compiler.charts.CompilationChartsViewModel.CpuMemoryStatisticsType.MEMORY
|
||||
import com.intellij.openapi.actionSystem.DataKey
|
||||
import com.intellij.openapi.actionSystem.DataSink
|
||||
import com.intellij.openapi.actionSystem.UiDataProvider
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.ui.components.JBScrollPane
|
||||
import com.intellij.util.ui.JBUI
|
||||
@@ -12,7 +15,10 @@ import com.jetbrains.rd.util.reactive.IViewableList
|
||||
import javax.swing.JViewport
|
||||
import javax.swing.ScrollPaneConstants
|
||||
|
||||
class CompilationChartsView(project: Project, private val vm: CompilationChartsViewModel) : BorderLayoutPanel() {
|
||||
class CompilationChartsView(project: Project, private val vm: CompilationChartsViewModel) : BorderLayoutPanel(), UiDataProvider {
|
||||
private val diagrams: CompilationChartsDiagramsComponent
|
||||
private val rightAdhesionScrollBarListener: RightAdhesionScrollBarListener
|
||||
|
||||
init {
|
||||
val zoom = Zoom()
|
||||
val scrollType = AutoScrollingType()
|
||||
@@ -26,9 +32,9 @@ class CompilationChartsView(project: Project, private val vm: CompilationChartsV
|
||||
viewport.scrollMode = JViewport.SIMPLE_SCROLL_MODE
|
||||
name = "compilation-charts-scroll-pane"
|
||||
}
|
||||
val rightAdhesionScrollBarListener = RightAdhesionScrollBarListener(scroll.viewport, zoom, scrollType)
|
||||
rightAdhesionScrollBarListener = RightAdhesionScrollBarListener(scroll.viewport, zoom, scrollType)
|
||||
scroll.horizontalScrollBar.addAdjustmentListener(rightAdhesionScrollBarListener)
|
||||
val diagrams = CompilationChartsDiagramsComponent(vm, zoom, scroll.viewport).apply {
|
||||
diagrams = CompilationChartsDiagramsComponent(vm, zoom, scroll.viewport).apply {
|
||||
addMouseWheelListener(rightAdhesionScrollBarListener)
|
||||
name = "compilation-charts-diagrams-component"
|
||||
isFocusable = true
|
||||
@@ -80,18 +86,31 @@ class CompilationChartsView(project: Project, private val vm: CompilationChartsV
|
||||
vm.scrollToEndEvent.advise(vm.lifetime) { _ ->
|
||||
rightAdhesionScrollBarListener.scrollToEnd()
|
||||
}
|
||||
}
|
||||
|
||||
vm.zoomEvent.advise(vm.lifetime) { zoomType ->
|
||||
when (zoomType) {
|
||||
is CompilationChartsViewModel.ZoomEvent.In -> rightAdhesionScrollBarListener.increase()
|
||||
is CompilationChartsViewModel.ZoomEvent.Out -> rightAdhesionScrollBarListener.decrease()
|
||||
is CompilationChartsViewModel.ZoomEvent.Reset -> rightAdhesionScrollBarListener.reset()
|
||||
}
|
||||
diagrams.smartDraw(true, false)
|
||||
override fun uiDataSnapshot(sink: DataSink) {
|
||||
sink[COMPILATION_CHARTS_VIEW_KEY] = this
|
||||
}
|
||||
|
||||
internal fun zoom(zoomType: ZoomEvent) {
|
||||
when (zoomType) {
|
||||
ZoomEvent.IN -> rightAdhesionScrollBarListener.increase()
|
||||
ZoomEvent.OUT -> rightAdhesionScrollBarListener.decrease()
|
||||
ZoomEvent.RESET -> rightAdhesionScrollBarListener.reset()
|
||||
}
|
||||
diagrams.smartDraw(true, false)
|
||||
}
|
||||
}
|
||||
|
||||
enum class ZoomEvent {
|
||||
IN,
|
||||
OUT,
|
||||
RESET
|
||||
}
|
||||
|
||||
|
||||
internal val COMPILATION_CHARTS_VIEW_KEY = DataKey.create<CompilationChartsView>("CompilationChartsView")
|
||||
|
||||
data class Statistic(var start: Long, var end: Long, var maxMemory: Long, var maxCpu: Long = 100) {
|
||||
constructor() : this(Long.MAX_VALUE, 0, 0, 0)
|
||||
|
||||
|
||||
+7
-12
@@ -62,20 +62,15 @@ internal class RightAdhesionScrollBarListener(
|
||||
shouldScroll.stop()
|
||||
}
|
||||
|
||||
fun increase() {
|
||||
disableShouldScroll()
|
||||
zoom.adjust(viewport, viewport.getMiddlePoint(), ZOOM_IN_MULTIPLIER)
|
||||
scheduleUpdateShouldScroll()
|
||||
}
|
||||
fun increase() = applyZoomTransformation { adjust(viewport, viewport.getMiddlePoint(), ZOOM_IN_MULTIPLIER) }
|
||||
|
||||
fun decrease() {
|
||||
disableShouldScroll()
|
||||
zoom.adjust(viewport, viewport.getMiddlePoint(), ZOOM_OUT_MULTIPLIER)
|
||||
scheduleUpdateShouldScroll()
|
||||
}
|
||||
fun decrease() = applyZoomTransformation { adjust(viewport, viewport.getMiddlePoint(), ZOOM_OUT_MULTIPLIER) }
|
||||
|
||||
fun reset() {
|
||||
zoom.reset(viewport, viewport.getMiddlePoint())
|
||||
fun reset() = applyZoomTransformation { reset(viewport, viewport.getMiddlePoint()) }
|
||||
|
||||
private fun applyZoomTransformation(transformation: Zoom.() -> Unit) {
|
||||
disableShouldScroll()
|
||||
zoom.transformation()
|
||||
scheduleUpdateShouldScroll()
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,9 @@ class Zoom {
|
||||
}
|
||||
|
||||
fun reset(viewport: JViewport, xPosition: Int) {
|
||||
val delta = INITIAL_SCALE / scale
|
||||
adjust(viewport, xPosition, delta)
|
||||
scale = INITIAL_SCALE
|
||||
adjust(viewport, xPosition, 1.0)
|
||||
}
|
||||
|
||||
private fun toPixels(duration: Double, scale: Double): Double = nanosToSeconds(duration * scale)
|
||||
|
||||
Reference in New Issue
Block a user