You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MouseEventDetails.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client;
  5. import com.google.gwt.dom.client.NativeEvent;
  6. import com.google.gwt.user.client.Event;
  7. /**
  8. * Helper class to store and transfer mouse event details.
  9. */
  10. public class MouseEventDetails {
  11. public static final int BUTTON_LEFT = Event.BUTTON_LEFT;
  12. public static final int BUTTON_MIDDLE = Event.BUTTON_MIDDLE;
  13. public static final int BUTTON_RIGHT = Event.BUTTON_RIGHT;
  14. private static final char DELIM = ',';
  15. private int button;
  16. private int clientX;
  17. private int clientY;
  18. private boolean altKey;
  19. private boolean ctrlKey;
  20. private boolean metaKey;
  21. private boolean shiftKey;
  22. private int type;
  23. public int getButton() {
  24. return button;
  25. }
  26. public int getClientX() {
  27. return clientX;
  28. }
  29. public int getClientY() {
  30. return clientY;
  31. }
  32. public boolean isAltKey() {
  33. return altKey;
  34. }
  35. public boolean isCtrlKey() {
  36. return ctrlKey;
  37. }
  38. public boolean isMetaKey() {
  39. return metaKey;
  40. }
  41. public boolean isShiftKey() {
  42. return shiftKey;
  43. }
  44. public MouseEventDetails(NativeEvent evt) {
  45. button = evt.getButton();
  46. clientX = evt.getClientX();
  47. clientY = evt.getClientY();
  48. altKey = evt.getAltKey();
  49. ctrlKey = evt.getCtrlKey();
  50. metaKey = evt.getMetaKey();
  51. shiftKey = evt.getShiftKey();
  52. type = Event.getTypeInt(evt.getType());
  53. }
  54. private MouseEventDetails() {
  55. }
  56. @Override
  57. public String toString() {
  58. return serialize();
  59. }
  60. public String serialize() {
  61. return "" + button + DELIM + clientX + DELIM + clientY + DELIM + altKey
  62. + DELIM + ctrlKey + DELIM + metaKey + DELIM + shiftKey + DELIM
  63. + type;
  64. }
  65. public static MouseEventDetails deSerialize(String serializedString) {
  66. MouseEventDetails instance = new MouseEventDetails();
  67. String[] fields = serializedString.split(",");
  68. instance.button = Integer.parseInt(fields[0]);
  69. instance.clientX = Integer.parseInt(fields[1]);
  70. instance.clientY = Integer.parseInt(fields[2]);
  71. instance.altKey = Boolean.valueOf(fields[3]).booleanValue();
  72. instance.ctrlKey = Boolean.valueOf(fields[4]).booleanValue();
  73. instance.metaKey = Boolean.valueOf(fields[5]).booleanValue();
  74. instance.shiftKey = Boolean.valueOf(fields[6]).booleanValue();
  75. instance.type = Integer.parseInt(fields[7]);
  76. return instance;
  77. }
  78. public String getButtonName() {
  79. if (button == BUTTON_LEFT) {
  80. return "left";
  81. } else if (button == BUTTON_RIGHT) {
  82. return "right";
  83. } else if (button == BUTTON_MIDDLE) {
  84. return "middle";
  85. }
  86. return "";
  87. }
  88. public Class<MouseEventDetails> getType() {
  89. return MouseEventDetails.class;
  90. }
  91. public boolean isDoubleClick() {
  92. return type == Event.ONDBLCLICK;
  93. }
  94. }