My guess is that it's because Button is an abstract class - try <PushButton
buttonData="Sumit" />.   Also, I think you should be calling
window.setContent(c) instead of window.add(c).

Give those a shot, and hopefully it'll work - exciting stuff!

-T

On Sun, Nov 15, 2009 at 7:25 AM, Christopher Brind <[email protected]>wrote:

> Typical - I just hit send and then I realise I can create my own Graphics
> 2D
> sub-class and just delegate to a Graphics2D created elsewhere, or to a SWT
> graphics context. I'll have a play with this later, but any ideas about the
> instantiation problem?
>
> Thanks,
> Chris
>
>
>
> 2009/11/15 Christopher Brind <[email protected]>
>
> > Hi,
> >
> > I don't want to get people too excited, but I'm working on an Eclipse
> > plugin for Pivot.  At the moment it simply recognises WTKX as an XML
> format,
> > and I've extended the XML editor to add a new page called 'Preview'.
> >
> > My original plan was use the SWT AWT bridge and some very simple code to
> > render the WTKX.  That is, I don't render the the contents of the WTKX
> using
> > Pivot code, I simply call paint(Graphics2D) directly.
> >
> > However, I've hit a couple of problems:
> >
> > 1) SWT AWT Bridge doesn't work on Mac!
> >
> > The problem is also described here, ignoring the fact that the original
> > poster isn't actually using the SWT/AWT bridge - he has come across the
> same
> > problem as me, that something in Eclipse basically breaks AWT.  In his
> case
> > he can run it on the command line, but when it comes to using the SWT/AWT
> > bridge, this has fail written all over it.
> >
> > I'm looking in to this in more detail, but I wonder if it would be worth
> > abstracting the graphics context so that it isn't AWT specific?  Perhaps
> a
> > lot of work, but it would mean I could implement a pure SWT version for
> > rendering in Eclipse.
> >
> >
> >
> > 2) Instantiation problems when deserialising the WTKX
> >
> > Here's my rendering code, but in a stand alone way outside of Eclipse (I
> > got here by trying to debug the SWT/AWT problem) :
> >
> > public static void main(String[] args) throws Exception {
> >
> >
> >  // Frame frame = new Frame();
> >
> > Properties props = System.getProperties();
> >
> > Iterator iter = props.keySet().iterator();
> >
> > while (iter.hasNext()) {
> >
> > String key = (String) iter.next();
> >
> > System.out.println(key + " : " + props.getProperty(key));
> >
> > }
> >
> >
> >  JFrame frame = new JFrame();
> >
> > frame.setSize(800, 600);
> >
> > frame.setVisible(true);
> >
> >
> >  JApplet applet = new JApplet();
> >
> > applet.setSize(800, 600);
> >
> > frame.add(applet);
> >
> > frame.setVisible(true);
> >
> >
> >  WTKXSerializer wtkx = new WTKXSerializer();
> >
> > Object o = wtkx.readObject(new FileInputStream("assets/template.wtkx"));
> >
> >
> >  Window window = null;
> >
> > if (o instanceof Window) {
> >
> > window = (Window) o;
> >
> > } else {
> >
> > window = new Window();
> >
> >
> >  Component c = (Component) o;
> >
> > c.setSize(applet.getWidth(), applet.getHeight());
> >
> >
> >  window.add(c);
> >
> > }
> >
> >
> >  window.setSize(applet.getWidth(), applet.getHeight());
> >
> > window.validate();
> >
> >
> >  Graphics2D g2d = (Graphics2D) applet.getGraphics();
> >
> > window.paint(g2d);
> >
> >
> >  }
> >
> > Similar code will be used inside the Eclipse plugin to render the WTKX in
> > the Eclipse editor - as you can see, it's a render-only process, it
> doesn't
> > handle events or anything like that.
> >
> > Now this actually works OK for the given WTKX:
> >
> > <BoxPane xmlns="org.apache.pivot.wtk"
> >
> >     xmlns:wtkx="http://pivot.apache.org/wtkx";>
> >
> >          <Label wtkx:id="label" text="Enter your name: "/>
> >
> >         <TextInput preferredWidth="200" />
> >
> >
> >
> > </BoxPane>
> >
> > But, if I drop in a Button, like this:
> >
> > <BoxPane xmlns="org.apache.pivot.wtk"
> >
> >     xmlns:wtkx="http://pivot.apache.org/wtkx";>
> >
> >          <Label wtkx:id="label" text="Enter your name: "/>
> >
> >         <TextInput preferredWidth="200" />
> >
> >         <Button label="Submit" />
> >
> >
> >
> > </BoxPane>
> >
> > I get some exceptions:
> >
> > An error occurred while processing  element <BoxPane> starting at line
> > number 6:
> > org.apache.pivot.serialization.SerializationException:
> > java.lang.InstantiationException
> > at
> >
> org.apache.pivot.wtkx.WTKXSerializer.processStartElement(WTKXSerializer.java:585)
> >  at
> > org.apache.pivot.wtkx.WTKXSerializer.readObject(WTKXSerializer.java:426)
> > at
> >
> org.apache.pivot.wtkxeditor.editors.WTKXPreviewer.main(WTKXPreviewer.java:37)
> > Caused by: java.lang.InstantiationException
> > at
> >
> sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
> >  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> > at java.lang.Class.newInstance0(Class.java:355)
> >  at java.lang.Class.newInstance(Class.java:308)
> > at
> >
> org.apache.pivot.wtkx.WTKXSerializer.processStartElement(WTKXSerializer.java:583)
> >  ... 2 more
> > Exception in thread "main"
> > org.apache.pivot.serialization.SerializationException:
> > java.lang.InstantiationException
> >  at
> >
> org.apache.pivot.wtkx.WTKXSerializer.processStartElement(WTKXSerializer.java:585)
> > at
> org.apache.pivot.wtkx.WTKXSerializer.readObject(WTKXSerializer.java:426)
> >  at
> >
> org.apache.pivot.wtkxeditor.editors.WTKXPreviewer.main(WTKXPreviewer.java:37)
> > Caused by: java.lang.InstantiationException
> > at
> >
> sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
> >  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> > at java.lang.Class.newInstance0(Class.java:355)
> >  at java.lang.Class.newInstance(Class.java:308)
> > at
> >
> org.apache.pivot.wtkx.WTKXSerializer.processStartElement(WTKXSerializer.java:583)
> >  ... 2 more
> >
> >
> > I realise my circumventing the usual Pivot lifecycle might have something
> > to do with it, so any ideas?
> >
> > If I can get around problem #2 somehow I think I can still produce an
> alpha
> > version Eclipse plugin that will work on Windows/Linux, just not Mac =(
>  but
> > like I say - being able to implement a pure SWT graphics context would
> get
> > around that problem.
> >
> > Cheers,
> > Chris
> >
> >
> >
> >
>

Reply via email to