/** Creates a new instance with format name "Drawing", file extension "xml" * and mime type "image/x-jhotdraw". */ public SerializationInputOutputFormat() { this("Drawing", "ser", new DefaultDrawing()); }
/** * Creates a drawing with input and output formats, so that drawing figures * can be copied and pasted between drawing views. * * @return a drawing */ private static Drawing createDrawing() { // Create a default drawing with // input/output formats for basic clipboard support. DefaultDrawing drawing = new DefaultDrawing(); drawing.addInputFormat(new SerializationInputOutputFormat()); drawing.addOutputFormat(new SerializationInputOutputFormat()); return drawing; } }
@Override public void draw(Graphics2D g) { synchronized (getLock()) { ensureSorted(); ArrayList<Figure> toDraw = new ArrayList<Figure>(getChildren().size()); Rectangle clipRect = g.getClipBounds(); for (Figure f : getChildren()) { if (f.getDrawingArea().intersects(clipRect)) { toDraw.add(f); } } draw(g, toDraw); } }
/** * Returns an iterator to iterate in * Z-order front to back over the children. */ @Override public java.util.List<Figure> getFiguresFrontToBack() { ensureSorted(); return new ReversedList<Figure>(getChildren()); }
DefaultDrawing drawing = new DefaultDrawing(); view.setDrawing(drawing); drawing.addUndoableEditListener(undoManager);
/** * Creates a new Drawing for this view. */ protected Drawing createDrawing() { DefaultDrawing drawing = new DefaultDrawing(); DOMStorableInputOutputFormat ioFormat = new DOMStorableInputOutputFormat(new PertFactory()); LinkedList<InputFormat> inputFormats = new LinkedList<InputFormat>(); inputFormats.add(ioFormat); drawing.setInputFormats(inputFormats); LinkedList<OutputFormat> outputFormats = new LinkedList<OutputFormat>(); outputFormats.add(ioFormat); outputFormats.add(new ImageOutputFormat()); drawing.setOutputFormats(outputFormats); return drawing; }
@Override public java.util.List<Figure> sort(Collection<? extends Figure> c) { HashSet<Figure> unsorted = new HashSet<Figure>(); unsorted.addAll(c); ArrayList<Figure> sorted = new ArrayList<Figure>(c.size()); for (Figure f : getChildren()) { if (unsorted.contains(f)) { sorted.add(f); unsorted.remove(f); } } for (Figure f : c) { if (unsorted.contains(f)) { sorted.add(f); unsorted.remove(f); } } return sorted; }
@Override public void drawCanvas(Graphics2D g) { if (get(CANVAS_WIDTH) != null && get(CANVAS_HEIGHT) != null) { // Determine canvas color and opacity Color canvasColor = get(CANVAS_FILL_COLOR); Double fillOpacity = get(CANVAS_FILL_OPACITY); if (canvasColor != null && fillOpacity > 0) { canvasColor = new Color( (canvasColor.getRGB() & 0xffffff) | ((int) (fillOpacity * 255) << 24), true); // Fill the canvas Rectangle2D.Double r = new Rectangle2D.Double( 0, 0, get(CANVAS_WIDTH), get(CANVAS_HEIGHT)); g.setColor(canvasColor); g.fill(r); } } } }
@Override public Figure findFigureInside(Point2D.Double p) { Figure f = findFigure(p); return (f == null) ? null : f.findFigureInside(p); }
DefaultDrawing drawing = new DefaultDrawing(); view.setDrawing(drawing); drawing.addUndoableEditListener(undoManager);
@Override public java.util.List<Figure> findFigures(Rectangle2D.Double bounds) { LinkedList<Figure> intersection = new LinkedList<Figure>(); for (Figure f : getChildren()) { if (f.isVisible() && f.getBounds().intersects(bounds)) { intersection.add(f); } } return intersection; }
@Override public Drawing construct() throws IOException { Drawing drawing = new DefaultDrawing(); InputFormat in = (file.getName().toLowerCase().endsWith(".svg")) ? new SVGInputFormat() : new SVGZInputFormat(); in.read(file.toURI(), drawing); return drawing; }
/** * Creates a drawing with input and output formats, so that drawing figures * can be copied and pasted between drawing views. * * @return a drawing */ private static Drawing createDrawing() { // Create a default drawing with // input/output formats for basic clipboard support. DefaultDrawing drawing = new DefaultDrawing(); drawing.addInputFormat(new SerializationInputOutputFormat()); drawing.addOutputFormat(new SerializationInputOutputFormat()); drawing.addOutputFormat(new ImageOutputFormat()); return drawing; } }
DefaultDrawing drawing = new DefaultDrawing(); view.setDrawing(drawing); drawing.addUndoableEditListener(undoManager);
@Override public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) { LinkedList<Figure> contained = new LinkedList<Figure>(); for (Figure f : getChildren()) { Rectangle2D.Double r = f.getBounds(); if (f.get(TRANSFORM) != null) { Rectangle2D rt = f.get(TRANSFORM).createTransformedShape(r).getBounds2D(); r = (rt instanceof Rectangle2D.Double) ? (Rectangle2D.Double) rt : new Rectangle2D.Double(rt.getX(), rt.getY(), rt.getWidth(), rt.getHeight()); } if (f.isVisible() && Geom.contains(bounds, r)) { contained.add(f); } } return contained; }
@Override public void run() { // Create a simple drawing consisting of three // text areas and an elbow connection. LabeledEllipseFigure ta = new LabeledEllipseFigure(); ta.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100)); LabeledEllipseFigure tb = new LabeledEllipseFigure(); tb.setBounds(new Point2D.Double(220, 120), new Point2D.Double(310, 210)); LabeledEllipseFigure tc = new LabeledEllipseFigure(); tc.setBounds(new Point2D.Double(220, 10), new Point2D.Double(310, 100)); Drawing drawing = new DefaultDrawing(); drawing.add(ta); drawing.add(tb); drawing.add(tc); // Create a frame with a drawing view and a drawing editor JFrame f = new JFrame("My Drawing"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 300); DrawingView view = new DefaultDrawingView(); view.setDrawing(drawing); f.add(view.getComponent()); f.add(new JLabel("Press space bar to toggle handles."), BorderLayout.SOUTH); DrawingEditor editor = new DefaultDrawingEditor(); editor.add(view); editor.setTool(new DelegationSelectionTool()); f.setVisible(true); } });
/** * Creates the drawing. */ protected Drawing createDrawing() { DefaultDrawing drawing = new DefaultDrawing(); drawing.addInputFormat(new SVGZInputFormat()); drawing.addInputFormat(new ImageInputFormat(new SVGImageFigure())); drawing.addOutputFormat(new SVGOutputFormat()); drawing.addOutputFormat(new SVGZOutputFormat()); drawing.addOutputFormat(new ImageOutputFormat()); drawing.addOutputFormat(new ImageOutputFormat("JPG", "Joint Photographics Experts Group (JPEG)", "jpg", BufferedImage.TYPE_INT_RGB)); drawing.addOutputFormat(new ImageOutputFormat("BMP", "Windows Bitmap (BMP)", "bmp", BufferedImage.TYPE_BYTE_INDEXED)); return drawing; }
DefaultDrawing drawing = new DefaultDrawing(); view.setDrawing(drawing); drawing.addUndoableEditListener(undoManager);
Drawing drawing = new DefaultDrawing();
/** * Creates a new Drawing for this view. */ protected Drawing createDrawing() { DefaultDrawing drawing = new DefaultDrawing(); DOMStorableInputOutputFormat ioFormat = new DOMStorableInputOutputFormat(new NetFactory()); drawing.addInputFormat(ioFormat); drawing.addInputFormat(new TextInputFormat(new NodeFigure())); drawing.addOutputFormat(ioFormat); drawing.addOutputFormat(new ImageOutputFormat()); return drawing; }