Example usage for java.awt Container paintComponents

List of usage examples for java.awt Container paintComponents

Introduction

In this page you can find the example usage for java.awt Container paintComponents.

Prototype

public void paintComponents(Graphics g) 

Source Link

Document

Paints each of the components in this container.

Usage

From source file:net.panthema.BispanningGame.GamePanel.java

public void writePdf() throws FileNotFoundException, DocumentException {

    // Query user for filename
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Specify PDF file to save");
    chooser.setCurrentDirectory(new File("."));
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf");
    chooser.setFileFilter(filter);/*w  w w.  jav a2 s .  co  m*/

    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;

    File outfile = chooser.getSelectedFile();
    if (!outfile.getAbsolutePath().endsWith(".pdf")) {
        outfile = new File(outfile.getAbsolutePath() + ".pdf");
    }

    // Calculate page size rectangle
    Dimension size = mVV.getSize();
    Rectangle rsize = new Rectangle(size.width, size.height);

    // Open the PDF file for writing - and create a Graphics2D object
    Document document = new Document(rsize);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outfile));
    document.open();

    PdfContentByte contentByte = writer.getDirectContent();
    PdfGraphics2D graphics2d = new PdfGraphics2D(contentByte, size.width, size.height, new DefaultFontMapper());

    // Create a container to hold the visualization
    Container container = new Container();
    container.addNotify();
    container.add(mVV);
    container.setVisible(true);
    container.paintComponents(graphics2d);

    // Dispose of the graphics and close the document
    graphics2d.dispose();
    document.close();

    // Put mVV back onto visible plane
    setLayout(new BorderLayout());
    add(mVV, BorderLayout.CENTER);
}

From source file:com.schnee.tweetgeister.visualization.TweetgeisterBalloonLayout.java

private void writeGraph() {
    Container c = new Container();

    VisualizationViewer<Node, Integer> vv = new VisualizationViewer<Node, Integer>(balloonLayout,
            new Dimension(3000, 3000));
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new TopicNodeLabeller(graph));
    vv.getRenderContext().setVertexIncludePredicate(new VertexDisplayPredicate(false));
    // add a listener for ToolTips
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    //vv.addPreRenderPaintable(rings);
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    rings = new Rings(balloonLayout, vv);
    vv.addPreRenderPaintable(rings);//from w  w  w.  ja v a 2  s.c o  m
    java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(3000, 3000,
            java.awt.image.BufferedImage.TYPE_INT_RGB);

    Graphics2D gr = bi.createGraphics();

    // MOST-IMPORTANT

    vv.setSize(3000, 3000);

    final ScalingControl scaler = new CrossoverScalingControl();

    vv.scaleToLayout(scaler);

    // MOST-IMPORTANT

    c.addNotify();

    c.add(vv);

    c.setVisible(true);

    c.paintComponents(gr);

    try {
        ImageIO.write(bi, "png", new File("vis.png"));
        System.out.println("done");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}