Author: mmichaud
Date: 2009-05-27 10:47:26 -0700 (Wed, 27 May 2009)
New Revision: 16823

Modified:
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerFactory.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/FlexiblyBoundedHandler.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/GuiHandlerFactory.java
   
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/PropHandlerFactory.java
Log:
[]

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
       2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
       2009-05-27 17:47:26 UTC (rev 16823)
@@ -1,5 +1,5 @@
+
 package org.example.command;
-
 import org.example.tunable.Tunable;
 import org.example.tunable.HandlerController;
 import org.example.tunable.Handler;
@@ -38,22 +38,35 @@
        public ListMultipleSelection<String> lms = new 
ListMultipleSelection<String>("one","two","three","four");
        
        
-       public int age;
-       public BoundedInteger height = new 
BoundedInteger(0,150,200,false,false);
+       public Integer age;
        
-       @Tunable(description="to set the Height")
-       public void sHeight(int h) {
-               height.setValue(h);
+       @Tunable(description="to set your age")
+       public void setAge(Integer a) {
+               age = a;
        }
+       @Tunable(description="to get your age")
+       public Integer getAge(){
+               return age;
+       }
+       
+       
+       
+//     test
+       public BoundedInteger height = new 
BoundedInteger(0,150,200,false,false);;
+//     public BoundedInteger test
+//     
+//     @Tunable(description="to set the Height")
+//     public void setHeight(int a) {
+//             height.setValue();
+//             height = test;
+//     }
 
        
-       @Tunable(description="your age")
-       public void sAge(int a) {
-               age = a;
-       }
+
        
        public void execute() {
-               System.out.println("\t name : " + firstName + " " + lastName + 
"\n \t age : " + age + "\n \t foot size : " + footSize.getValue() + "\n \t kids 
= " + kids.getValue() + "\n \t income : $" + income.getValue() + "\n \t result 
for boolean = " + bool + "\n \t listsingleselection = "+lss.getSelectedValue() 
+ "\n \t listmultipleselection = "+lms.getSelectedValues() + "\n \t height = 
"+height.getValue());
+               System.out.println("\t name : " + firstName + " " + lastName + 
"\n \t age : " + getAge() + "\n \t foot size : " + footSize.getValue() + "\n \t 
kids = " + kids.getValue() + "\n \t income : $" + income.getValue() + "\n \t 
result for boolean = " + bool + "\n \t listsingleselection = 
"+lss.getSelectedValue() + "\n \t listmultipleselection = 
"+lms.getSelectedValues() + "\n \t height = "+height.getValue());
+//             System.out.println("test = " + height.getValue());
        }
        
 

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractHandler.java
      2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractHandler.java
      2009-05-27 17:47:26 UTC (rev 16823)
@@ -10,9 +10,14 @@
 public abstract class AbstractHandler implements Handler {
 
        protected Field f;
+       protected Method gmethod;
+       protected Method smethod;
        protected Method m;
        protected Object o;
        protected Tunable t;
+       protected Tunable tg;
+       protected Tunable ts;
+       
        protected List<HandlerListener> listeners;
 
        public AbstractHandler(Field f, Object o, Tunable t) {
@@ -27,6 +32,14 @@
                this.o = o;
                this.t = t;
        }
+       
+       public AbstractHandler(Method getm, Method setm, Object o, Tunable tg, 
Tunable ts){
+               this.gmethod = getm;
+               this.smethod = setm;
+               this.o = o;
+               this.tg = tg;
+               this.ts = ts;
+       }
 
        public Field getField() {
                return f;
@@ -36,6 +49,14 @@
                return m;
        }
 
+       public Method getGetMethod() {
+               return gmethod;
+       }
+       public Method getSetMethod() {
+               return smethod;
+       }
+       
+       
        public Object getObject() {
                return o;
        }

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
   2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
   2009-05-27 17:47:26 UTC (rev 16823)
@@ -61,21 +61,50 @@
                                        }
                                }
                
+                               Map<String, Method> setMethodsMap = new 
HashMap<String,Method>();
+                               Map<String, Method> getMethodsMap = new 
HashMap<String,Method>();
+                               
+                               Map<String, Tunable> getTunableMap = new 
HashMap<String,Tunable>();
+                               Map<String, Tunable> setTunableMap = new 
HashMap<String,Tunable>();
+                                               
+                               
                                // Find each public method in the class.
                                for (Method method : 
obj.getClass().getMethods()) {
-               
                                        // See if the method is annotated as a 
Tunable.
                                        if 
(method.isAnnotationPresent(Tunable.class)) {
                                                try {
                                                        Tunable tunable = 
method.getAnnotation(Tunable.class);
-                                                       
+                                                       
if(method.getName().startsWith("get")){
+                                                               
getMethodsMap.put(method.getName().substring(3),method);
+                                                               
getTunableMap.put(method.getName().substring(3),tunable);
+                                                               
if(setMethodsMap.containsKey(method.getName().substring(3))){
+                                                                       //get a 
handler with the getMethod and setMethod
+                                                                       T 
handler = 
factory.getHandler(getMethodsMap.get(method.getName().substring(3)),setMethodsMap.get(method.getName().substring(3)),
 obj, 
getTunableMap.get(method.getName().substring(3)),setTunableMap.get(method.getName().substring(3)));
+                                                                       if ( 
handler != null ) {
+                                                                               
handlerList.put( "getset" + method.getName().substring(3), handler ); 
+                                                                       }
+                                                               }
+                                                       }
+                                                       else 
if(method.getName().startsWith("set")){
+                                                               
setMethodsMap.put(method.getName().substring(3),method);
+                                                               
setTunableMap.put(method.getName().substring(3),tunable);
+                                                               
if(getMethodsMap.containsKey(method.getName().substring(3))){
+                                                                       //get a 
handler with the getMethod and setMethod
+                                                                       T 
handler = 
factory.getHandler(getMethodsMap.get(method.getName().substring(3)),setMethodsMap.get(method.getName().substring(3)),
 obj, 
getTunableMap.get(method.getName().substring(3)),setTunableMap.get(method.getName().substring(3)));
+                                                                       if ( 
handler != null ) {
+                                                                               
handlerList.put( "getset" + method.getName().substring(3), handler ); 
+                                                                       }
+                                                               }
+                                                       }
+                                                       else throw new 
Exception("the name of the method has to start with \"set\" or \"get\"");
+                                               
                                                        // Get a handler for 
this particular field type and
                                                        // add it to the list.
-                                                       T handler = 
factory.getHandler(method,obj,tunable);
-               
-                                                       if ( handler != null ) {
-                                                               
handlerList.put( method.getName(), handler ); 
-                                                       }
+//                                                     T handler = 
factory.getHandler(method,obj,tunable);
+//                                                     if ( handler != null ) {
+//                                                             
handlerList.put( method.getName(), handler ); 
+//                                                     }
+
                                                } catch (Throwable ex) {
                                                        
System.out.println("tunable method intercept failed: " + method.toString() );
                                                        ex.printStackTrace();

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerFactory.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerFactory.java
       2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerFactory.java
       2009-05-27 17:47:26 UTC (rev 16823)
@@ -23,5 +23,10 @@
         * given method type.
         */
        public T getHandler(Method m, Object o, Tunable t);
+       
+       /**
+        * Test with getMethod and setMethod as arguments
+        */
+       public T getHandler(Method gmethod, Method smethod, Object o, Tunable 
tg, Tunable ts);
 
 }

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
        2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
        2009-05-27 17:47:26 UTC (rev 16823)
@@ -14,17 +14,33 @@
        public AbstractCLHandler(Method m, Object o, Tunable t) {
                super(m,o,t);
        }
+       
+       public AbstractCLHandler(Method gmethod, Method smethod, Object o, 
Tunable tg, Tunable ts){
+               super(gmethod,smethod,o,tg,ts);
+       }
 
+//     protected String getName() {
+//             if ( f != null ) {
+//                     String ns = f.getDeclaringClass().toString();
+//                     return ns.substring( ns.lastIndexOf(".")+1) + "." + 
f.getName();
+//             } else if ( m != null ) {
+//                     String ns = m.getDeclaringClass().toString();
+//                     return ns.substring( ns.lastIndexOf(".")+1) + "." + 
m.getName();
+//             } else 
+//                     return "";
+//     }
+
        protected String getName() {
-               if ( f != null ) {
+               if ( f!=null ) {
                        String ns = f.getDeclaringClass().toString();
                        return ns.substring( ns.lastIndexOf(".")+1) + "." + 
f.getName();
-               } else if ( m != null ) {
-                       String ns = m.getDeclaringClass().toString();
-                       return ns.substring( ns.lastIndexOf(".")+1) + "." + 
m.getName();
-               } else 
+               } else if ( gmethod != null && smethod != null) {
+                       String ns = smethod.getDeclaringClass().toString();
+                       return ns.substring( ns.lastIndexOf(".")+1) + "." + 
"getset" + smethod.getName().substring(3);
+               } else
                        return "";
        }
-
+       
+       
        public abstract void handleLine( CommandLine line );
 }

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
 2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
 2009-05-27 17:47:26 UTC (rev 16823)
@@ -13,12 +13,12 @@
 public class CLHandlerFactory implements HandlerFactory<CLHandler> {
 
        public CLHandler getHandler(Method m, Object o, Tunable t) {
-               Class<?>[] types = m.getParameterTypes();
-               if ( types.length != 1 ) {
+               Class<?>[] paramsTypes = m.getParameterTypes();
+               if ( paramsTypes.length != 1 ) {
                        System.err.println("found bad method");
                        return null;
                }
-               Class<?> type = types[0];
+               Class<?> type = paramsTypes[0];
 
                if ( type == int.class || type == Integer.class )
                        return new IntCLHandler(m,o,t);
@@ -35,8 +35,30 @@
 
        }
 
+       public CLHandler getHandler(Method gmethod, Method smethod, Object o, 
Tunable tg, Tunable ts){
+               Class<?>[] paramsTypes = smethod.getParameterTypes();
+               Class<?> returnType = gmethod.getReturnType();
+               if ( paramsTypes.length != 1 ) {
+                       System.err.println("found bad method");
+                       return null;
+               }
+               Class<?> type = paramsTypes[0];
+               if(!type.equals(returnType)) {
+                       System.err.println("return type and parameter type are 
differents for the methods " + gmethod.getName() + " and " + smethod.getName());
+                       return null;
+               }
+               
+               if( type == int.class || type == Integer.class)
+                       return new IntCLHandler(gmethod,smethod,o,tg,ts);
+               else 
+                       return null;    
+       }
+       
+       
+       
+       
        public CLHandler getHandler(Field f, Object o, Tunable t) {
-               Class type = f.getType();
+               Class<?> type = f.getType();
 
                if ( type == int.class || type == Integer.class )
                        return new IntCLHandler(f,o,t);

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
     2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
     2009-05-27 17:47:26 UTC (rev 16823)
@@ -14,7 +14,12 @@
        public IntCLHandler(Method m, Object o, Tunable t) {
                super(m,o,t);
        }
-
+       
+       public IntCLHandler(Method gmethod, Method smethod, Object o, Tunable 
tg, Tunable ts){
+               super(gmethod,smethod,o,tg,ts);
+       }
+       
+       
        public void handleLine( CommandLine line ) {
                String n = getName();
                int ind = n.lastIndexOf(".")+1;         
@@ -28,8 +33,9 @@
                        
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
                        if ( f != null )
                                
f.set(o,Integer.parseInt(line.getOptionValue(fc)) );
-                       else if ( m != null )
-                               
m.invoke(o,Integer.parseInt(line.getOptionValue(fc)) );
+                       else if ( smethod != null )
+                               
//m.invoke(o,Integer.parseInt(line.getOptionValue(fc)) );
+                               
smethod.invoke(o,Integer.parseInt(line.getOptionValue(fc)) );
                        else 
                                throw new Exception("no Field or Method to 
set!");
                }
@@ -37,7 +43,31 @@
        }
        
        
-       public Option getOption() {
+//     public Option getOption() {
+//             String n = getName();
+//             int ind = n.lastIndexOf(".")+1;
+//             String fc;
+//             //if(n.substring(ind).length()<3)fc = n.substring(ind); 
+//             //else fc = n.substring(ind,ind+3);
+//             fc = n.substring(ind);
+//             Integer currentValue = null;            
+//             if( f!=null){
+//                     try{
+//                             currentValue = (Integer)f.get(o);
+//                     }catch(Exception e){e.printStackTrace();}
+//                     return new Option(fc, true,"-- "+ t.description()+" 
--\n  current value : "+ currentValue);
+//             }
+//             
+//             else if(m!=null){
+//                     Type[] types = m.getParameterTypes();
+//                     java.util.List list = new java.util.ArrayList();
+//                     for(int i=0;i<types.length;i++) list.add(i,types[i]);
+//                     return new Option(fc,true,"-- "+ t.description()+" --\n 
Method's parameter : "+list);
+//             }
+//             else return null;
+//     }
+       
+       public Option getOption(){
                String n = getName();
                int ind = n.lastIndexOf(".")+1;
                String fc;
@@ -45,20 +75,21 @@
                //else fc = n.substring(ind,ind+3);
                fc = n.substring(ind);
                Integer currentValue = null;            
-               if( f!=null){
+               if ( f!=null){
                        try{
                                currentValue = (Integer)f.get(o);
                        }catch(Exception e){e.printStackTrace();}
-                       return new Option(fc, true,"-- "+ t.description()+" 
--\n  current value : "+ currentValue);
+                       return new Option(fc, true,"-- " + t.description() + " 
--\n  current value : "+ currentValue);
                }
-               
-               else if(m!=null){
-                       Type[] types = m.getParameterTypes();
+               if ( smethod!=null){
+                       Type[] type = smethod.getParameterTypes();
                        java.util.List list = new java.util.ArrayList();
-                       for(int i=0;i<types.length;i++) list.add(i,types[i]);
-                       return new Option(fc,true,"-- "+ t.description()+" --\n 
Method's parameter : "+list);
+                       for(int i=0;i<type.length;i++) list.add(i,type[i]);
+                       return new Option(fc,true,"-- "+ tg.description() + " / 
" + ts.description() + " --\n Method's set parameter : "+list);
+                       
                }
                else return null;
+               
        }
        
        private void displayCmds(String fc){

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/FlexiblyBoundedHandler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/FlexiblyBoundedHandler.java
  2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/FlexiblyBoundedHandler.java
  2009-05-27 17:47:26 UTC (rev 16823)
@@ -11,17 +11,19 @@
 import org.example.tunable.*;
 import org.example.tunable.util.*;
 
+
 public class FlexiblyBoundedHandler<T extends AbstractFlexiblyBounded> extends 
AbstractGuiHandler {
 
        JTextField tf;
        final T b;
        final JLabel label;
-
+       
+       
        public FlexiblyBoundedHandler(Field f, Object o, Tunable t) {
                super(f,o,t);
                T bb; 
                try {
-               bb = (T)f.get(o);
+                       bb = (T)f.get(o);
                } catch (IllegalAccessException iae) {
                        iae.printStackTrace();  
                        bb = null;
@@ -30,27 +32,31 @@
                b = bb;
 
                panel = new JPanel();
+               
+               JButton up = new JButton( new SetAction("Set Upper 
Bound",panel,false));
+               JButton low = new JButton( new SetAction("Set Lower 
Bound",panel,true));
+               
                label = new JLabel();
                setLabelText();
                try {
-               panel.add( label );
-               tf = new JTextField( b.getValue().toString(), 10);
-               tf.addActionListener( this );
-               panel.add( tf );
-               panel.add( new JButton( new SetAction("Set Lower 
Bound",panel,true) ) );
-               panel.add( new JButton( new SetAction("Set Upper 
Bound",panel,false) ) );
+                       panel.add( label );
+                       tf = new JTextField( b.getValue().toString(), 6);
+                       tf.addActionListener( this );
+                       panel.add( tf );
+                       panel.add(low);
+                       panel.add(up);
                } catch (Exception e) { e.printStackTrace(); }
                        
        }
 
        private void setLabelText() {
-               label.setText( t.description() + " (max: " + 
b.getLowerBound().toString() + "  min: " + b.getUpperBound().toString() + ")" );
+               label.setText( t.description() + " (min: " + 
b.getLowerBound().toString() + "  max: " + b.getUpperBound().toString() + ")" );
        }
 
        public void handle() {
                String s = tf.getText();
                try {
-               b.setValue(s);
+                       b.setValue(s);
                } catch (Exception e) { e.printStackTrace(); }
        }
 

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/GuiHandlerFactory.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/GuiHandlerFactory.java
       2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/gui/GuiHandlerFactory.java
       2009-05-27 17:47:26 UTC (rev 16823)
@@ -2,6 +2,7 @@
 package org.example.tunable.internal.gui;
 
 import java.lang.reflect.*;
+
 import org.example.tunable.*;
 import org.example.tunable.util.*;
 
@@ -42,4 +43,16 @@
 
                return null;
        }
+
+       public GuiHandler getHandler(Method gmethod, Method smethod, Object o,
+                       Tunable t) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public GuiHandler getHandler(Method gmethod, Method smethod, Object o,
+                       Tunable tg, Tunable ts) {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }

Modified: 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/PropHandlerFactory.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/PropHandlerFactory.java
    2009-05-26 23:35:47 UTC (rev 16822)
+++ 
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/props/PropHandlerFactory.java
    2009-05-27 17:47:26 UTC (rev 16823)
@@ -2,6 +2,7 @@
 package org.example.tunable.internal.props;
 
 import java.lang.reflect.*;
+
 import org.example.tunable.*;
 
 public class PropHandlerFactory implements HandlerFactory<PropHandler> {
@@ -19,4 +20,16 @@
                else
                        return null;
        }
+
+       public PropHandler getHandler(Method gmethod, Method smethod, Object o,
+                       Tunable t) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public PropHandler getHandler(Method gmethod, Method smethod, Object o,
+                       Tunable tg, Tunable ts) {
+               // TODO Auto-generated method stub
+               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