SV: GUI components creation idioms

"Christian Hessenbruch" <[email protected]>
Newsgroups gmane.comp.java.netbeans.user-interface
Message-ID <AE8BABF1A8D7C64F8CE8F6405A6B6CB13025CD@guidom>
http://www.netbeans.org/issues/show_bug.cgi?id=67764 

-----Oprindelig meddelelse-----
Fra: Christian Hessenbruch [mailto:[email protected]] 
Sendt: 2. oktober 2006 09:42
Til: [email protected]
Emne: SV: [nbui] GUI components creation idioms

I've allready made a suggestion on this list that IMHO could be a
perfect solution to this problem. What I suggested was that the Mattise
team created a parser, that at runtime can parse the .form xml-file, and
whenever it encountered a component, it should ask a factory provided by
the client to create it. That way it would be much easier to develop
thin clients using Matisse.

I think the automatically generated java files are fine for prototyping,
but for real scaleable programs it would be much better just using the
xml files establishing the gui runtime. That would enable the client to
do the binding itself (maybe using a binding framework), only leaving to
Matisse what it goes best - layout.

Could someone from the Matisse-team verify if such a parser is beeing
considered?

Best Regards,

Christian




-----Oprindelig meddelelse-----
Fra: Gregg Wonderly [mailto:[email protected]]
Sendt: 2. oktober 2006 06:50
Til: [email protected]
Emne: Re: [nbui] GUI components creation idioms



King Lung Chiu wrote:
> Hi again,
> 
> Usually when I create a form, there are multiple components of the 
> same type, eg. 5 combo boxes, or 5 text fields, and Netbeans creates a

> new variable for each of those components.
> 
> I'd like to have them created as items in a data structure (eg. an 
> array or ArrayList or HashMap of combo boxes),to make it easier to 
> reference them later. Is there an automatic way to do that?
> 
> My current workaround is to create the data structure myself (eg.
> EnumMap<FieldAttribute, JTextField>), and manually add the components 
> to that data structure in each comopnent's post-creation code (in this

> case, maping each component to its corresponding enum value). However,

> this method doesn't scale when I have a large number of components to 
> add. (lots of code copy + paste + small-edit).

In this case, I don't use Matisse to create such panels. I write all the
helper methods and do all of the layout by hand using tools like my
Packer
(http://packer.dev.java.net) layout manager which provides a friendlier
interface to GridBagLayout.

public int makeFields( EnumMap<FieldAttribute,JTextField> map,
		FieldAttribute[] flds, Packer pk, int y ) {
	for( int i = 0; i < flds.length; ++i ) {
		// See
http://www.artima.com/weblogs/viewpost.jsp?thread=98193
		// for more information on what its ++y and not y++
here.
		pk.pack( new JLabel(flds[i].desc) ).gridx(0).gridy(++y);
		JTextField fld;
		pk.pack( fld = new JTextField( flds[i].default )
			 ).gridx(1).gridy(y).fillx();
		map.put( flds[i], fld );
	}
	return y;
}

public void init() {

	... some initialization ...

	JPanel fldPan = new JPanel();
	Packer fldPk = new Packer( fldPan );
	int y = makeFields( map, flds, fldPk, -1 );

	... more initialization ...
}

You can use Matisse for other things, and then just add such a
mechanically generated panel into an empty panel that is a place holder
created in matisse.

Gregg Wonderly
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.