Author: jm
Date: 2010-11-09 14:54:03 -0800 (Tue, 09 Nov 2010)
New Revision: 22790

Added:
   core3/filter-api/trunk/
   core3/filter-api/trunk/osgi.bnd
   core3/filter-api/trunk/pom.xml
   core3/filter-api/trunk/src/
   core3/filter-api/trunk/src/main/
   core3/filter-api/trunk/src/main/java/
   core3/filter-api/trunk/src/main/java/org/
   core3/filter-api/trunk/src/main/java/org/cytoscape/
   core3/filter-api/trunk/src/main/java/org/cytoscape/filter/
   core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilter.java
   
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterFactory.java
   
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterManager.java
   core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResult.java
   
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResultFactory.java
   core3/filter-api/trunk/src/main/java/org/cytoscape/filter/MergeType.java
   
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/TunableCyFilter.java
   core3/filter-api/trunk/src/main/resources/
   core3/filter-api/trunk/src/test/
   core3/filter-api/trunk/src/test/java/
   core3/filter-api/trunk/src/test/resources/
Log:
Initial import



Property changes on: core3/filter-api/trunk
___________________________________________________________________
Name: svn:ignore
   + .settings
.classpath
.project
target


Added: core3/filter-api/trunk/osgi.bnd
===================================================================
--- core3/filter-api/trunk/osgi.bnd                             (rev 0)
+++ core3/filter-api/trunk/osgi.bnd     2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,7 @@
+#-----------------------------------------------------------------
+# Use this file to add customized Bnd instructions for the bundle
+#-----------------------------------------------------------------
+
+Spring-Context: META-INF/spring/*.xml
+Private-Package: ${bundle.namespace}.internal.*
+Export-Package: 
!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"

Added: core3/filter-api/trunk/pom.xml
===================================================================
--- core3/filter-api/trunk/pom.xml                              (rev 0)
+++ core3/filter-api/trunk/pom.xml      2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";
+       xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+       <parent>
+               <groupId>org.cytoscape</groupId>
+               <artifactId>parent</artifactId>
+               <version>1.0-SNAPSHOT</version>
+       </parent>
+       <properties>
+               
<bundle.symbolicName>org.cytoscape.filter-api</bundle.symbolicName>
+               <bundle.namespace>org.cytoscape.filter</bundle.namespace>
+       </properties>
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>org.cytoscape</groupId>
+       <artifactId>filter-api</artifactId>
+       <version>1.0-SNAPSHOT</version>
+       <name>${bundle.symbolicName}
+               [${bundle.namespace}]</name>
+       <packaging>bundle</packaging>
+       <dependencies>
+               <dependency>
+                       <groupId>cytoscape</groupId>
+                       <artifactId>application</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>osgi_R4_core</artifactId>
+                       <version>1.0</version>
+                       <scope>provided</scope>
+                       <optional>true</optional>
+               </dependency>
+               <dependency>
+                       <groupId>org.osgi</groupId>
+                       <artifactId>osgi_R4_compendium</artifactId>
+                       <version>1.0</version>
+                       <scope>provided</scope>
+                       <optional>true</optional>
+               </dependency>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>${junit.version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>test-support</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+                       <scope>test</scope>
+               </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <version>1.8.1</version>
+            <scope>test</scope>
+        </dependency>
+       </dependencies>
+       
+       <repositories>
+               <repository>
+                       <id>cytoscape_thirdparty</id>
+                       <snapshots>
+                               <enabled>false</enabled>
+                       </snapshots>
+                       <releases>
+                               <enabled>true</enabled>
+                       </releases>
+                       <name>Wrapped Third Party Libraries</name>
+                       
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/thirdparty/</url>
+               </repository>
+       </repositories>
+       
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.ops4j</groupId>
+                               <artifactId>maven-pax-plugin</artifactId>
+                               <version>1.4</version>
+                               <extensions>true</extensions>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <version>1.4.3</version>
+                               <configuration>
+                                       <instructions>
+                                               
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
+                                               
<Bundle-Version>${pom.version}</Bundle-Version>
+                                               <_include>-osgi.bnd</_include>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
\ No newline at end of file

Added: core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilter.java
===================================================================
--- core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilter.java     
                        (rev 0)
+++ core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilter.java     
2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,65 @@
+package org.cytoscape.filter;
+
+import java.util.Map;
+
+import javax.swing.JComponent;
+
+/**
+ * Selects nodes and edges from a <code>CyNetwork</code> through some
+ * implementation-defined heuristic.
+ */
+public interface CyFilter {
+       /**
+        * Returns the name of this filter.
+        * @return
+        */
+    String getName();
+    
+    /**
+     * Sets the name of this filter to <code>name</code>.
+     * @param name
+     */
+    void setName(String name);
+    
+    /**
+     * Returns the value associated with the property named <code>name</code>,
+     * or <code>null</code> if no value was previously associated.
+     * @param <T> the type of the property value to fetch.
+     * @param name the name of the property
+     * @param type
+     * @return
+     */
+    <T> T getProperty(String name, Class<T> type);
+    
+    /**
+     * Associates the given value with the property named <code>name</code>.
+     * Setting the value to <code>null</code> effectively removes the
+     * association.
+     * @param <T> the type of the property value to set.
+     * @param name
+     * @param value
+     */
+    <T> void setProperty(String name, T value);
+    
+    /**
+     * Returns a <code>Map</code> where the keys are property names and the
+     * values are their respective values.  Each supported property name is
+     * present as a key in this map.  The values of unset properties is
+     * <code>null</code>.
+     * @return
+     */
+    Map<String, Object> getAllProperties();
+    
+    /**
+     * Adds the nodes and edges selected by the filter to <code>result</code>.
+     * @param result
+     */
+    void apply(CyFilterResult result);
+    
+    /**
+     * Returns a Swing component that contains a GUI for configuring the
+     * properties of this <code>CyFilter</code>.
+     * @return
+     */
+    JComponent getSettingsUI();
+}

Added: 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterFactory.java
===================================================================
--- 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterFactory.java  
                            (rev 0)
+++ 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterFactory.java  
    2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,29 @@
+package org.cytoscape.filter;
+
+import java.io.Reader;
+
+/**
+ * A factory for creating a specific type of <code>CyFilter</code>. 
+ */
+public interface CyFilterFactory {
+       /**
+        * Returns the unique identifier of the type of filter created by this
+        * factory.
+        * @return
+        */
+       String getIdentifier();
+       
+       /**
+        * Returns a new <code>CyFilter</code> instance.
+        * @return
+        */
+       CyFilter getFilter();
+       
+       /**
+        * Returns a new <code>CyFilter</code> instance from its serialized
+        * representation.
+        * @param reader
+        * @return
+        */
+       CyFilter getFilter(Reader reader);
+}

Added: 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterManager.java
===================================================================
--- 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterManager.java  
                            (rev 0)
+++ 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterManager.java  
    2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,24 @@
+package org.cytoscape.filter;
+
+import java.util.Collection;
+
+/**
+ * The central registry for all <code>CyFilter</code>s and their
+ * corresponding factories. 
+ */
+public interface CyFilterManager {
+       /**
+        * Returns the <code>CyFilterFactory</code> with the given identifier, 
or
+        * null, if no such factory was previously registered.
+        * @param identifier
+        * @return
+        */
+       CyFilterFactory getFilterFactory(String identifier);
+       
+       /**
+        * Returns all of the <code>CyFilterFactory</code>s registered with this
+        * object.
+        * @return
+        */
+       Collection<CyFilterFactory> getAllFilterFactories();
+}

Added: 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResult.java
===================================================================
--- 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResult.java   
                            (rev 0)
+++ 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResult.java   
    2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,87 @@
+package org.cytoscape.filter;
+
+import org.cytoscape.model.CyNetwork;
+
+/**
+ * Tracks the nodes and edges that have been filtered from a
+ * <code>CyNetwork</code>.
+ */
+public interface CyFilterResult {
+       /**
+        * Returns the <code>CyNetwork</code> this result set applies to.
+        * @return
+        */
+    CyNetwork getNetwork();
+    
+       /**
+        * Adds the edge with the given index to this result set.  If the edge
+        * was previously added, this method does nothing.
+        * @param index
+        */
+    void addEdge(int index);
+    
+    /**
+     * Removes the edge with the given index from this result set.  If the
+     * edge was not previously added, this method does nothing.
+     * @param index
+     */
+    void removeEdge(int index);
+    
+    /**
+     * Returns <code>true</code> if the edge with the given index is part of
+     * this result set, and <code>false</code> otherwise.
+     * @param index
+     * @return
+     */
+    boolean hasEdge(int index);
+    
+    /**
+     * Returns an <code>Iterable</code> over all the edges in this result set.
+     * @return
+     */
+    Iterable<Integer> edges();
+    
+    /**
+     * Adds the node with the given index to this result set.  If the node
+     * was previously added, this method does nothing. 
+     * @param index
+     */
+    void addNode(int index);
+    
+    /**
+     * Removes the node with the given index from this result set.  If the
+     * node was not previously added, this method does nothing. 
+     * @param index
+     */
+    void removeNode(int index);
+    
+    /**
+     * Returns <code>true</code> if the node with the given index is part of
+     * this result set, and <code>false</code> otherwise. 
+     * @param index
+     * @return
+     */
+    boolean hasNode(int index);
+    
+    /**
+     * Returns an <code>Iterable</code> over all the nodes in this result set.
+     * @return
+     */
+    Iterable<Integer> nodes();
+    
+    /**
+     * Merges this object with <code>result</code> using the combination
+     * method specified by <code>type</code>.
+     * @param result
+     * @param type
+     */
+    void merge(CyFilterResult result, MergeType type);
+    
+    /**
+     * Updates this object so that it contains the set complement of its
+     * edges and its nodes, with respect to the network it belongs to.
+     */
+    void invert();
+    
+    void clear();
+}

Added: 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResultFactory.java
===================================================================
--- 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResultFactory.java
                                (rev 0)
+++ 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/CyFilterResultFactory.java
        2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,17 @@
+package org.cytoscape.filter;
+
+import org.cytoscape.model.CyNetwork;
+
+/**
+ * A factory for creating <code>CyFilterResult</code>s for specific
+ * <code>CyNetwork</code>s.
+ */
+public interface CyFilterResultFactory {
+       /**
+        * Creates a <code>CyFilterResult</code> for tracking filtered nodes and
+        * edges from the given network.  
+        * @param network
+        * @return
+        */
+       CyFilterResult getResult(CyNetwork network);
+}

Added: core3/filter-api/trunk/src/main/java/org/cytoscape/filter/MergeType.java
===================================================================
--- core3/filter-api/trunk/src/main/java/org/cytoscape/filter/MergeType.java    
                        (rev 0)
+++ core3/filter-api/trunk/src/main/java/org/cytoscape/filter/MergeType.java    
2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,22 @@
+package org.cytoscape.filter;
+
+/**
+ * Different methods for combining two <code>CyFilterResult</code>s together.
+ */
+public enum MergeType {
+       /**
+        * Computes the set-union of the nodes and edges in both
+        * <code>CyFilterResult</code>s.  In other words, the resulting
+        * <code>CyFilterResult</code> will contain nodes and edges that
+        * occur in either of the input <code>CyFilterResult</code>s.
+        */
+       UNION,
+       
+       /**
+        * Computes the set-intersection of the nodes and edges in both
+        * <code>CyFilterResult</code>s.  In other words, the resulting
+        * <code>CyFilterResult</code> will only contain the nodes and
+        * edges that occur in both input <code>CyFilterResult</code>s.
+        */
+       INTERSECTION,
+}

Added: 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/TunableCyFilter.java
===================================================================
--- 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/TunableCyFilter.java  
                            (rev 0)
+++ 
core3/filter-api/trunk/src/main/java/org/cytoscape/filter/TunableCyFilter.java  
    2010-11-09 22:54:03 UTC (rev 22790)
@@ -0,0 +1,181 @@
+package org.cytoscape.filter;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JComponent;
+
+import org.cytoscape.work.Tunable;
+
+/**
+ * A base class for <code>CyFilter</code>s that declare their properties
+ * through <code>Tunable</code>s.
+ */
+public abstract class TunableCyFilter implements CyFilter {
+       private static final Collection<String> GETTER_NAME_PREFIXES = 
Collections.unmodifiableCollection(Arrays.asList(new String[] { "get", "is", 
"has" })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+       private String name;
+
+       @Override
+       public String getName() {
+               return name;
+       }
+       
+       @Override
+       public void setName(String name) {
+               this.name = name;
+       }
+       
+       @SuppressWarnings("unchecked")
+       @Override
+       public <T> T getProperty(String name, Class<T> type) {
+               Class<?> currentClass = getClass();
+               while (currentClass != null) {
+                       for (String prefix : GETTER_NAME_PREFIXES) {
+                               String suffix = name.substring(0, 
1).toLowerCase() + name.substring(1);
+                               try {
+                                       Method method = 
currentClass.getDeclaredMethod(String.format("%s%s", prefix, suffix)); 
//$NON-NLS-1$
+                                       if 
(!method.isAnnotationPresent(Tunable.class)) {
+                                               continue;
+                                       }
+                                       if 
(!type.isAssignableFrom(method.getReturnType())) {
+                                               throw new ClassCastException();
+                                       }
+                                       return (T) method.invoke(this);
+                               } catch (SecurityException e) {
+                               } catch (IllegalArgumentException e) {
+                               } catch (IllegalAccessException e) {
+                               } catch (NoSuchMethodException e) {
+                               } catch (InvocationTargetException e) {
+                               }
+                       }
+                       
+                       try {
+                               Field field = 
currentClass.getDeclaredField(name);
+                               if (!field.isAnnotationPresent(Tunable.class)) {
+                                       continue;
+                               }
+                               return (T) field.get(this);
+                       } catch (SecurityException e) {
+                       } catch (NoSuchFieldException e) {
+                       } catch (IllegalArgumentException e) {
+                       } catch (IllegalAccessException e) {
+                       }
+                       currentClass = currentClass.getSuperclass();
+               }
+               return null;
+       }
+       
+       @Override
+       public <T> void setProperty(String name, T value) {
+               String suffix = Character.toUpperCase(name.charAt(0)) + 
name.substring(1);
+               String setterName = String.format("set%s", suffix); 
//$NON-NLS-1$
+               Class<?> currentClass = getClass();
+               
+               while (currentClass != null) {
+                       try {
+                               for (String prefix : GETTER_NAME_PREFIXES) {
+                                       String getterName = 
String.format("%s%s", prefix, suffix); //$NON-NLS-1$
+                                       Method getter = 
currentClass.getDeclaredMethod(getterName);
+                                       if 
(!getter.isAnnotationPresent(Tunable.class)) {
+                                               continue;
+                                       }
+                                       Method setter = 
currentClass.getDeclaredMethod(setterName, value.getClass());
+                                       setter.invoke(this, value);
+                                       return;
+                               }
+                       } catch (SecurityException e) {
+                       } catch (NoSuchMethodException e) {
+                       } catch (IllegalArgumentException e) {
+                       } catch (IllegalAccessException e) {
+                       } catch (InvocationTargetException e) {
+                       }
+                       
+                       try {
+                               Field field = 
currentClass.getDeclaredField(name);
+                               if (!field.isAnnotationPresent(Tunable.class)) {
+                                       continue;
+                               }
+                               field.set(this, value);
+                               return;
+                       } catch (SecurityException e) {
+                       } catch (NoSuchFieldException e) {
+                       } catch (IllegalArgumentException e) {
+                       } catch (IllegalAccessException e) {
+                       }
+                       currentClass = currentClass.getSuperclass();
+               }
+       };
+       
+       @Override
+       public Map<String, Object> getAllProperties() {
+               Map<String, Object> properties = new HashMap<String, Object>();
+               Class<?> currentClass = getClass();
+               
+               while (currentClass != null) {
+                       for (Method method : currentClass.getDeclaredMethods()) 
{
+                               if (method.getParameterTypes().length > 0) {
+                                       continue;
+                               }
+                               String name = 
extractPropertyName(method.getName());
+                               if (name == null) {
+                                       continue;
+                               }
+                               try {
+                                       if 
(!method.isAnnotationPresent(Tunable.class)) {
+                                               continue;
+                                       }
+                                       Object value = method.invoke(this);
+                                       properties.put(name, value);
+                               } catch (SecurityException e) {
+                               } catch (IllegalArgumentException e) {
+                               } catch (IllegalAccessException e) {
+                               } catch (InvocationTargetException e) {
+                               }
+                       }
+                       for (Field field : currentClass.getDeclaredFields()) {
+                               if (!field.isAnnotationPresent(Tunable.class)) {
+                                       continue;
+                               }
+                               try {
+                                       Object value = field.get(this);
+                                       properties.put(field.getName(), value);
+                               } catch (IllegalArgumentException e) {
+                               } catch (IllegalAccessException e) {
+                               }
+                       }
+                       currentClass = currentClass.getSuperclass();
+               }
+               return properties;
+       }
+
+       private String extractPropertyName(String fullName) {
+               for (String prefix : GETTER_NAME_PREFIXES) {
+                       if (!fullName.startsWith(prefix)) {
+                               return null;
+                       }
+                       
+                       String suffix = fullName.substring(prefix.length());
+                       char firstLetter = suffix.charAt(0);
+                       if (!Character.isUpperCase(firstLetter)) {
+                               return null;
+                       }
+                       
+                       return Character.toLowerCase(firstLetter) + 
suffix.substring(1);
+               }
+               return null;
+       }
+       
+       @Override
+       public JComponent getSettingsUI() {
+               // TODO Should we reuse Tunable UI bits in work-swing-impl or 
create
+               // a different UI widget library for filters?
+               return null;
+       }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to