Esempio n. 1
0
 /** Brings a figure to the front. */
 public synchronized void bringToFront(Figure figure) {
   if (fFigures.contains(figure)) {
     fFigures.removeElement(figure);
     fFigures.addElement(figure);
     figure.changed();
   }
 }
Esempio n. 2
0
 /** Sends a figure to the back of the drawing. */
 public synchronized void sendToBack(Figure figure) {
   if (fFigures.contains(figure)) {
     fFigures.removeElement(figure);
     fFigures.insertElementAt(figure, 0);
     figure.changed();
   }
 }
Esempio n. 3
0
  @Override
  public void keyPressed(KeyEvent evt) {
    Figure f = getOwner();
    if (f.isTransformable()) {
      AffineTransform tx = new AffineTransform();

      switch (evt.getKeyCode()) {
        case KeyEvent.VK_UP:
          tx.translate(0, -1);
          evt.consume();
          break;
        case KeyEvent.VK_DOWN:
          tx.translate(0, +1);
          evt.consume();
          break;
        case KeyEvent.VK_LEFT:
          tx.translate(-1, 0);
          evt.consume();
          break;
        case KeyEvent.VK_RIGHT:
          tx.translate(+1, 0);
          evt.consume();
          break;
      }
      f.willChange();
      f.transform(tx);
      f.changed();
      fireUndoableEditHappened(new TransformEdit(f, tx));
    }
  }
Esempio n. 4
0
  public Rectangle2D.Double layout(
      CompositeFigure compositeFigure, Point2D.Double anchor, Point2D.Double lead) {
    Rectangle2D.Double bounds = null;

    for (Figure child : compositeFigure.getChildren()) {
      Locator locator = getLocator(child);

      Rectangle2D.Double r;
      if (locator == null) {
        r = child.getBounds();
      } else {
        Point2D.Double p = locator.locate(compositeFigure, child);
        Dimension2DDouble d = child.getPreferredSize();
        r = new Rectangle2D.Double(p.x, p.y, d.width, d.height);
      }
      child.willChange();
      child.setBounds(
          new Point2D.Double(r.getMinX(), r.getMinY()),
          new Point2D.Double(r.getMaxX(), r.getMaxY()));
      child.changed();
      if (!r.isEmpty()) {
        if (bounds == null) {
          bounds = r;
        } else {
          bounds.add(r);
        }
      }
    }

    return (bounds == null) ? new Rectangle2D.Double() : bounds;
  }
Esempio n. 5
0
 /** Replaces a figure in the drawing without removing it from the drawing. */
 public synchronized void replace(Figure figure, Figure replacement) {
   int index = fFigures.indexOf(figure);
   if (index != -1) {
     replacement.addToContainer(this); // will invalidate figure
     figure.changed();
     fFigures.setElementAt(replacement, index);
   }
 }
Esempio n. 6
0
  @Override
  public void trackStep(Point anchor, Point lead, int modifiersEx) {
    Figure f = getOwner();
    if (f.isTransformable()) {
      Point2D.Double newPoint = view.getConstrainer().constrainPoint(view.viewToDrawing(lead));
      AffineTransform tx = new AffineTransform();
      tx.translate(newPoint.x - oldPoint.x, newPoint.y - oldPoint.y);
      f.willChange();
      f.transform(tx);
      f.changed();

      oldPoint = newPoint;
    }
  }