All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.future.earth.gwt.client.date.ComponentSizeEvent Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
/*
 * Copyright 2007 Future Earth, [email protected]
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package eu.future.earth.gwt.client.date;

import com.google.gwt.event.shared.GwtEvent;

public class ComponentSizeEvent extends GwtEvent {

	public enum ComponentSizeEventActions {

		HEIGHT_CHANGE,

		WIDHT_CHANGE,

		SIZE_CHANGE

	}

	private ComponentSizeEventActions command = ComponentSizeEventActions.SIZE_CHANGE;

	public ComponentSizeEvent() {
		super();
	}

	/**
	 * Handler type.
	 */
	private static Type TYPE;

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static ComponentSizeEvent fire(HasComponentSizeEventHandlers source, ComponentSizeEventActions action, int newWidht, int newHeight) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final ComponentSizeEvent event = new ComponentSizeEvent(action, newWidht, newHeight);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static ComponentSizeEvent fire(HasComponentSizeEventHandlers source, ComponentSizeEventActions action, int newValue) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {

			final ComponentSizeEvent event = new ComponentSizeEvent(action);
			switch (action) {
			case WIDHT_CHANGE:
				event.setWidth(newValue);
				break;
			case HEIGHT_CHANGE:
				event.setHeight(newValue);
				break;
			default:
				break;
			}
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	/**
	 * Fires a before selection event on all registered handlers in the handler manager. If no such handlers exist, this
	 * method will do nothing.
	 * 
	 * @param source
	 *            the source of the handlers
	 * @param navigator
	 *            the navigator associated with this event
	 * @param token
	 *            the navigation token associated with this event
	 * @return the event so that the caller can check if it was canceled, or null if no handlers of this event type have
	 *         been registered
	 */
	public static ComponentSizeEvent fire(HasComponentSizeEventHandlers source, ComponentSizeEventActions action) {
		// If no handlers exist, then type can be null.
		if (TYPE != null) {
			final ComponentSizeEvent event = new ComponentSizeEvent(action);
			source.fireEvent(event);
			return event;
		}
		return null;
	}

	public ComponentSizeEventActions getCommand() {
		return command;
	}

	/**
	 * Gets the type associated with this event.
	 * 
	 * @return returns the handler type
	 */
	public static Type getType() {
		if (TYPE == null) {
			TYPE = new Type();
		}
		return TYPE;
	}

	private int height = -1;

	private int width = -1;

	protected ComponentSizeEvent(ComponentSizeEventActions newAction, int newWidht, int newHeight) {
		super();
		width = newWidht;
		height = newHeight;
		command = newAction;
	}

	protected ComponentSizeEvent(ComponentSizeEventActions newAction) {
		super();
		command = newAction;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	@SuppressWarnings({
			"unchecked", "rawtypes"
	})
	@Override
	public final Type getAssociatedType() {
		return (Type) TYPE;
	}

	protected void dispatch(ComponentSizehandler handler) {
		handler.handleSizingEvent(this);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy