You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/11/03 13:43:19 UTC

svn commit: r832403 - in /incubator/pivot/trunk: demos/src/org/apache/pivot/demos/explorer/ tools/src/org/apache/pivot/tools/wtk/

Author: tvolkert
Date: Tue Nov  3 12:43:18 2009
New Revision: 832403

URL: http://svn.apache.org/viewvc?rev=832403&view=rev
Log:
Updates to event logger, component explorer

Modified:
    incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/component_explorer.wtkx
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLogger.java
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.java
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.json
    incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/event_logger_skin.wtkx

Modified: incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/component_explorer.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/component_explorer.wtkx?rev=832403&r1=832402&r2=832403&view=diff
==============================================================================
--- incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/component_explorer.wtkx (original)
+++ incubator/pivot/trunk/demos/src/org/apache/pivot/demos/explorer/component_explorer.wtkx Tue Nov  3 12:43:18 2009
@@ -310,7 +310,7 @@
                 <right>
                     <SplitPane orientation="vertical" splitRatio="0.6">
                         <top>
-                            <SplitPane orientation="horizontal" splitRatio="0.6">
+                            <SplitPane orientation="horizontal" splitRatio="0.5">
                                 <left>
                                     <TabPane>
                                         <tabs>

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLogger.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLogger.java?rev=832403&r1=832402&r2=832403&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLogger.java (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLogger.java Tue Nov  3 12:43:18 2009
@@ -23,14 +23,11 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
-import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.ArrayList;
 import org.apache.pivot.collections.Group;
 import org.apache.pivot.collections.HashMap;
 import org.apache.pivot.collections.HashSet;
-import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.util.ThreadUtilities;
@@ -39,7 +36,7 @@
 import org.apache.pivot.wtk.Container;
 
 /**
- *
+ * A component that monitors a source component for events.
  */
 public class EventLogger extends Container {
     /**
@@ -53,50 +50,32 @@
     }
 
     /**
-     * Declared event sequence.
+     * A read-only group of events that an event logger is capable of firing.
+     * To make an event logger actually fire declared events, callers add them
+     * to the event logger's include event group.
      */
-    public final class DeclaredEventSequence implements Sequence<Method>, Iterable<Method> {
-        private DeclaredEventSequence() {
+    public final class DeclaredEventGroup implements Group<Method>, Iterable<Method> {
+        private DeclaredEventGroup() {
         }
 
         @Override
-        public int add(Method event) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public void insert(Method event, int index) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public Method update(int index, Method event) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public int remove(Method event) {
+        public boolean add(Method event) {
             throw new UnsupportedOperationException();
         }
 
         @Override
-        public Sequence<Method> remove(int index, int count) {
+        public boolean remove(Method event) {
             throw new UnsupportedOperationException();
         }
 
         @Override
-        public Method get(int index) {
-            return declaredEvents.get(index);
-        }
-
-        @Override
-        public int indexOf(Method event) {
-            return declaredEvents.indexOf(event);
+        public boolean contains(Method event) {
+            return declaredEvents.contains(event);
         }
 
         @Override
-        public int getLength() {
-            return declaredEvents.getLength();
+        public boolean isEmpty() {
+            return declaredEvents.isEmpty();
         }
 
         @Override
@@ -106,7 +85,8 @@
     }
 
     /**
-     * Include events group.
+     * A read/write group of events that an event logger will actually fire.
+     * This group is guaranteed to be a subset of the declared event group.
      */
     public final class IncludeEventGroup implements Group<Method>, Iterable<Method> {
         private IncludeEventGroup() {
@@ -116,6 +96,10 @@
         public boolean add(Method event) {
             boolean added = false;
 
+            if (!declaredEvents.contains(event)) {
+                throw new IllegalArgumentException("Event has not been declared.");
+            }
+
             if (!includeEvents.contains(event)) {
                 includeEvents.add(event);
                 eventLoggerListeners.eventIncluded(EventLogger.this, event);
@@ -154,26 +138,9 @@
         }
     }
 
-    private static class EventComparator implements Comparator<Method> {
-        @Override
-        public int compare(Method event1, Method event2) {
-            int result = 0;
-
-            Class<?> listenerInterface1 = event1.getDeclaringClass();
-            Class<?> listenerInterface2 = event2.getDeclaringClass();
-
-            if (listenerInterface1 != listenerInterface2) {
-                result = listenerInterface1.getName().compareTo(listenerInterface2.getName());
-            }
-
-            if (result == 0) {
-                result = event1.getName().compareTo(event2.getName());
-            }
-
-            return result;
-        }
-    }
-
+    /**
+     * Event logger invocation handler.
+     */
     private class LoggerInvocationHandler implements InvocationHandler {
         @Override
         public Object invoke(Object proxy, Method event, Object[] arguments) throws Throwable {
@@ -193,6 +160,9 @@
         }
     }
 
+    /**
+     * Event logger listener list.
+     */
     private static class EventLoggerListenerList extends ListenerList<EventLoggerListener>
         implements EventLoggerListener {
         @Override
@@ -229,8 +199,8 @@
     private HashMap<Class<?>, Object> eventListenerProxies = new HashMap<Class<?>, Object>();
     private LoggerInvocationHandler loggerInvocationHandler = new LoggerInvocationHandler();
 
-    private ArrayList<Method> declaredEvents = new ArrayList<Method>(new EventComparator());
-    private DeclaredEventSequence declaredEventSequence = new DeclaredEventSequence();
+    private HashSet<Method> declaredEvents = new HashSet<Method>();
+    private DeclaredEventGroup declaredEventGroup = new DeclaredEventGroup();
 
     private HashSet<Method> includeEvents = new HashSet<Method>();
     private IncludeEventGroup includeEventGroup = new IncludeEventGroup();
@@ -290,19 +260,22 @@
     }
 
     /**
-     * Gets the declared events sequence, a read-only sequence that includes
-     * the complete list of events that this event logger's source declares.
+     * Gets the declared event group, a read-only group that includes the
+     * complete list of events that this event logger's source declares.
      *
      * @return
-     * the declared events sequence.
+     * the declared events group.
      */
-    public DeclaredEventSequence getDeclaredEvents() {
-        return declaredEventSequence;
+    public DeclaredEventGroup getDeclaredEvents() {
+        return declaredEventGroup;
     }
 
     /**
      * Gets the include events group, which callers can use to include or
      * exclude declared events from those that get fired by this logger.
+     * This group is guaranteed to be a subset of the declared event group
+     * (attempts to add events to this group that are not included in the
+     * declared event group will fail).
      *
      * @return
      * The include events group.
@@ -319,6 +292,9 @@
         eventLoggerSkin.clearLog();
     }
 
+    /**
+     * Registers event listeners on this event logger's source.
+     */
     private void registerEventListeners() {
         Method[] methods = source.getClass().getMethods();
 
@@ -384,6 +360,9 @@
         }
     }
 
+    /**
+     * Unregisters event listeners on this event logger's source.
+     */
     private void unregisterEventListeners() {
         Method[] methods = source.getClass().getMethods();
 

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.java?rev=832403&r1=832402&r2=832403&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.java (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.java Tue Nov  3 12:43:18 2009
@@ -100,6 +100,7 @@
         declaredEventsTreeView = wtkxSerializer.getValue("declaredEventsTreeView");
         firedEventsTableView = wtkxSerializer.getValue("firedEventsTableView");
 
+        // Propagate check state upwards or downwards as necessary
         declaredEventsTreeView.getTreeViewNodeStateListeners().add(new TreeViewNodeStateListener() {
             @Override
             public void nodeCheckStateChanged(TreeView treeView, Path path,

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.json?rev=832403&r1=832402&r2=832403&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.json (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/EventLoggerSkin.json Tue Nov  3 12:43:18 2009
@@ -1,3 +1,5 @@
 {
-    clearEvents: "Clear"
+    interface: "Declaring Class",
+    method: "Event",
+    arguments: "Arguments"
 }

Modified: incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/event_logger_skin.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/event_logger_skin.wtkx?rev=832403&r1=832402&r2=832403&view=diff
==============================================================================
--- incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/event_logger_skin.wtkx (original)
+++ incubator/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/event_logger_skin.wtkx Tue Nov  3 12:43:18 2009
@@ -46,11 +46,11 @@
                         <TableView wtkx:id="firedEventsTableView" selectMode="none">
                             <columns>
                                 <TableView.Column name="interface" width="175"
-                                    headerData="Declaring Class"/>
+                                    headerData="%interface"/>
                                 <TableView.Column name="method" width="200"
-                                    headerData="Event"/>
+                                    headerData="%method"/>
                                 <TableView.Column name="arguments" width="1*"
-                                    headerData="Arguments" minimumWidth="200"/>
+                                    headerData="%arguments" minimumWidth="200"/>
                             </columns>
                         </TableView>
                     </view>