Strategy for clean well structured code

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Strategy for clean well structured code

Postby blombar » Sat Oct 09, 2010 7:20 am

I am looking for some infomation on strategies for producing clean and well structured code for a swing GUI application. I notice that by default Swing Designer generates inline code for each component. There are some preference option to generate lazy instantiation of components, or to generate blocks, but all the code still goes into one big long method. I would think that cleaner, more understandable and more maintainable code would come from generating methods to instantiate components. For example, I would like to define a titlePanel, logoPanel, helpPanel, buttonPanel and several dataPanels and put them together into a JFrame. I would envision a high-level method that would have only about one line for each panel. Then the structure of the application would be apparent and the panels reusable. Is there a way that I can acheive this without hand restructuring the code? I see that custom components can be defined is that the way to do it?
blombar
 
Posts: 5
Joined: Sat Oct 09, 2010 5:20 am

Re: Strategy for clean well structured code

Postby Eric Clayberg » Sat Oct 09, 2010 8:00 am

You can do this in a variety of ways:

    1) Use lazy code gen so that every widget is defined in it sown method

    2) Create custom reusable JPanels

    3) Create custom reusable Factories

    4) Refactor code by hand
If you want to create panels that can be reused in multiple places, then you should use #2 or #3 above.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Strategy for clean well structured code

Postby blombar » Mon Oct 11, 2010 3:58 pm

To move toward a beter design, Is there a way to get WindowBuilder to regenerate the code after a preference has been changes, for example from inline to lazy instantiation?
blombar
 
Posts: 5
Joined: Sat Oct 09, 2010 5:20 am

Re: Strategy for clean well structured code

Postby Eric Clayberg » Mon Oct 11, 2010 4:25 pm

blombar wrote:To move toward a beter design, Is there a way to get WindowBuilder to regenerate the code after a preference has been changes, for example from inline to lazy instantiation?

No. One of the fundamental, core features of the product is that it only makes the smallest possible change (e.g., micro editing) to your code when you make a change in the design view. It will never touch existing code or existing formatting unless it absolutely has to. The tool never regenerates the entire class, so making a code gen pref change will only effect new code.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest

cron