Example #1
0
 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);
   }
 }
Example #2
0
 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);
   }
 }