Field

Changeset 146:51af7da249bd

Show
Ignore:
Timestamp:
08/08/2008 12:10:54 AM (4 months ago)
Author:
marc@f1.local
branch:
default
Message:

fix for #92

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • development/java/field/core/ui/FloatingPalettes.java

    r144 r146  
    99import java.lang.ref.WeakReference; 
    1010import java.util.ArrayList; 
     11import java.util.Arrays; 
    1112import java.util.List; 
     13 
     14import javax.media.opengl.GLCanvas; 
    1215 
    1316import field.bytecode.protect.Woven; 
     
    105108 
    106109                        @Woven 
    107                         @NextUpdate(delay = 5) 
    108                         private void restoreFocus(final Component focus2) { 
     110                        @NextUpdate(delay = 2) 
     111                        private void restoreFocus(Component focus2) { 
     112                                if (focus2 instanceof Frame) 
     113                                { 
     114                                        List<Component> a = Arrays.asList(((Frame) focus2).getComponents()); 
     115                                        focus2.requestFocus(); 
     116                                        if (a.size()>0 && a.get(0) instanceof GLCanvas) 
     117                                                focus2 = a.get(0); 
     118                                } 
     119                                final Component f = focus2; 
     120 
    109121                                if (focus2 != null) { 
    110122                                        // completely crazy! Why do I have to 
     
    117129                                                public void update() { 
    118130 
     131                                                        f.requestFocus(); 
    119132                                                        n++; 
    120                                                         focus2.requestFocus(); 
    121                                                         if (focus2.isFocusOwner() || n > 5) { 
     133 
     134                                                        if (n > 5) { 
    122135                                                                Launcher.getLauncher().deregisterUpdateable(this); 
    123136                                                        } 
    124137                                                } 
     138 
    125139                                        }); 
    126140                                } 
     141                        } 
     142                        public Frame  windowForComponent(Component  n ) 
     143                        { 
     144                                while(!(n instanceof Frame )) 
     145                                { 
     146                                        n = n.getParent(); 
     147                                        if (n == null) return null; 
     148                                } 
     149                                return (Frame)n; 
    127150                        } 
    128151 
  • development/java/field/core/ui/text/PythonTextEditor.java

    r145 r146  
    1313import java.io.StringWriter; 
    1414import java.io.Writer; 
     15import java.lang.reflect.Constructor; 
    1516import java.lang.reflect.Field; 
    1617import java.lang.reflect.Method; 
     
    4243import org.python.core.PyFunction; 
    4344import org.python.core.PyIterator; 
     45import org.python.core.PyJavaClass; 
    4446import org.python.core.PyJavaInstance; 
    4547import org.python.core.PyJavaPackage; 
     
    649651                                        comp.add(c); 
    650652 
     653                                } else if (e.getValue() instanceof Class) { 
     654                                        System.out.println(" we have a class <" + e.getKey() + "> <" + e.getValue() + "> <" + ((Class) e.getValue()).getSimpleName() + " " + cc + ">"); 
     655                                        completionsFromReflectingUponConstructors(cc, comp, ((Class) e.getValue()), false); 
    651656                                } else { 
    652657 
     
    727732                        return; 
    728733 
    729                 //System.out.println(" completions from reflecting upon " + ret + " " + ret.getClass()); 
     734                // System.out.println(" completions from reflecting upon " + ret 
     735                // + " " + ret.getClass()); 
    730736 
    731737                if (ret instanceof PyJavaInstance) { 
     
    733739                } 
    734740 
    735                 if (ret instanceof PyObject) { 
     741                if (ret instanceof PyJavaClass) { 
     742                        Class c = (Class) ((PyJavaClass) ret).__tojava__(Class.class); 
     743 
     744                        String doc = new ClassDocumentation().getClassDocumentation(right, null, c); 
     745                        if (doc != null) { 
     746                                Completion cc = new Completion() { 
     747 
     748                                        @Override 
     749                                        public void update() { 
     750                                        } 
     751                                }; 
     752                                cc.text = doc; 
     753                                cc.isDocumentation = true; 
     754                                comp.add(cc); 
     755                        } 
     756 
     757                        List<Comp> customcomp = new ClassDocumentation().getClassCustomCompletion(right, null, c); 
     758                        if (customcomp != null) { 
     759                                for (Comp cc : customcomp) { 
     760                                        makeCompletion(right, comp, cc); 
     761                                } 
     762                        } 
     763 
     764                        completionsFromReflectingUponClass(right, comp, c, publicOnly); 
     765 
     766                } else if (ret instanceof PyObject) { 
    736767                        PyObject po = (PyObject) ret; 
    737768 
     
    796827 
    797828                } else { 
    798                         completionsFromReflectingUponClass(ret, right, comp, ret.getClass(), publicOnly); 
     829                        completionsFromReflectingUponInstance(ret, right, comp, ret.getClass(), publicOnly); 
    799830                } 
    800831        } 
    801832 
    802833        private String convertPythonDoc(String ascii) { 
    803                 if (ascii ==null) return ""; 
     834                if (ascii == null) 
     835                        return ""; 
    804836                int firstLine = ascii.indexOf('\n'); 
    805837                if (firstLine == -1) 
     
    813845        } 
    814846 
    815         private void completionsFromReflectingUponClass(Object ret, final String right, ArrayList<Completion> comp, Class<? extends Object> class1, boolean publicOnly) { 
     847        protected void completionsFromReflectingUponClass(String right, ArrayList<Completion> comp, Class class1, boolean publicOnly) { 
     848                Object ret = null; 
     849 
     850                boolean added = false; 
     851                Field[] fields = class1.getDeclaredFields(); 
     852                for (Field f : fields) { 
     853                        if (Modifier.isStatic(f.getModifiers())) 
     854                                if (f.getName().startsWith(right) && (!publicOnly || Modifier.isPublic(f.getModifiers()))) { 
     855                                        if (!added) { 
     856                                                comp.add(getSeparatorFor(ret, class1, right)); 
     857                                                added = true; 
     858                                        } 
     859                                        comp.add(getCompletionFor(ret, class1, f, right)); 
     860                                } 
     861                } 
     862                // methods 
     863                Method[] methods = class1.getDeclaredMethods(); 
     864                for (Method m : methods) { 
     865                        if (Modifier.isStatic(m.getModifiers())) 
     866                                if (m.getName().startsWith(right) && (!publicOnly || Modifier.isPublic(m.getModifiers()))) { 
     867                                        if (!added) { 
     868                                                comp.add(getSeparatorFor(ret, class1, right)); 
     869                                                added = true; 
     870                                        } 
     871                                        comp.add(getCompletionFor(ret, class1, m, right)); 
     872                                } 
     873                } 
     874                Class c = class1.getSuperclass(); 
     875                if (c != null) 
     876                        completionsFromReflectingUponClass(right, comp, c, publicOnly); 
     877        } 
     878 
     879        protected void completionsFromReflectingUponConstructors(String right, ArrayList<Completion> comp, Class class1, boolean publicOnly) { 
     880                Object ret = null; 
     881 
     882                boolean added = false; 
     883 
     884                Constructor[] methods = class1.getDeclaredConstructors(); 
     885                for (Constructor m : methods) { 
     886                        { 
     887                                if (!added) { 
     888                                        Completion setp = getSeparatorFor(ret, class1, right); 
     889                                        setp.text += " (constructors)"; 
     890                                        comp.add(setp); 
     891                                        added = true; 
     892                                } 
     893                                comp.add(getCompletionFor(class1, m, right)); 
     894                        } 
     895                } 
     896        } 
     897 
     898        private void completionsFromReflectingUponInstance(Object ret, final String right, ArrayList<Completion> comp, Class<? extends Object> class1, boolean publicOnly) { 
    816899 
    817900                String doc = new ClassDocumentation().getClassDocumentation(right, ret, class1); 
     
    859942                Class c = class1.getSuperclass(); 
    860943                if (c != null) 
    861                         completionsFromReflectingUponClass(ret, right, comp, c, publicOnly); 
     944                        completionsFromReflectingUponInstance(ret, right, comp, c, publicOnly); 
    862945        } 
    863946 
     
    10021085                                                                        JavaMethod method = jc.getMethodBySignature(m.getName(), types); 
    10031086 
    1004                                                                         //System.out.println(" looking for method <" + method + "> <" + m.getName() + "><" + Arrays.asList(types) + ">"); 
     1087                                                                        // System.out.println(" 
     1088                                                                        // looking 
     1089                                                                        // for 
     1090                                                                        // method 
     1091                                                                        // <" + 
     1092                                                                        // method 
     1093                                                                        // + "> 
     1094                                                                        // <" + 
     1095                                                                        // m.getName() 
     1096                                                                        // + 
     1097                                                                        // "><" 
     1098                                                                        // + 
     1099                                                                        // Arrays.asList(types) 
     1100                                                                        // + 
     1101                                                                        // ">"); 
    10051102                                                                        if (method != null) { 
    10061103                                                                                if (method.getParameters() != null) { 
     
    10561153                                                        JavaMethod method = jc.getMethodBySignature(m.getName(), types); 
    10571154 
    1058                                                         //System.out.println(" looking for method <" + method + "> <" + m.getName() + "><" + Arrays.asList(types) + ">"); 
     1155                                                        // System.out.println(" 
     1156                                                        // looking for method <" 
     1157                                                        // + method + "> <" + 
     1158                                                        // m.getName() + "><" + 
     1159                                                        // Arrays.asList(types) 
     1160                                                        // + ">"); 
    10591161                                                        if (method != null) { 
    10601162                                                                if (method.getParameters() != null) { 
     
    10751177                                                                } 
    10761178                                                        } else { 
    1077 //                                                              System.out.println(" didn't find it "); 
    1078 // 
    1079 //                                                              for (JavaMethod jm : jc.getMethods()) { 
    1080 //                                                                      JavaParameter[] p = jm.getParameters(); 
    1081 //                                                                      System.out.println("name: <" + jm.getName() + ">: signature"); 
    1082 //                                                                      for (JavaParameter pp : p) { 
    1083 //                                                                              System.out.println(pp.getName() + "          " + pp.getType()); 
    1084 //                                                                      } 
    1085 //                                                              } 
     1179                                                                // System.out.println(" 
     1180                                                                // didn't find 
     1181                                                                // it "); 
     1182                                                                // 
     1183                                                                // for 
     1184                                                                // (JavaMethod 
     1185                                                                // jm : 
     1186                                                                // jc.getMethods()) 
     1187                                                                // { 
     1188                                                                // JavaParameter[] 
     1189                                                                // p = 
     1190                                                                // jm.getParameters(); 
     1191                                                                // System.out.println("name: 
     1192                                                                // <" + 
     1193                                                                // jm.getName() 
     1194                                                                // + ">: 
     1195                                                                // signature"); 
     1196                                                                // for 
     1197                                                                // (JavaParameter 
     1198                                                                // pp : p) { 
     1199                                                                // System.out.println(pp.getName() 
     1200                                                                // + " " + 
     1201                                                                // pp.getType()); 
     1202                                                                // } 
     1203                                                                // } 
     1204 
     1205                                                        } 
     1206                                                } catch (Exception e) { 
     1207                                                        // e.printStackTrace(); 
     1208                                                } 
     1209                                        } 
     1210                                } 
     1211                        } 
     1212                } 
     1213 
     1214                c.enabled = true; 
     1215                return c; 
     1216        } 
     1217 
     1218        private Completion getCompletionFor(Class<? extends Object> class1, final Constructor m, final String right) { 
     1219                Completion c = new Completion() { 
     1220                        @Override 
     1221                        public void update() { 
     1222                                try { 
     1223                                        ed.getDocument().remove(ed.getCaretPosition() - right.length(), right.length()); 
     1224                                        ed.getDocument().insertString(ed.getCaretPosition(), m.getName(), SimpleAttributeSet.EMPTY); 
     1225                                        hint = this.text; 
     1226                                        hintAlpha = 0.75f; 
     1227                                } catch (BadLocationException e) { 
     1228                                        e.printStackTrace(); 
     1229                                } 
     1230                        } 
     1231                }; 
     1232 
     1233                c.text = "\u1d39 <font face='" + field.core.Constants.defaultFont + "' color='#000000'>" + strip(m.getName()) + "(" + (m.getParameterTypes().length == 0 ? "" : Arrays.asList(m.getParameterTypes())) + ")"; 
     1234 
     1235                String name = m.getDeclaringClass().getCanonicalName(); 
     1236                System.out.println(" constructor dc name is <"+name+">"); 
     1237                if (name != null) { 
     1238                        String[] sd = getSourceDirs(); 
     1239                        for (int n = 0; n < sd.length; n++) { 
     1240                                if (sd[n].endsWith(".jar/")) 
     1241                                        sd[n] = sd[n].substring(0, sd[n].length() - 1); 
     1242 
     1243                                if (sd[n].endsWith(".jar")) { 
     1244                                        try { 
     1245 
     1246                                                JarFile jar = new JarFile(sd[n]); 
     1247                                                try { 
     1248                                                        ZipEntry entry = jar.getEntry("src/" + name.replace(".", "/") + ".java"); 
     1249                                                        if (entry != null) { 
     1250                                                                InputStream is = jar.getInputStream(entry); 
     1251                                                                try { 
     1252                                                                        db.addSource(new InputStreamReader(is)); 
     1253 
     1254                                                                        com.thoughtworks.qdox.model.JavaClass jc = db.getClassByName(name); 
     1255 
     1256                                                                        Type[] types = new Type[m.getParameterTypes().length]; 
     1257                                                                        for (int i = 0; i < m.getParameterTypes().length; i++) { 
     1258                                                                                types[i] = new Type(m.getParameterTypes()[i].getCanonicalName().replace("[", "").replace("]", ""), m.getParameterTypes()[i].isArray() ? 1 : 0); 
     1259                                                                        } 
     1260 
     1261                                                                        JavaMethod method = jc.getMethodBySignature(m.getDeclaringClass().getSimpleName(), types); 
     1262 
     1263                                                                        System.out.println(" looking for a method called <"+m.getDeclaringClass().getSimpleName()+"> inside <"+jc+"> found <"+method+">"); 
     1264 
     1265                                                                        if (method != null) { 
     1266                                                                                if (method.getParameters() != null) { 
     1267 
     1268                                                                                        String ctext = "<b>" + m.getDeclaringClass().getSimpleName() + "</b>" + " ( "; 
     1269                                                                                        for (int i = 0; i < method.getParameters().length; i++) { 
     1270                                                                                                ctext += strip(m.getParameterTypes()[i].getCanonicalName()) + " <b><i>" + method.getParameters()[i].getName() + "</i></b>" + (i != method.getParameters().length - 1 ? ", " : ""); 
     1271                                                                                        } 
     1272                                                                                        ctext += " )"; 
     1273 
     1274                                                                                        String comment = method.getComment(); 
     1275                                                                                        if (comment == null) 
     1276                                                                                                comment = ""; 
     1277 
     1278                                                                                        c.text = (Modifier.isPublic(m.getModifiers()) ? "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#000000'> " : "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#444444'>") + ctext + (comment.length() > 0 ? " Ñ " + smaller(limitDocumentation(comment)) : ""); 
     1279                                                                                } else { 
     1280                                                                                        System.out.println(" does this ever happen ? "); 
     1281                                                                                } 
     1282                                                                        } else { 
     1283 
     1284                                                                        } 
     1285                                                                } catch (Exception e) { 
     1286                                                                        // e.printStackTrace(); 
     1287                                                                } 
     1288                                                        } 
     1289                                                } finally { 
     1290                                                        jar.close(); 
     1291                                                } 
     1292                                                // Enumeration<JarEntry> 
     1293                                                // entries 
     1294                                                // = 
     1295                                                // jar.entries(); 
     1296                                                // for(JarEntry 
     1297                                                // j : 
     1298                                                // entries) 
     1299                                                // { 
     1300                                                // } 
     1301                                        } catch (IOException e) { 
     1302                                                e.printStackTrace(); 
     1303                                        } 
     1304                                } else { 
     1305                                        String filename = sd[n] + "/" + name.replace(".", "/") + ".java"; 
     1306                                        if (new File(filename).exists()) { 
     1307                                                try { 
     1308                                                        db.addSource(new FileReader(filename)); 
     1309 
     1310                                                        com.thoughtworks.qdox.model.JavaClass jc = db.getClassByName(name); 
     1311 
     1312                                                        Type[] types = new Type[m.getParameterTypes().length]; 
     1313                                                        for (int i = 0; i < m.getParameterTypes().length; i++) { 
     1314                                                                types[i] = new Type(m.getParameterTypes()[i].getCanonicalName().replace("[", "").replace("]", ""), m.getParameterTypes()[i].isArray() ? 1 : 0); 
     1315                                                        } 
     1316                                                        JavaMethod method = jc.getMethodBySignature(m.getDeclaringClass().getSimpleName(), types); 
     1317 
     1318                                                        System.out.println(" looking for a method called <"+m.getDeclaringClass().getSimpleName()+"> inside <"+jc+"> found <"+method+">"); 
     1319 
     1320                                                        // System.out.println(" 
     1321                                                        // looking for method <" 
     1322                                                        // + method + "> <" + 
     1323                                                        // m.getName() + "><" + 
     1324                                                        // Arrays.asList(types) 
     1325                                                        // + ">"); 
     1326                                                        if (method != null) { 
     1327                                                                if (method.getParameters() != null) { 
     1328 
     1329                                                                        String ctext = "<b>" + m.getDeclaringClass().getSimpleName() + "</b>" + " ( "; 
     1330                                                                        for (int i = 0; i < method.getParameters().length; i++) { 
     1331                                                                                ctext += strip(m.getParameterTypes()[i].getCanonicalName()) + " <b><i>" + method.getParameters()[i].getName() + "</i></b>" + (i != method.getParameters().length - 1 ? ", " : ""); 
     1332                                                                        } 
     1333                                                                        ctext += " )"; 
     1334 
     1335                                                                        String comment = method.getComment(); 
     1336                                                                        if (comment == null) 
     1337                                                                                comment = ""; 
     1338 
     1339                                                                        c.text = (Modifier.isPublic(m.getModifiers()) ? "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#000000'> " : "\u24d2 <font face='" + field.core.Constants.defaultFont + "' color='#444444'>") + ctext + (comment.length() > 0 ? " Ñ " + smaller(comment) : ""); 
     1340                                                                } else { 
     1341                                                                        System.out.println(" does this ever happen ? "); 
     1342                                                                } 
     1343                                                        } else { 
     1344                                                                // System.out.println(" 
     1345                                                                // didn't find 
     1346                                                                // it "); 
     1347                                                                // 
     1348                                                                // for 
     1349                                                                // (JavaMethod 
     1350                                                                // jm : 
     1351                                                                // jc.getMethods()) 
     1352                                                                // { 
     1353                                                                // JavaParameter[] 
     1354                                                                // p = 
     1355                                                                // jm.getParameters(); 
     1356                                                                // System.out.println("name: 
     1357                                                                // <" + 
     1358                                                                // jm.getName() 
     1359                                                                // + ">: 
     1360                                                                // signature"); 
     1361                                                                // for 
     1362                                                                // (JavaParameter 
     1363                                                                // pp : p) { 
     1364                                                                // System.out.println(pp.getName() 
     1365                                                                // + " " + 
     1366                                                                // pp.getType()); 
     1367                                                                // } 
     1368                                                                // } 
    10861369 
    10871370                                                        } 
     
    11781461                                        print((PyJavaPackage) a, "", allClassesMap); 
    11791462                                } 
    1180 //                              } else if (a instanceof PyJavaClass){ 
    1181 //                                      String name = ((PyJavaClass)a).__name__; 
    1182 //                                      System.out.println(" class hanging out <"+name+" "+topLevelPackage.__name__+">"); 
    1183 //                                      allClassesMap.put(name, new ClassRecord(name, topLevelPackage.__name__+"."+name)); 
    1184 //                              } 
    1185                                 else 
    1186                                 { 
     1463                                // } else if (a instanceof PyJavaClass){ 
     1464                                // String name = ((PyJavaClass)a).__name__; 
     1465                                // System.out.println(" class hanging out 
     1466                                // <"+name+" "+topLevelPackage.__name__+">"); 
     1467                                // allClassesMap.put(name, new ClassRecord(name, 
     1468                                // topLevelPackage.__name__+"."+name)); 
     1469                                // } 
     1470                                else { 
    11871471                                } 
    11881472                        } else { 
     
    12371521 
    12381522                for (Class c : allLoadedClasses) { 
    1239                         System.out.println(" class <"+c+">"); 
     1523                        System.out.println(" class <" + c + ">"); 
    12401524                        if (!allClassesMap.containsKey(c.getName())) { 
    12411525                                if (c.getName().indexOf(".") != -1) 
  • development/java/field/core/windowing/GLComponentWindow.java

    r104 r146  
    77import java.awt.Graphics; 
    88import java.awt.Rectangle; 
     9import java.awt.event.FocusEvent; 
     10import java.awt.event.FocusListener; 
    911import java.awt.event.KeyEvent; 
    1012import java.awt.event.KeyListener; 
     
    341343 
    342344                        for (iComponent c : allEvents) 
    343                                 if (c != mouseFocus) 
    344                                 { 
     345                                if (c != mouseFocus) { 
    345346                                        c.mousePressed(this, arg0); 
    346347                                } 
     
    712713                        protected void processMouseWheelEvent(MouseWheelEvent e) { 
    713714 
    714                                 int dx =0, dy = 0; 
    715                                  
     715                                int dx = 0, dy = 0; 
     716 
    716717                                if (e.isShiftDown()) 
    717718                                        dx = e.getWheelRotation(); 
    718719                                else 
    719720                                        dy = e.getWheelRotation(); 
    720                                  
    721                                 dx*=4; 
    722                                 dy*=-4; 
    723                                  
     721 
     722                                dx *= 4; 
     723                                dy *= -4; 
     724 
    724725                                MouseEvent me1 = new MouseEvent((Component) e.getSource(), MouseEvent.MOUSE_PRESSED, e.getWhen(), 0, e.getX(), e.getY(), 1, false, MouseEvent.BUTTON2); 
    725726                                processMouseEvent(me1); 
    726                                  
    727                                 MouseEvent drag = new MouseEvent((Component) e.getSource(), MouseEvent.MOUSE_DRAGGED, e.getWhen(), 0, e.getX() + dx, e.getY()+dy, 1, false, MouseEvent.BUTTON2); 
     727 
     728                                MouseEvent drag = new MouseEvent((Component) e.getSource(), MouseEvent.MOUSE_DRAGGED, e.getWhen(), 0, e.getX() + dx, e.getY() + dy, 1, false, MouseEvent.BUTTON2); 
    728729                                processMouseMotionEvent(drag); 
    729                                  
    730                                 MouseEvent me2 = new MouseEvent((Component) e.getSource(), MouseEvent.MOUSE_RELEASED, e.getWhen(), 0, e.getX() + dx, e.getY()+dy, 1, false, MouseEvent.BUTTON2); 
     730 
     731                                MouseEvent me2 = new MouseEvent((Component) e.getSource(), MouseEvent.MOUSE_RELEASED, e.getWhen(), 0, e.getX() + dx, e.getY() + dy, 1, false, MouseEvent.BUTTON2); 
    731732                                processMouseEvent(me2); 
    732733 
     
    747748                                super.processKeyEvent(e); 
    748749                        } 
     750 
    749751                }; 
    750                  
     752 
     753                frame.addFocusListener(new FocusListener() { 
     754 
     755                        public void focusGained(FocusEvent e) { 
     756                                System.out.println(" frame has focus, requesting that the canvas gets some focus"); 
     757                                canvas.requestFocus(); 
     758                        } 
     759 
     760                        public void focusLost(FocusEvent e) { 
     761                        } 
     762                }); 
     763 
    751764                canvas.setAutoSwapBufferMode(false); 
    752765 
     
    790803                T_TransWindow.maybeFixWindow(frame); 
    791804 
    792                 canvas.setFocusable(true); 
     805                canvas.setFocusable(false); 
    793806                frame.setFocusable(true); 
    794807 
     
    11421155                floatResMouseEvents.put(arg0, new Vector2(at.x * sx + tx, at.y * sy + ty)); 
    11431156        } 
    1144          
    1145         public void transformDrawingToWindow(Vector2 v) 
    1146         { 
    1147                 v.x = (v.x-tx)/sx; 
    1148                 v.y = (v.y-ty)/sy; 
     1157 
     1158        public void transformDrawingToWindow(Vector2 v) { 
     1159                v.x = (v.x - tx) / sx; 
     1160                v.y = (v.y - ty) / sy; 
    11491161        } 
    11501162