/ftr-gwt-library-date/src/main/java/eu/future/earth/gwt/client/date/horizontal/HorizontalHourPanel.java
Java | 76 lines | 49 code | 12 blank | 15 comment | 11 complexity | 74fac4bd4577811bb31d75307e14d002 MD5 | raw file
Possible License(s): Apache-2.0
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.horizontal; 18 19import com.google.gwt.user.client.ui.Label; 20import com.google.gwt.user.client.ui.VerticalPanel; 21 22import eu.future.earth.gwt.client.FtrGwtDateCss; 23 24public class HorizontalHourPanel<T, M> extends BaseHorizontalRowPanel<T, M> { 25 26 public HorizontalHourPanel(HorizontalDateRenderer<T, M> renderer, boolean useCss) { 27 super(renderer); 28 if (useCss) { 29 setStyleName(FtrGwtDateCss.HOUR_PANEL); 30 } else { 31 setStyleName(FtrGwtDateCss.HOUR_PANEL_NOBACKGROUND); 32 } 33 int hourHeight = renderer.getIntervalsPerHour() * renderer.getIntervalWidth(); 34 int intervalMinutes = (60 / renderer.getIntervalsPerHour()); 35 int x = 0; 36 37 for (int hour = startHour; hour < endHour; hour++) { 38 VerticalPanel drow = new VerticalPanel(); 39 drow.setStyleName(FtrGwtDateCss.HOUR); 40 drow.setSize("30px", renderer.getRowHeight() + "px"); 41 42 int displayHour = hour; 43 String displaySuffix = ""; 44 if (!renderer.show24HourClock()) { 45 if (hour < 12) { 46 displaySuffix = " AM"; 47 } else { 48 displaySuffix = " PM"; 49 } 50 51 if (hour == 0) { 52 displayHour = 12; 53 } else { 54 if (hour > 12) { 55 displayHour = hour - 12; 56 } 57 } 58 } 59 60 for (int interval = 0; interval < (renderer.showIntervalTimes() ? renderer.getIntervalsPerHour() : 1); interval++) { 61 int minute = (interval * intervalMinutes); 62 String displayMinute = (minute < 10) ? "0" + minute : "" + minute; 63 Label label = new Label(displayHour + ":" + displayMinute + displaySuffix); 64 label.setStyleName(FtrGwtDateCss.HOUR_LABEL); 65 drow.add(label); 66 } 67 68 super.add(drow, x, 0); 69 x = x + hourHeight; 70 } 71 72 } 73 74 public void repaint() { 75 } 76}