You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by pm...@apache.org on 2008/01/29 13:25:48 UTC

svn commit: r616283 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule: ScheduleDetailedDayRenderer.java model/AbstractScheduleModel.java model/Interval.java model/ScheduleModel.java util/ScheduleUtil.java

Author: pmahoney
Date: Tue Jan 29 04:25:41 2008
New Revision: 616283

URL: http://svn.apache.org/viewvc?rev=616283&view=rev
Log:
TOMAHAWK-724: Use the gutter to display the interval name, if all days contain equivalent intervals

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/model/AbstractScheduleModel.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java

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?rev=616283&r1=616282&r2=616283&view=diff
==============================================================================
--- 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 Jan 29 04:25:41 2008
@@ -285,6 +285,7 @@
 
     	int startHour = getRenderedStartHour(schedule);
     	int endHour = getRenderedEndHour(schedule);
+    	boolean repeatedIntervals = schedule.getModel().containsRepeatedIntervals();
 
     	DateFormat hourFormater = getDateFormat(context, schedule, HtmlSchedule.HOUR_NOTATION_12.equals(schedule.getHourNotation()) ? "h" : "HH");
     	DateFormat minuteFormater = getDateFormat(context, schedule, HtmlSchedule.HOUR_NOTATION_12.equals(schedule.getHourNotation()) ? "':'mma" : "mm");        
@@ -350,12 +351,14 @@
     					"height: " + headerHeight + "px; vertical-align: top; border-style: none; border-width: 0px; overflow: hidden;",
     					null);
 
+    	        boolean isToday = ScheduleUtil.isSameDay(day.getDate(), new Date(), schedule.getModel().getTimeZone());
+
     			// write the date
     			writer.startElement(HTML.ANCHOR_ELEM, schedule);
                 writer.writeAttribute(HTML.ID_ATTR, dayHeaderId, null);
                 writer.writeAttribute(HTML.HREF_ATTR, "#", null);
-    			writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule,
-    					"date"), null);
+    			writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "date") 
+    					+ (isToday ? " today" : ""), null);
     			writer
     			.writeAttribute(
     					HTML.STYLE_ATTR,
@@ -447,21 +450,31 @@
     						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);
+    					if (!repeatedIntervals || interval.getLabel() == null)
+    					{
+    						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((renderGutter ? minuteFormater : shortMinuteFormater).format(interval.getStartTime()), null);
+    					if (repeatedIntervals && interval.getLabel() != null)
+    					{
+    						writer.writeText(interval.getLabel(), null);
+    					}
+    					else
+    					{
+    						writer.writeText((renderGutter ? minuteFormater : shortMinuteFormater).format(interval.getStartTime()), null);
+    					}
     					writer.endElement(HTML.SPAN_ELEM);
     				}
     				writer.endElement(HTML.TD_ELEM);
@@ -473,7 +486,7 @@
     						day, renderGutter, interval.getStartHours(getTimeZone(schedule))), null);
     				writer.writeAttribute(HTML.STYLE_ATTR,
     						"overflow: hidden; height: " + intervalHeight + "px;", null);
-    				if (interval.getLabel() != null)
+    				if (!repeatedIntervals && interval.getLabel() != null)
     				{
     					writer.write(interval.getLabel());
     				}

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java?rev=616283&r1=616282&r2=616283&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/AbstractScheduleModel.java Tue Jan 29 04:25:41 2008
@@ -470,6 +470,41 @@
      */
     protected abstract void loadDayAttributes(Day day);
 
+    /**
+     * @return true, if each day contains the same set of intervals
+     */
+    public boolean containsRepeatedIntervals() {
+    	boolean firstDay = true;
+    	TreeSet firstDayIntervals = null;
+    	
+    	for (Iterator dayIterator = iterator(); dayIterator.hasNext(); )
+    	{
+    		Day day = (Day) dayIterator.next();
+    		
+    		if (firstDay)
+    		{
+    			firstDayIntervals = day.getIntervals();
+    			firstDay = false;
+    		}
+    		else
+    		{
+    			if (firstDayIntervals == null || firstDayIntervals.size() == 0) {
+    				if (day.getIntervals() != null && day.getIntervals().size() > 0)
+    				{
+    					return false;
+    				}
+    			}
+    			else if (!ScheduleUtil.areEquivalentIntervals(firstDayIntervals, day.getIntervals()))
+    			{
+    				
+    				return false;
+    			}
+    		}
+    	}
+    	
+    	return true;
+    }
+    
     private void load(Date startDate, Date endDate)
     {
         Collection entries = loadEntries(startDate, endDate);

Modified: 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?rev=616283&r1=616282&r2=616283&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/Interval.java Tue Jan 29 04:25:41 2008
@@ -116,6 +116,42 @@
 		return getEndTime().getTime() - getStartTime().getTime();
 	}
 	
+    /**
+     * <p>
+     * Intervals are equivalent if their label is the same and they begin and end
+     * at the same time of day.
+     * </p>
+     *
+     * @param other the interval to compare with
+     *
+     * @return true, if this interval is equivalent to the given interval
+     */
+	public boolean isEquivalent(Interval other)
+	{
+			
+		return label.equals(other.label) 
+				&& ScheduleUtil.isSameTime(startTime, other.startTime) 
+				&& ScheduleUtil.isSameTime(endTime, other.endTime);
+	}
+	
+	public int hashCode() {
+
+		return label.hashCode() + startTime.hashCode() + endTime.hashCode();
+	}
+	
+	public boolean equals(Object obj)
+	{
+		if (obj != null && obj instanceof Interval) {
+			Interval other = (Interval) obj;
+			
+			return label.equals(other.label) 
+					&& startTime.equals(other.startTime) 
+					&& endTime.equals(other.endTime);
+		}
+		
+		return false;
+	}
+	
 	public String toString()
 	{
 		

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java?rev=616283&r1=616282&r2=616283&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/model/ScheduleModel.java Tue Jan 29 04:25:41 2008
@@ -146,5 +146,10 @@
      * @return The timezone for which the model should be built
      */
     public abstract TimeZone getTimeZone();
+    
+    /**
+     * @return true, if each day contains the same set of intervals
+     */
+    public abstract boolean containsRepeatedIntervals();
 }
 //The End

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java?rev=616283&r1=616282&r2=616283&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/schedule/util/ScheduleUtil.java Tue Jan 29 04:25:41 2008
@@ -24,12 +24,16 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.Iterator;
 import java.util.TimeZone;
+import java.util.TreeSet;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 
+import org.apache.myfaces.custom.schedule.model.Interval;
+
 
 /**
  * <p>
@@ -303,6 +307,71 @@
             calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR));
     }
 
+    /**
+     * <p>
+     * Check if the 2 dates are at the same time of day.
+     * </p>
+     *
+     * @param date1 the first date
+     * @param date2 the second date
+     *
+     * @return whether the dates are at the same time of day
+     */
+    public static boolean isSameTime(Date date1, Date date2)
+    {
+        if ((date1 == null) || (date2 == null))
+        {
+            return false;
+        }
+
+        Calendar calendar1 = getCalendarInstance(date1, null);
+        Calendar calendar2 = getCalendarInstance(date2, null);
+
+        return (calendar1.get(Calendar.HOUR_OF_DAY) == calendar2.get(Calendar.HOUR_OF_DAY) &&
+        		calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE) &&
+        		calendar1.get(Calendar.SECOND) == calendar2.get(Calendar.SECOND));
+    }
+
+
+    /**
+     * <p>
+     * Check if two sets of intervals are equivalent.
+     * Intervals are equivalent if their label is the same and they begin and end
+     * at the same time of day.
+     * </p>
+     *
+     * @param intervals1 the first set of intervals
+     * @param intervals2 the second set of intervals
+     *
+     * @return whether the dates are at the same time of day
+     */
+    public static boolean areEquivalentIntervals(TreeSet intervals1, TreeSet intervals2)
+    {
+    	if (intervals1 == null || intervals2 == null)
+    	{
+    		return !(intervals1 != null || intervals2 != null);
+    	}
+    	
+    	if (intervals1.size() == intervals2.size())
+    	{
+    		Iterator it1 = intervals1.iterator();
+    		Iterator it2 = intervals2.iterator();
+    		
+    		while (it1.hasNext())
+    		{
+    			if (!((Interval) it1.next()).isEquivalent(((Interval) it2.next()))) {
+    				return false;
+    			}
+    		}
+    		
+    		return true;
+    	}
+    	else
+    	{
+    		return false;
+    	}
+    }
+    
     /**
      * <p>
      * Get the String value of a UIComponent, even if it is a value