Losing my patience with Java

Associate
Joined
19 Oct 2003
Posts
1,112
Location
Olympia, WA, USA
I've been brought into a project at work, and need to create compelling, modern user interfaces. The main problem is that the software is based in Eclipse using SWT for the graphics.

I've created a package on top of SWT that is similar to Quartz 2D in that it handles resolution independent drawing. I've been extending it to include tweening animation of properties in a manner similar to Core Animation. It's taken a lot of effort and research to get it to be clean and elegant. Java seems so restrictive and convoluted.

At the moment, I've created a proxy class for animation using the Reflection APIs. This is so that you can subclass the base View class, and add custom properties... and by inserting the proxy class, you can animate, without any additional code.

E.g.

Code:
view.setFrame(new Rect(10, 0, 50, 20)); // set the frame instantly

view.animator().setFrame(new Rect(10, 0, 50, 20)); // animate to the new values

So... all you need to do is create the getters and setters, and using the animator proxy, it will animate a transition.

That all works, except that the animator() method (InvocationHandler) has to return as the class interface. In any subclass, this means that the coder will have to create a animator() method and implementation for their class. This is the last stumbling block (I hope). But I cannot figure out how to remove that requirement.

No dynamic return types.
No dynamically extending of interfaces
No function pointers
No compiler macros.


Grrrrrrrrrrrrrrrr!

Help.
 
Code:
public class InvocationHandler<T>  {
  /* snip */

  public T animator()
  {
    /* snip */
    return (T)returnValue;
  }
}
?

use as:
Code:
public SomeClass extends InvocationHandler<SomeClass> {
  /* snip */
}
 
Thanks Dj_jestar.

I already have all of that in place and working. My question is, is someone subclasses the class for which is proxy object is for, and adds additional methods, can I dynamically add to the original interface?... I can't see a way of doing it without the subclass needing it's own animator() method (because the animator method returns the proxy casted to the class interface).

This means additional work that really should have to be done by all subclasses.
 
So, to continue my example, you mean what happens if:
Code:
public SomeOtherClass extends SomeClass {

}
?

I'm not too sure, without seeing the intent behind it anyway. However I would hazard a guess that perhaps the two classes (SomeClass and SomeOtherClass) might need some serious refactoring to isolate them from each other?
 
Also just had a thought that perhaps you need to place the generic on the method rather than the class, so something like:
Code:
public class InvocationHandler {
 /* snip */
  public <T> T animator() {
    /* snip */
    return (T) returnValue;
  }
}
Then use it as such:
Code:
SomeClass animatedObject = someObject.animator();
 
Last edited:
Back
Top Bottom