You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by noobmike <md...@lakeheadu.ca> on 2011/06/01 15:12:47 UTC

BXML Rendering

Hey Experts, I have yet another question for you!

In my App, I want to essentially render user typed bxml code(say in a text
area) and have it shown (functional preferably if not that's fine too) in
real time. Or as close to real time as possible, so if they have to click a
"Render Code" button so be it. 

Is this possible? I read a previous thread that was somewhat similar, but am
not sure if its exactly what I am trying to do. 

Any suggestions? 

Thanks for your wisdom

Mike.

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3010653.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by noobmike <md...@lakeheadu.ca>.
I recoded it that way, and it turns out its working. 
The error must have been from something that I 
deleted! ha ha. Thanks for the suggestions. 

Mike. 

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011779.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by Edvin Syse <ed...@sysedata.no>.
What errors?

Den 01.06.2011 19:02, skrev noobmike:
> Thanks so much fellas!
>
> Everything is working PERFECTLY!
>
> the only problem is I am using the StringBufferInputStream. My code snippet
> is:
>
> BXMLSerializer bxmlSerializer = new BXMLSerializer();
> @SuppressWarnings("deprecation")
> StringBufferInputStream sbis = new
> StringBufferInputStream(dndTextArea.getText());
> Component component = (Component) bxmlSerializer.readObject(sbis);
> mainSplitPane.setRight(component);
>
> I tried ByteArrayInputStream(yourString.getBytes()), but It was giving me
> some errors, which I think meant that it wasnt reading properly. I will try
> to use this or something similar because I know it is not
> good to use a deprecated class.
>
> Thanks again guys. you all have been very helpful!
> Mike
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011719.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by noobmike <md...@lakeheadu.ca>.
Thanks so much fellas!

Everything is working PERFECTLY! 

the only problem is I am using the StringBufferInputStream. My code snippet
is: 

BXMLSerializer bxmlSerializer = new BXMLSerializer();
@SuppressWarnings("deprecation")
StringBufferInputStream sbis = new
StringBufferInputStream(dndTextArea.getText());              
Component component = (Component) bxmlSerializer.readObject(sbis);                
mainSplitPane.setRight(component); 

I tried ByteArrayInputStream(yourString.getBytes()), but It was giving me
some errors, which I think meant that it wasnt reading properly. I will try
to use this or something similar because I know it is not 
good to use a deprecated class. 

Thanks again guys. you all have been very helpful!
Mike

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011719.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by Edvin Syse <ed...@sysedata.no>.
Use new ByteArrayInputStream(yourString.getBytes()) instead. If you need 
to convert charsets you can use the getBytes(encoding) method of String.

StringBufferInputStream was deprecated for that reason - it won't 
properly take care of charset conversion for you.

-- Edvin

Den 01.06.2011 18:26, skrev Greg Brown:
>> So I used Edvins advice, although I assumes he meant StringBufferInputStream
>> because it didnt seem to recognize StringInputStream();
>>
>> My code is:
>> ...
>> which gives the error:
>>
>> java.lang.IllegalArgumentException: Window parent must be null or display,
>> cannot be org.apache.pivot.wtk.SplitPane
>
> You need to make sure that the root element of your BXML is not a Window.
>
>> on a side note. when I import java.io.StringBufferInputStream; the
>> StringBufferInputStream has a line right through the middle of it like its
>> crossing it off a list. and anytime I use it in the rest of the file it
>> strikes it out as well. Why is this?
>
> That's because StringBufferInputStream is deprecated (meaning its use is not recommended).
>

Re: BXML Rendering

Posted by Greg Brown <gk...@verizon.net>.
> So I used Edvins advice, although I assumes he meant StringBufferInputStream
> because it didnt seem to recognize StringInputStream(); 
> 
> My code is: 
> ...
> which gives the error:
> 
> java.lang.IllegalArgumentException: Window parent must be null or display,
> cannot be org.apache.pivot.wtk.SplitPane

You need to make sure that the root element of your BXML is not a Window.

> on a side note. when I import java.io.StringBufferInputStream; the
> StringBufferInputStream has a line right through the middle of it like its
> crossing it off a list. and anytime I use it in the rest of the file it
> strikes it out as well. Why is this? 

That's because StringBufferInputStream is deprecated (meaning its use is not recommended).


Re: BXML Rendering

Posted by noobmike <md...@lakeheadu.ca>.
So I used Edvins advice, although I assumes he meant StringBufferInputStream
because it didnt seem to recognize StringInputStream(); 

My code is: 

 BXMLSerializer bxmlSerializer = new BXMLSerializer();
 @SuppressWarnings("deprecation")
 StringBufferInputStream sbis = new
StringBufferInputStream(dndTextArea.getText());       
 Component component = (Component) bxmlSerializer.readObject(sbis);                
 mainSplitPane.setRight(component);

which gives the error:

java.lang.IllegalArgumentException: Window parent must be null or display,
cannot be org.apache.pivot.wtk.SplitPane

so I tried to switch 

 Component component = (Component) bxmlSerializer.readObject(sbis);                
 mainSplitPane.setRight(component);

to 

which gives me an error:

An error occurred at line number 1:
org.apache.pivot.serialization.SerializationException:
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.

so I think I may have one of 2 problems, either im not setting it to the
rightside of the split pane correctly, or that my streamreader isnt reading
in the text properly. or both. haha. 

Thanks for the help and any more help or ideas would be great! 

on a side note. when I import java.io.StringBufferInputStream; the
StringBufferInputStream has a line right through the middle of it like its
crossing it off a list. and anytime I use it in the rest of the file it
strikes it out as well. Why is this? 


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011384.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by Greg Brown <gk...@verizon.net>.
Ah, you're right.  :-(  I couldn't find a way to wrap a Reader in an InputStream - anybody know of one? Worst case, you can write the text out to a file using FileWriter and then wrap it in a FileInputStream to read it back in.

BXMLSerializer should probably support a method signature that takes a Reader.

On Jun 1, 2011, at 10:52 AM, noobmike wrote:

> Turns out this didnt work. 
> 
> It looks like bxmlSerializer.readObject() needs an InputStream the
> StringReader didnt work. 
> I tried StreamReader, or even making an Input stream, but had trouble
> instantiating it. 
> 
> any ideas?
> 
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011127.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: BXML Rendering

Posted by Gerrick Bivins <gb...@objectreservoir.com>.
It can be done. I still have in my queue to finish up the project mentioned
here.
http://blogs.oracle.com/geertjan/entry/pivot_integration_into_netbeans

code is up on kenai if you want to reference it but it hasn't been updated
at in a couple of months and is probably not the cleanest.
Gerrick
<http://blogs.oracle.com/geertjan/entry/pivot_integration_into_netbeans>

On Wed, Jun 1, 2011 at 10:11 AM, Greg Brown <gk...@verizon.net> wrote:

> I don't see a StringInputStream in the JDK. There is a
> StringBufferInputStream, but it is deprecated.
> G
>
> On Jun 1, 2011, at 11:06 AM, Edvin Syse wrote:
>
> > Use StringInputStream()
> >
> > -- Edvin
> >
> > Den 01.06.2011 16:52, skrev noobmike:
> >> Turns out this didnt work.
> >>
> >> It looks like bxmlSerializer.readObject() needs an InputStream the
> >> StringReader didnt work.
> >> I tried StreamReader, or even making an Input stream, but had trouble
> >> instantiating it.
> >>
> >> any ideas?
> >>
> >>
> >> --
> >> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011127.html
> >> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>

Re: BXML Rendering

Posted by Edvin Syse <ed...@sysedata.no>.
Sorry, so used to having it around I forgot it's not in the JDK :)

new ByteArrayInputStream(yourString.getBytes()) should work though.

-- Edvin

Den 01.06.2011 17:11, skrev Greg Brown:
> I don't see a StringInputStream in the JDK. There is a StringBufferInputStream, but it is deprecated.
> G
>
> On Jun 1, 2011, at 11:06 AM, Edvin Syse wrote:
>
>> Use StringInputStream()
>>
>> -- Edvin
>>
>> Den 01.06.2011 16:52, skrev noobmike:
>>> Turns out this didnt work.
>>>
>>> It looks like bxmlSerializer.readObject() needs an InputStream the
>>> StringReader didnt work.
>>> I tried StreamReader, or even making an Input stream, but had trouble
>>> instantiating it.
>>>
>>> any ideas?
>>>
>>>
>>> --
>>> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011127.html
>>> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>

Re: BXML Rendering

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
and try to read the string into a byte[] (maybe with the
ByteArraySerializer), like in the ByteArraySerializerTest, and then
use/convert it ?

Bye


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011238.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by Greg Brown <gk...@verizon.net>.
I don't see a StringInputStream in the JDK. There is a StringBufferInputStream, but it is deprecated.
G

On Jun 1, 2011, at 11:06 AM, Edvin Syse wrote:

> Use StringInputStream()
> 
> -- Edvin
> 
> Den 01.06.2011 16:52, skrev noobmike:
>> Turns out this didnt work.
>> 
>> It looks like bxmlSerializer.readObject() needs an InputStream the
>> StringReader didnt work.
>> I tried StreamReader, or even making an Input stream, but had trouble
>> instantiating it.
>> 
>> any ideas?
>> 
>> 
>> --
>> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011127.html
>> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: BXML Rendering

Posted by Edvin Syse <ed...@sysedata.no>.
Use StringInputStream()

-- Edvin

Den 01.06.2011 16:52, skrev noobmike:
> Turns out this didnt work.
>
> It looks like bxmlSerializer.readObject() needs an InputStream the
> StringReader didnt work.
> I tried StreamReader, or even making an Input stream, but had trouble
> instantiating it.
>
> any ideas?
>
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011127.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by noobmike <md...@lakeheadu.ca>.
Turns out this didnt work. 

It looks like bxmlSerializer.readObject() needs an InputStream the
StringReader didnt work. 
I tried StreamReader, or even making an Input stream, but had trouble
instantiating it. 

any ideas?


--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3011127.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by noobmike <md...@lakeheadu.ca>.
Very Awesome! 

Youre the MAN! 

Ill let you know how it works, 

Thanks Greg.

Mike.

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3010837.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by Greg Brown <gk...@verizon.net>.
> So instead of using the serializer like this:
> 
> window = (Window)bxmlSerializer.readObject(IIADashboard.class,
> "iiaDashboard.bxml");
> 
> I would use it something like this? :
> 
> BoxPane = (BoxPane)bxmlSerializer.readObject(IIADashboard.class,
> "iiaDashboard.bxml");
> 
> and then just put that boxpane in the right side of the splitpane? 

If you are pulling the content from a text area on the left side of the split pane, it might not be a BoxPane. But maybe it would be safe to assume that it is a Component. If so, you could do something like this:

StringReader reader = new StringReader(textArea.getText());
Component component = bxmlSerializer.readObject(reader);
splitPane.setRight(component); 


Re: BXML Rendering

Posted by noobmike <md...@lakeheadu.ca>.
Great! thats relieving, I for some reason thought I was going to have to
create my own parser... etc.
My goal is exactly the second point. I want the text area on the left side
of the split pane and the preview on the right. 

So instead of using the serializer like this:

window = (Window)bxmlSerializer.readObject(IIADashboard.class,
"iiaDashboard.bxml");

I would use it something like this? :

BoxPane = (BoxPane)bxmlSerializer.readObject(IIADashboard.class,
"iiaDashboard.bxml");

and then just put that boxpane in the right side of the splitpane? 

Thanks for the help as always,

Mike.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3010767.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: BXML Rendering

Posted by Greg Brown <gk...@verizon.net>.
Yup, very easy. Just use BXMLSerializer to load the text the user enters. You may need to wrap it in a StringReader to pass to readObject().

The only real trick is how to get it on screen. Every UI element in a Pivot app must ultimately be contained by some kind of Window. You could require your users to create a Window (or subclass) as a root element, but that might be kind of limiting. Alternatively, if you allow them to create any kind of component except Window (and Display) as a root element, you could open your preview in a Frame, or the right-hand side of a SplitPane, etc.

G

On Jun 1, 2011, at 9:12 AM, noobmike wrote:

> Hey Experts, I have yet another question for you!
> 
> In my App, I want to essentially render user typed bxml code(say in a text
> area) and have it shown (functional preferably if not that's fine too) in
> real time. Or as close to real time as possible, so if they have to click a
> "Render Code" button so be it. 
> 
> Is this possible? I read a previous thread that was somewhat similar, but am
> not sure if its exactly what I am trying to do. 
> 
> Any suggestions? 
> 
> Thanks for your wisdom
> 
> Mike.
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/BXML-Rendering-tp3010653p3010653.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.