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

eu.future.earth.gwt.client.date.week.staend.HourPanel 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.week.staend;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import eu.future.earth.gwt.client.FtrGwtDateCss;
import eu.future.earth.gwt.client.date.DateRenderer;

public class HourPanel extends FocusPanel {

	protected DateRenderer renderer;

	private AbsolutePanel body = null;

	public int getNeededHeight() {
		return renderer.getIntervalHeight() * getDailyIntervals();
	}

	protected int getDailyIntervals() {
		return (renderer.getEndHour() - renderer.getStartHour()) * renderer.getIntervalsPerHour();
	}

	public HourPanel(DateRenderer newRenderer) {
		super();
		this.renderer = newRenderer;
		body = new AbsolutePanel();
		this.setWidget(body);
		body.setStyleName(FtrGwtDateCss.DATE_DAY_FULL);
		super.setWidth(getPrefferedWitdh());
		super.setHeight(getNeededHeight() + "px");
		setStyleName(FtrGwtDateCss.HOUR_PANEL);
		int hourHeight = renderer.getIntervalsPerHour() * renderer.getIntervalHeight();
		int intervalMinutes = (60 / renderer.getIntervalsPerHour());
		int x = 0;
		int y = 2;
		final int startHour = renderer.getStartHour();
		final int endHour = renderer.getEndHour();
		for (int hour = startHour; hour < endHour; hour++) {
			VerticalPanel drow = new VerticalPanel();
			drow.setStyleName(FtrGwtDateCss.HOUR);
			drow.setSize("100%", (hourHeight - 2) + "px");

			int displayHour = hour;
			String displaySuffix = "";
			if (!renderer.show24HourClock()) {
				if (hour < 12) {
					displaySuffix = " AM";
				} else {
					displaySuffix = " PM";
				}

				if (hour == 0) {
					displayHour = 12;
				} else {
					if (hour > 12) {
						displayHour = hour - 12;
					}
				}
			}

			for (int interval = 0; interval < (renderer.showIntervalTimes() ? renderer.getIntervalsPerHour() : 1); interval++) {
				int minute = (interval * intervalMinutes);
				String displayMinute = (minute < 10) ? "0" + minute : "" + minute;
				Label label = new Label(displayHour + ":" + displayMinute + displaySuffix);
				label.setStyleName(FtrGwtDateCss.HOUR_LABEL);
				label.setWidth("95%");
				label.setHorizontalAlignment(Label.ALIGN_RIGHT);
				drow.add(label);
			}

			body.add(drow, x, y);
			y = y + hourHeight;
		}
	}

	public int getHeight() {
		return (renderer.getEndHour() - renderer.getStartHour()) * renderer.getIntervalsPerHour() * renderer.getIntervalHeight();
	}

	public int getPrefferedWitdhInt() {
		return renderer.show24HourClock() ? 45 : 60;
	}

	public String getPrefferedWitdh() {
		return renderer.show24HourClock() ? "45px" : "60px";
	}

	public void repaintEvents() {
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy