You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/10/15 01:55:21 UTC

svn commit: r825345 - in /incubator/pivot/trunk: core/src/org/apache/pivot/util/ tutorials/src/org/apache/pivot/tutorials/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/content/ wtk/src/org/apache/pivot/wtk/skin/terra/ wtk/test/org/apache/...

Author: gbrown
Date: Wed Oct 14 23:55:20 2009
New Revision: 825345

URL: http://svn.apache.org/viewvc?rev=825345&view=rev
Log:
Add getTime() method to CalendarDate; add support for CalendarDate in TableViewDateCellRenderer; walk value class hierarchy looking for a renderer match in TableViewMultiCellRenderer; vertically center expander button in TerraExpanderSkin.

Added:
    incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/table_view_test.wtkx
Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewDateCellRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewMultiCellRenderer.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraExpanderSkin.java

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java?rev=825345&r1=825344&r2=825345&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/util/CalendarDate.java Wed Oct 14 23:55:20 2009
@@ -46,6 +46,8 @@
      */
     public final int day;
 
+    private long time = -1;
+
     private static final int[] MONTH_LENGTHS = {
         31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
     };
@@ -115,7 +117,7 @@
      * Compares this calendar date with another calendar date.
      *
      * @param calendarDate
-     * The calendar date against which to compare
+     * The calendar date against which to compare.
      *
      * @return
      * A negative number, zero, or a positive number if the specified calendar
@@ -150,10 +152,10 @@
      *
      * @param days
      * The number of days to add to (or subtract from if negative) this
-     * calendar date
+     * calendar date.
      *
      * @return
-     * The resulting calendar date
+     * The resulting calendar date.
      */
     public CalendarDate add(int days) {
         GregorianCalendar calendar = toCalendar();
@@ -165,7 +167,7 @@
      * Gets the number of days in between this calendar date and the specified
      * calendar date. If this calendar date represents a day after the
      * specified calendar date, the difference will be positive. If this
-     * calendardate represents a day before the specified calendar date, the
+     * calendar date represents a day before the specified calendar date, the
      * difference will be negative. If the two calendar dates represent the
      * same day, the difference will be zero.
      * <p>
@@ -176,30 +178,42 @@
      * </pre>
      *
      * @param calendarDate
-     * The calendar date to subtract from this calendar date
+     * The calendar date to subtract from this calendar date.
      *
      * @return
      * The number of days in between this calendar date and
-     * <tt>calendarDate</tt>
+     * <tt>calendarDate</tt>.
      */
     public int subtract(CalendarDate calendarDate) {
-        GregorianCalendar c1 = toCalendar();
-        GregorianCalendar c2 = calendarDate.toCalendar();
-
-        long t1 = c1.getTimeInMillis();
-        long t2 = c2.getTimeInMillis();
+        long t1 = getTime();
+        long t2 = calendarDate.getTime();
 
         return (int)((t1 - t2) / (1000l * 60 * 60 * 24));
     }
 
     /**
+     * Returns this calendar date as a millisecond value. The value is the
+     * number of milliseconds since midnight GMT on January 1, 1970.
+     *
+     * @return
+     * The number of milliseconds since midnight GMT on January 1, 1970.
+     */
+    public long getTime() {
+        if (time == -1) {
+            time = toCalendar().getTimeInMillis();
+        }
+
+        return time;
+    }
+
+    /**
      * Translates this calendar date to an instance of
      * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and
      * <tt>dayOfMonth</tt> fields set in the default time zone with the default
      * locale.
      *
      * @return
-     * This calendar date as a <tt>GregorianCalendar</tt>
+     * This calendar date as a <tt>GregorianCalendar</tt>.
      */
     public GregorianCalendar toCalendar() {
         return new GregorianCalendar(year, month, day + 1);
@@ -211,7 +225,7 @@
      * same day as this one.
      *
      * @param o
-     * Reference to the object against which to compare
+     * Reference to the object against which to compare.
      */
     @Override
     public boolean equals(Object o) {
@@ -260,7 +274,7 @@
      * which is <tt>[YYYY]-[MM]-[DD]</tt>.
      *
      * @param date
-     * A string in the form of <tt>[YYYY]-[MM]-[DD]</tt>. (e.g. 2008-07-23)
+     * A string in the form of <tt>[YYYY]-[MM]-[DD]</tt> (e.g. 2008-07-23).
      */
     public static CalendarDate forString(String date) {
         Pattern pattern = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})$");

Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/kitchen_sink.wtkx?rev=825345&r1=825344&r2=825345&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java?rev=825345&r1=825344&r2=825345&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ScriptApplication.java Wed Oct 14 23:55:20 2009
@@ -16,8 +16,11 @@
  */
 package org.apache.pivot.wtk;
 
+import java.net.URL;
+
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.util.Resources;
+import org.apache.pivot.util.ThreadUtilities;
 import org.apache.pivot.wtkx.WTKXSerializer;
 
 /**
@@ -43,7 +46,12 @@
         }
 
         WTKXSerializer wtkxSerializer = new WTKXSerializer(resources);
-        window = (Window)wtkxSerializer.readObject(src);
+
+        ClassLoader classLoader = ThreadUtilities.getClassLoader();
+        URL location = classLoader.getResource(src);
+
+        wtkxSerializer.put("location", location);
+        window = (Window)wtkxSerializer.readObject(location);
         window.open(display);
     }
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewDateCellRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewDateCellRenderer.java?rev=825345&r1=825344&r2=825345&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewDateCellRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewDateCellRenderer.java Wed Oct 14 23:55:20 2009
@@ -23,6 +23,7 @@
 
 import org.apache.pivot.beans.BeanDictionary;
 import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.util.CalendarDate;
 import org.apache.pivot.wtk.TableView;
 
 
@@ -78,10 +79,11 @@
                     } else if (cellData instanceof Long) {
                         formattedDate = dateFormat.format(new Date((Long)cellData));
                     } else if (cellData instanceof Calendar) {
-                        formattedDate = dateFormat.format( ((Calendar)cellData).getTime() );
+                        formattedDate = dateFormat.format(((Calendar)cellData).getTime());
+                    } else if (cellData instanceof CalendarDate) {
+                        formattedDate = dateFormat.format(new Date(((CalendarDate)cellData).getTime()));
                     } else {
-                        System.err.println("Data for \"" + columnName + "\" is not an instance of "
-                            + Date.class.getName());
+                        System.err.println(getClass().getName() + " cannot render " + cellData);
                     }
                 }
             }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewMultiCellRenderer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewMultiCellRenderer.java?rev=825345&r1=825344&r2=825345&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewMultiCellRenderer.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewMultiCellRenderer.java Wed Oct 14 23:55:20 2009
@@ -349,8 +349,17 @@
                 cellData = rowData.get(columnName);
             }
 
+            TableView.CellRenderer cellRenderer = null;
+
             Class<?> valueClass = (cellData == null ? null : cellData.getClass());
-            TableView.CellRenderer cellRenderer = cellRenderers.get(valueClass);
+            while (cellRenderer == null
+                && valueClass != Object.class) {
+                cellRenderer = cellRenderers.get(valueClass);
+
+                if (cellRenderer == null) {
+                    valueClass = valueClass.getSuperclass();
+                }
+            }
 
             if (cellRenderer == null) {
                 cellRenderer = defaultRenderer;

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraExpanderSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraExpanderSkin.java?rev=825345&r1=825344&r2=825345&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraExpanderSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraExpanderSkin.java Wed Oct 14 23:55:20 2009
@@ -41,6 +41,7 @@
 import org.apache.pivot.wtk.Orientation;
 import org.apache.pivot.wtk.TablePane;
 import org.apache.pivot.wtk.Theme;
+import org.apache.pivot.wtk.VerticalAlignment;
 import org.apache.pivot.wtk.content.ButtonDataRenderer;
 import org.apache.pivot.wtk.effects.Transition;
 import org.apache.pivot.wtk.effects.TransitionListener;
@@ -236,6 +237,7 @@
 
         buttonBoxPane = new BoxPane(Orientation.HORIZONTAL);
         buttonBoxPane.getStyles().put("horizontalAlignment", HorizontalAlignment.RIGHT);
+        buttonBoxPane.getStyles().put("verticalAlignment", VerticalAlignment.CENTER);
 
         titleRow.add(titleBoxPane);
         titleRow.add(buttonBoxPane);

Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/table_view_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/table_view_test.wtkx?rev=825345&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/table_view_test.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/table_view_test.wtkx Wed Oct 14 23:55:20 2009
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<Window title="Table View Test" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns:collections="org.apache.pivot.collections"
+    xmlns:content="org.apache.pivot.wtk.content"
+    xmlns="org.apache.pivot.wtk">
+    <wtkx:script>
+    <![CDATA[
+    importPackage(java.net);
+    importPackage(org.apache.pivot.util);
+    importPackage(org.apache.pivot.wtk);
+    importPackage(org.apache.pivot.wtk.media);
+
+    var s = "ABCDE";
+    var b = true;
+    var n = 100.25;
+    var d = new CalendarDate();
+    var i = Image.load(new URL(location, "go-home.png"));
+    ]]>
+    </wtkx:script>
+    <content>
+        <TableView>
+            <columns>
+                <TableView.Column name="value" width="-1">
+                    <cellRenderer>
+                        <content:TableViewMultiCellRenderer>
+                            <wtkx:define>
+                                <content:TableViewBooleanCellRenderer wtkx:id="booleanCellRenderer"/>
+                                <content:TableViewNumberCellRenderer wtkx:id="numberCellRenderer"/>
+                                <content:TableViewDateCellRenderer wtkx:id="dateCellRenderer"/>
+                                <content:TableViewImageCellRenderer wtkx:id="imageCellRenderer" preferredHeight="40"/>
+                            </wtkx:define>
+
+                            <rendererMappings>
+                                <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Boolean"
+                                    cellRenderer="$booleanCellRenderer"/>
+                                <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Number"
+                                    cellRenderer="$numberCellRenderer"/>
+                                <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.util.CalendarDate"
+                                    cellRenderer="$dateCellRenderer"/>
+                                <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.media.Image"
+                                    cellRenderer="$imageCellRenderer"/>
+                            </rendererMappings>
+                        </content:TableViewMultiCellRenderer>
+                    </cellRenderer>
+                </TableView.Column>
+
+                <TableView.Column width="1*"/>
+            </columns>
+            <tableData>
+                <collections:ArrayList>
+                    <collections:HashMap value="$s"/>
+                    <collections:HashMap value="$b"/>
+                    <collections:HashMap value="$n"/>
+                    <collections:HashMap value="$d"/>
+                    <collections:HashMap value="$i"/>
+                </collections:ArrayList>
+            </tableData>
+        </TableView>
+    </content>
+</Window>