private void initPreview(Component parent, ReportState state) {

        //
        // Save the report state
        //
        this.state = state;

        //
        // Create the report view
        //
        reportView = new ReportView();
        reportView.setOpaque(true);

        //
        // Create the scroll pane containing the report view
        //
        JScrollPane scrollPane = new JScrollPane(reportView);

        //
        // Create the dialog tool bar using both icons and text descriptions
        //
        JToolBar toolBar = new JToolBar();
        toolBar.setFloatable(false);
        URL imageURL;
        JButton button;

        imageURL = ReportPreview.class.getResource("/images/Back24.gif");
        button = new JButton("Back");
        button.setActionCommand("back");
        button.addActionListener(this);
        if (imageURL != null)
            button.setIcon(new ImageIcon(imageURL));
        toolBar.add(button);

        imageURL = ReportPreview.class.getResource("/images/Forward24.gif");
        button = new JButton("Forward");
        button.setActionCommand("forward");
        button.addActionListener(this);
        if (imageURL != null)
            button.setIcon(new ImageIcon(imageURL));
        toolBar.add(button);
        toolBar.addSeparator();

        imageURL = ReportPreview.class.getResource("/images/ZoomIn24.gif");
        button = new JButton("Zoom In");
        button.setActionCommand("zoom in");
        button.addActionListener(this);
        if (imageURL != null)
            button.setIcon(new ImageIcon(imageURL));
        toolBar.add(button);

        imageURL = ReportPreview.class.getResource("/images/ZoomOut24.gif");
        button = new JButton("Zoom Out");
        button.setActionCommand("zoom out");
        button.addActionListener(this);
        if (imageURL != null)
            button.setIcon(new ImageIcon(imageURL));
        toolBar.add(button);
        toolBar.addSeparator();

        imageURL = ReportPreview.class.getResource("/images/Print24.gif");
        button = new JButton("Print");
        button.setActionCommand("print");
        button.addActionListener(this);
        if (imageURL != null)
            button.setIcon(new ImageIcon(imageURL));
        toolBar.add(button);
        toolBar.addSeparator();

        //
        // Get the display configuration
        //
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();

        Dimension screenSize = toolkit.getScreenSize();
        int baseX = 0;
        int baseY = 0;
        int screenWidth = screenSize.width;
        int screenHeight = screenSize.height;

        screenResolution = toolkit.getScreenResolution();
        screenAdjustment = (double)screenResolution/72.0;

        Insets screenInsets = toolkit.getScreenInsets(gc);
        if (screenInsets != null) {
            baseX = screenInsets.left;
            baseY = screenInsets.top;
            screenWidth -= screenInsets.left+screenInsets.right;
            screenHeight -= screenInsets.top+screenInsets.bottom;
        }

        //
        // Size the report view based on the page format and the
        // screen resolution
        //
        PageFormat pageFormat = state.getPageFormat();
        viewSize.setSize(pageFormat.getWidth()*screenAdjustment,
                         pageFormat.getHeight()*screenAdjustment);
        zoomSize.setSize(viewSize);
        reportView.setPreferredSize(viewSize);
        reportView.setMinimumSize(viewSize);

        //
        // Set the viewport size based on the screen size
        //
        JViewport viewPort = scrollPane.getViewport();
        Dimension scrollSize = viewPort.getPreferredSize();
        scrollSize.setSize(Math.min(scrollSize.width, screenWidth-75),
                           Math.min(scrollSize.height, screenHeight-75));
        viewPort.setPreferredSize(scrollSize);

        //
        // Create the content pane containing the tool bar and the scroll pane
        //
        JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.setOpaque(true);
        contentPane.add(toolBar, BorderLayout.NORTH);
        contentPane.add(scrollPane, BorderLayout.CENTER);
        setContentPane(contentPane);

        //
        // Position the dialog window relative to the parent and ensure that
        // it will fit within the screen insets
        //
        pack();
        setLocationRelativeTo(parent);
        Rectangle bounds = getBounds();
        if (bounds.x-baseX+bounds.width > screenWidth)
            bounds.setLocation(baseX, bounds.y);

        if (bounds.y-baseY+bounds.height > screenHeight)
            bounds.setLocation(bounds.x, baseY);

        setBounds(bounds);

        //
        // Build the report
        //
        reportPage = new ReportPage(state);
        numPages = reportPage.paginate();

        //
        // Display the first page
        //
        if (numPages != 0) {
            displayPage();
            setTitle(state.getReportTitle()+" - Page 1 of "+numPages);
        }
    }