/** 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; } } } }
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); } } }
/** Clear the current selection. */ public void removeFromSelection(SelectableGraphElement element) { selection.remove(element); }