public void actionPerformed(ActionEvent ae) { if (front) { stack.toFront(primitive); } else { stack.toBack(primitive); } if (repainter != null) { repainter.requestRepaint(); ; } }
public void actionPerformed(ActionEvent ae) { Area area = null; List<Attribute> attrs = new ArrayList<Attribute>(); boolean fill = false; for (Vector v : shapes) { Primitive vv = v; while (vv instanceof Proxy && !(vv instanceof PaintedPrimitive)) { vv = ((Proxy) vv).getProxiedPrimitive(); } if (vv instanceof PaintedPrimitive) { PaintedPrimitive pp = (PaintedPrimitive) vv; List<Attribute> atts = pp.allAttributes(); System.err.println(" include attributes " + atts); attrs.addAll(pp.allAttributes()); } fill |= v instanceof Fillable && ((Fillable) v).isFill(); if (area == null) { area = new Area(v.toShape()); } else { Area other = new Area(v.toShape()); switch (kind) { case UNION: area.add(other); break; case INTERSECTION: area.intersect(other); break; case SUBTRACTION: area.subtract(other); break; case XOR: area.exclusiveOr(other); break; default: throw new AssertionError(); } } } if (area != null) { PathIteratorWrapper wrap = new PathIteratorWrapper( area.getPathIterator(AffineTransform.getTranslateInstance(0, 0)), fill); // XXX probably don't want all attributes, they may be // redundant PaintedPrimitive pp = PaintedPrimitive.create(wrap, attrs); stack.replace(shapes, pp); if (repainter != null) { repainter.requestRepaint(); ; } } }
public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); return; } if (stack == null && layer != null) stack = layer.getLookup().lookup(ShapeStack.class); List<Primitive> l = stack.getPrimitives(); Rectangle2D.Double scratch = new Rectangle2D.Double(0, 0, 0, 0); Point point = mousePressPoint = e.getPoint(); if (shape != null) { ControlPoint[] p = new ControlPointFactory().getControlPoints((Adjustable) shape, this); for (int i = 0; i < p.length; i++) { ControlPoint pt = p[i]; if (pt.hit(point.x, point.y)) { setSelectedControlPoint(pt); return; } } } boolean found = false; for (Primitive p : l) { if (p instanceof Vector) { Vector vector = (Vector) p; Shape shape = vector.toShape(); if (shape.contains(point.x, point.y)) { setSelectedShape(p); found = true; } } else if (p instanceof Volume) { Volume volume = (Volume) p; volume.getBounds(scratch); System.err.println(p); if (scratch.contains(point.x, point.y)) { setSelectedShape(p); found = true; } } } if (!found) { setSelectedShape(null); } }
private void showPopup(MouseEvent e) { Point point = e.getPoint(); List<Primitive> l = stack.getPrimitives(); Rectangle2D.Double scratch = new Rectangle2D.Double(0, 0, 0, 0); List<Primitive> shapes = new ArrayList<Primitive>(); List<Vector> vectors = new ArrayList<Vector>(); Primitive topMost = null; for (Primitive p : l) { if (p instanceof Vector) { Vector vector = (Vector) p; Shape shape = vector.toShape(); System.err.println(shape); if (shape.contains(point.x, point.y)) { topMost = vector; shapes.add(vector); vectors.add(vector); } } else if (p instanceof Volume) { Volume volume = (Volume) p; volume.getBounds(scratch); System.err.println(p); if (scratch.contains(point.x, point.y)) { topMost = volume; shapes.add(volume); } } } if (!shapes.isEmpty()) { assert topMost != null; JPopupMenu menu = new JPopupMenu(); menu.add(new FrontBackAction(true, topMost, stack)); menu.add(new FrontBackAction(false, topMost, stack)); menu.add(new CSGAction(UNION, vectors, stack)); menu.add(new CSGAction(INTERSECTION, vectors, stack)); menu.add(new CSGAction(SUBTRACTION, vectors, stack)); menu.add(new CSGAction(XOR, vectors, stack)); menu.show(repainter.getDialogParent(), point.x, point.y); } }