Example #1
0
 boolean touches(Block b, int x, int y) {
   DrawFBP.Side side = null;
   if (driver.nearpln(
       x, y, b.cx - b.width / 2, b.cy - b.height / 2, b.cx - b.width / 2, b.cy + b.height / 2)) {
     side = Side.LEFT;
   }
   if (driver.nearpln(
       x, y, b.cx - b.width / 2, b.cy - b.height / 2, b.cx + b.width / 2, b.cy - b.height / 2)) {
     side = Side.TOP;
   }
   if (driver.nearpln(
       x, y, b.cx + b.width / 2, b.cy - b.height / 2, b.cx + b.width / 2, b.cy + b.height / 2)) {
     side = Side.RIGHT;
   }
   if (driver.nearpln(
       x, y, b.cx - b.width / 2, b.cy + b.height / 2, b.cx + b.width / 2, b.cy + b.height / 2)) {
     side = Side.BOTTOM;
   }
   if (side != null) {
     if (tailMarked) fromSide = side;
     if (headMarked) toSide = side;
     return true;
   }
   return false;
 }
Example #2
0
  void createBend(int bendx, int bendy) {
    Bend bn = null;
    int index = 0;
    if (bends == null) {
      if (driver.nearpln(bendx, bendy, fromX, fromY, toX, toY)) {
        bends = new LinkedList<Bend>();
        bn = new Bend(bendx, bendy);
        if (fromX == toX) // if line vertical
        bn.x = fromX;
        if (fromY == toY) // if line horizontal
        bn.y = fromY;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
        return;
      }
    } else {
      int x = fromX;
      int y = fromY;
      Object[] oa = bends.toArray();
      for (Object o : oa) {
        Bend b = (Bend) o;
        if (sameBend(bendx, bendy, b)) {
          bn = b;
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        if (driver.nearpln(bendx, bendy, x, y, b.x, b.y)) {
          bn = new Bend(bendx, bendy);
          if (x == b.x) // if line vertical
          bn.x = x;
          if (y == b.y) // if line horizontal
          bn.y = y;
          bends.add(index, bn);
          bn.marked = true;
          driver.bendForDragging = bn;
          return;
        }
        x = b.x;
        y = b.y;
        index++;
      }

      if (driver.nearpln(bendx, bendy, x, y, toX, toY)) {
        bn = new Bend(bendx, bendy);
        if (x == toX) // if line vertical
        bn.x = x;
        if (y == toY) // if line horizontal
        bn.y = y;
        bends.add(bn);
        bn.marked = true;
        driver.bendForDragging = bn;
      }
    }
  }
Example #3
0
  public void actionPerformed(ActionEvent e) {
    String s = e.getActionCommand();

    diag.jpm = null;

    if (s.equals("Edit Upstream Port Name")) {

      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit upstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  upStreamPort);

      if (ans != null /* && ans.length() > 0 */) {
        Block b = diag.blocks.get(new Integer(fromId));
        // upStreamPort = ans;
        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == fromId
                  && a.upStreamPort != null
                  && a.upStreamPort.equals(ans)
                  && !(upStreamPort.equals(ans))
              || a.toId == fromId && a.downStreamPort != null && a.downStreamPort.equals(ans))
            found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // upStreamPort = "";
          // return;
        }
        upStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_IN_BLOCK) || b instanceof IIPBlock) {
          MyOptionPane.showMessageDialog(driver.frame, "Upstream port must be blank");
          upStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Edit Downstream Port Name") && endsAtBlock) {
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Edit downstream port name",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  downStreamPort);

      if (ans != null /* && ans.length() > 0 */) {

        Block b = diag.blocks.get(new Integer(toId));

        diag.changed = true;
        boolean found = false;
        for (Arrow a : diag.arrows.values()) {
          if (a.fromId == toId && a.upStreamPort != null && a.upStreamPort.equals(ans)
              || a.toId == toId
                  && a.downStreamPort != null
                  && a.downStreamPort.equals(ans)
                  && !(downStreamPort.equals(ans))) found = true;
        }
        if (found) {
          MyOptionPane.showMessageDialog(driver.frame, "Duplicate port name: " + ans);
          // downStreamPort = "";
          // return;
        }

        downStreamPort = ans;

        if (b.type.equals(Block.Types.EXTPORT_OUT_BLOCK)) {
          MyOptionPane.showMessageDialog(driver.frame, "Downstream port must be blank");
          downStreamPort = "";
        }
      }
      driver.frame.repaint();

    } else if (s.equals("Set Capacity")) {

      String capString = null;
      if (capacity == 0) capString = "";
      else capString = Integer.toString(capacity);
      String ans =
          (String)
              MyOptionPane.showInputDialog(
                  driver.frame,
                  "Enter or change text",
                  "Set Capacity",
                  JOptionPane.PLAIN_MESSAGE,
                  null,
                  null,
                  capString);
      if ((ans != null) && (ans.length() > 0)) {
        capacity = Integer.parseInt(ans);
        if (capLegend == null) {
          diag.xa = 2; // get around fudge in DrawFBP
          diag.ya = 2; // get around fudge in DrawFBP
          capLegend = (LegendBlock) diag.driver.createBlock(Block.Types.LEGEND_BLOCK, false);

          int x = toX;
          int y = toY;
          if (bends != null) {
            Bend bd = bends.peek();
            x = bd.x;
            y = bd.y;
          }

          capLegend.cx = (fromX + x) / 2;
          capLegend.cy = (fromY + y) / 2 + 20;
          if (fromX == x) capLegend.cx -= 20;
        }
        capLegend.description = "(" + capacity + ")";
      }
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Remove Capacity")) {
      capacity = 0;
      diag.delBlock(capLegend, false);
      capLegend = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Upstream Port Automatic / Normal")) {
      if (upStreamPort == null || !upStreamPort.equals("*")) upStreamPort = "*";
      else upStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle Downstream Port Automatic / Normal")) {
      if (downStreamPort == null || !downStreamPort.equals("*")) downStreamPort = "*";
      else downStreamPort = null;
      driver.frame.repaint();
      diag.changed = true;

    } else if (s.equals("Toggle DropOldest")) {
      dropOldest = !dropOldest;

    } else if (s.equals("Drag Tail")) {
      tailMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag Head")) {
      headMarked = true;
      driver.arrowEndForDragging = this;

    } else if (s.equals("Drag New or Existing Bend")) {
      createBend(driver.curx, driver.cury);

    } else if (s.equals("Add Extra Arrowhead")) {
      Point p = new Point(driver.curx, driver.cury);
      int fx = fromX;
      int fy = fromY;
      int tx, ty;
      if (bends != null) {
        for (Bend bend : bends) {
          tx = bend.x;
          ty = bend.y;
          if (pointInLine(p, fx, fy, tx, ty)) {
            extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
            return;
          }
          fx = tx;
          fy = ty;
        }
      }
      tx = toX;
      ty = toY;
      if (pointInLine(p, fx, fy, tx, ty))
        extraArrowhead = new Arrowhead(fx, fy, driver.curx, driver.cury);
      return;

    } else if (s.equals("Remove Extra Arrowhead")) {
      extraArrowhead = null;
      return;

    } else if (s.equals("Delete")) {

      if (JOptionPane.YES_OPTION
          == MyOptionPane.showConfirmDialog(
              driver.frame,
              "Do you want to delete this arrow?",
              "Delete arrow",
              JOptionPane.YES_NO_OPTION)) {
        diag.delArrow(this);

        diag.changed = true;
        diag.currentArrow = null;
      }

      driver.frame.repaint();
      diag.foundArrow = null;
    }
    // if (s.equals("Exit")) {
    //	diag.foundArrow = null;
    //	driver.frame.repaint();
    // }
  }