예제 #1
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();
   }
 }
 /**
  * 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);
 }
 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);
    }
  }