UI Tracker initial

GitOrigin-RevId: ee04e511ebff2bd5438fdbc41ff5de4543f1ad5a
This commit is contained in:
Konstantin Bulenkov
2020-10-10 14:48:14 +00:00
committed by intellij-monorepo-bot
parent fff70071d7
commit 2efd1b4175
2 changed files with 63 additions and 0 deletions
@@ -219,6 +219,7 @@ public final class IdeEventQueue extends EventQueue {
addDispatcher(new WindowsUpMaximizer(), null);
}
addDispatcher(new EditingCanceller(), null);
//addDispatcher(new UIMouseTracker(), null);
abracadabraDaberBoreh();
@@ -0,0 +1,62 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.wm.impl.IdeGlassPaneImpl
import java.awt.*
import java.awt.event.MouseEvent
import javax.swing.SwingUtilities
import kotlin.math.sqrt
/**
* @author Konstantin Bulenkov
*/
class UIMouseTracker : IdeEventQueue.EventDispatcher {
var mouseCoordinates = MouseInfo.getPointerInfo().location ?: Point(0,0)
var totalMouseTrack = 0f
override fun dispatch(e: AWTEvent): Boolean {
if (e is MouseEvent) {
when (e.id) {
MouseEvent.MOUSE_RELEASED -> onMouseClicked(e)
MouseEvent.MOUSE_MOVED -> onMouseMove(e)
}
}
return false
}
private fun onMouseMove(e: MouseEvent) {
val dX = (e.xOnScreen - mouseCoordinates.x).toFloat()
val dY = (e.yOnScreen - mouseCoordinates.y).toFloat()
mouseCoordinates.x = e.xOnScreen
mouseCoordinates.y = e.yOnScreen
totalMouseTrack += sqrt(dX*dX + dY*dY)
}
private fun onMouseClicked(e: MouseEvent) {
if (e.clickCount == 0) return
val component = e.component
val clickedComponent = if (component is Container) component.findComponentAt(e.point) else null
if (clickedComponent != null) {
if (clickedComponent is IdeGlassPaneImpl) {
val dialog = DialogWrapper.findInstance(clickedComponent)
if (dialog != null) {
val pointOnDialog = SwingUtilities.convertPoint(e.component, e.point, dialog.contentPane)
val comp = dialog.contentPane.findComponentAt(pointOnDialog.x, pointOnDialog.y)
if (comp != null) {
componentClicked(comp)
}
}
} else {
componentClicked(clickedComponent)
}
}
}
private fun componentClicked(comp: Component) {
//todo[kb] API with UI components to report stats
}
}