ZenScript main repository
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DSimpleTooltip.java 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package org.openzen.drawablegui;
  7. import live.LiveString;
  8. import org.openzen.drawablegui.style.DStyleClass;
  9. /**
  10. *
  11. * @author Hoofdgebruiker
  12. */
  13. public class DSimpleTooltip {
  14. private final DStyleClass styleClass;
  15. private final LiveString tooltip;
  16. private DUIContext context;
  17. private DSimpleTooltipStyle style;
  18. private DTimerHandle timerHandle = null;
  19. private int enterMouseX;
  20. private int enterMouseY;
  21. private DUIWindow window;
  22. public DSimpleTooltip(DStyleClass styleClass, LiveString tooltip) {
  23. this.styleClass = styleClass;
  24. this.tooltip = tooltip;
  25. }
  26. public void setContext(DUIContext context) {
  27. this.context = context;
  28. }
  29. public void onTargetMouseEnter(DMouseEvent e) {
  30. if (timerHandle != null)
  31. timerHandle.close();
  32. timerHandle = context.setTimer(1000, this::show);
  33. enterMouseX = e.x;
  34. enterMouseY = e.y;
  35. }
  36. public void onTargetMouseMove(DMouseEvent e) {
  37. enterMouseX = e.x;
  38. enterMouseY = e.y;
  39. }
  40. public void onTargetMouseExit(DMouseEvent e) {
  41. if (timerHandle != null) {
  42. timerHandle.close();
  43. timerHandle = null;
  44. }
  45. hide();
  46. }
  47. private void show() {
  48. DSimpleTooltipComponent view = new DSimpleTooltipComponent(styleClass, tooltip);
  49. window = context.openView(enterMouseX, enterMouseY + context.dp(8), DAnchor.TOP_LEFT, view);
  50. if (timerHandle != null) {
  51. timerHandle.close();
  52. timerHandle = null;
  53. }
  54. }
  55. private void hide() {
  56. if (window != null) {
  57. window.close();
  58. window = null;
  59. }
  60. }
  61. public void close() {
  62. if (window != null) {
  63. window.close();
  64. window = null;
  65. }
  66. }
  67. }