List of usage examples for java.awt Container addNotify
public void addNotify()
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);//from ww w . j a v a 2s . 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);// w ww .j av a 2s . 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(); } }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void sizeContainerToComponent(Container container, Component component) { if (container.isDisplayable() == false) { container.addNotify(); }//from w ww . ja va2 s . c om Insets insets = container.getInsets(); Dimension size = component.getPreferredSize(); int width = insets.left + insets.right + size.width; int height = insets.top + insets.bottom + size.height; container.setSize(width, height); }