@SuppressWarnings("unchecked") @Override public void read(Transferable t, Drawing drawing, boolean replace) throws UnsupportedFlavorException, IOException { try { Drawing d = (Drawing) t.getTransferData(dataFlavor); if (replace) { for (Map.Entry<AttributeKey, Object> e : d.getAttributes().entrySet()) { drawing.set(e.getKey(), e.getValue()); } } for (Figure f : d.getChildren()) { drawing.add(f); } } catch (Throwable th) { th.printStackTrace(); } }
@SuppressWarnings("unchecked") @Override public void read(InputStream in, Drawing drawing, boolean replace) throws IOException { try { ObjectInputStream oin = new ObjectInputStream(in); Drawing d = (Drawing) oin.readObject(); if (replace) { for (Map.Entry<AttributeKey, Object> e : d.getAttributes().entrySet()) { drawing.set(e.getKey(), e.getValue()); } } for (Figure f : d.getChildren()) { drawing.add(f); } } catch (ClassNotFoundException ex) { IOException ioe = new IOException("Couldn't read drawing."); ioe.initCause(ex); throw ioe; } }
@Override public void read(InputStream in, Drawing drawing, boolean replace) throws IOException { ImageHolderFigure figure = createImageHolder(in); if (replace) { drawing.removeAllChildren(); drawing.set(CANVAS_WIDTH, figure.getBounds().width); drawing.set(CANVAS_HEIGHT, figure.getBounds().height); } drawing.basicAdd(figure); }
@Override public void redo() { super.redo(); // restoreData.add(figure.getAttributesRestoreData()); drawing.willChange(); drawing.set(key, undoValue); drawing.changed(); } };
public void read(File file, Drawing drawing, boolean replace) throws IOException { ImageHolderFigure figure = (ImageHolderFigure) prototype.clone(); figure.loadImage(file); figure.setBounds( new Point2D.Double(0, 0), new Point2D.Double( figure.getBufferedImage().getWidth(), figure.getBufferedImage().getHeight())); if (replace) { drawing.removeAllChildren(); drawing.set(CANVAS_WIDTH, figure.getBounds().width); drawing.set(CANVAS_HEIGHT, figure.getBounds().height); } drawing.basicAdd(figure); }
/** Creates new form AnimationSample */ public AnimationSample() { initComponents(); DefaultDrawingView view = new DefaultDrawingView(); view.setDrawingDoubleBuffered(false); add(view); setSize(400, 400); Drawing d = new DefaultDrawing(); d.set(CANVAS_FILL_COLOR, new Color(0x76a9d2)); final EllipseFigure ellipse = new EllipseFigure(160, 160, 80, 80); ellipse.set(STROKE_WIDTH, 7d); d.add(ellipse); view.setDrawing(d); Timer t = new Timer(10, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double alpha = 2d * Math.PI * (System.currentTimeMillis() % 1000) / 1000d; ellipse.willChange(); ellipse.setBounds(new Rectangle2D.Double(160 + Math.sin(alpha) * 100, 160 + Math.cos(alpha) * 100, 80, 80)); ellipse.changed(); } }); t.setRepeats(true); t.start(); }
drawing.set(key, selectedColor); drawing.changed();