Пример #1
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();
    // }
  }
Пример #2
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;

  }