Author: mmichaud
Date: 2009-05-29 07:06:13 -0700 (Fri, 29 May 2009)
New Revision: 16843

Added:
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BooleanPropHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BoundedPropHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/FlexiblyBoundedPropHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListMultipleSelectionPropHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListSingleSelectionPropHandler.java
Removed:
   csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/AppCL3.java
Log:
[]

Deleted: csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/AppCL3.java
===================================================================
--- csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/AppCL3.java       
2009-05-29 14:01:54 UTC (rev 16842)
+++ csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/AppCL3.java       
2009-05-29 14:06:13 UTC (rev 16843)
@@ -1,133 +0,0 @@
-package org.example;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
-import org.example.tunable.*;
-import org.example.tunable.internal.props.*;
-import org.example.tunable.internal.cl.*;
-import org.example.command.*;
-
-import java.util.*;
-
-public class AppCL3
-{
-    public static void main(String[] args) {
-
-               java.util.List<taskFactory> list = new 
java.util.ArrayList<taskFactory>();
-               list.add(0,new taskFactory(new TunableSampler(), "This is a 
TaskFactory example for TunableSampler" ));
-               list.add(1,new taskFactory(new PrintSomething(), "This is a 
TaskFactory example for PrintSomething" ));
-               list.add(2,new taskFactory(new JActiveModules(), "This is a 
TaskFactory example for JActiveModules" ));
-               
-               Options options = new Options();
-               for ( taskFactory tf : list ){
-                       options.addOption( tf.getOption() );
-               }
-               options.addOption("h", "listTask", false, "Display all the 
available taskFactories.");
-               
-
-               
-        CommandLineParser parser = new PosixParser();
-        CommandLine line = null;
-        String[] args1 = new String[1];
-        String[] args2 = null;
-               java.util.List test = new java.util.ArrayList();
-        
-        try {
-               if(args.length>1){
-               args2 = new String[args.length-1];
-
-                       for(int i=0;i<args.length;i++)test.add(args[i]);
-                       args1[0]= (String) test.get(0);           
-
-                       for(int i=0;i<test.size()-1;i++)args2[i]=(String) 
test.get(i+1);
-                       line = parser.parse(options, args1);
-               }
-               else line = parser.parse(options, args);
-
-        } catch (ParseException e) {
-            System.err.println("Parsing command line failed: " + 
e.getMessage());
-                       printHelp(options);
-            System.exit(1);
-        }
-
-        // use what is found on the command line to set values
-        if (line.hasOption("h")) {
-                       printHelp(options);
-                       System.exit(0);
-        }
-
-        for(taskFactory tf : list) tf.checkFactory(line,args2);
-
-        if(args.length==0){
-               printHelp(options);
-                       System.exit(0);
-        }
-    }
-    
-       private static void printHelp(Options options) {
-               HelpFormatter formatter = new HelpFormatter();
-               System.out.println("\n");
-               formatter.printHelp("java -Xmx512M -jar cytoscape.jar 
[Options]","\nHere are the different taskFactories implemented :", options,"");
-       }
-
-       
-       
-    static private class taskFactory{
-       Command com;
-       String desc;
-       String name;
-       private taskFactory(Command com,String desc){
-               this.com=com;
-               this.desc=desc;
-               this.name=com.getClass().getSimpleName();
-       }
-       
-       Option getOption(){
-            return new Option(name.substring(0, 3),name,false,desc);
-       }
-       
-       void checkFactory(CommandLine line,String[] args){
-               if(line.hasOption(name.substring(0, 3))){
-                       for(String ar : args)System.out.println("the arguments 
= "+ar);
-                       getFactory(com,args);
-               }
-       }
-       
-       void getFactory(Command com,String[] args){
-               TunableInterceptor cl = new CLTunableInterceptor(args);
-               cl.loadTunables(com);
-//             if ( com instanceof HandlerController )
-//                     
((HandlerController)com).controlHandlers(cl.getHandlers(com));
-               cl.createUI(com);
-               System.out.println("\n"+"result of command execution:");
-               com.execute();
-               System.out.println();
-
-               
-               Properties p = new Properties();
-               p.setProperty("printSomething.firstName","marge");
-               TunableInterceptor lp = new LoadPropsInterceptor(p);
-               lp.loadTunables(com);
-//             if ( com instanceof HandlerController )
-//                     
((HandlerController)com).controlHandlers(lp.getHandlers(com));
-               lp.createUI(com);
-               System.out.println("result of command execution after 
properties have been loaded:");
-               com.execute();
-               System.out.println();
-               
-               
-               Properties store = new Properties();
-               TunableInterceptor sp = new StorePropsInterceptor(store);
-               sp.loadTunables(com);
-//             if ( com instanceof HandlerController )
-//                     
((HandlerController)com).controlHandlers(sp.getHandlers(com));
-               sp.createUI(com);
-               System.out.println("result of storing properties 
interceptor:\n"+store.toString()+"\n");
-       }
-    }
-}

Added: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BooleanPropHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BooleanPropHandler.java
    2009-05-29 14:01:54 UTC (rev 16842)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BooleanPropHandler.java
    2009-05-29 14:06:13 UTC (rev 16843)
@@ -0,0 +1,34 @@
+package org.example.tunable.internal.props;
+
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+import org.example.tunable.Tunable;
+
+
+public class BooleanPropHandler extends AbstractPropHandler{
+       
+       public BooleanPropHandler(Field f, Object o, Tunable t){
+               super(f,o,t);
+       }
+
+       
+       public Properties getProps(){
+               Properties p = new Properties();
+               try{
+                               p.setProperty(propKey,f.get(o).toString());
+               }catch(Exception e){e.printStackTrace();}
+               return p;
+       }
+       
+       
+       public void setProps(Properties p){
+               try{
+                       if(p.containsKey(propKey)){
+                               String val = p.getProperty(propKey).toString();
+                               if(val != null) f.set(o, Boolean.valueOf(val));
+                       }
+               }catch(Exception e){e.printStackTrace();}
+       }
+       
+}
\ No newline at end of file

Added: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BoundedPropHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BoundedPropHandler.java
    2009-05-29 14:01:54 UTC (rev 16842)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/BoundedPropHandler.java
    2009-05-29 14:06:13 UTC (rev 16843)
@@ -0,0 +1,36 @@
+package org.example.tunable.internal.props;
+
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+import org.example.tunable.Tunable;
+import org.example.tunable.util.AbstractBounded;
+
+
+public class BoundedPropHandler<T extends AbstractBounded<?>> extends 
AbstractPropHandler {
+       
+       public BoundedPropHandler(Field f, Object o, Tunable t){
+               super(f,o,t);
+       }
+
+       public Properties getProps() {
+               Properties p = new Properties();
+               try {
+                       p.setProperty(propKey, 
((T)f.get(o)).getValue().toString());
+        }catch(IllegalAccessException iae) {iae.printStackTrace();}
+               return p;
+       }
+
+       public void setProps(Properties p) {
+               try{
+                       if(p.containsKey(propKey)){
+                               T bo = (T) f.get(o);
+                               String val = p.getProperty(propKey).toString();
+                               if(val != null) {
+                                       bo.setValue(val);
+                                       f.set(o, bo);
+                               }
+                       }
+               }catch(Exception e){e.printStackTrace();}
+       }       
+}
\ No newline at end of file

Added: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/FlexiblyBoundedPropHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/FlexiblyBoundedPropHandler.java
    2009-05-29 14:01:54 UTC (rev 16842)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/FlexiblyBoundedPropHandler.java
    2009-05-29 14:06:13 UTC (rev 16843)
@@ -0,0 +1,41 @@
+package org.example.tunable.internal.props;
+
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+import org.example.tunable.Tunable;
+import org.example.tunable.util.AbstractFlexiblyBounded;
+
+
+public class FlexiblyBoundedPropHandler<T extends AbstractFlexiblyBounded<?>> 
extends AbstractPropHandler {
+       
+       public FlexiblyBoundedPropHandler(Field f, Object o, Tunable t){
+               super(f,o,t);
+       }
+
+       public Properties getProps() {
+               Properties p = new Properties();
+               try {
+                       T bo = (T)f.get(o);
+                       p.put(propKey, new 
String(bo.getLowerBound()+","+bo.getValue()+","+bo.getUpperBound()+","+bo.isLowerBoundStrict()+","+bo.isUpperBoundStrict()));
+        }catch(IllegalAccessException iae) {iae.printStackTrace();}
+               return p;
+       }
+
+       public void setProps(Properties p) {
+               try{
+                       if(p.containsKey(propKey)){
+                               T bo = (T)f.get(o);
+                               String[] vals = 
p.getProperty(propKey).split(",");
+                               if(vals != null){
+                                       bo.setLowerBound(vals[0]);
+                                       bo.setValue(vals[1]);
+                                       bo.setUpperBound(vals[2]);
+                                       
bo.setLowerBoundStrict(Boolean.getBoolean(vals[3]));
+                                       
bo.setUpperBoundStrict(Boolean.getBoolean(vals[4]));
+                               }
+                               if(bo != null) f.set(o, bo);
+                       }
+               }catch(Exception e){e.printStackTrace();}
+       }       
+}
\ No newline at end of file

Added: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListMultipleSelectionPropHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListMultipleSelectionPropHandler.java
      2009-05-29 14:01:54 UTC (rev 16842)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListMultipleSelectionPropHandler.java
      2009-05-29 14:06:13 UTC (rev 16843)
@@ -0,0 +1,35 @@
+package org.example.tunable.internal.props;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Properties;
+import org.example.tunable.Tunable;
+import org.example.tunable.util.ListMultipleSelection;
+
+public class ListMultipleSelectionPropHandler<T> extends AbstractPropHandler {
+
+       public ListMultipleSelectionPropHandler(Field f, Object o, Tunable t){
+               super(f,o,t);
+       }
+       
+       public Properties getProps() {
+               Properties p = new Properties();
+               try{
+                       
p.setProperty(propKey,((ListMultipleSelection<T>)f.get(o)).getSelectedValues().toString());
+               }catch (Exception e){e.printStackTrace();}              
+               return p;
+       }
+
+       public void setProps(Properties p) {
+               try{
+                       if(p.containsKey(propKey)){
+                               ListMultipleSelection<T> lms = 
(ListMultipleSelection<T>) f.get(o);
+                               T[] tab = 
(T[])p.getProperty(propKey).split(",");
+                               if(tab != null){
+                                       
lms.setSelectedValues(Arrays.asList(tab));
+                                       f.set(o, lms);
+                               }
+                       }
+               }catch(Exception e){e.printStackTrace();}
+       }
+}

Added: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListSingleSelectionPropHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListSingleSelectionPropHandler.java
        2009-05-29 14:01:54 UTC (rev 16842)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/ListSingleSelectionPropHandler.java
        2009-05-29 14:06:13 UTC (rev 16843)
@@ -0,0 +1,37 @@
+package org.example.tunable.internal.props;
+
+import java.lang.reflect.Field;
+import java.util.Properties;
+
+import org.example.tunable.Tunable;
+import org.example.tunable.util.ListSingleSelection;
+
+public class ListSingleSelectionPropHandler<T> extends AbstractPropHandler{
+       
+       
+       public ListSingleSelectionPropHandler(Field f, Object o, Tunable t){
+               super(f,o,t);
+       }
+       
+       public Properties getProps(){
+               Properties p = new Properties();
+               try{
+                       
p.setProperty(propKey,((ListSingleSelection<T>)f.get(o)).getSelectedValue().toString());
+               }catch(Exception e){e.printStackTrace();}
+               return p;
+       }
+       
+       public void setProps(Properties p){
+               try{
+                       if(p.containsKey(propKey)){
+                               ListSingleSelection<T> lss = 
(ListSingleSelection<T>) f.get(o);
+                               T val = (T) p.getProperty(propKey).toString();
+                               if(val != null) {
+                                       lss.setSelectedValue(val);
+                                       f.set(o, lss);
+                               }
+                       }
+               }catch(Exception e){e.printStackTrace();}
+       }
+       
+}
\ No newline at end of file


--~--~---------~--~----~------------~-------~--~----~
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