@Override public void mouseDragged(MouseEvent e) { if (resizing) { config.width = widthStart + (resizeStart - e.getXOnScreen()); if (config.width < 1) { config.width = 1; } configService.dispatch().configChanged(); } if (dragging) { // Disable animation when dragging for better experience. editor.getScrollingModel().disableAnimation(); editor .getScrollingModel() .scrollVertically( scrollStart + coords.pixelsToLines(e.getY() - mouseStart) * editor.getLineHeight()); editor.getScrollingModel().enableAnimation(); } }
void forwardEventToParent(MouseEvent e) { getParent() .dispatchEvent( new MouseEvent( getParent(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON)); }
@Override public void mousePressed(MouseEvent e) { if (!dragging && inResizeGutter(e.getX())) { resizing = true; } else if (!resizing) { dragging = true; } if (resizing) { resizeStart = e.getXOnScreen(); widthStart = config.width; } if (dragging) { Rectangle visibleArea = editor.getScrollingModel().getVisibleArea(); int firstVisibleLine = getMapYFromEditorY((int) visibleArea.getMinY()); int height = coords.linesToPixels( (int) ((visibleArea.getMaxY() - visibleArea.getMinY()) / editor.getLineHeight())); int panelY = e.getY() - getY(); if (config.jumpOnMouseDown && (panelY <= firstVisibleLine || panelY >= (firstVisibleLine + height))) { editor.getScrollingModel().disableAnimation(); editor .getScrollingModel() .scrollTo( editor.offsetToLogicalPosition( coords.screenSpaceToOffset(e.getY(), config.percentageBasedClick)), ScrollType.CENTER); editor.getScrollingModel().enableAnimation(); } scrollStart = editor.getScrollingModel().getVerticalScrollOffset(); mouseStart = e.getY(); } }
/** * When a MenuElement receives an event from a MouseListener, it should never process the event * directly. Instead all MenuElements should call this method with the event. * * @param event a MouseEvent object */ public void processMouseEvent(MouseEvent event) { int screenX, screenY; Point p; int i, c, j, d; Component mc; Rectangle r2; int cWidth, cHeight; MenuElement menuElement; MenuElement subElements[]; MenuElement path[]; Vector<MenuElement> tmp; int selectionSize; p = event.getPoint(); Component source = event.getComponent(); if ((source != null) && !source.isShowing()) { // This can happen if a mouseReleased removes the // containing component -- bug 4146684 return; } int type = event.getID(); int modifiers = event.getModifiers(); // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2 if ((type == MouseEvent.MOUSE_ENTERED || type == MouseEvent.MOUSE_EXITED) && ((modifiers & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0)) { return; } if (source != null) { SwingUtilities.convertPointToScreen(p, source); } screenX = p.x; screenY = p.y; tmp = (Vector<MenuElement>) selection.clone(); selectionSize = tmp.size(); boolean success = false; for (i = selectionSize - 1; i >= 0 && success == false; i--) { menuElement = (MenuElement) tmp.elementAt(i); subElements = menuElement.getSubElements(); path = null; for (j = 0, d = subElements.length; j < d && success == false; j++) { if (subElements[j] == null) continue; mc = subElements[j].getComponent(); if (!mc.isShowing()) continue; if (mc instanceof JComponent) { cWidth = mc.getWidth(); cHeight = mc.getHeight(); } else { r2 = mc.getBounds(); cWidth = r2.width; cHeight = r2.height; } p.x = screenX; p.y = screenY; SwingUtilities.convertPointFromScreen(p, mc); /** * Send the event to visible menu element if menu element currently in the selected path or * contains the event location */ if ((p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) { int k; if (path == null) { path = new MenuElement[i + 2]; for (k = 0; k <= i; k++) path[k] = (MenuElement) tmp.elementAt(k); } path[i + 1] = subElements[j]; MenuElement currentSelection[] = getSelectedPath(); // Enter/exit detection -- needs tuning... if (currentSelection[currentSelection.length - 1] != path[i + 1] && (currentSelection.length < 2 || currentSelection[currentSelection.length - 2] != path[i + 1])) { Component oldMC = currentSelection[currentSelection.length - 1].getComponent(); MouseEvent exitEvent = new MouseEvent( oldMC, MouseEvent.MOUSE_EXITED, event.getWhen(), event.getModifiers(), p.x, p.y, event.getXOnScreen(), event.getYOnScreen(), event.getClickCount(), event.isPopupTrigger(), MouseEvent.NOBUTTON); currentSelection[currentSelection.length - 1].processMouseEvent(exitEvent, path, this); MouseEvent enterEvent = new MouseEvent( mc, MouseEvent.MOUSE_ENTERED, event.getWhen(), event.getModifiers(), p.x, p.y, event.getXOnScreen(), event.getYOnScreen(), event.getClickCount(), event.isPopupTrigger(), MouseEvent.NOBUTTON); subElements[j].processMouseEvent(enterEvent, path, this); } MouseEvent mouseEvent = new MouseEvent( mc, event.getID(), event.getWhen(), event.getModifiers(), p.x, p.y, event.getXOnScreen(), event.getYOnScreen(), event.getClickCount(), event.isPopupTrigger(), MouseEvent.NOBUTTON); subElements[j].processMouseEvent(mouseEvent, path, this); success = true; event.consume(); } } } }