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

eu.future.earth.gwt.client.date.picker.DatePickerMonthPanelDayPanel 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.picker;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import eu.future.earth.gwt.client.FtrGwtDatePickerCss;
import eu.future.earth.gwt.client.date.DateUtils;
import eu.future.earth.gwt.client.date.picker.DateSelectEvent.DateSelectEventActions;

public class DatePickerMonthPanelDayPanel extends VerticalPanel implements ClickHandler, HasDateSelectHandlers {

	private Label dayLabel = null; // NOPMD;

	private Calendar theDay = new GregorianCalendar();

	private DatePickerRenderer renderer = null;

	private boolean enabled = true;

	public DatePickerMonthPanelDayPanel(int day, Date newDate, DatePickerRenderer newRenderer) {
		super();
		renderer = newRenderer;
		theDay.setTime(newDate);
		dayLabel = new Label(String.valueOf(day));
		super.add(dayLabel);
		super.setCellVerticalAlignment(dayLabel, HorizontalPanel.ALIGN_MIDDLE);
		Widget bottum = renderer.getBottumWidget(newDate);
		if (bottum != null) {
			super.add(bottum);
			if (bottum instanceof HasClickHandlers) {
				HasClickHandlers real = (HasClickHandlers) bottum;
				real.addClickHandler(this);
			}
		}
		setEnabled(renderer.isEnabled(newDate, this));
		String extraStyle = renderer.getExtraStyle(newDate);
		if (extraStyle != null) {
			dayLabel.addStyleName(extraStyle);
			super.addStyleName(extraStyle);
		}
		String title = renderer.getTitle(newDate);
		if (title != null) {
			dayLabel.setTitle(title);
		}
	}

	private HandlerRegistration registration = null;

	public void addStyleName(String style) {
		dayLabel.addStyleName(style);
	}

	public void removeStyleName(String style) {
		dayLabel.removeStyleName(style);
	}

	public void setEnabled(boolean newEnabled) {
		enabled = newEnabled;
		if (enabled) {
			registration = dayLabel.addClickHandler(this);
			super.addStyleName(FtrGwtDatePickerCss.DAY);
			super.removeStyleName(FtrGwtDatePickerCss.DAY_DISABLED);
			dayLabel.addStyleName(FtrGwtDatePickerCss.DAY_LABEL);
			dayLabel.removeStyleName(FtrGwtDatePickerCss.DAY_DISABLED);
		} else {
			super.removeStyleName(FtrGwtDatePickerCss.DAY);
			super.addStyleName(FtrGwtDatePickerCss.DAY_DISABLED);
			dayLabel.removeStyleName(FtrGwtDatePickerCss.DAY_LABEL);
			dayLabel.addStyleName(FtrGwtDatePickerCss.DAY_DISABLED);
			if (registration != null) {
				registration.removeHandler();
				registration = null;
			}
		}
	}

	public void setToday(boolean newState) {
		if (enabled && newState) {
			super.addStyleName(FtrGwtDatePickerCss.DAY_TODAY);
		}
	}

	public void setOtherMonth(boolean newState) {
		if (enabled && newState) {
			super.addStyleName(FtrGwtDatePickerCss.DAY_OTHER);
		}
	}

	public void setWeekend(boolean newState) {
		if (enabled && newState) {
			super.addStyleName(FtrGwtDatePickerCss.DAY_WEEKEND);
		}
	}

	public void setSelected(boolean newState) {
		if (enabled) {
			if (newState) {
				super.addStyleName(FtrGwtDatePickerCss.DAY_SELECTED);
			} else {
				super.removeStyleName(FtrGwtDatePickerCss.DAY_SELECTED);
			}
		}
	}

	public boolean isDay(Date date) {
		if (DateUtils.isSameDay(theDay.getTime(), date)) {
			return true;
		} else {
			return false;
		}

	}

	public HandlerRegistration addDateSelectEventHandler(DateSelectListener handler) {
		return addHandler(handler, DateSelectEvent.getType());
	}

	public void onClick(ClickEvent event) {
		DateSelectEvent.fire(this, theDay.getTime(), DateSelectEventActions.SELECT_DAY);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy