Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MouseEventDetails.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.shared;
  5. import java.io.Serializable;
  6. /**
  7. * Helper class to store and transfer mouse event details.
  8. */
  9. public class MouseEventDetails implements Serializable {
  10. // From com.google.gwt.dom.client.NativeEvent
  11. public static final int BUTTON_LEFT = 1;
  12. public static final int BUTTON_MIDDLE = 4;
  13. public static final int BUTTON_RIGHT = 2;
  14. private static final char DELIM = ',';
  15. // From com.google.gwt.user.client.Event
  16. private static final int ONDBLCLICK = 0x00002;
  17. private int button;
  18. private int clientX;
  19. private int clientY;
  20. private boolean altKey;
  21. private boolean ctrlKey;
  22. private boolean metaKey;
  23. private boolean shiftKey;
  24. private int type;
  25. private int relativeX = -1;
  26. private int relativeY = -1;
  27. public int getButton() {
  28. return button;
  29. }
  30. public int getClientX() {
  31. return clientX;
  32. }
  33. public int getClientY() {
  34. return clientY;
  35. }
  36. public boolean isAltKey() {
  37. return altKey;
  38. }
  39. public boolean isCtrlKey() {
  40. return ctrlKey;
  41. }
  42. public boolean isMetaKey() {
  43. return metaKey;
  44. }
  45. public boolean isShiftKey() {
  46. return shiftKey;
  47. }
  48. public int getRelativeX() {
  49. return relativeX;
  50. }
  51. public int getRelativeY() {
  52. return relativeY;
  53. }
  54. public void setButton(int button) {
  55. this.button = button;
  56. }
  57. public void setClientX(int clientX) {
  58. this.clientX = clientX;
  59. }
  60. public void setClientY(int clientY) {
  61. this.clientY = clientY;
  62. }
  63. public void setAltKey(boolean altKey) {
  64. this.altKey = altKey;
  65. }
  66. public void setCtrlKey(boolean ctrlKey) {
  67. this.ctrlKey = ctrlKey;
  68. }
  69. public void setMetaKey(boolean metaKey) {
  70. this.metaKey = metaKey;
  71. }
  72. public void setShiftKey(boolean shiftKey) {
  73. this.shiftKey = shiftKey;
  74. }
  75. public void setType(int type) {
  76. this.type = type;
  77. }
  78. public void setRelativeX(int relativeX) {
  79. this.relativeX = relativeX;
  80. }
  81. public void setRelativeY(int relativeY) {
  82. this.relativeY = relativeY;
  83. }
  84. public MouseEventDetails() {
  85. }
  86. @Override
  87. public String toString() {
  88. return serialize();
  89. }
  90. public String serialize() {
  91. return "" + button + DELIM + clientX + DELIM + clientY + DELIM + altKey
  92. + DELIM + ctrlKey + DELIM + metaKey + DELIM + shiftKey + DELIM
  93. + type + DELIM + relativeX + DELIM + relativeY;
  94. }
  95. public static MouseEventDetails deSerialize(String serializedString) {
  96. MouseEventDetails instance = new MouseEventDetails();
  97. String[] fields = serializedString.split(",");
  98. instance.button = Integer.parseInt(fields[0]);
  99. instance.clientX = Integer.parseInt(fields[1]);
  100. instance.clientY = Integer.parseInt(fields[2]);
  101. instance.altKey = Boolean.valueOf(fields[3]).booleanValue();
  102. instance.ctrlKey = Boolean.valueOf(fields[4]).booleanValue();
  103. instance.metaKey = Boolean.valueOf(fields[5]).booleanValue();
  104. instance.shiftKey = Boolean.valueOf(fields[6]).booleanValue();
  105. instance.type = Integer.parseInt(fields[7]);
  106. instance.relativeX = Integer.parseInt(fields[8]);
  107. instance.relativeY = Integer.parseInt(fields[9]);
  108. return instance;
  109. }
  110. public String getButtonName() {
  111. if (button == BUTTON_LEFT) {
  112. return "left";
  113. } else if (button == BUTTON_RIGHT) {
  114. return "right";
  115. } else if (button == BUTTON_MIDDLE) {
  116. return "middle";
  117. }
  118. return "";
  119. }
  120. public int getType() {
  121. return type;
  122. }
  123. public boolean isDoubleClick() {
  124. return type == ONDBLCLICK;
  125. }
  126. }