Exemplo n.º 1
0
 void calcLimits(int x1, int x2, int y1, int y2) {
   if (x1 < x2) {
     diag.maxX = Math.max(x2, diag.maxX);
     diag.minX = Math.min(x1, diag.minX);
   } else {
     diag.maxX = Math.max(x1, diag.maxX);
     diag.minX = Math.min(x2, diag.minX);
   }
   if (y1 < y2) {
     diag.maxY = Math.max(y2, diag.maxY);
     diag.minY = Math.min(y1, diag.minY);
   } else {
     diag.maxY = Math.max(y2, diag.maxY);
     diag.minY = Math.min(y1, diag.minY);
   }
 }
Exemplo n.º 2
0
  void buildArrow(HashMap<String, String> item) {
    String s;

    s = item.get("fromx").trim();
    fromX = Integer.parseInt(s);
    s = item.get("fromy").trim();
    fromY = Integer.parseInt(s);
    s = item.get("tox").trim();
    toX = Integer.parseInt(s);
    s = item.get("toy").trim();
    toY = Integer.parseInt(s);
    upStreamPort = item.get("upstreamport");
    downStreamPort = item.get("downstreamport");
    s = item.get("dropoldest");
    if (s != null) dropOldest = true;
    s = item.get("fromid").trim();
    fromId = Integer.parseInt(s);

    s = item.get("toid").trim();
    toId = Integer.parseInt(s);
    s = item.get("id");
    if (s == null) id = 0;
    else id = Integer.parseInt(s.trim());
    if (id == 0) id = diag.maxArrowNo + 1;

    diag.maxArrowNo = Math.max(id, diag.maxArrowNo);

    endsAtBlock = true;
    endsAtLine = false;
    s = item.get("fromside");
    if (s != null) {
      s = s.trim();
      if (s.equals("L")) fromSide = Side.LEFT;
      else if (s.equals("R")) fromSide = Side.RIGHT;
      else if (s.equals("T")) fromSide = Side.TOP;
      else if (s.equals("B")) fromSide = Side.BOTTOM;
    }
    s = item.get("toside");
    if (s != null) {
      s = s.trim();
      if (s.equals("L")) toSide = Side.LEFT;
      else if (s.equals("R")) toSide = Side.RIGHT;
      else if (s.equals("T")) toSide = Side.TOP;
      else if (s.equals("B")) toSide = Side.BOTTOM;
    }
  }
Exemplo n.º 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();
    // }
  }
Exemplo n.º 4
0
  void buildArrowPopupMenu() {
    diag.jpm = new JPopupMenu("            Arrow-related Actions");
    // driver.curPopup = jpm;
    diag.jpm.setVisible(true);
    JLabel label2 = new JLabel();
    label2.setText(diag.jpm.getLabel());
    label2.setFont(driver.fontg);
    // label2.setForeground(Color.BLUE);
    diag.jpm.add(label2);
    diag.jpm.addSeparator();
    JMenuItem menuItem;
    Block from = diag.blocks.get(new Integer(fromId));
    Block to = diag.blocks.get(new Integer(toId));
    if (!(from instanceof ExtPortBlock) && !(from instanceof IIPBlock)) {
      menuItem = new JMenuItem("Edit Upstream Port Name");
      menuItem.addActionListener(this);
      diag.jpm.add(menuItem);
    }
    if (!(to instanceof ExtPortBlock)) {
      menuItem = new JMenuItem("Edit Downstream Port Name");
      menuItem.addActionListener(this);
      diag.jpm.add(menuItem);
    }
    diag.jpm.addSeparator();
    menuItem = new JMenuItem("Set Capacity");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    menuItem = new JMenuItem("Remove Capacity");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    diag.jpm.addSeparator();
    menuItem = new JMenuItem("Toggle Upstream Port Automatic / Normal");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);

    menuItem = new JMenuItem("Toggle Downstream Port Automatic / Normal");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    diag.jpm.addSeparator();
    menuItem = new JMenuItem("Toggle DropOldest");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);

    diag.jpm.addSeparator();
    menuItem = new JMenuItem("Drag Tail");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    menuItem = new JMenuItem("Drag Head");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    menuItem = new JMenuItem("Drag New or Existing Bend");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    diag.jpm.addSeparator();
    menuItem = new JMenuItem("Add Extra Arrowhead");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);
    menuItem = new JMenuItem("Remove Extra Arrowhead");
    menuItem.addActionListener(this);
    diag.jpm.add(menuItem);

    diag.jpm.addSeparator();
    menuItem = new JMenuItem("Delete");
    diag.jpm.add(menuItem);
    menuItem.addActionListener(this);
    // menuItem = new JMenuItem("Exit");
    // jpm.add(menuItem);
    // menuItem.addActionListener(this);
    // diag.curMenuRect = new Rectangle(p.x, p.y, d.width, d.height);
    // return jpm;

  }