Ejemplo n.º 1
0
  @Override
  public void mouseDragged(
      final MouseEvent me,
      final Layer la,
      final int x_p,
      final int y_p,
      int x_d,
      int y_d,
      int x_d_old,
      int y_d_old) {
    final int tool = ProjectToolbar.getToolId();
    if (ProjectToolbar.PEN != tool) return;

    // transform to the local coordinates
    if (!this.at.isIdentity()) {
      // final Point2D.Double p = inverseTransformPoint(x_p, y_p);
      // x_p = (int)p.x;
      // y_p = (int)p.y;
      final Point2D.Double pd = inverseTransformPoint(x_d, y_d);
      x_d = (int) pd.x;
      y_d = (int) pd.y;
      final Point2D.Double pdo = inverseTransformPoint(x_d_old, y_d_old);
      x_d_old = (int) pdo.x;
      y_d_old = (int) pdo.y;
    }

    if (-1 != index) {
      if (me.isShiftDown()) {
        // resize
        item.radius =
            (int)
                Math.ceil(
                    Math.sqrt(
                        (x_d - item.p[0][index]) * (x_d - item.p[0][index])
                            + (y_d - item.p[1][index]) * (y_d - item.p[1][index])));
        if (item.radius < 1) item.radius = 1;
      } else {
        item.translate(index, x_d - x_d_old, y_d - y_d_old);
      }
      Rectangle repaint_bbox = bbox;
      final Rectangle current_bbox =
          this.at.createTransformedShape(item.getBoundingBox()).getBounds();
      if (null == bbox) repaint_bbox = current_bbox;
      else {
        repaint_bbox = (Rectangle) bbox.clone();
        repaint_bbox.add(current_bbox);
      }
      bbox = current_bbox;
      Display.repaint(layer_set, repaint_bbox);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void mousePressed(
      final MouseEvent me, final Layer la, int x_p, int y_p, final double mag) {
    final int tool = ProjectToolbar.getToolId();
    if (ProjectToolbar.PEN != tool) return;

    final long lid = la.getId(); // isn't this.layer pointing to the current layer always?

    // transform the x_p, y_p to the local coordinates
    if (!this.at.isIdentity()) {
      final Point2D.Double p = inverseTransformPoint(x_p, y_p);
      x_p = (int) p.x;
      y_p = (int) p.y;
    }

    // find if the click is within radius of an existing point for the current layer
    for (final Item tmp : al_items) {
      index = tmp.find(lid, x_p, y_p, mag);
      if (-1 != index) {
        this.item = tmp;
        break;
      }
    }

    // final boolean is_zoom_invariant = "true".equals(project.getProperty("dissector_zoom"));

    // TODO: if zoom invariant, should check for nearest point. Or nearest point anyway, when
    // deleting
    // (but also for adding a new one?)

    if (me.isShiftDown() && Utils.isControlDown(me)) {
      if (-1 != index) {
        // delete
        item.remove(index);
        if (0 == item.n_points) al_items.remove(item);
        item = null;
        index = -1;
        Display.repaint(layer_set, this, 0);
      }
      // in any case:
      return;
    }
    if (-1 != index) return;
    // else try to add a point to a suitable item
    // Find an item in the previous or the next layer,
    //     which falls within radius of the clicked point
    try {
      for (final Item tmp : al_items) {
        index = tmp.add(x_p, y_p, la);
        if (-1 != index) {
          this.item = tmp;
          return;
        }
      }
      // could not be added to an existing item, so creating a new item with a new point in it
      int max_tag = 0;
      for (final Item tmp : al_items) {
        if (tmp.tag > max_tag) max_tag = tmp.tag;
      }
      int radius = 8; // default
      if (al_items.size() > 0) radius = al_items.get(al_items.size() - 1).radius;
      this.item = new Item(max_tag + 1, radius, x_p, y_p, la);
      index = 0;
      al_items.add(this.item);
    } finally {
      if (null != item) {
        bbox = this.at.createTransformedShape(item.getBoundingBox()).getBounds();
        Display.repaint(layer_set, bbox);
      } else Display.repaint(layer_set, this, 0);
    }
  }