You'd think I'd know a thing or three about GUI by now, but I'm stumped. I've released a project on SourceForge: JFCML - JFC/Swing XML Markup Language
http://meta-solutions.com/jfcml/index.html .
I'm creating a demo for the website:
http://meta-solutions.com/jfcml/demo/index.html . I'm running into a little trouble setting the JRootPane more than once.
Basically, the demo lets the user edit a JFCML description file and see the results. I use javascript to call the runDemo( String ) method defined in the demo class. The base window container in my package is called JFCMLWindow. It extends JRootPane and is basically the component that the JFCMLWindowFactory draws on based on the XML. (That's why I need to set the rootpane more than once).
It works the first time(when i call it from init()), but when you click on the button (and call it with javascript), it kills the window.
Here's my demo class (you'll need my jar if you're going to compile it):
import com.metasolutions.jfcml.JF
CMLWindow;
import com.metasolutions.jfcml.JF
CMLWindowF
actory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyn
taxExcepti
on;
import java.util.regex.MatchResul
t;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.SwingUtilities
;
import java.io.File;
public class test extends JApplet
{
private JFCMLWindowFactory factory;
private JFCMLWindow jfcmlw;
public void init()
{
factory = new JFCMLWindowFactory();
runDemo( "<JFCML><JRootPane><Conten
tPane><JPa
nel><JLabe
l Text=\"Hello World\" Background=\"Color(0,255,0
)\"/></JPa
nel></Cont
entPane></
JRootPane>
</JFCML>")
;
}
private static final String HEADER =
"<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n\
r\n" +
"<!DOCTYPE JFCML SYSTEM \"
http://meta-solutions.com/jfcml.dtd\">\r\n";
public void runDemo( String input ) {
final String s = HEADER + input;
try {
SwingUtilities.invokeAndWa
it( new Runnable() {
public void run() {
createAndShowGUI( s );
System.out.println( "ALL DONE!" );
System.out.flush();
}
});
} catch( Exception e ) {
throw new RuntimeException( "Failed to create GUI", e );
}
System.out.println( "returning from rundemo()" );
System.out.flush();
}
private void createAndShowGUI( String s ) {
if( jfcmlw != null )
remove( jfcmlw );
invalidate();
jfcmlw = new JFCMLWindow();
factory.build( new java.io.CharArrayReader( s.toCharArray() ), jfcmlw );
System.out.println( "returned from build" );
System.out.flush();
add( jfcmlw );
repaint();
System.out.println( "set root pane" );
System.out.flush();
setSize( 300,300 );
setVisible( true );
}
}