views:

48

answers:

3

I'm working on a utility that will be used to test the project I'm currently working on. What the utility will do is allow user to provide various inputs and it will sends out requests and provide the response as output.

However, at this point the exact format (which input is required and what is optional) has yet to be fleshed out. In addition, coding in Swing is somewhat repetitive since the overall work is simple though this should be the safest route to go as I have more or less full control and every component can be tweaked as I want. I'm considering using a configuration file that's in XML to describe the GUI (at least one part of it) and then coding the event handling part (in addition to validation, etc). The GUI itself shouldn't be too complicated. For each type of request to make there's a tab for the request and within each tab are various inputs.

There seems to be quite a few questions about this already but I'm not asking for a 3rd party library to do this. I'm looking to do this myself, since I don't think it'll be too overly complicated (hopefully). My main consideration for using this is re-usability (later on, for other projects) and for simplifying the GUI work. My question is: are there other pros/cons that I'm overlooking? Is it worth the (unknown) time to do this?

I've built GUI in VB.NET and with Flex3 before.

+1  A: 

XML is so 2000. It's code, put it in real source files. If it really is so simple that it could be XML, all you are doing is removing the XML handling step and using a clearer syntax. If it turns out to be a little more complicated than you first expected, then you have the full power of your favourite programming language to hand.

Tom Hawtin - tackline
Well it doesn't have to be XML, it was however the first thing that I thought I could use. But I think this makes sense overall.
nevets1219
I have to completely disagree. Although XML might not be the best solution, GUIs tend to be very repetitive and not really code at all but boilerplate--few languages have a good, clean way to define GUIs and some outside language is often appropriate..
Bill K
Where you have repetition, a general purpose programming language is a great way to factor that out. Where it is just data, although Java doesn't have a great syntax, with appropriate use of builders (and the Double Brace Idiom if you are feeling adventurous) then it's much the same as XML (only very much simpler to deal with).
Tom Hawtin - tackline
I think I will just code the GUI myself, based on the feedback there doesn't seem to be any particular big advantages for building the GUI from a config file.
nevets1219
+1  A: 

In my experience, if your layout really is simple, something like the non-visual builders in FormLayout can lead to really concise code with a minimum of repetition.

Matt McHenry
+1  A: 

If you have to specify the precise location of every control you might look at a declarative swing helper toolkit that can minimize boilerplate and simplify layout. Groovy supports this as does JavaFX, and both are simple library extensions to Java (give or take).

If the form is laid out in a pattern, using a definition file in a format like XML or YAML will work. I've done that and have even set up data bindings in that file so that you don't even have to deal with listeners or initial values...

If you are sure you want XML, I'd seriously consider YAML though, it's really close but instead of:

<outer>
    <inner a=1> abc </inner>
</outer>

I think it's a lot more like:

outer
    inner a=1
        abc

(I may have that a bit wrong, but that's close I think. Anyway, you should never force anyone to type XML--if you are set on XML, provide a GUI with which to edit it!)

Bill K