public void setData(String text) { if (text != null && text.length() > 0) { InputStream in = null; try { Object result = null; Drawing drawing = createDrawing(); // Try to read the data using all known input formats. for (InputFormat fmt : drawing.getInputFormats()) { try { fmt.read(in, drawing); in = new ByteArrayInputStream(text.getBytes("UTF8")); result = drawing; break; } catch (IOException e) { result = e; } } if (result instanceof IOException) { throw (IOException) result; } setDrawing(drawing); } catch (Throwable e) { getDrawing().removeAllChildren(); SVGTextFigure tf = new SVGTextFigure(); tf.setText(e.getMessage()); tf.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100)); getDrawing().add(tf); e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } }
/** * Writes the drawing to the specified output stream. * This method applies the specified drawingTransform to the drawing, and draws * it on an image of the specified getChildCount. */ public void write(OutputStream out, Drawing drawing, AffineTransform drawingTransform, Dimension imageSize) throws IOException { write(out, drawing.getChildren(), drawingTransform, imageSize); }
public void write(OutputStream out, Drawing drawing) throws IOException { write(out, drawing.getChildren()); }