bug #312, add unregisterXxx() for libs

This commit is contained in:
benfry
2007-08-29 02:38:10 +00:00
parent aed3be5226
commit 7bfaff2b25
2 changed files with 83 additions and 0 deletions
+80
View File
@@ -716,6 +716,30 @@ public class PApplet extends Applet
methods[count] = method;
count++;
}
/**
* Removes first object/method pair matched (and only the first,
* must be called multiple times if object is registered multiple times).
* Does not shrink array afterwards, silently returns if method not found.
*/
public void remove(Object object, Method method) {
boolean foundMethod = false;
for (int i = 0; i < count; i++){
if (objects[i] == object && methods[i].equals(method)) {
//objects[i].equals() might be overridden, so use == for safety
// since here we do care about actual object identity
//methods[i]==method is never true even for same method, so must use
// equals(), this should be safe because of object identity
foundMethod = true;
}
// shift remaining methods by one to preserve ordering
if (foundMethod) {
objects[i] = objects[i+1];
}
}
if (foundMethod) count--;
}
}
@@ -778,6 +802,62 @@ public class PApplet extends Applet
}
public void unregisterSize(Object o) {
Class methodArgs[] = new Class[] { Integer.TYPE, Integer.TYPE };
unregisterWithArgs(sizeMethods, "size", o, methodArgs);
}
public void unregisterPre(Object o) {
unregisterNoArgs(preMethods, "pre", o);
}
public void unregisterDraw(Object o) {
unregisterNoArgs(drawMethods, "draw", o);
}
public void unregisterPost(Object o) {
unregisterNoArgs(postMethods, "post", o);
}
public void unregisterMouseEvent(Object o) {
Class methodArgs[] = new Class[] { MouseEvent.class };
unregisterWithArgs(mouseEventMethods, "mouseEvent", o, methodArgs);
}
public void unregisterKeyEvent(Object o) {
Class methodArgs[] = new Class[] { KeyEvent.class };
unregisterWithArgs(keyEventMethods, "keyEvent", o, methodArgs);
}
public void unregisterDispose(Object o) {
unregisterNoArgs(disposeMethods, "dispose", o);
}
protected void unregisterNoArgs(RegisteredMethods meth,
String name, Object o) {
Class c = o.getClass();
try {
Method method = c.getMethod(name, new Class[] {});
meth.remove(o, method);
} catch (Exception e) {
die("Could not unregister " + name + "() for " + o, e);
}
}
protected void unregisterWithArgs(RegisteredMethods meth,
String name, Object o, Class cargs[]) {
Class c = o.getClass();
try {
Method method = c.getMethod(name, cargs);
meth.remove(o, method);
} catch (Exception e) {
die("Could not unregister " + name + "() for " + o, e);
}
}
//////////////////////////////////////////////////////////////
+3
View File
@@ -18,6 +18,9 @@ _ the number of cases where this works is small (half of url streams)
_ and who knows if the value returned will be correct
_ (i.e. will it be the uncompressed or compressed size of the data?)
_ opengl mipmaps are leaking
_ http://dev.processing.org/bugs/show_bug.cgi?id=610
_ loadBytes() doesn't do auto gunzip? but loadStrings and createReader do?
X this might be a good solution for dealing with the differences
_ with loadBytes(), they can use gzipInput (or loadBytesGZ?)