コード例 #1
0
ファイル: MoveShapeTool.java プロジェクト: imagej/envisaje
 public void activate(Layer layer) {
   this.layer = layer;
   ShapeStack stack = (ShapeStack) layer.getLookup().lookup(ShapeStack.class);
   assert stack != null;
   this.stack = stack;
   if (repainter != null) {
     repainter.requestRepaint(layer.getBounds());
   }
 }
コード例 #2
0
ファイル: MoveShapeTool.java プロジェクト: imagej/envisaje
 public void paint(Graphics2D g, Rectangle layerBounds, boolean commit) {
   if (shape == null || stack == null) {
     return;
   }
   int full = 6;
   int half = 3;
   Rectangle2D.Double scratch = new Rectangle2D.Double(0, 0, full, full);
   g.setStroke(new BasicStroke(1F));
   int max = ((Adjustable) shape).getControlPointCount();
   double[] d = new double[max * 2];
   ((Adjustable) shape).getControlPoints(d);
   Point p = layer.getSurface().getLocation();
   for (int i = 0; i < d.length; i += 2) {
     d[i] -= p.x;
     d[i + 1] -= p.y;
     scratch.x = d[i] - half;
     scratch.y = d[i + 1] - half;
     g.setColor(Color.WHITE);
     g.fill(scratch);
     g.setColor(Color.BLACK);
     g.draw(scratch);
     if (cpoint != null && cpoint.getX() == d[i] && cpoint.getY() == d[i + 1]) {
       scratch.x -= 3;
       scratch.y -= 3;
       scratch.width += 6;
       scratch.height += 6;
       g.setColor(Color.YELLOW);
       g.draw(scratch);
     }
   }
 }
コード例 #3
0
ファイル: MoveShapeTool.java プロジェクト: imagej/envisaje
 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);
   }
 }
コード例 #4
0
ファイル: MoveShapeTool.java プロジェクト: imagej/envisaje
 public void attachRepainter(Repainter repainter) {
   this.repainter = repainter;
   if (layer != null) {
     repainter.requestRepaint(layer.getBounds());
   }
 }
コード例 #5
0
ファイル: MoveShapeTool.java プロジェクト: imagej/envisaje
 private void setSelectedShape(Primitive p) {
   if (this.shape != p) {
     this.shape = p;
     repainter.requestRepaint(layer.getBounds());
   }
 }