Fred, thanks for the clarification. I suspected something like that but got confused about the "initialized by swixml", which is not what you want (and describe below). You want to initialize the component yourself and assign certain attributes to it.
The changes you suggest are possible but IMHO rather confusing. First, there is no way to have a component inside a container twice. So, what to do if you use the id "xc_panel" twice? Second, the changes you suggest are (as far as I remember the places correctly) in swixml much greater than the code you need to add this new tag: Swixml: - check if the variable specified by "id" does exist - check if it has the right type (what if not?) - check if the variable is alreay in some container (this may not be necessary, or may lay in the responsibility of the callers class) Allthough reflection gained a lot of speed, this would be quite time consuming, I suppose. In your code, you write simple swix.getTaglib().registerTag( "diagram", Diagram.class ); Third, this leads to unflexible xml-files. If you have a varity diagrams to choose from (preferable sharing an appropriate interface) you just register these classes. Then you choose whatever diagram is best in your xml-file. With your approach, this would'nt work easily. Yours, Frank List for Users of Carlsbad Cubes' Technologies and Products schrieb am 27.03.04 23:54:54: > > Frank, > > Here's a clarification. > > I had proposed a simple way to use subclassed components by allowing the > user to intitialize them. My original text was > > > The Swix engine could check > > to see if a variable to which a tag is bound already has a non-null value. > > If it's null, then it should create a new instance as it does now. If it's > > non-null and it's an instance of the appropriate type, then the xml > > attributes should be applied to the existing value. I'm not sure whether > > it's an easy solution to any other problems, but it would be a simple > > solution to my subclassing problem. > > Here are some snippets of code to illustrate what I mean more concretely. > > === From XML file ======================= > <!-- I want a panel (xc_panel) in the frame, but really want it to be a > Diagram (subclass of JPanel). See below. --> > . . . > <panel id="xc_panel" preferredSize="500,500" > constraints="BorderLayout.CENTER"> > </panel> > . . . > > === From Diagram.java ============================= > // This is the subclass of JPanel that I want xc_panel to be. > public class Diagram extends JPanel { > . . . > public paintComponent(Graphics g) { > // Draw my diagram to repaint the panel. > . . . > } > } > > === From my main class =========================== > // A possible solution is the following. Note that THIS DOES NOT WORK > // because Swixml always creates a new JPanel from the xml file > // and overwrites my assignment to xc_panel. > public class MyController { > . . . > public Diagram xc_panel; // This is initialized by swixml > . . . > public MyController() { > xc_panel = new Diagram(); // I WOULD LIKE THIS TO WORK. > SwingEngine swix = new SwingEngine( this ); > swix.render( "XXX.xml" ); > . . . // render() has assigned a new panel to xc_panel :-( > } > . . . > > The Diagram/JPanel variable xc_panel is specified in the .xml and > initialized by the swix.render call. What I'd prefer the SwingEngine > to do it take a look at the contents of xc_panel before it creates > a new JPanel. If xc_panel already contains a JPanel, as my example > does, it should not create a new one, but use the existing one and > simply apply any specifed attributes to it -- in my case a preferred > size of 500x500 was specified. > > This appears to be a simple solution to my problem where I must subclass > JPanel to override paintComponent(). I believe allowing user initialization > of components might also provide a solution to problems that initclass can't > easily solve. > > -- Fred > > > > > > > > [EMAIL PROTECTED] writes: > > > List for Users of Carlsbad Cubes' Technologies and Products schrieb am > > 27.03.04 18:16:58: > >> > >> It appears that the way to do this is to register a new tag for this > >> subclass of JPanel that I've defined. Is this the correct approach? > > > > At least this seems the most reasonable thing to me. > > Easy, documented and IMHO well used. > > > >> > >> This got me to thinking about other approaches. The Swix engine could > >> check > >> to see if a variable to which a tag is bound already has a non-null value. > >> > >> If it's null, then it should create a new instance as it does now. If > >> it's > >> non-null and it's an instance of the appropriate type, then the xml > >> attributes should be applied to the existing value. I'm not sure whether > >> it's an easy solution to any other problems, but it would be a simple > >> solution to my subclassing problem. > > > > Could you please explain this with some (pseudo) code? I do not > > grab it... > > > > Frank > > > > > > > > > > _______________________________________________ > > Forum mailing list > > Forum@carlsbadcubes.com > > http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com > > > > _______________________________________________ > Forum mailing list > Forum@carlsbadcubes.com > http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com