/ftr-gwt-library-date/src/main/java/eu/future/earth/gwt/client/date/EventPanel.java

http://ftr-gwt-library.googlecode.com/ · Java · 158 lines · 103 code · 32 blank · 23 comment · 20 complexity · 633e51777a73c86e8b20f6fafc5489ce MD5 · raw file

  1. /*
  2. * Copyright 2007 Future Earth, info@future-earth.eu
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package eu.future.earth.gwt.client.date;
  17. import java.util.Date;
  18. import com.google.gwt.event.shared.HandlerRegistration;
  19. import com.google.gwt.user.client.ui.SimplePanel;
  20. import com.google.gwt.user.client.ui.Widget;
  21. public abstract class EventPanel<T> extends SimplePanel implements HasDateEventHandlers<T>, Comparable<EventPanel<T>> {
  22. private T value = null;
  23. private TimeEventRenderer<T> renderer = null;
  24. @SuppressWarnings("unchecked")
  25. protected EventPanel(TimeEventRenderer<? extends T> newRenderer, T newData) {
  26. super();
  27. renderer = (TimeEventRenderer<T>) newRenderer;
  28. value = newData;
  29. }
  30. public abstract void setContentHeight(int height);
  31. public abstract int getContentHeight();
  32. public abstract void setWidth(int width);
  33. public int compareTo(EventPanel<T> other) {
  34. Date one = getStart();
  35. Date two = other.getStart();
  36. if (one != null) {
  37. return one.compareTo(two);
  38. }
  39. return 0;
  40. }
  41. private String eventStyleName = null;
  42. public String getEventStyleName() {
  43. return eventStyleName;
  44. }
  45. public void setEventStyleName(String eventStyleName) {
  46. this.eventStyleName = eventStyleName;
  47. }
  48. public void setStart(Date newStart) {
  49. if (value != null) {
  50. renderer.setStartTime(value, newStart);
  51. }
  52. }
  53. public int getPosY() {
  54. return posY;
  55. }
  56. public void setPosY(int posY) {
  57. this.posY = posY;
  58. }
  59. private int posY = 0;
  60. public void setEndTime(Date newEnd) {
  61. if (value != null) {
  62. renderer.setEndTime(value, newEnd);
  63. }
  64. }
  65. public Date getStart() {
  66. if (value != null) {
  67. return renderer.getStartTime(value);
  68. } else {
  69. return null;
  70. }
  71. }
  72. public Date getEnd() {
  73. if (value != null) {
  74. return renderer.getEndTime(value);
  75. } else {
  76. return null;
  77. }
  78. }
  79. public T getValue() {
  80. return value;
  81. }
  82. public void setValue(T value) {
  83. this.value = value;
  84. }
  85. private HandlerRegistration parent = null;
  86. public void addParentDateEventHandler(DateEventListener<? extends T> handler) {
  87. parent = addDateEventHandler(handler);
  88. }
  89. public void clearParent() {
  90. if (parent != null) {
  91. parent.removeHandler();
  92. }
  93. }
  94. public HandlerRegistration addDateEventHandler(DateEventListener<? extends T> handler) {
  95. return addHandler(handler, DateEvent.getType());
  96. }
  97. /**
  98. * Indicates whether some other object is "equal to" this one.
  99. *
  100. * @param obj
  101. * the reference object with which to compare.
  102. * @return <code>true</code> if this object is the same as the obj argument; <code>false</code> otherwise.
  103. * @todo Implement this java.lang.Object method
  104. */
  105. @SuppressWarnings("unchecked")
  106. public boolean equals(Object obj) {
  107. if (obj instanceof EventPanel<?>) {
  108. final EventPanel<? extends T> real = (EventPanel<? extends T>) obj;
  109. if (renderer == null) {
  110. return value.equals(real.getValue());
  111. }
  112. if (renderer.equal(value, real.getValue())) {
  113. return true;
  114. }
  115. }
  116. return false;
  117. }
  118. public boolean isDraggable() {
  119. if (renderer == null) {
  120. return false;
  121. }
  122. return renderer.enableDragAndDrop();
  123. }
  124. public abstract void repaintTime();
  125. public abstract Widget getDraggableItem();
  126. }