コード例 #1
0
  /** A menu popup trigger has been detected. Handle it. */
  public void handlePopupTrigger(MouseEvent evt) {
    int clickX = evt.getX();
    int clickY = evt.getY();

    SelectableGraphElement clickedElement = graph.findGraphElement(clickX, clickY);
    if (clickedElement != null) {
      selection.selectOnly(clickedElement);
      postMenu(clickedElement, clickX, clickY);
    } else {
      postMenu(clickX, clickY);
    }
  }
コード例 #2
0
  /** A mouse-pressed event. Analyse what we should do with it. */
  public void mousePressed(MouseEvent evt) {
    graphEditor.requestFocus();
    int clickX = evt.getX();
    int clickY = evt.getY();

    SelectableGraphElement clickedElement = graph.findGraphElement(clickX, clickY);
    notifyPackage(clickedElement);

    if (clickedElement == null) { // nothing hit
      if (!isMultiselectionKeyDown(evt)) {
        selection.clear();
      }
      if (isButtonOne(evt)) marquee.start(clickX, clickY);
    } else if (isButtonOne(evt)) { // clicked on something
      if (isMultiselectionKeyDown(evt)) {
        // a class was clicked, while multiselectionKey was down.
        if (clickedElement.isSelected()) {
          selection.remove(clickedElement);
        } else {
          selection.add(clickedElement);
        }
      } else {
        // a class was clicked without multiselection
        if (!clickedElement.isSelected()) {
          selection.selectOnly(clickedElement);
        }
      }

      if (isDrawingDependency()) {
        if (clickedElement instanceof Target)
          rubberBand = new RubberBand(clickX, clickY, clickX, clickY);
      } else {
        dragStartX = clickX;
        dragStartY = clickY;

        if (clickedElement.isHandle(clickX, clickY)) {
          resizing = true;
        } else {
          moving = true;
        }
      }
    }
  }
コード例 #3
0
 /**
  * Post the context menu of one selected element of the current selection. If any dependencies are
  * selected, show the menu for one of those. Otherwise show the menu for a randomly chosen target.
  */
 private void postMenu() {
   // first check whether we have selected edges
   Dependency dependency = (Dependency) selection.getAnyEdge();
   if (dependency != null) {
     Point p =
         ((GraphPainterStdImpl) GraphPainterStdImpl.getInstance())
             .getDependencyPainter(dependency)
             .getPopupMenuPosition(dependency);
     postMenu(dependency, p.x, p.y);
   } else {
     // if not, choose a target
     Vertex vertex = selection.getAnyVertex();
     if (vertex != null) {
       selection.selectOnly(vertex);
       int x = vertex.getX() + vertex.getWidth() - 20;
       int y = vertex.getY() + 20;
       postMenu(vertex, x, y);
     }
   }
 }
コード例 #4
0
  private void selectDependency(KeyEvent evt) {
    Vertex vertex = selection.getAnyVertex();
    if (vertex != null && vertex instanceof DependentTarget) {
      selection.selectOnly(vertex);
      List<Dependency> dependencies = ((DependentTarget) vertex).dependentsAsList();

      Dependency currentDependency = dependencies.get(currentDependencyIndex);
      if (currentDependency != null) {
        selection.remove(currentDependency);
      }
      currentDependencyIndex += (evt.getKeyCode() == KeyEvent.VK_PAGE_UP ? 1 : -1);
      currentDependencyIndex %= dependencies.size();
      if (currentDependencyIndex < 0) { // % is not a real modulo
        currentDependencyIndex = dependencies.size() - 1;
      }
      currentDependency = (Dependency) dependencies.get(currentDependencyIndex);
      if (currentDependency != null) {
        selection.add(currentDependency);
      }
    }
  }
コード例 #5
0
 /**
  * Move the current selection to another selected class, depending on current selection and the
  * key pressed.
  */
 private void navigate(KeyEvent evt) {
   Vertex currentTarget = findSingleVertex();
   currentTarget = traverseStragegiImpl.findNextVertex(graph, currentTarget, evt.getKeyCode());
   selection.selectOnly(currentTarget);
 }