SVEvent.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2007 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"); You may not
  4. // use this file except in compliance with the License. You may obtain a copy of
  5. // the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
  6. // applicable law or agreed to in writing, software distributed under the
  7. // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  8. // OF ANY KIND, either express or implied. See the License for the specific
  9. // language governing permissions and limitations under the License.
  10. package com.google.scrollview.events;
  11. import com.google.scrollview.ui.SVWindow;
  12. /**
  13. * The SVEvent is a structure which holds the actual values of a message to be
  14. * transmitted. It corresponds to the client structure defined in scrollview.h
  15. *
  16. * @author wanke@google.com
  17. */
  18. public class SVEvent {
  19. SVEventType type; // What kind of event.
  20. SVWindow window; // Window event relates to.
  21. int x; // Coords of click or selection.
  22. int y;
  23. int xSize; // Size of selection.
  24. int ySize;
  25. int commandId;
  26. String parameter; // Any string that might have been passed as argument.
  27. /**
  28. * A "normal" SVEvent.
  29. *
  30. * @param t The type of the event as specified in SVEventType (e.g.
  31. * SVET_CLICK)
  32. * @param w The window the event corresponds to
  33. * @param x1 X position of the mouse at the time of the event
  34. * @param y1 Y position of the mouse at the time of the event
  35. * @param x2 X selection size at the time of the event
  36. * @param y2 Y selection size at the time of the event
  37. * @param p A parameter associated with the event (e.g. keyboard input)
  38. */
  39. public SVEvent(SVEventType t, SVWindow w, int x1, int y1, int x2, int y2,
  40. String p) {
  41. type = t;
  42. window = w;
  43. x = x1;
  44. y = y1;
  45. xSize = x2;
  46. ySize = y2;
  47. commandId = 0;
  48. parameter = p;
  49. }
  50. /**
  51. * An event which issues a command (like clicking on an item in the menubar).
  52. *
  53. * @param eventtype The type of the event as specified in SVEventType
  54. * (usually SVET_MENU or SVET_POPUP)
  55. * @param svWindow The window the event corresponds to
  56. * @param commandid The associated id with the command (given by the client
  57. * on construction of the item)
  58. * @param value A parameter associated with the event (e.g. keyboard input)
  59. */
  60. public SVEvent(SVEventType eventtype, SVWindow svWindow, int commandid,
  61. String value) {
  62. type = eventtype;
  63. window = svWindow;
  64. parameter = value;
  65. x = 0;
  66. y = 0;
  67. xSize = 0;
  68. ySize = 0;
  69. commandId = commandid;
  70. }
  71. /**
  72. * This is the string representation of the message, which is what will
  73. * actually be transferred over the network.
  74. */
  75. @Override
  76. public String toString() {
  77. return (window.hash + "," + type.ordinal() + "," + x + "," + y + ","
  78. + xSize + "," + ySize + "," + commandId + "," + parameter);
  79. }
  80. }