开发者

When creating a custom Toolkit, why does createFrame fail on OSX?

We are trying to extend the UISpec4j testing framework to display the user interface when running tests. So we have a custom toolkit that wraps around the native toolkit for the relevant platform. We managed to get everything working well on windows XP, however when testing our changes on OSX, our extension of createFrame appears to behave oddly:

 public FramePeer createFrame(Frame target) {
   FramePeer resultc = new UISpecFramePeer(target);
   //super.createFrame(target);

   return resultc;
 }

Essentially with the above, we want to create a UISpecFramePeer as an interception class... So that UISpec4j can interrogate what is happening within the UI. But in our changes, we also want to display the UI. So we attempt this by creating a frame using the native toolkit and wrapping it in the UISpecFramePeer (not shown in the code above).

When we run the above code, the tests run (as we expect) but obviously nothing is displayed. However, when we include super.createFrame(target). We get the following exception:

SEVERE: Application class org.openshapa.OpenSHAPA failed to launch
java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:236)
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
    at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
    at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
    at java.awt.Component.firePropertyChange(Component.java:7277)
    at javax.swing.JComponent.addNotify(JComponent.java:4479)
    at javax.swing.JRootPane.addNotify(JRootPane.java:680)
    at java.awt.Container.addNotify(Container.java:2544)
    at java.awt.Window.addNotify(Window.java:467)
    at java.awt.Frame.addNotify(Frame.java:501)
    at java.awt.Window.pack(Window.java:485)
    at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
    at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
    at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-2" java.lang.Error: Application class org.openshapa.OpenSHAPA failed to launch
    at org.jdesktop.application.Application$1.run(Application.java:177)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.lang.ClassCastException: org.uispec4j.interception.toolkit.UISpecFramePeer
    at apple.awt.CWindow$8.conve开发者_开发技巧rtJComponentToTarget(CWindow.java:236)
    at apple.awt.CWindow$8.convertJComponentToTarget(CWindow.java:233)
    at apple.awt.ClientPropertyApplicator.attachAndApplyClientProperties(ClientPropertyApplicator.java:24)
    at apple.awt.CWindow$1.propertyChange(CWindow.java:190)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:341)
    at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:270)
    at java.awt.Component.firePropertyChange(Component.java:7277)
    at javax.swing.JComponent.addNotify(JComponent.java:4479)
    at javax.swing.JRootPane.addNotify(JRootPane.java:680)
    at java.awt.Container.addNotify(Container.java:2544)
    at java.awt.Window.addNotify(Window.java:467)
    at java.awt.Frame.addNotify(Frame.java:501)
    at java.awt.Window.pack(Window.java:485)
    at org.jdesktop.application.SingleFrameApplication.initRootPaneContainer(SingleFrameApplication.java:216)
    at org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:463)
    at org.openshapa.OpenSHAPA.startup(OpenSHAPA.java:444)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    ... 7 more

Why would simply using the native toolkit to create a frame (but not return it) create an exception, when it would otherwise behaves as normal when the super.createFrame is commented?


I havent worked on OSX, but the same problem would occur on Windows too and the reason would be this:

When you do super.createFrame(), you are essentially creating the native peer which ends up trying to show and hence addNotify methods are called. Now inside there are lot of methods that directly cast the peer to WFramePeer(this is incase of Windows, OSX it may be CWindowPeer or whatever), hence the ClassCastException. In your case, my guess is, the class CWindow is trying to cast your UISpecFramePeer to WFramePeer(or CFramePeer or whatever). Just check the CWindow code by decompiling and check. Please don't forget to post your findings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜