xmlgraphics-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Артур Гареев <reflexive...@gmail.com>
Subject FOP preview
Date Fri, 28 May 2010 11:41:40 GMT
Hi!
My name is Artur. I am from Russia and sorry for my bad English.
I try to embed PreviewPanel into my Java application but always I get
PreviewDialog.  I looked at Internet about this question but i did not find.

Here my Java code:

public class Viewer
    extends JFrame
{
    private FopFactory fopFactory;
    private FOUserAgent foUserAgent;
    private AWTRenderer renderer;
    private PreviewPanel previewPanel;
    //private PreviewDialog previewDialog;

    public Viewer()
    {
        renderer = new AWTRenderer();
        fopFactory = FopFactory.newInstance();
        foUserAgent = fopFactory.newFOUserAgent();
        foUserAgent.setRendererOverride( renderer );
        renderer.setPreviewDialogDisplayed( false );
        renderer.setUserAgent( foUserAgent );
        previewPanel = new PreviewPanel( foUserAgent, null, renderer );
        renderer.clearViewportList();
        renderer.setPreviewDialogDisplayed( false );
        //
        try
        {
            jbInit();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    private void jbInit() throws FOPException
    {
        this.setLayout( new GridBagLayout() );
        this.setSize( 500, 500 );

        double scale = previewPanel.getScaleToFitWindow();
        previewPanel.setScaleFactor( scale );
        previewPanel.setDisplayMode( PreviewPanel.CONTINUOUS );
        this.add( previewPanel );
    }

    public void setData( Document foDoc )
    {

    }

    public void convert( File xml, File xsl, File fo )
        throws TransformerException, IOException
    {
        OutputStream out = new FileOutputStream( fo );
        try
        {
            //Setup XSLT
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer(new
StreamSource(xsl));

            //Setup input for XSLT transformation
            Source src = new StreamSource(xml);

            //Resulting SAX events (the generated FO) must be piped through
to FOP
            Result res = new StreamResult(out);

            //Start XSLT transformation and FOP processing
            transformer.transform(src, res);
        }
        finally
        {
            out.close();
        }
    }

    public void showView( File foDoc ) throws FOPException,
TransformerException
    {
        Fop fop = fopFactory.newFop( MimeConstants.MIME_FOP_AWT_PREVIEW );
        try
        {
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            Source src = new StreamSource( foDoc );
            Result res = new SAXResult(fop.getDefaultHandler());
            transformer.transform(src, res);
        }
        catch (Exception e)
        {
            if (e instanceof FOPException) {
                throw (FOPException)e;
            }
            throw new FOPException(e);
        }
    }
}

Here I create Jframe and place Jpanel to it, then i embed PreviewPanel on
Jpanel. But my rendered document views in PreviewDialog but not in
PreviewPanel. How I can show document in PreviewPanel embedded to my
application??

Thanks in advance!
With respect, Artur!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message