myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmaho...@apache.org
Subject svn commit: r548680 - in /myfaces/tomahawk/trunk/core/src/main: java/org/apache/myfaces/custom/schedule/ java/org/apache/myfaces/custom/schedule/model/ resources/org/apache/myfaces/custom/schedule/resource/css/
Date Tue, 19 Jun 2007 10:22:03 GMT
Author: pmahoney
Date: Tue Jun 19 03:21:59 2007
New Revision: 548680

URL: http://svn.apache.org/viewvc?view=rev&rev=548680
Log:
TOMAHAWK-724: Support user defined intervals in detailed views

Added:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/HalfHourInterval.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleMouseEvent.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
    myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/schedule/resource/css/schedule.css

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java?view=diff&rev=548680&r1=548679&r2=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleDetailedDayRenderer.java
Tue Jun 19 03:21:59 2007
@@ -19,8 +19,23 @@
 
 package org.apache.myfaces.custom.schedule;
 
+import java.io.IOException;
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.TreeSet;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.schedule.model.HalfHourInterval;
+import org.apache.myfaces.custom.schedule.model.Interval;
 import org.apache.myfaces.custom.schedule.model.ScheduleDay;
 import org.apache.myfaces.custom.schedule.model.ScheduleEntry;
 import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
@@ -28,13 +43,6 @@
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
 
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.*;
-
 /**
  * <p>
  * Renderer for the day and workweek views of the Schedule component
@@ -103,7 +111,7 @@
         {
             return;
         }
-        
+
         HtmlSchedule schedule = (HtmlSchedule) component;
         ResponseWriter writer = context.getResponseWriter();
         String clientId = schedule.getClientId(context);
@@ -163,11 +171,9 @@
         writer.endElement(HTML.DIV_ELEM);
     }
 
-    protected String getCellClass(HtmlSchedule schedule, int column, int row, int hour)
+    protected String getCellClass(HtmlSchedule schedule, ScheduleDay day, boolean even, int
hour)
     {
         String cellClass = "free";
-        ScheduleDay day = (ScheduleDay) schedule.getModel().get(column);
-
         if (!day.isWorkingDay())
         {
             return getStyleClass(schedule, cellClass);
@@ -176,7 +182,7 @@
         if (hour >= schedule.getWorkingStartHour()
                 && hour < schedule.getWorkingEndHour())
         {
-            cellClass = ((row % 2) == 0) ? "even" : "uneven";
+            cellClass = even ? "even" : "uneven";
         }
 
         return getStyleClass(schedule, cellClass);
@@ -246,172 +252,248 @@
     }
 
     protected void writeBackground(FacesContext context, HtmlSchedule schedule,
-                                 ResponseWriter writer) throws IOException
-    {
-        final int rowHeight = getRowHeight(schedule) - 1;
-        final int headerHeight = rowHeight + 10;
-        writer.startElement(HTML.DIV_ELEM, schedule);
-        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                "background"), null);
-        writer
-                .writeAttribute(
-                        HTML.STYLE_ATTR,
-                        "position: absolute; left: 0px; top: 0px; width: 100%; height: 100%;
z-index: 0;",
-                        null);
-
-        //background table for the schedule grid
-        writer.startElement(HTML.TABLE_ELEM, schedule);
-        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                "background"), null);
-        writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
-        writer.writeAttribute(HTML.CELLSPACING_ATTR, "1", null);
-        writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%; height: 100%",
-                null);
-        writer.startElement(HTML.TBODY_ELEM, schedule);
-
-        //header row, containing the column names
-        writer.startElement(HTML.TR_ELEM, schedule);
-        writer.startElement(HTML.TD_ELEM, schedule);
-        writer.writeAttribute(HTML.CLASS_ATTR,
-                getStyleClass(schedule, "gutter"), null);
-        writer
-                .writeAttribute(
-                        HTML.STYLE_ATTR,
-                        "height: "
-                                + rowHeight
-                                + "px; border-style: none; border-width: 0px; overflow: hidden;
padding: 0px",
-                        null);
-        writer.startElement(HTML.DIV_ELEM, schedule);
-        writer
-                .writeAttribute(HTML.STYLE_ATTR, "height: 1px; width: 56px",
-                        null);
-        writer.endElement(HTML.DIV_ELEM);
-        writer.endElement(HTML.TD_ELEM);
-
-        float columnWidth = (schedule.getModel().size() == 0) ? 100
-                : (100 / schedule.getModel().size());
-
-        for (Iterator dayIterator = schedule.getModel().iterator(); dayIterator
-                .hasNext();)
-        {
-            ScheduleDay day = (ScheduleDay) dayIterator.next();
-            writer.startElement(HTML.TD_ELEM, schedule);
-            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                    "header"), null);
-            writer
-                    .writeAttribute(
-                            HTML.STYLE_ATTR,
-                            "height: " + headerHeight + "px; border-style: none; border-width:
0px; overflow: hidden;",
-                            null);
-            writer.writeAttribute(HTML.WIDTH_ATTR, String.valueOf(columnWidth)
-                    + "%", null);
-            writer.startElement(HTML.DIV_ELEM, schedule);
-            writer
-                    .writeAttribute(
-                            HTML.STYLE_ATTR,
-                            "position: relative; left: 0px; top: 0px; width: 100%; height:
100%;",
-                            null);
-
-            //write the date
-            writer.startElement(HTML.SPAN_ELEM, schedule);
-            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                    "date"), null);
-            writer
-                    .writeAttribute(
-                            HTML.STYLE_ATTR,
-                            "position: absolute; left: 0px; top: 0px; height: 15px; width:
100%; vertical-align: top; overflow: hidden; white-space: nowrap;",
-                            null);
-            writer.writeText(getDateString(context, schedule, day.getDate()),
-                    null);
-            writer.endElement(HTML.SPAN_ELEM);
-
-            //write the name of the holiday, if there is one
-            if ((day.getSpecialDayName() != null)
-                    && (day.getSpecialDayName().length() > 0))
-            {
-                writer.startElement(HTML.SPAN_ELEM, schedule);
-                writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                        "holiday"), null);
-                writer
-                        .writeAttribute(
-                                HTML.STYLE_ATTR,
-                                "position: absolute; left: 0px; top: 15px; width: 100%; vertical-align:
top; overflow: hidden; white-space: nowrap;",
-                                null);
-                writer.writeText(day.getSpecialDayName(), null);
-                writer.endElement(HTML.SPAN_ELEM);
-            }
-
-            writer.endElement(HTML.DIV_ELEM);
-            writer.endElement(HTML.TD_ELEM);
-        }
-
-        writer.endElement(HTML.TR_ELEM);
-
-        int startHour = getRenderedStartHour(schedule);
-        int endHour = getRenderedEndHour(schedule);
-        int numberOfRows = (endHour - startHour) * 2;
+    		ResponseWriter writer) throws IOException
+    		{
+    	final int rowHeight = getRowHeight(schedule);
+    	final int headerHeight = rowHeight + 9;
+    	writer.startElement(HTML.DIV_ELEM, schedule);
+    	writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    			"background"), null);
+    	writer
+    			.writeAttribute(
+    					HTML.STYLE_ATTR,
+    					"position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 0;",
+    					null);
+
+    	//background table for the schedule grid
+    	writer.startElement(HTML.TABLE_ELEM, schedule);
+    	writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    			"background"), null);
+    	writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
+    	writer.writeAttribute(HTML.CELLSPACING_ATTR, "0", null);
+    	writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%; height: 100%",
+    			null);
+    	writer.startElement(HTML.TBODY_ELEM, schedule);
+    	writer.startElement(HTML.TR_ELEM, schedule);
+
+    	float columnWidth = (schedule.getModel().size() == 0) ? 100
+    			: (100 / schedule.getModel().size());
+
+    	int startHour = getRenderedStartHour(schedule);
+    	int endHour = getRenderedEndHour(schedule);
+
+    	SimpleDateFormat hourFormater = new SimpleDateFormat(HtmlSchedule.HOUR_NOTATION_12.equals(schedule.getHourNotation())
? "hh" : "HH");
+    	SimpleDateFormat minuteFormater = new SimpleDateFormat("mm");        
+
+    	// When firstDay is true, render the gutter
+    	boolean firstDay = true;
+    	ScheduleDay day = null;
+
+    	for (Iterator dayIterator = schedule.getModel().iterator(); dayIterator.hasNext() ||
(firstDay && day != null);)
+    	{
+    		writer.startElement(HTML.TD_ELEM, schedule);
+
+			writer.writeAttribute(HTML.STYLE_ATTR, "width: " + (firstDay && day == null ?
"56px" : String.valueOf(columnWidth)+ "%"), null);
+    		
+    		if (firstDay && day != null)
+    		{
+    			// Render the intervals
+    			firstDay = false;
+    		}
+    		else
+    		{
+    			day = (ScheduleDay) dayIterator.next();
+    		}
+
+    		writer.startElement(HTML.TABLE_ELEM, schedule);
+    		writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
+    		writer.writeAttribute(HTML.CELLSPACING_ATTR, "1", null);
+    		writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%; height: 100%",
+    				null);
+    		writer.startElement(HTML.TBODY_ELEM, schedule);
+
+    		writer.startElement(HTML.TR_ELEM, schedule);
+
+    		if (firstDay) 
+    		{
+    			// the header gutter
+    			writer.startElement(HTML.TD_ELEM, schedule);
+    			writer.writeAttribute(HTML.CLASS_ATTR,
+    					getStyleClass(schedule, "gutter"), null);
+    			writer.writeAttribute(
+    					HTML.STYLE_ATTR,
+    					"height: "
+    					+ headerHeight
+    					+ "px; border-style: none; border-width: 0px; overflow: hidden; padding: 0px",
+    					null);
+    	        writer.startElement(HTML.DIV_ELEM, schedule);
+    	        writer.writeAttribute(HTML.STYLE_ATTR, "height: 1px; width: 56px", null);
+    	        writer.endElement(HTML.DIV_ELEM);
+    	        writer.endElement(HTML.TD_ELEM);
+    		}
+    		else
+    		{
+    			// the header
+    			writer.startElement(HTML.TD_ELEM, schedule);
+    			writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    			"header"), null);
+    			writer
+    			.writeAttribute(
+    					HTML.STYLE_ATTR,
+    					"height: " + headerHeight + "px; border-style: none; border-width: 0px; overflow:
hidden;",
+    					null);
+    			writer.startElement(HTML.DIV_ELEM, schedule);
+    			writer
+    			.writeAttribute(
+    					HTML.STYLE_ATTR,
+    					"position: relative; left: 0px; top: 0px; width: 100%; height: 100%;",
+    					null);
+
+    			// write the date
+    			writer.startElement(HTML.SPAN_ELEM, schedule);
+    			writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    			"date"), null);
+    			writer
+    			.writeAttribute(
+    					HTML.STYLE_ATTR,
+    					"position: absolute; left: 0px; top: 0px; height: 15px; width: 100%; vertical-align:
top; overflow: hidden; white-space: nowrap;",
+    					null);
+    			writer.writeText(getDateString(context, schedule, day.getDate()),
+    					null);
+    			writer.endElement(HTML.SPAN_ELEM);
+
+    			// write the name of the holiday, if there is one
+    			if ((day.getSpecialDayName() != null)
+    					&& (day.getSpecialDayName().length() > 0))
+    			{
+    				writer.startElement(HTML.SPAN_ELEM, schedule);
+    				writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    				"holiday"), null);
+    				writer
+    				.writeAttribute(
+    						HTML.STYLE_ATTR,
+    						"position: absolute; left: 0px; top: 15px; width: 100%; vertical-align: top; overflow:
hidden; white-space: nowrap;",
+    						null);
+    				writer.writeText(day.getSpecialDayName(), null);
+    				writer.endElement(HTML.SPAN_ELEM);
+    			}
+
+    			writer.endElement(HTML.DIV_ELEM);
+    			writer.endElement(HTML.TD_ELEM);
+    		}
+			writer.endElement(HTML.TR_ELEM);
+
+    		// the intervals
+    		Iterator intervalIt = day.getIntervals(startHour, endHour).iterator();
+    		Interval nextInterval = intervalIt.hasNext() ? (Interval) intervalIt.next() : null;
+
+    		boolean renderGutter = true;
+
+    		while (intervalIt.hasNext() || nextInterval != null)
+    		{
+    			Interval interval = nextInterval;
+    			nextInterval = intervalIt.hasNext() ? (Interval) intervalIt.next() : null;
+    			int intervalHeight = calcRowHeight(rowHeight, interval.getDuration()) - 1;
+
+    			// Don't render rows where the timespan is too small
+    			if (intervalHeight <= 0)
+    			{
+    				continue;
+    			}
+
+    			if (!renderGutter)
+    			{
+    				renderGutter = true;
+    				continue;
+    			}
+    			
+    			writer.startElement(HTML.TR_ELEM, schedule);
+
+    			if (firstDay)
+    			{
+    				int gutterHeight = intervalHeight;
+
+    				if (day.getIntervals() == null && interval.getStartMinutes() == 0)
+    				{
+    					gutterHeight = (gutterHeight * 2) + 1;
+    					renderGutter = false;
+    				}    				
+
+    				//write the hours of the day on the left
+    				//this only happens on even rows, or every hour
+    				writer.startElement(HTML.TD_ELEM, schedule);
+    				writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    				"gutter"), null);
+    				writer
+    				.writeAttribute(
+    						HTML.STYLE_ATTR,
+    						"height: " + gutterHeight
+    						+ "px; border-style: none; border-width: 0px; overflow: hidden; padding: 0px",
+    						null);
+    				if (interval.getDuration() >= HalfHourInterval.HALF_HOUR)
+    				{
+    					writer.startElement(HTML.SPAN_ELEM, schedule);
+    					writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    							renderGutter ? "minutes" : "hours"), null);
+    					writer.writeAttribute(HTML.STYLE_ATTR,
+    							"vertical-align: top; height: 100%; padding: 0px;",
+    							null);
+    					writer.writeText(hourFormater.format(interval.getStartTime()), null);
+    					writer.endElement(HTML.SPAN_ELEM);
+    					writer.startElement(HTML.SPAN_ELEM, schedule);
+    					writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
+    							"minutes"), null);
+    					writer.writeAttribute(HTML.STYLE_ATTR,
+    							"vertical-align: top; height: 100%; padding: 0px;",
+    							null);
+    					writer.writeText(minuteFormater.format(interval.getStartTime()), null);
+    					writer.endElement(HTML.SPAN_ELEM);
+    				}
+    				writer.endElement(HTML.TD_ELEM);
+    			}
+    			else
+    			{
+    				writer.startElement(HTML.TD_ELEM, schedule);
+    				writer.writeAttribute(HTML.CLASS_ATTR, getCellClass(schedule,
+    						day, renderGutter, interval.getStartHours()), null);
+    				writer.writeAttribute(HTML.STYLE_ATTR,
+    						"overflow: hidden; height: " + intervalHeight + "px;", null);
+    				if (interval.getLabel() != null)
+    				{
+    					writer.write(interval.getLabel());
+    				}
+    				writer.endElement(HTML.TD_ELEM);
+    			}
+
+    			writer.endElement(HTML.TR_ELEM);
+    		}
+
+    		writer.endElement(HTML.TBODY_ELEM);
+    		writer.endElement(HTML.TABLE_ELEM);            
+
+    		writer.endElement(HTML.TD_ELEM);
+    	}
+
+    	writer.endElement(HTML.TR_ELEM);
+    	writer.endElement(HTML.TBODY_ELEM);
+    	writer.endElement(HTML.TABLE_ELEM);
 
-        for (int row = 0; row < numberOfRows; row++)
-        {
-            writer.startElement(HTML.TR_ELEM, schedule);
-
-            //write the hours of the day on the left
-            //this only happens on even rows, or every hour
-            if ((row % 2) == 0)
-            {
-                writer.startElement(HTML.TD_ELEM, schedule);
-                writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                        "gutter"), null);
-                writer
-                        .writeAttribute(
-                                HTML.STYLE_ATTR,
-                                "height: "
-                                        + rowHeight
-                                        + "px; border-style: none; border-width: 0px; overflow:
hidden; padding: 0px",
-                                null);
-                writer.writeAttribute("rowspan", "2", null);
-                writer.startElement(HTML.SPAN_ELEM, schedule);
-                writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                        "hours"), null);
-                writer.writeAttribute(HTML.STYLE_ATTR,
-                        "vertical-align: top; height: 100%; padding: 0px;",
-                        null);
-                writer.writeText(String.valueOf(startHour + (row / 2)), null);
-                writer.endElement(HTML.SPAN_ELEM);
-                writer.startElement(HTML.SPAN_ELEM, schedule);
-                writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-                        "minutes"), null);
-                writer.writeAttribute(HTML.STYLE_ATTR,
-                        "vertical-align: top; height: 100%; padding: 0px;",
-                        null);
-                writer.writeText("00", null);
-                writer.endElement(HTML.SPAN_ELEM);
-                writer.endElement(HTML.TD_ELEM);
-            }
-
-            //write the cells of the day columns on this row
-            for (int column = 0; column < schedule.getModel().size(); column++)
-            {
-                writer.startElement(HTML.TD_ELEM, schedule);
-                writer.writeAttribute(HTML.CLASS_ATTR, getCellClass(schedule,
-                        column, row, startHour + (row / 2)), null);
-                writer.writeAttribute(HTML.STYLE_ATTR,
-                        "overflow: hidden; height: " + rowHeight + "px;", null);
-                writer.writeAttribute(HTML.WIDTH_ATTR, String
-                        .valueOf(columnWidth)
-                        + "%", null);
-                writer.write(HTML.NBSP_ENTITY);
-                writer.endElement(HTML.TD_ELEM);
-            }
-
-            writer.endElement(HTML.TR_ELEM);
-        }
-
-        writer.endElement(HTML.TBODY_ELEM);
-        writer.endElement(HTML.TABLE_ELEM);
-        writer.endElement(HTML.DIV_ELEM);
+    	writer.endElement(HTML.DIV_ELEM);
     }
 
+    /**
+     * Calculate an actual row height, given a specified height for a half hour duration.
+     * 
+     * @param halfHourHeight The height for a half hour duration
+     * @param duration The actual interval duration
+     * @return The height for the actual interval duration
+     */
+    private int calcRowHeight(int halfHourHeight, long duration) {
+    	
+    	return duration == HalfHourInterval.HALF_HOUR ? halfHourHeight : 
+			(int)((halfHourHeight / (float)(30 * 60 * 1000)) * duration);
+    }
+    
     protected int getRenderedStartHour(HtmlSchedule schedule)
     {
         int startHour = schedule.getVisibleStartHour();
@@ -460,13 +542,13 @@
         final String clientId = schedule.getClientId(context);
         FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
         String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();
-        
+
         TreeSet entrySet = new TreeSet();
-        
+
         for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();)
         {
-            ScheduleEntry entry = (ScheduleEntry) entryIterator.next();
-            entrySet.add(new EntryWrapper(entry, day));
+            entrySet.add(new EntryWrapper((ScheduleEntry) entryIterator.next(),
+                    day));
         }
 
         EntryWrapper[] entries = (EntryWrapper[]) entrySet
@@ -568,7 +650,7 @@
                 getEntryRenderer(schedule).renderContent(context, writer,
                         schedule, day, wrapper.entry, false, selected);
 
-                writer.endElement(schedule.isReadonly() ? HTML.DIV_ELEM : "a");
+                writer.endElement(schedule.isReadonly() ? HTML.DIV_ELEM : HTML.ANCHOR_ELEM);
             }
         }
     }
@@ -862,11 +944,18 @@
                 buffer.append("visibility: hidden; ");
             }
             buffer.append("position: absolute; height: ");
-            if (height > 0) {
+            if (height > 2)
+            {
+            	// Adjust for the width of the border
+                buffer.append((height - 2) + "px");
+            } else if (height > 0)
+            {
                 buffer.append(height + "px");
-            } else if (entryVisible) {
+            } else if (entryVisible)
+            {
                 buffer.append("auto");
-            } else {
+            } else
+            {
                 buffer.append("0px");
             }
             buffer.append("; top: ");

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleMouseEvent.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleMouseEvent.java?view=diff&rev=548680&r1=548679&r2=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleMouseEvent.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/ScheduleMouseEvent.java
Tue Jun 19 03:21:59 2007
@@ -20,10 +20,14 @@
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Iterator;
 
 import javax.faces.event.FacesEvent;
 import javax.faces.event.FacesListener;
 
+import org.apache.myfaces.custom.schedule.model.Interval;
+import org.apache.myfaces.custom.schedule.model.ScheduleDay;
+
 /**
  * An event that is fired when the schedule is clicked, and the submitOnClick
  * property on the schedule is set to true.
@@ -58,6 +62,22 @@
     public Date getClickedTime()
     {
         return getSchedule().getLastClickedDateAndTime();
+    }
+   
+    public Interval getClickedInterval()
+    {
+    	Date clickedDate = getClickedDate();
+    	
+    	for (Iterator intervalIt = getSchedule().getModel().iterator(); intervalIt.hasNext();
) {
+            ScheduleDay day = (ScheduleDay) intervalIt.next();
+
+            if (day.equalsDate(clickedDate))
+            {
+                return day.getInterval(clickedDate);
+            }
+    	}
+    	
+    	return null;
     }
 
     public int getEventType()

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java?view=diff&rev=548680&r1=548679&r2=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Day.java
Tue Jun 19 03:21:59 2007
@@ -23,8 +23,10 @@
 import java.io.Serializable;
 
 import java.util.Calendar;
+import java.util.Collection;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.TreeSet;
 
 import org.apache.myfaces.custom.schedule.util.ScheduleUtil;
 
@@ -51,6 +53,7 @@
     private final Date dayStart;
     private String specialDayName;
     private boolean workingDay;
+    private TreeSet intervals;
 
     //~ Constructors -----------------------------------------------------------
 
@@ -164,6 +167,40 @@
         return workingDay;
     }
 
+    /**
+     * 
+     * @return A chronologically ordered set of intervals.
+     */
+    public TreeSet getIntervals() {
+		return intervals;
+	}
+    
+    /**
+     * Set user defined intervals during the day.
+     * 
+     * @param intervals A Collection<Interval> of intervals during the day
+     */
+    public void setIntervals(Collection intervals)
+    {
+    	if (intervals instanceof TreeSet)
+    	{
+    		this.intervals = (TreeSet) intervals;
+    	}
+    	else
+    	{	
+    		this.intervals = new TreeSet(intervals);
+    	}
+	}
+    
+    public void addInterval(String label, Date startTime, Date endTime)
+    {
+    	if (intervals == null)
+    	{
+    		intervals = new TreeSet();
+    	}
+    	intervals.add(new Interval(label, startTime, endTime));
+    }
+    
     /**
      * @see java.lang.Comparable#compareTo(java.lang.Object)
      */

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/HalfHourInterval.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/HalfHourInterval.java?view=auto&rev=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/HalfHourInterval.java
(added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/HalfHourInterval.java
Tue Jun 19 03:21:59 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.schedule.model;
+
+import java.util.Date;
+
+/**
+ * <p>
+ * This class represents an interval of up to half an hour.
+ * The interval will always round up to the next half hour
+ * e.g. a start time of 14:15 will generate an interval with
+ * end time of 14:30.
+ * </p>
+ *
+ * @author Peter Mahoney
+ * @version $Revision: 371736 $
+ */
+public class HalfHourInterval extends Interval {
+
+	public static final long HALF_HOUR = 1000 * 60 * 30;
+
+	public HalfHourInterval(Date startTime, Date maxEnd)
+	{
+		super(null, startTime, new Date(Math.min(startTime.getTime() + HALF_HOUR, maxEnd.getTime())));
+	}
+
+	private HalfHourInterval(String label, Date startTime, Date endTime)
+	{
+		super(label, startTime, endTime); 
+	}
+	
+	/**
+	 * Create a new half hour interval following on from the supplied interval.
+	 * The interval will be anything up to half an hour, depending on when the
+	 * end of the previous interval was. If an interval cannot be fitted between
+	 * the end of the last interval and the maximum end time, null will be returned.
+	 * 
+	 * @param interval The previous interval
+	 * @param maxEnd The maximum end time of the new interval
+	 * @return The next half hour interval
+	 */
+	public static Interval next(Interval interval, Date maxEnd) {
+		Date startTime = interval.getEndTime();
+		
+		if (startTime.before(maxEnd))
+		{
+			Date endTime = new Date(Math.min(startTime.getTime() - (startTime.getTime() % HALF_HOUR)
+ HALF_HOUR, maxEnd.getTime()));
+			
+			return new HalfHourInterval(null, startTime, endTime);
+		}
+		else
+		{
+			
+			return null;
+		}
+	}
+}

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java?view=auto&rev=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
(added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
Tue Jun 19 03:21:59 2007
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.schedule.model;
+
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+/**
+ * <p>
+ * This class represents a period of time, which may be given a label.
+ * An interval is inclusive of the start time, but excludes the end time.
+ * </p>
+ *
+ * @author Peter Mahoney
+ * @version $Revision: 371736 $
+ */
+public class Interval implements Serializable, Comparable
+{
+
+	private String label;
+	private Date startTime;
+	private Date endTime;
+	
+	public Interval(String label, Date startTime, Date endTime)
+	{
+		this.label = label;
+		this.startTime = startTime;
+		this.endTime = endTime;
+	}
+	
+	public String getLabel()
+	{
+		return label;
+	}
+	public void setLabel(String label)
+	{
+		this.label = label;
+	}
+	
+	public Date getStartTime()
+	{
+		return startTime;
+	}
+	public void setStartTime(Date startTime)
+	{
+		this.startTime = startTime;
+	}
+	
+	public Date getEndTime()
+	{
+		return endTime;
+	}
+	public void setEndTime(Date endTime)
+	{
+		this.endTime = endTime;
+	}
+
+	public boolean containsDate(Date clickedDate)
+	{
+		return !getStartTime().after(clickedDate) && clickedDate.before(getEndTime());
+	}
+	
+	public int compareTo(Object o)
+	{
+		if (o instanceof Interval)
+		{
+			
+			return startTime.compareTo(((Interval) o).startTime);
+		}
+
+		return 1;
+	}
+
+	public boolean after(Interval last)
+	{
+		
+		return !startTime.before(last.getEndTime());
+	}
+
+	public int getStartHours()
+	{
+		Calendar calendar = GregorianCalendar.getInstance();
+		calendar.setTime(getStartTime());
+		
+		return calendar.get(Calendar.HOUR_OF_DAY);
+	}
+
+	public int getStartMinutes() {
+		Calendar calendar = GregorianCalendar.getInstance();
+		calendar.setTime(getStartTime());
+		
+		return calendar.get(Calendar.MINUTE);
+	}
+	
+	public long getDuration()
+	{
+		
+		return getEndTime().getTime() - getStartTime().getTime();
+	}
+	
+	public String toString()
+	{
+		
+		return this.getClass().getName() + " Start:" + startTime + " End:" + endTime;
+	}
+}

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java?view=diff&rev=548680&r1=548679&r2=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleDay.java
Tue Jun 19 03:21:59 2007
@@ -22,10 +22,12 @@
 
 import java.io.Serializable;
 
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Iterator;
+import java.util.List;
 import java.util.TreeSet;
 
 import org.apache.myfaces.custom.schedule.util.ScheduleEntryComparator;
@@ -217,6 +219,118 @@
     	}
 
     	return equalsDate(startTime.getTime()) ? startTime.get(Calendar.HOUR_OF_DAY) : 0;
+    }
+
+    public Interval getInterval(Date clickedDate) {
+    	if (getIntervals() != null)
+    	{
+    		for (Iterator intervalIt = getIntervals().iterator(); intervalIt.hasNext(); )
+    		{
+    			Interval interval = (Interval) intervalIt.next();
+
+    			if (interval.containsDate(clickedDate)) {
+
+    				return interval;
+    			}
+    		}
+    	}
+
+    	return null;
+    }
+	
+    /**
+     * Get an chronologically ordered list of intervals during the day. 
+     * These will consist of user defined intervals, packed with half 
+     * hour intervals to ensure contiguous intervals between the start 
+     * and end hour.
+     *  
+     * @param startHour The first hour
+     * @param endHour The last hour
+     * @return A List<Interval> of intervals covering the day
+     */
+    public List getIntervals(int startHour, int endHour) {
+    	Date endTime = initDate(getDate(), endHour);
+    	ArrayList intervals = new ArrayList();
+    	Interval last = null;
+    	
+    	// Iterate over the custom intervals, adding half hour intervals in any gaps
+    	if (getIntervals() != null)
+    	{
+    		for (Iterator intervalIt = getIntervals().iterator(); intervalIt.hasNext(); )
+    		{
+    			Interval interval = (Interval) intervalIt.next();
+    		
+    			if (last != null)
+    			{
+    				if (!interval.getEndTime().after(last.getEndTime()))
+    				{
+            			// Skip if the interval if entirely overlapped by the previous interval
+    					continue;
+    				}
+    				else if (interval.getStartTime().before(last.getEndTime()))
+    				{
+    	    			// Truncate the beginning of the interval, to remove overlap
+        				interval.setStartTime(last.getEndTime());
+    				}
+    			}
+    			
+    			// Don't add any intervals beyond the end time
+    			if (interval.getStartTime().after(endTime)) 
+    			{
+    				break;
+    			}
+    		
+    			if (last == null) 
+    			{
+    				// Calculate the first interval of the day
+    				last = new HalfHourInterval(initDate(getDate(), startHour), interval.getStartTime());
+    			} 
+    			else 
+    			{
+    				// Calculate a half hour interval following the last user defined interval
+    				last = HalfHourInterval.next(last, interval.getStartTime());    			
+    			}
+    			// Add half hours up to the current interval
+    			while (last != null && interval.after(last))
+    			{
+    				intervals.add(last);
+    				last = HalfHourInterval.next(last, interval.getStartTime());
+    			}
+    			intervals.add(interval);
+				last = interval;
+    		}
+    	}
+
+    	if (last == null)
+    	{
+    		// There are no user defined intervals, so start at the beginning of the day
+    		last = new HalfHourInterval(initDate(getDate(), startHour), endTime);    		
+    	}
+		else 
+		{
+	    	// Move on to the next interval after the last user defined one
+			last = HalfHourInterval.next(last, endTime);    			
+		}
+    	
+    	// Add half hour intervals up to the end time
+    	while(last != null)
+    	{
+			intervals.add(last);
+        	last = HalfHourInterval.next(last, endTime);
+    	}
+    	
+		return intervals;
+	}
+
+    private Date initDate(Date date, int hour) {
+		Calendar calendar = GregorianCalendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.HOUR_OF_DAY, hour);
+		calendar.set(Calendar.MINUTE, 0);
+		calendar.set(Calendar.SECOND, 0);
+		calendar.set(Calendar.MILLISECOND, 0);
+
+		return calendar.getTime();
     }
 }
 //The End

Modified: myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/schedule/resource/css/schedule.css
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/schedule/resource/css/schedule.css?view=diff&rev=548680&r1=548679&r2=548680
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/schedule/resource/css/schedule.css
(original)
+++ myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/schedule/resource/css/schedule.css
Tue Jun 19 03:21:59 2007
@@ -60,22 +60,20 @@
 div.schedule-detailed-default table.background td.free {
     font-family: Verdana, Arial, Helvetica, Sans-Serif;
     font-size: 10px;
-    text-align: center;
+    text-align: left;
+    color: rgb(0,0,0);
 }
 
 div.schedule-detailed-default table.background td.uneven {
     background-color: rgb(240,240,240);
-    color: rgb(240,240,240);
 }
 
 div.schedule-detailed-default table.background td.even {
     background-color: rgb(235,235,235);
-    color: rgb(235,235,235);
 }
 
 div.schedule-detailed-default table.background td.free {
 	background-color: rgb(221,221,221);
-	color: rgb(221,221,221);
 }
 
 div.schedule-detailed-default .entry, div.schedule-detailed-default div.entry-selected {
@@ -243,22 +241,20 @@
 div.schedule-detailed-evolution table.background td.free {
     font-family: Verdana, Arial, Helvetica, Sans-Serif;
     font-size: 10px;
-    text-align: center;
+    text-align: left;
+    color: rgb(0,0,0);
 }
 
 div.schedule-detailed-evolution table.background td.uneven {
     background-color: rgb(255,255,255);
-    color: rgb(255,255,255);
 }
 
 div.schedule-detailed-evolution table.background td.even {
     background-color: rgb(255,255,255);
-    color: rgb(255,255,255);
 }
 
 div.schedule-detailed-evolution table.background td.free {
 	background-color: rgb(217,217,217);
-	color: rgb(217,217,217);
 }
 
 div.schedule-detailed-evolution .entry, div.schedule-detailed-evolution div.entry-selected
{
@@ -427,22 +423,21 @@
 div.schedule-detailed-outlookxp table.background td.free {
     font-family: Verdana, Arial, Helvetica, Sans-Serif;
     font-size: 10px;
-    text-align: center;
+    text-align: left;
+    color: rgb(128,128,128);
+    vertical-align: top;
 }
 
 div.schedule-detailed-outlookxp table.background td.uneven {
     background-color: rgb(255,255,143);
-    color: rgb(255,255,143);
 }
 
 div.schedule-detailed-outlookxp table.background td.even {
     background-color: rgb(255,255,143);
-    color: rgb(255,255,143);
 }
 
 div.schedule-detailed-outlookxp table.background td.free {
     background-color: rgb(239,240,112);
-    color: rgb(239,240,112);
 }
 
 div.schedule-detailed-outlookxp .entry, div.schedule-detailed-outlookxp div.entry-selected
{



Mime
View raw message