List of usage examples for javax.swing JEditorPane setSize
public void setSize(Dimension d)
From source file:Main.java
public void createJEditorPane(Container bg, Dimension size) { JEditorPane pane = new JEditorPane(); pane.setEditable(false);//from w ww . ja va 2s . c o m HTMLEditorKit editorKit = new HTMLEditorKit(); pane.setEditorKit(editorKit); pane.setSize(size); pane.setMinimumSize(size); pane.setMaximumSize(size); pane.setOpaque(true); pane.setText( "<b><font face=\"Arial\" size=\"50\" align=\"center\" > Unfortunately when I display this string it is too long and doesn't wrap to new line!</font></b>"); bg.add(pane, BorderLayout.CENTER); }
From source file:embedding.ExampleJava2D2PDF.java
/** * Creates a PDF file. The contents are painted using a Graphics2D implementation that * generates an PDF file.// w ww . j a v a 2s .c om * @param outputFile the target file * @throws IOException In case of an I/O error * @throws ConfigurationException if an error occurs configuring the PDF output */ public void generatePDF(File outputFile) throws IOException, ConfigurationException { OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { //Instantiate the PDFDocumentGraphics2D instance PDFDocumentGraphics2D g2d = new PDFDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); //Configure the G2D with the necessary fonts configure(g2d, createAutoFontsConfiguration()); //Set up the document size Dimension pageSize = new Dimension((int) Math.ceil(UnitConv.mm2pt(210)), (int) Math.ceil(UnitConv.mm2pt(297))); //page size A4 (in pt) g2d.setupDocument(out, pageSize.width, pageSize.height); g2d.translate(144, 72); //Establish some page borders //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(70, 90, 50, 50); copy.rotate(-2 * Math.PI / c, 70, 90); } copy.dispose(); //Some text g2d.rotate(-0.25); g2d.setColor(Color.RED); g2d.setFont(new Font("sans-serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 140); g2d.setColor(Color.RED.darker()); g2d.setFont(new Font("serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 180); pageSize = new Dimension(pageSize.height, pageSize.width); g2d.nextPage(pageSize.width, pageSize.height); //Demonstrate painting rich text String someHTML = "<html><body style=\"font-family:Verdana\">" + "<p>Welcome to <b>page 2!</b></p>" + "<h2>PDFDocumentGraphics2D Demonstration</h2>" + "<p>We can <i>easily</i> paint some HTML here!</p>" + "<p style=\"color:green;\">" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan" + " condimentum ullamcorper. Sed varius quam id arcu fermentum luctus. Praesent" + " nisi ligula, cursus sed vestibulum vel, sodales sed lectus.</p>" + "</body></html>"; JEditorPane htmlComp = new JEditorPane(); htmlComp.setContentType("text/html"); htmlComp.read(new StringReader(someHTML), null); htmlComp.setSize(new Dimension(pageSize.width - 72, pageSize.height - 72)); //htmlComp.setBackground(Color.ORANGE); htmlComp.validate(); htmlComp.printAll(g2d); //Cleanup g2d.finish(); } finally { IOUtils.closeQuietly(out); } }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java
/** * Convert a html code to an image//from w w w.ja va 2s. c o m * * @param html html to convert * @return html converted to png * @throws IOException if error * @throws PPTGeneratorException */ protected byte[] htmlToImage(String html) throws IOException, PPTGeneratorException { try { JEditorPane editor = new JEditorPane(); editor.setContentType("text/html"); editor.setText(html); editor.setSize(editor.getPreferredSize()); editor.addNotify(); LOGGER.debug("Panel is built"); BufferedImage bufferSave = new BufferedImage(editor.getPreferredSize().width, editor.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR); Graphics g = bufferSave.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, editor.getPreferredSize().width, editor.getPreferredSize().height); editor.paint(g); LOGGER.debug("graphics is drawn"); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(bufferSave, "png", out); return out.toByteArray(); } catch (HeadlessException e) { LOGGER.error("X Server no initialized or -Djava.awt.headless=true not set !"); throw new PPTGeneratorException("X Server no initialized or -Djava.awt.headless=true not set !"); } }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.PPTData.java
/** * Add an image with a html code without change its dimension * /*from ww w .ja va 2 s . c om*/ * @param slideToSet slide to set * @param html html code * @param x horizontal position * @param y vertical position * @throws IOException if error * @throws PPTGeneratorException */ protected void addHtmlPicture(Slide slideToSet, String html, int x, int y) throws IOException, PPTGeneratorException { try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (!ge.isHeadlessInstance()) { LOGGER.warn("Runtime is not configured for supporting graphiv manipulation !"); } JEditorPane editor = new JEditorPane(); editor.setContentType("text/html"); editor.setText(html); LOGGER.debug("Editor pane is built"); editor.setSize(editor.getPreferredSize()); editor.addNotify(); // Serveur X requis LOGGER.debug("Panel rendering is done"); BufferedImage bufferSave = new BufferedImage(editor.getPreferredSize().width, editor.getPreferredSize().height, BufferedImage.TYPE_3BYTE_BGR); Graphics g = bufferSave.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, editor.getPreferredSize().width, editor.getPreferredSize().height); editor.paint(g); LOGGER.debug("graphics is drawn"); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(bufferSave, "png", out); LOGGER.debug("image is written"); addPicture(slideToSet, out.toByteArray(), new Rectangle(x, y, editor.getPreferredSize().width, editor.getPreferredSize().height)); LOGGER.debug("image is added"); } catch (HeadlessException e) { LOGGER.error("X Server no initialized or -Djava.awt.headless=true not set !"); throw new PPTGeneratorException("X Server no initialized or -Djava.awt.headless=true not set !"); } }
From source file:com.pironet.tda.TDA.java
/** * add a tree listener for enabling/disabling menu and toolbar ICONS. * * @param tree JTree// w ww. j a va2 s .c om */ private void addTreeListener(JTree tree) { tree.addTreeSelectionListener(new TreeSelectionListener() { ViewScrollPane emptyView = null; public void valueChanged(TreeSelectionEvent e) { getMainMenu().getCloseMenuItem().setEnabled(e.getPath() != null); if (getMainMenu().getCloseToolBarButton() != null) { getMainMenu().getCloseToolBarButton().setEnabled(e.getPath() != null); } // reset right pane of the top view: if (emptyView == null) { JEditorPane emptyPane = new JEditorPane("text/html", "<html><body bgcolor=\"ffffff\"></body></html>"); emptyPane.setEditable(false); emptyPane.setSize(Const.EMPTY_DIMENSION); emptyView = new ViewScrollPane(emptyPane, runningAsVisualVMPlugin); } if (e.getPath() == null || !(((DefaultMutableTreeNode) e.getPath().getLastPathComponent()) .getUserObject() instanceof Category)) { resetPane(); } } private void resetPane() { final Rectangle bounds = topSplitPane.getBounds(); final int width = bounds.width; int dividerLocation = topSplitPane.getDividerLocation(); if (width - dividerLocation < Const.MIN_RIGHT_PANE_SIZE && width - Const.MIN_RIGHT_PANE_SIZE > 300) { dividerLocation = width - Const.MIN_RIGHT_PANE_SIZE; } topSplitPane.setRightComponent(emptyView); topSplitPane.setDividerLocation(dividerLocation); } }); }
From source file:net.yacy.cora.util.Html2Image.java
/** * render a html page with a JEditorPane, which can do html up to html v 3.2. No CSS supported! * @param url/*from w w w .j a v a 2 s. c o m*/ * @param size * @throws IOException */ public static void writeSwingImage(String url, Dimension size, File destination) throws IOException { // set up a pane for rendering final JEditorPane htmlPane = new JEditorPane(); htmlPane.setSize(size); htmlPane.setEditable(false); final HTMLEditorKit kit = new HTMLEditorKit() { private static final long serialVersionUID = 1L; @Override public Document createDefaultDocument() { HTMLDocument doc = (HTMLDocument) super.createDefaultDocument(); doc.setAsynchronousLoadPriority(-1); return doc; } @Override public ViewFactory getViewFactory() { return new HTMLFactory() { @Override public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView) view).setLoadsSynchronously(true); } return view; } }; } }; htmlPane.setEditorKitForContentType("text/html", kit); htmlPane.setContentType("text/html"); htmlPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { } }); // load the page try { htmlPane.setPage(url); } catch (IOException e) { e.printStackTrace(); } // render the page Dimension prefSize = htmlPane.getPreferredSize(); BufferedImage img = new BufferedImage(prefSize.width, htmlPane.getPreferredSize().height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = img.getGraphics(); htmlPane.setSize(prefSize); htmlPane.paint(graphics); ImageIO.write(img, destination.getName().endsWith("jpg") ? "jpg" : "png", destination); }