/**
   * Action method invoked when an event triggers this action.
   *
   * <p>The {@link #_compartment} instance variable defines the action to take, and the {@link
   * #_display} instance variable whether it should set visibility or note.
   *
   * <p><em>Note</em>. The {@link #_display} instance variable is really redundant. Its value is
   * implied by the operation.
   *
   * @param ae The event that triggered us.
   */
  public void actionPerformed(ActionEvent ae) {

    // Only do anything if we have a single item selected (surely this
    // should work for multiple selections as well?).

    Vector sels = Globals.curEditor().getSelectionManager().selections();

    if (sels.size() == 1) {
      Selection sel = (Selection) sels.firstElement();
      Fig f = sel.getContent();

      // Perform the action

      if (_compartment.equals("Show Attribute Compartment")) {
        ((FigClass) f).setAttributeVisible(_display);
      } else if (_compartment.equals("Hide Attribute Compartment")) {
        ((FigClass) f).setAttributeVisible(_display);
      } else if (_compartment.equals("Show Operation Compartment")
          || _compartment.equals("Hide Operation Compartment")) {
        if (f instanceof FigClass) ((FigClass) f).setOperationVisible(_display);
        if (f instanceof FigInterface) ((FigInterface) f).setOperationVisible(_display);
      } else if (_compartment.equals("Show Extension Point Compartment")) {
        ((FigUseCase) f).setExtensionPointVisible(_display);
      } else if (_compartment.equals("Hide Extension Point Compartment")) {
        ((FigUseCase) f).setExtensionPointVisible(_display);
      } else if (_compartment.equals("Show All Compartments")) {
        ((FigClass) f).setAttributeVisible(_display);
        ((FigClass) f).setOperationVisible(_display);
      } else {
        ((FigClass) f).setAttributeVisible(_display);
        ((FigClass) f).setOperationVisible(_display);
      }
    }
  }
  // TODO: Move to different class?
  public static void jumpToDiagramShowing(List targets) {

    if (targets == null || targets.size() == 0) {
      return;
    }
    Object first = targets.get(0);
    if (first instanceof ArgoDiagram && targets.size() > 1) {
      setTarget(first);
      setTarget(targets.get(1));
      return;
    }
    if (first instanceof ArgoDiagram && targets.size() == 1) {
      setTarget(first);
      return;
    }

    // TODO: This should get the containing project from the list of
    // targets, not from some global
    Project project = ProjectManager.getManager().getCurrentProject();
    if (project == null) {
      return;
    }

    List<ArgoDiagram> diagrams = project.getDiagramList();
    Object target = TargetManager.getInstance().getTarget();
    if ((target instanceof ArgoDiagram)
        && ((ArgoDiagram) target).countContained(targets) == targets.size()) {
      setTarget(first);
      return;
    }

    ArgoDiagram bestDiagram = null;
    int bestNumContained = 0;
    for (ArgoDiagram d : diagrams) {
      int nc = d.countContained(targets);
      if (nc > bestNumContained) {
        bestNumContained = nc;
        bestDiagram = d;
      }
      if (nc == targets.size()) {
        break;
      }
    }
    if (bestDiagram != null) {
      if (!DiagramUtils.getActiveDiagram().equals(bestDiagram)) {
        setTarget(bestDiagram);
      }
      setTarget(first);
    }
    // making it possible to jump to the modelroots
    if (project.getRoots().contains(first)) {
      setTarget(first);
    }

    // and finally, adjust the scrollbars to show the Fig
    Object f = TargetManager.getInstance().getFigTarget();
    if (f instanceof Fig) {
      Globals.curEditor().scrollToShow((Fig) f);
    }
  }
  @Override
  public void actionPerformed(ActionEvent ae) {
    super.actionPerformed(ae);
    Editor ce = Globals.curEditor();
    GraphModel gm = ce.getGraphModel();
    if (!(gm instanceof MutableGraphModel)) {
      return;
    }

    String instructions = Translator.localize("misc.message.click-on-diagram-to-add");
    Globals.showStatus(instructions);

    final ModeAddToDiagram placeMode = new ModeAddToDiagram(objects, instructions);

    Globals.mode(placeMode, false);
  }
  /*
   * @see org.tigris.gef.base.SelectionButtons#paintButtons(Graphics)
   */
  public void paintButtons(Graphics g) {
    final Mode topMode = Globals.curEditor().getModeManager().top();
    if (!(topMode instanceof ModePlace)) {
      // If the user has selected ModePlace either by a diagram
      // tool or AddToDiagram then we don't want to show the
      // toolbelt items.
      Icon[] icons = getIcons();
      if (icons == null) {
        return;
      }
      int cx = getContent().getX();
      int cy = getContent().getY();
      int cw = getContent().getWidth();
      int ch = getContent().getHeight();

      if (icons[0] != null) {
        paintButtonAbove(icons[0], g, cx + cw / 2, cy - OFFSET, TOP);
      }
      if (icons[1] != null) {
        paintButtonBelow(icons[1], g, cx + cw / 2, cy + ch + OFFSET, BOTTOM);
      }
      if (icons[2] != null) {
        paintButtonLeft(icons[2], g, cx - OFFSET, cy + ch / 2, LEFT);
      }
      if (icons[3] != null) {
        paintButtonRight(icons[3], g, cx + cw + OFFSET, cy + ch / 2, RIGHT);
      }
      if (icons[4] != null) {
        paintButtonLeft(icons[4], g, cx - OFFSET, cy + ch, LOWER_LEFT);
      }
    }
  }
  /** @see org.tigris.gef.presentation.Fig#getTipString(java.awt.event.MouseEvent) */
  public String getTipString(MouseEvent me) {
    // #if defined(COGNITIVE)
    // @#$LPS-COGNITIVE:GranularityType:Statement
    // @#$LPS-COGNITIVE:Localization:StartMethod
    ToDoItem item = hitClarifier(me.getX(), me.getY());
    // #endif
    String tip = "";
    // #if defined(COGNITIVE)
    // @#$LPS-COGNITIVE:GranularityType:Statement
    if (item != null && Globals.curEditor().getSelectionManager().containsFig(this)) {
      tip = item.getHeadline();
    } else
    // #endif
    if (getOwner() != null) {
      try {
        tip = Model.getFacade().getTipString(getOwner());
      } catch (InvalidElementException e) {
        // We moused over an object just as it was deleted
        // transient condition - doesn't require I18N
        LOG.warn("A deleted element still exists on the diagram");
        return Translator.localize("misc.name.deleted");
      }
    } else {
      tip = toString();
    }

    if (tip != null && tip.length() > 0 && !tip.endsWith(" ")) {
      tip += " ";
    }
    return tip;
  }
示例#6
0
 /** @see org.tigris.gef.presentation.Fig#translate(int, int) */
 public void translate(int dx, int dy) {
   super.translate(dx, dy);
   Editor ce = Globals.curEditor();
   Selection sel = ce.getSelectionManager().findSelectionFor(this);
   if (sel instanceof SelectionClass) {
     ((SelectionClass) sel).hideButtons();
   }
 }
 public void actionPerformed(ActionEvent e) {
   Editor ce = Globals.curEditor();
   Guide guide = ce.getGuide();
   if (guide instanceof GuideGrid) {
     ((GuideGrid) guide).gridSize(guideSize);
     Configuration.setString(Argo.KEY_SNAP, (String) getValue("ID"));
   }
 }
 /**
  * Enabled the remove action if an item is selected in anything other then the activity or state
  * diagrams.
  */
 private void determineRemoveEnabled() {
   Editor editor = Globals.curEditor();
   Collection figs = editor.getSelectionManager().getFigs();
   boolean removeEnabled = !figs.isEmpty();
   GraphModel gm = editor.getGraphModel();
   if (gm instanceof UMLMutableGraphSupport) {
     removeEnabled = ((UMLMutableGraphSupport) gm).isRemoveFromDiagramAllowed(figs);
   }
   removeFromDiagram.setEnabled(removeEnabled);
 }
 /**
  * @param f the fig to indicate the bounds of
  * @param g the graphics
  */
 protected void indicateBounds(FigText f, Graphics g) {
   String text = f.getText();
   if (text == null || text.length() == 0) {
     Rectangle rect = f.getBounds();
     Color c = g.getColor();
     g.setColor(Globals.getPrefs().handleColorFor(f));
     g.drawRect(rect.x, rect.y, rect.width, rect.height);
     g.setColor(c); // TODO: Is this needed?
   }
 }
 /*
  * @see org.tigris.gef.base.SelectionButtons#paint(java.awt.Graphics)
  */
 @Override
 public void paint(Graphics g) {
   final Mode topMode = Globals.curEditor().getModeManager().top();
   if (!(topMode instanceof ModePlace)) {
     // If the user has selected ModePlace either by a diagram
     // tool or AddToDiagram then we don't want to show the
     // clarifiers.
     ((Clarifiable) getContent()).paintClarifiers(g);
   }
   super.paint(g);
 }
 /*
  * @see org.tigris.gef.graph.GraphFactory#makeNode()
  */
 public Object makeNode() {
   Object node = null;
   Editor ce = Globals.curEditor();
   GraphModel gm = ce.getGraphModel();
   if (gm instanceof CollabDiagramGraphModel) {
     Object collaboration = ((CollabDiagramGraphModel) gm).getHomeModel();
     node = Model.getCollaborationsFactory().buildClassifierRole(collaboration);
   } else {
     throw new IllegalStateException("Graphmodel is not a " + "collaboration diagram graph model");
   }
   return node;
 }
示例#12
0
  /** The main constructor. */
  public FigFinalState() {
    super();
    setEditable(false);
    Color handleColor = Globals.getPrefs().getHandleColor();
    FigCircle bigPort = new FigCircle(X, Y, WIDTH, HEIGHT, Color.black, Color.white);
    inCircle = new FigCircle(X + 5, Y + 5, WIDTH - 10, HEIGHT - 10, handleColor, Color.black);

    bigPort.setLineWidth(1);
    inCircle.setLineWidth(0);

    addFig(bigPort);
    addFig(inCircle);
    setBigPort(bigPort);

    setBlinkPorts(false); // make port invisble unless mouse enters
  }
示例#13
0
  public void selectionChanged(GraphSelectionEvent selectionEvent) {
    removeAll();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    if (selectionEvent.getSelections().size() == 0) {
      Layer lay = Globals.curEditor().getLayerManager().getActiveLayer();
      for (Object o : lay.getContents()) {
        addFig((Fig) o, rootNode, false);
      }
    } else if (selectionEvent.getSelections().size() == 1) {
      addFig((Fig) selectionEvent.getSelections().get(0), rootNode, true);
    }

    FigTree tree = new FigTree(rootNode);
    tree.setRootVisible(false);
    tree.expandAll();

    JScrollPane scroller = new JScrollPane(tree);
    add(scroller);
  }
示例#14
0
  /*
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  @Override
  public void actionPerformed(ActionEvent ae) {
    super.actionPerformed(ae);
    List sels = Globals.curEditor().getSelectionManager().selections();
    if (sels.size() == 1) {
      Selection sel = (Selection) sels.get(0);
      Fig f = sel.getContent();
      Object owner = ((FigEdgeModelElement) f).getOwner();
      Collection ascEnds = Model.getFacade().getConnections(owner);
      Iterator iter = ascEnds.iterator();
      Object ascEnd = null;
      if (str.equals("src")) {
        ascEnd = iter.next();
      } else {
        while (iter.hasNext()) {
          ascEnd = iter.next();
        }
      }

      if (!mult.equals(Model.getFacade().toString(Model.getFacade().getMultiplicity(ascEnd)))) {
        Model.getCoreHelper().setMultiplicity(ascEnd, (String) mult);
      }
    }
  }
  /*
   * @see org.tigris.gef.base.Selection#dragHandle(int, int, int, int,
   * org.tigris.gef.presentation.Handle)
   */
  public void dragHandle(int mX, int mY, int anX, int anY, Handle hand) {

    // Don't allow drag outside of bounds of diagram
    mX = Math.max(mX, 0);
    mY = Math.max(mY, 0);

    if (hand.index < 10) {
      setPaintButtons(false);
      super.dragHandle(mX, mY, anX, anY, hand);
      return;
    }
    if (!isDraggableHandle(hand.index)) {
      return;
    }
    int cx = getContent().getX(), cy = getContent().getY();
    int cw = getContent().getWidth(), ch = getContent().getHeight();

    int bx = mX, by = mY;

    // Remember what handle was clicked for the case where the drag
    // is released over empty space
    button = hand.index;

    switch (hand.index) {
      case TOP:
        by = cy;
        bx = cx + cw / 2;
        break;
      case BOTTOM:
        by = cy + ch;
        bx = cx + cw / 2;
        break;
      case LEFT:
        by = cy + ch / 2;
        bx = cx;
        break;
      case RIGHT:
        by = cy + ch / 2;
        bx = cx + cw;
        break;
      case LOWER_LEFT:
        by = cy + ch;
        bx = cx;
        break;
      default:
        LOG.log(Level.WARNING, "invalid handle number");
        break;
    }

    Object nodeType = getNewNodeType(hand.index);
    Object edgeType = getNewEdgeType(hand.index);
    boolean reverse = isReverseEdge(hand.index);

    if (edgeType != null && nodeType != null) {
      Editor ce = Globals.curEditor();
      ModeCreateEdgeAndNode m =
          getNewModeCreateEdgeAndNode(ce, edgeType, isEdgePostProcessRequested(), this);
      m.setup((FigNode) getContent(), getContent().getOwner(), bx, by, reverse);
      ce.pushMode(m);
    }
  }
示例#16
0
 /** Constructor. */
 private FigInspectorPanel() {
   Globals.curEditor().getSelectionManager().addGraphSelectionListener(this);
   setLayout(new BorderLayout());
 }
 public void mousePressed(MouseEvent me) {
   super.mousePressed(me);
   Editor ce = Globals.curEditor();
   Selection sel = ce.getSelectionManager().findSelectionFor(this);
   if (sel instanceof SelectionComponentInstance) ((SelectionComponentInstance) sel).hideButtons();
 }
  /**
   * Compute handle selection, if any, from cursor location.
   *
   * @param cursor cursor point represented by a 0-size rectangle
   * @param h handle in which to return selected Handle information (output parameter). A handle
   *     index of -1 indicates that the cursor is not over any handle.
   *     <p>If GEF had any API documentation you could see the following:
   * @see org.tigris.gef.base.SelectionResize#hitHandle(java.awt.Rectangle,
   *     org.tigris.gef.presentation.Handle)
   */
  public void hitHandle(Rectangle cursor, Handle h) {
    super.hitHandle(cursor, h);
    if (h.index != -1) {
      // super implementation found a hit
      return;
    }
    if (!isPaintButtons()) {
      return;
    }
    Icon[] icons = getIcons();
    if (icons == null) {
      return;
    }
    Editor ce = Globals.curEditor();
    SelectionManager sm = ce.getSelectionManager();
    if (sm.size() != 1) {
      return;
    }
    ModeManager mm = ce.getModeManager();
    if (mm.includes(ModeModify.class) && getPressedButton() == -1) {
      return;
    }
    int cx = getContent().getX();
    int cy = getContent().getY();
    int cw = getContent().getWidth();
    int ch = getContent().getHeight();

    /*
     * Crazy numbering scheme at work here.  Here's how the handle numbers
     * are laid out.  Values 0-7 are defined by GEF and go left to
     * right, top to bottom (ie not clockwise or counterclockwise).
     * Values 10-14 zigzag North, South, West, East, Southwest.
     * If you can correctly guess where 15 will go, you should buy
     * a lottery ticket immediately.
     *  <pre>
     *            10
     *     0-------1-------2
     *     |               |
     *  12 3               4 13
     *     |               |
     *  14 5-------6-------7
     *            11
     * </pre>
     */
    if (icons[0] != null
        && hitAbove(cx + cw / 2, cy, icons[0].getIconWidth(), icons[0].getIconHeight(), cursor)) {
      h.index = TOP;
    } else if (icons[1] != null
        && hitBelow(
            cx + cw / 2, cy + ch, icons[1].getIconWidth(), icons[1].getIconHeight(), cursor)) {
      h.index = BOTTOM;
    } else if (icons[2] != null
        && hitLeft(cx, cy + ch / 2, icons[2].getIconWidth(), icons[2].getIconHeight(), cursor)) {
      h.index = LEFT;
    } else if (icons[3] != null
        && hitRight(
            cx + cw, cy + ch / 2, icons[3].getIconWidth(), icons[3].getIconHeight(), cursor)) {
      h.index = RIGHT;
    } else if (icons[4] != null
        && hitLeft(cx, cy + ch, icons[4].getIconWidth(), icons[4].getIconHeight(), cursor)) {
      h.index = LOWER_LEFT;
    } else {
      h.index = -1;
    }
    if (h.index == -1) {
      h.instructions = getInstructions(15);
    } else {
      h.instructions = getInstructions(h.index);
    }
  }