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

eu.future.earth.gwt.client.date.week.staend.DayField Maven / Gradle / Ivy

The 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.week.staend;

import com.allen_sauer.gwt.dnd.client.util.Location;
import com.allen_sauer.gwt.dnd.client.util.WidgetLocation;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import eu.future.earth.gwt.client.FtrGwtDateCss;
import eu.future.earth.gwt.client.date.EventPanel;
import eu.future.earth.gwt.client.date.TimeEventRendererVertical;

public abstract class DayField extends EventPanel {

	public static class DirectionConstant {
		public final int directionBits;

		public final String directionLetters;

		private DirectionConstant(int directionBits, String directionLetters) {
			this.directionBits = directionBits;
			this.directionLetters = directionLetters;
		}
	}

	/**
	 * Specifies that resizing occur at the east edge.
	 */
	public static final int DIRECTION_EAST = 0x0001;

	/**
	 * Specifies that resizing occur at the both edge.
	 */
	public static final int DIRECTION_NORTH = 0x0002;

	/**
	 * Specifies that resizing occur at the south edge.
	 */
	public static final int DIRECTION_SOUTH = 0x0004;

	/**
	 * Specifies that resizing occur at the west edge.
	 */
	public static final int DIRECTION_WEST = 0x0008;

	/**
	 * Specifies that resizing occur at the east edge.
	 */
	public static final DirectionConstant EAST = new DirectionConstant(DIRECTION_EAST, "e");

	/**
	 * Specifies that resizing occur at the both edge.
	 */
	public static final DirectionConstant NORTH = new DirectionConstant(DIRECTION_NORTH, "n");

	/**
	 * Specifies that resizing occur at the north-east edge.
	 */
	public static final DirectionConstant NORTH_EAST = new DirectionConstant(DIRECTION_NORTH | DIRECTION_EAST, "ne");

	/**
	 * Specifies that resizing occur at the north-west edge.
	 */
	public static final DirectionConstant NORTH_WEST = new DirectionConstant(DIRECTION_NORTH | DIRECTION_WEST, "nw");

	/**
	 * Specifies that resizing occur at the south edge.
	 */
	public static final DirectionConstant SOUTH = new DirectionConstant(DIRECTION_SOUTH, "s");

	/**
	 * Specifies that resizing occur at the south-east edge.
	 */
	public static final DirectionConstant SOUTH_EAST = new DirectionConstant(DIRECTION_SOUTH | DIRECTION_EAST, "se");

	/**
	 * Specifies that resizing occur at the south-west edge.
	 */
	public static final DirectionConstant SOUTH_WEST = new DirectionConstant(DIRECTION_SOUTH | DIRECTION_WEST, "sw");

	/**
	 * Specifies that resizing occur at the west edge.
	 */
	public static final DirectionConstant WEST = new DirectionConstant(DIRECTION_WEST, "w");

	private ResizeDragController resizeDragController;

	private Widget southWidget = null; // NOPMD;

	protected Widget dataWidget = null; // NOPMD;

	private VerticalPanel holder = new VerticalPanel();

	private TimeEventRendererVertical dateRenderer = null;

	public DayField(TimeEventRendererVertical newRenderer, T data) {
		super(newRenderer, data);
		dateRenderer = newRenderer;
		setWidget(holder);
		setWidth("100%");
		holder.setSpacing(0);
		holder.setWidth("100%");
		
	}

	public void setResizeDragController(ResizeDragController newResizeDragController) {
		if (resizeDragController != null && isDraggable()) {
			resizeDragController.makeNotDraggable(southWidget);
		}
		this.resizeDragController = newResizeDragController;
		if (southWidget != null) {
			if (resizeDragController != null && isDraggable()) {
				resizeDragController.makeDraggable(southWidget, direction);
			}
		}
	}

	private DirectionConstant direction = SOUTH;

	protected void setWidgetInsizeResize(Widget title, Widget newPanel, SimplePanel newbottom) {
		dataWidget = newPanel;
		bottom = newbottom;

		if (title != null) {
			holder.add(title);
			holder.setCellVerticalAlignment(title, VerticalPanel.ALIGN_TOP);
		}

		if (dataWidget != null) {
			HorizontalPanel bottomHolder = new HorizontalPanel();
			holder.add(dataWidget);
			// holder.addStyleName(getEventStyleName());
			if (isDraggable()) {
				southWidget = new FocusPanel();
				if (resizeDragController != null) {
					resizeDragController.makeDraggable(southWidget, direction);
				}
				southWidget.setSize("10%", "2px");
				southWidget.addStyleName("downDrag");
				if (bottom != null) {
					holder.add(bottom);
					if (bottom != null) {
						bottomHolder.add(southWidget);
						bottomHolder.setWidth("100%");
						bottomHolder.setCellHorizontalAlignment(southWidget, HorizontalPanel.ALIGN_CENTER);
						// holder.add(southWidget);
						bottom.setWidget(bottomHolder);
						bottom.setHeight(dateRenderer.getEventBottomHeight() + "px");
					}
					holder.setCellHorizontalAlignment(bottom, VerticalPanel.ALIGN_CENTER);
					holder.setCellVerticalAlignment(bottom, VerticalPanel.ALIGN_BOTTOM);
				} else {
					holder.add(southWidget);
					holder.setCellHorizontalAlignment(southWidget, VerticalPanel.ALIGN_CENTER);
					holder.setCellVerticalAlignment(southWidget, VerticalPanel.ALIGN_BOTTOM);
				}

			} else {
				if (bottom instanceof SimplePanel) {
					SimplePanel real = (SimplePanel) bottom;
					bottomHolder.setWidth("100%");
					real.setWidget(bottomHolder);
					real.setHeight(dateRenderer.getEventBottomHeight() + "px");
					holder.add(bottom);
				} else {
					if (bottom != null) {
						bottomHolder.setWidth("100%");
						bottom.setWidget(bottomHolder);
						bottom.setHeight(dateRenderer.getEventBottomHeight() + "px");
						holder.add(bottom);

					}
				}
			}
		}
	}

	

	private SimplePanel bottom = null;

	public void setEventStyleName(String newStyleName) {
		super.setEventStyleName(newStyleName);
//		if (bottom != null) {
//			bottomHolder.setStyleName(getEventStyleName());
//		}
//		bottomHolder.setStyleName(getEventStyleName());
		if (dataWidget != null) {
			dataWidget.setStyleName(getEventStyleName());
			dataWidget.addStyleName(FtrGwtDateCss.EVENT_DAY_PANEL);
		}
		if (southWidget != null) {
			southWidget.setStyleName(getEventStyleName());
			southWidget.addStyleName("downDrag");
		}
	}

	private String mainColor = null;

	public void setMainColor(String newColor) {
		mainColor = newColor;
		if (mainColor != null) {
//			if (bottomHolder != null) {
//				bottomHolder.getElement().getStyle().setBackgroundColor(newColor);
//			}
			if (southWidget != null) {
				southWidget.getElement().getStyle().setBackgroundColor(newColor);
			}
		}
	}

	private String foregroundColor = null;

	public void setForeGroundColor(String newColor) {
		foregroundColor = newColor;
		if (foregroundColor != null) {
//			if (bottomHolder != null) {
//				bottomHolder.getElement().getStyle().setColor(foregroundColor);
//			}
			if (southWidget != null) {
				southWidget.getElement().getStyle().setColor(foregroundColor);
			}
		}
	}

	public abstract Widget getDraggableItem();

	public int getContentHeight() {
		return contentHeight;
	}

	private int contentHeight = 15;

	public void setContentHeight(int height) {
		// use either the specified height or the minimum height, whichever is greater
		height = Math.max(height, dateRenderer.getEventMinimumHeight());
		// set up day field piece sizes
		super.setHeight(height + "px");
		int widgetHeight = Math.max(0, (height - dateRenderer.getEventTopHeight() - (dateRenderer.getEventBottomHeight() + 3)));
		if (dataWidget != null) {
			dataWidget.setHeight(widgetHeight + "px");
		}
		contentHeight = height;
		if (dataWidget != null) {
			dataWidget.setVisible(true);
		}
	}

	public void moveBy(int right, int down) {
		final AbsolutePanel parent = getSizerPanel(this);
		final Location location = new WidgetLocation(this, parent);
		final int left = location.getLeft() + right;
		final int top = location.getTop() + down;
		parent.setWidgetPosition(this, left, top);
	}

	private AbsolutePanel getSizerPanel(Widget current) {
		Widget parent = current.getParent();
		if (parent instanceof AbsolutePanel) {
			return (AbsolutePanel) parent;
		} else {
			if (parent != null) {
				return getSizerPanel(parent);
			} else {
				return null;
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy