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/08/28 16:40:52 UTC

svn commit: r808902 - in /incubator/pivot/trunk: core/src/org/apache/pivot/collections/ core/test/org/apache/pivot/collections/test/ tutorials/src/org/apache/pivot/tutorials/calendars/

Author: gbrown
Date: Fri Aug 28 14:40:51 2009
New Revision: 808902

URL: http://svn.apache.org/viewvc?rev=808902&view=rev
Log:
Resolve issues PIVOT-250 and PIVOT-252; add a Calendar tutorial example (just code, no docs).

Added:
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/Calendars.java
    incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx
Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/LinkedListTest.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java Fri Aug 28 14:40:51 2009
@@ -21,6 +21,48 @@
  */
 public interface Dictionary<K, V> {
     /**
+     * Class representing a key/value pair.
+     */
+    public static final class Pair<K, V> {
+        public final K key;
+        public final V value;
+
+        public Pair(K key, V value) {
+            if (key == null) {
+                throw new IllegalArgumentException();
+            }
+
+            this.key = key;
+            this.value = value;
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public boolean equals(Object object) {
+           boolean equals = false;
+
+           if (object instanceof Pair<?, ?>) {
+              Pair<K, V> pair = (Pair<K, V>)object;
+              equals = (key.equals(pair.key)
+                  && ((value == null && pair.value == null)
+                      || (value != null && value.equals(pair.value))));
+           }
+
+           return equals;
+        }
+
+        @Override
+        public int hashCode() {
+           return key.hashCode();
+        }
+
+        @Override
+        public String toString() {
+           return "{" + key + ": " + value + "}";
+        }
+    }
+
+    /**
      * Retrieves the value for the given key.
      *
      * @param key

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java Fri Aug 28 14:40:51 2009
@@ -47,8 +47,8 @@
             // Move to the next bucket
             while (entryIterator != null
                 && !entryIterator.hasNext()) {
-                entryIterator = (bucketIndex < buckets.getLength()) ?
-                    getBucketIterator(bucketIndex++) : null;
+                entryIterator = (++bucketIndex < buckets.getLength()) ?
+                    getBucketIterator(bucketIndex) : null;
             }
 
             return (entryIterator != null);

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java Fri Aug 28 14:40:51 2009
@@ -26,48 +26,6 @@
  */
 public interface Map<K, V> extends Dictionary<K, V>, Collection<K> {
     /**
-     * Class representing a key/value pair.
-     */
-    public static final class Pair<K, V> {
-        public final K key;
-        public final V value;
-
-        public Pair(K key, V value) {
-            if (key == null) {
-                throw new IllegalArgumentException();
-            }
-
-            this.key = key;
-            this.value = value;
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public boolean equals(Object object) {
-           boolean equals = false;
-
-           if (object instanceof Pair<?, ?>) {
-              Pair<K, V> pair = (Pair<K, V>)object;
-              equals = (key.equals(pair.key)
-                  && ((value == null && pair.value == null)
-                      || (value != null && value.equals(pair.value))));
-           }
-
-           return equals;
-        }
-
-        @Override
-        public int hashCode() {
-           return key.hashCode();
-        }
-
-        @Override
-        public String toString() {
-           return "{" + key + ": " + value + "}";
-        }
-    }
-
-    /**
      * Map listener list.
      */
     public static class MapListenerList<K, V>

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/MapList.java Fri Aug 28 14:40:51 2009
@@ -19,7 +19,7 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.Map.Pair;
+import org.apache.pivot.collections.Dictionary.Pair;
 import org.apache.pivot.util.ListenerList;
 
 /**

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java Fri Aug 28 14:40:51 2009
@@ -17,7 +17,7 @@
 
 package org.apache.pivot.collections.test;
 
-import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -181,4 +181,16 @@
         System.out.println("java.util.HashMap " + (t1 - t0) + "ms");
     }
 
+    @Test
+    public void iteratorTest() {
+        HashMap<String, Object> map = new HashMap<String, Object>();
+        map.put("font", "Verdana 11");
+        map.put("colors", "#ff0000");
+
+        Iterator<String> iterator = map.iterator();
+        while (iterator.hasNext()) {
+            String key = iterator.next();
+            System.out.println(key);
+        }
+    }
 }

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/LinkedListTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/LinkedListTest.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/LinkedListTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/LinkedListTest.java Fri Aug 28 14:40:51 2009
@@ -22,6 +22,7 @@
 
 import java.util.Comparator;
 
+import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.LinkedList;
 import org.apache.pivot.collections.Sequence;
 import org.junit.Test;
@@ -58,6 +59,14 @@
 
         list.insert("G", 0);
         assertEquals(list, new LinkedList<String>("G", "B", "F", "D"));
+
+        assertEquals(4, list.getLength());
+
+        ArrayList<String> copy = new ArrayList<String>("G", "B", "F", "D");
+        int i = 0;
+        for (String item : list) {
+            assertEquals(item, copy.get(i++));
+        }
     }
 
     @Test

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java?rev=808902&r1=808901&r2=808902&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/MapListTest.java Fri Aug 28 14:40:51 2009
@@ -30,7 +30,7 @@
 import org.apache.pivot.collections.MapList;
 import org.apache.pivot.collections.MapListListener;
 import org.apache.pivot.collections.Sequence;
-import org.apache.pivot.collections.Map.Pair;
+import org.apache.pivot.collections.Dictionary.Pair;
 import org.junit.Before;
 import org.junit.Test;
 

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/Calendars.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/Calendars.java?rev=808902&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/Calendars.java (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/Calendars.java Fri Aug 28 14:40:51 2009
@@ -0,0 +1,96 @@
+/*
+ * 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.pivot.tutorials.calendars;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.util.CalendarDate;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Calendar;
+import org.apache.pivot.wtk.CalendarButton;
+import org.apache.pivot.wtk.CalendarButtonSelectionListener;
+import org.apache.pivot.wtk.CalendarSelectionListener;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class Calendars implements Application {
+    private Window window = null;
+    private Calendar calendar = null;
+    private CalendarButton calendarButton = null;
+    private Label selectedDateLabel = null;
+
+    private boolean updatingSelectedDate = false;
+
+    public void startup(Display display, Map<String, String> properties)
+        throws Exception {
+        WTKXSerializer wtkxSerializer = new WTKXSerializer();
+        window = (Window)wtkxSerializer.readObject(this, "calendars.wtkx");
+        calendar = (Calendar)wtkxSerializer.get("calendar");
+        calendarButton = (CalendarButton)wtkxSerializer.get("calendarButton");
+        selectedDateLabel = (Label)wtkxSerializer.get("selectedDateLabel");
+
+        calendar.getCalendarSelectionListeners().add(new CalendarSelectionListener() {
+            @Override
+            public void selectedDateChanged(Calendar calendar, CalendarDate previousSelectedDate) {
+                updateSelectedDate(calendar.getSelectedDate());
+            }
+        });
+
+        calendarButton.getCalendarButtonSelectionListeners().add(new CalendarButtonSelectionListener() {
+            @Override
+            public void selectedDateChanged(CalendarButton calendarButton, CalendarDate previousSelectedDate) {
+                updateSelectedDate(calendarButton.getSelectedDate());
+            }
+        });
+
+
+
+        window.open(display);
+    }
+
+    public boolean shutdown(boolean optional) {
+        if (window != null) {
+            window.close();
+        }
+
+        return false;
+    }
+
+    public void suspend() {
+    }
+
+    public void resume() {
+    }
+
+    private void updateSelectedDate(CalendarDate selectedDate) {
+        if (!updatingSelectedDate) {
+            updatingSelectedDate = true;
+
+            calendar.setSelectedDate(selectedDate);
+            calendarButton.setSelectedDate(selectedDate);
+            selectedDateLabel.setText(selectedDate.toString());
+
+            updatingSelectedDate = false;
+        }
+    }
+
+    public static void main(String[] args) {
+        DesktopApplicationContext.main(Calendars.class, args);
+    }
+}

Added: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx?rev=808902&view=auto
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx (added)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/calendars/calendars.wtkx Fri Aug 28 14:40:51 2009
@@ -0,0 +1,44 @@
+<?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="Calendars" maximized="true"
+    xmlns:wtkx="http://pivot.apache.org/wtkx"
+    xmlns="org.apache.pivot.wtk">
+    <content>
+        <Border styles="{padding:8}">
+            <content>
+                <Form styles="{rightAlignLabels:true}">
+                    <sections>
+                        <Form.Section>
+                            <Border Form.label="Calendar" styles="{padding:0, color:10}">
+                                <content>
+                                    <Calendar wtkx:id="calendar"/>
+                                </content>
+                            </Border>
+                            <CalendarButton wtkx:id="calendarButton" Form.label="Calendar button"/>
+                        </Form.Section>
+                        <Form.Section>
+                            <Label wtkx:id="selectedDateLabel" Form.label="Selected date"/>
+                        </Form.Section>
+                    </sections>
+                </Form>
+            </content>
+        </Border>
+    </content>
+</Window>
+