I'm working on an XSL:FO template editor and I want to do a realtime 
preview of what
it will look like. I just want to render it to a component and then 
refresh it quickly. I have
been unsuccessful at making anything render directly from a bytestream 
in memory,
so I'm writing it out to a temp file and then reading it in with
        FOInputHandler inputHandler = new FOInputHandler(new 
java.io.File("/tmp/foo.foo"));
which seems to work. Eventually I want to avoid the disk altogether and 
just do it from
memory, but I'll take what I can get for now.

My main problem is that I can't get the window to refresh. In the code 
below 'setup()' is
called once and then 'refresh()' is called each time the document is 
updated. Originally
I had the Renderer allocated in the setup and reused, but that seemed 
never to update
after the first render, so now I allocate a new Renderer each time. What 
is the appropriate
way to do this? What objects can I reuse (Renderer? Driver?) and what do 
I have
to reallocate each time. Also, what method should I call on the JFrame 
to force it
to refresh. Invalidate doesn't always seem to do it.   Thanks so much for
your help.

- Joshua


public class FOViewer {
     public static String TRANSLATION_PATH =
         "/org/apache/fop/viewer/resources/";
     JLabel previewImageLabel;
     JFrame frame;

     public void setup() {
        try {
        // create a new renderer

        frame = new JFrame("fooboo");
        previewImageLabel = new JLabel();
        frame.getContentPane().add(previewImageLabel);
        frame.validate();
        frame.setVisible(true);
        frame.setSize(400,400);

        //      renderer.setProgressListener(frame);
        } catch (Exception e) {
            u.p(e);
        }
     }

     public void refresh(InputStream in) {
        try {
            // set up the language stuff
            String language = null;
            if (language == null) {
                try {
                    language = System.getProperty("user.language");
                } catch(SecurityException se) {
                    // if this is running in a secure place
                }
            }
            Translator resource = getResourceBundle(TRANSLATION_PATH + 
"resources." + language);
            UserMessage.setTranslator(getResourceBundle(TRANSLATION_PATH + 
"messages." + language));
            resource.setMissingEmphasized(false);
            AWTRenderer renderer;
            renderer = new AWTRenderer(resource);
            renderer.setComponent(frame);

        // old stuff
        FOInputHandler inputHandler = new FOInputHandler(new 
java.io.File("/tmp/foo.foo"));
        XMLReader reader2 = inputHandler.getParser();


        Driver driver = new Driver();
        driver.setRenderer(renderer);
        driver.render(reader2, inputHandler.getInputSource()); // old
        //      driver.render(reader, new InputSource(in)); // new
        BufferedImage pageImage = renderer.getLastRenderedPage();

        //      frame.getContentPane().remove(previewImageLabel);
        //      frame.invalidate();
        //      frame.repaint();

        //      previewImageLabel = new JLabel();
        previewImageLabel.setIcon(new ImageIcon(pageImage));
        //      frame.getContentPane().add(previewImageLabel);
        previewImageLabel.invalidate();
        frame.invalidate();
        previewImageLabel.repaint();
        frame.repaint();

        u.p("done 1");

        } catch (Exception e) {
            u.p(e);
        }
     }


     public static SecureResourceBundle getResourceBundle(String path) {
         InputStream in = null;

         try {
            FOViewer foo = new FOViewer();
             URL url = foo.getClass().getResource(path);
             in = url.openStream();
         } catch (Exception ex) {
            u.p("Can't find URL to: <" + path + "> " + ex.getMessage());
            u.p(ex);
         }
         return new SecureResourceBundle(in);
     }

}


- Joshua

    ... but I still haven't found what I'm looking for.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to