PageRenderTime 29ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 17package eu.future.earth.gwt.client.date;
 18
 19import java.util.Date;
 20
 21import com.google.gwt.event.shared.HandlerRegistration;
 22import com.google.gwt.user.client.ui.SimplePanel;
 23import com.google.gwt.user.client.ui.Widget;
 24
 25public abstract class EventPanel<T> extends SimplePanel implements HasDateEventHandlers<T>, Comparable<EventPanel<T>> {
 26
 27	private T value = null;
 28
 29	private TimeEventRenderer<T> renderer = null;
 30
 31	@SuppressWarnings("unchecked")
 32	protected EventPanel(TimeEventRenderer<? extends T> newRenderer, T newData) {
 33		super();
 34		renderer = (TimeEventRenderer<T>) newRenderer;
 35		value = newData;
 36	}
 37
 38	public abstract void setContentHeight(int height);
 39
 40	public abstract int getContentHeight();
 41
 42	public abstract void setWidth(int width);
 43
 44	public int compareTo(EventPanel<T> other) {
 45		Date one = getStart();
 46		Date two = other.getStart();
 47		if (one != null) {
 48			return one.compareTo(two);
 49		}
 50		return 0;
 51	}
 52
 53	private String eventStyleName = null;
 54
 55	public String getEventStyleName() {
 56		return eventStyleName;
 57	}
 58
 59	public void setEventStyleName(String eventStyleName) {
 60		this.eventStyleName = eventStyleName;
 61	}
 62
 63	public void setStart(Date newStart) {
 64		if (value != null) {
 65			renderer.setStartTime(value, newStart);
 66		}
 67	}
 68
 69	public int getPosY() {
 70		return posY;
 71	}
 72
 73	public void setPosY(int posY) {
 74		this.posY = posY;
 75	}
 76
 77	private int posY = 0;
 78
 79	public void setEndTime(Date newEnd) {
 80		if (value != null) {
 81			renderer.setEndTime(value, newEnd);
 82		}
 83	}
 84
 85	public Date getStart() {
 86		if (value != null) {
 87			return renderer.getStartTime(value);
 88		} else {
 89			return null;
 90		}
 91	}
 92
 93	public Date getEnd() {
 94		if (value != null) {
 95			return renderer.getEndTime(value);
 96		} else {
 97			return null;
 98		}
 99	}
100
101	public T getValue() {
102		return value;
103	}
104
105	public void setValue(T value) {
106		this.value = value;
107	}
108
109	private HandlerRegistration parent = null;
110
111	public void addParentDateEventHandler(DateEventListener<? extends T> handler) {
112		parent = addDateEventHandler(handler);
113	}
114
115	public void clearParent() {
116		if (parent != null) {
117			parent.removeHandler();
118		}
119	}
120
121	public HandlerRegistration addDateEventHandler(DateEventListener<? extends T> handler) {
122		return addHandler(handler, DateEvent.getType());
123	}
124
125	/**
126	 * Indicates whether some other object is "equal to" this one.
127	 * 
128	 * @param obj
129	 *            the reference object with which to compare.
130	 * @return <code>true</code> if this object is the same as the obj argument; <code>false</code> otherwise.
131	 * @todo Implement this java.lang.Object method
132	 */
133	@SuppressWarnings("unchecked")
134	public boolean equals(Object obj) {
135		if (obj instanceof EventPanel<?>) {
136			final EventPanel<? extends T> real = (EventPanel<? extends T>) obj;
137			if (renderer == null) {
138				return value.equals(real.getValue());
139			}
140			if (renderer.equal(value, real.getValue())) {
141				return true;
142			}
143		}
144		return false;
145	}
146
147	public boolean isDraggable() {
148		if (renderer == null) {
149			return false;
150		}
151		return renderer.enableDragAndDrop();
152	}
153
154	public abstract void repaintTime();
155
156	public abstract Widget getDraggableItem();
157
158}