Java Forum / General / November 2005
XML --> Java User Interface
snuffie_456@yahoo.com - 14 Nov 2005 22:51 GMT Hello,
I'm a newbie to this, but I wonder if anyone can help me. I've already searched in many books and websites, but I don't seem to find the answer... My problem is that I want to show a Java User Interface of a description that has been made in XML. (So in the XML-file, there's a description of the user interface and of the actions). I already read that I must program a kind of parser in Java, using the Xerces libraries. I want to do it with DOM instead of SAX, this because of the flexibility... I already tried some things, but without success...
I hope someone can give me some advice!
Thanks in advance, Greetings! Tari
Daniel Dyer - 14 Nov 2005 23:20 GMT > Hello, > [quoted text clipped - 10 lines] > > I hope someone can give me some advice! The first step is probably to work out what the XML format will look like, it could get quite involved when you get to adding actions to components.
If you don't want to use pure SAX, it might be preferable to use something like Castor (http://www.castor.org), which will allow you to map directly to your object model without going via the DOM representation. It might be worth experimenting to see if you could map XML directly to Swing objects using a Castor mapping file that looks something like this:
<class name="javax.swing.JButton"> <map-to xml="Button" /> <field name="text"> <bind-xml name="text" node="attribute" /> </field> </class>
This would map the following XML directly to a JButton object in your application:
<Button text="My Button" />
You might also want to take a look at Thinlet (http://thinlet.sourceforge.net/), it does something similar to want you are trying to achieve.
Dan.
 Signature Daniel Dyer http://www.dandyer.co.uk
Roedy Green - 15 Nov 2005 06:41 GMT On Mon, 14 Nov 2005 23:20:40 -0000, "Daniel Dyer" <dan@dannospamformepleasedyer.co.uk> wrote, quoted or indirectly quoted someone who said :
><class name="javax.swing.JButton"> > <map-to xml="Button" /> > <field name="text"> > <bind-xml name="text" node="attribute" /> > </field> ></class> WHY? for God sake. Java is a much more flexible and terse way to represent the data than XML.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Dag Sunde - 15 Nov 2005 07:56 GMT > On Mon, 14 Nov 2005 23:20:40 -0000, "Daniel Dyer" > <dan@dannospamformepleasedyer.co.uk> wrote, quoted or indirectly [quoted text clipped - 9 lines] > WHY? for God sake. Java is a much more flexible and terse way to > represent the data than XML. Terse, yes. Flexible? doubt it...
Think runtime changes. Reparse gui def. instead of recompile App.
BTW... Isn't this what XUL already does? http://xul.sourceforge.net/links.html
 Signature Dag.
Thomas Hawtin - 15 Nov 2005 08:52 GMT >>On Mon, 14 Nov 2005 23:20:40 -0000, "Daniel Dyer" >><dan@dannospamformepleasedyer.co.uk> wrote, quoted or indirectly [quoted text clipped - 11 lines] > > Terse, yes. Flexible? doubt it... On the one hand we have a data format with an awkward syntax that can't comfortably represent directed acyclic graphs. On the other we have a full, funky programming language, with an awkward syntax. One of these wins hands down.
> Think runtime changes. Reparse gui def. instead of recompile App. Never had a problem with this. I tend to write a tiny class that calls a setup routing and just opens the panel in question. If ti was a problem, I'd just shove in a class loader. Much less hassle than some wacko XML solution, which have been tried many, many, many times before and ended in failure.
I might understand if it truly raised the level of abstraction, but even then it would, nine times out of ten, be a mistake.
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Roedy Green - 15 Nov 2005 09:53 GMT >Terse, yes. Flexible? doubt it... What ever XML scheme you come up with can't come anywhere near the power of Java. You can only a do a tiny subset of standard things.
A method call, a loop, an if -- all these things are ever so much easier in Java. Just look at ANT - which takes 10 times as much typing to get a simple thing done as it does with Java code, and is locked into a narrow range of possibilities.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 15 Nov 2005 09:54 GMT >Think runtime changes. Reparse gui def. instead of recompile App. They are conceptually the same. The end result though, java byte code, is vastly superior to any DOM tree, for actually getting something accomplished.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Daniel Dyer - 15 Nov 2005 09:41 GMT > On Mon, 14 Nov 2005 23:20:40 -0000, "Daniel Dyer" > <dan@dannospamformepleasedyer.co.uk> wrote, quoted or indirectly [quoted text clipped - 9 lines] > WHY? for God sake. Java is a much more flexible and terse way to > represent the data than XML. That's the mapping rules, not the GUI representation. The GUI reperesentation would be something like this:
<?xml version="1.0" ?> <GUI> <Window> <Panel> <Button text="My Button" /> </Panel> <Window> </GUI>
The advantage of this is that it is not Swing-specific and could be rendered to Swing, AWT, SWT or something else by using different mapping files (though to do anything complex in a a way that is independent of the GUI framework would be quite difficult, particularly in terms of adding logic). I'm not sure what the original poster is intending to do with it. If he only ever wants to map to Swing then you are right, it's unlikely to be worth the effort.
Dan.
 Signature Daniel Dyer http://www.dandyer.co.uk
Jeffrey Schwab - 16 Nov 2005 05:12 GMT >> On Mon, 14 Nov 2005 23:20:40 -0000, "Daniel Dyer" >> <dan@dannospamformepleasedyer.co.uk> wrote, quoted or indirectly [quoted text clipped - 20 lines] > </Panel> > <Window> ITYM </Window>. (A fine example of the sort of thing compilers are meant to catch.)
> </GUI> > [quoted text clipped - 7 lines] > > Dan. snuffie_456@yahoo.com - 16 Nov 2005 19:37 GMT Hello,
In the meantime, I developed an xml-file and some code in java that should do the parsing and showing of the user interface. I used the instruction javac filename.java to compile my javafiles, and the instruction java filename filename_of_the_xml_file.xml, but nothing is happening... Is there some kind of other instruction I can use to run the program and check if it's working without errors? Thanks!
Tari
Rémi Bastide - 15 Nov 2005 12:21 GMT > Hello, > [quoted text clipped - 4 lines] > description that has been made in XML. (So in the XML-file, there's a > description of the user interface and of the actions). ... This is a pretty good idea IMHO, and here I disagree with other posts in this thread. The interest of doing this is that you have an implementation-independent, abstract description of the UI, which can be mapped to different technologies (e.g. java, DHTML, Tcl-Tk, C#...) Actually, it is so good an idea that several persons have had it before, and advanced proposals do exist : USIXML : http://www.usixml.org XUL: http://www.mozilla.org/projects/xul/
 Signature Rémi Bastide http://liihs.irit.fr/bastide
Robert M. Gary - 16 Nov 2005 22:17 GMT Sounds like you want to be using XUL. I find it very irritating when Java GUIs of any complication are put inline in code. It makes them harder to maintain and certainly harder to localize. Check out http://luxor-xul.sourceforge.net/
Rémi Bastide - 17 Nov 2005 11:56 GMT > Hello, > [quoted text clipped - 7 lines] > Xerces libraries. I want to do it with DOM instead of SAX, this because > of the flexibility... Also, don't forget about the XMLEncoder that does a great job in serializing a UI (or any bean for that matter) in XML and reloading it. http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html Maybe what you need is already completely in the standard library !
 Signature Rémi Bastide http://liihs.irit.fr/bastide
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|