📄 clickzoomwirelistener.java
字号:
} } /** * Method to examine load the "worstFrom" and "worstTo" field variables with the * closest two points on two polygons. * @param from one of the Polys to examine. * @param to the other Poly to examine. */ private void findClosestPoints(Poly from, Poly to) { // if both are manhattan, use special cases Rectangle2D fromBox = from.getBox(); Rectangle2D toBox = to.getBox(); if (fromBox != null && toBox != null) { if (fromBox.getMinX() < toBox.getMaxX() && fromBox.getMaxX() > toBox.getMinX()) { // one above the other: find Y distance double xPos = (Math.max(fromBox.getMinX(), toBox.getMinX()) + Math.min(fromBox.getMaxX(), toBox.getMaxX())) / 2; if (fromBox.getMinY() > toBox.getMaxY()) { // from is above to worstFrom.setLocation(xPos, fromBox.getMinY()); worstTo.setLocation(xPos, toBox.getMaxY()); return; } if (toBox.getMinY() > fromBox.getMaxY()) { // to is above from worstFrom.setLocation(xPos, fromBox.getMaxY()); worstTo.setLocation(xPos, toBox.getMinY()); return; } return; } if (fromBox.getMinY() < toBox.getMaxY() && fromBox.getMaxY() > toBox.getMinY()) { // one next to the other: find X distance double yPos = (Math.max(fromBox.getMinY(), toBox.getMinY()) + Math.min(fromBox.getMaxY(), toBox.getMaxY())) / 2; if (fromBox.getMinX() > toBox.getMaxX()) { // from is above to worstFrom.setLocation(fromBox.getMinX(), yPos); worstTo.setLocation(toBox.getMaxX(), yPos); return; } if (toBox.getMinX() > fromBox.getMaxX()) { // to is above from worstFrom.setLocation(fromBox.getMaxX(), yPos); worstTo.setLocation(toBox.getMinX(), yPos); return; } return; } } // use generalized algorithm double minPD = 0; Point2D [] fromPoints = from.getPoints(); for(int f=0; f<fromPoints.length; f++) { Point2D c = to.closestPoint(fromPoints[f]); double pd = c.distance(fromPoints[f]); if (f != 0 && pd >= minPD) continue; minPD = pd; worstFrom.setLocation(fromPoints[f]); } minPD = 0; Point2D [] toPoints = to.getPoints(); for(int t=0; t<toPoints.length; t++) { double pd = worstFrom.distance(toPoints[t]); if (t != 0 && pd >= minPD) continue; minPD = pd; worstTo.setLocation(toPoints[t]); } } } /** Handle mouse released event * * @param evt the MouseEvent */ public void mouseReleased(MouseEvent evt) { if (debug) System.out.println(" ["+modeLeft+","+modeRight+"] "+evt.paramString()); if (evt.getSource() instanceof EditWindow) { EditWindow wnd = (EditWindow)evt.getSource(); Highlighter highlighter = wnd.getHighlighter(); Cell cell = wnd.getCell(); if (cell == null) return; if (cell != startCell) { escapePressed(wnd); return; } // add back in offset int releaseX = evt.getX(); int releaseY = evt.getY(); Point2D dbMouse = wnd.screenToDatabase(releaseX, releaseY); boolean another = (evt.getModifiersEx()&MouseEvent.CTRL_DOWN_MASK) != 0; specialSelect = ToolBar.isSelectSpecial(); // ===== Right Mouse Release ===== if (isRightMouse(evt)) { if (modeRight == Mode.zoomIn) { // zoom in by a factor of two double scale = wnd.getScale(); wnd.setScale(scale * 2); wnd.clearDoingAreaDrag(); wnd.getSavedFocusBrowser().saveCurrentFocus(); wnd.fullRepaint(); } if (modeRight == Mode.zoomOut) { // zoom out by a factor of two double scale = wnd.getScale(); wnd.setScale(scale / 2); if (wnd.isInPlaceEdit()) wnd.getInPlaceTransformOut().transform(dbMouse, dbMouse); wnd.setOffset(dbMouse); wnd.clearDoingAreaDrag(); wnd.getSavedFocusBrowser().saveCurrentFocus(); wnd.fullRepaint(); } if (modeRight == Mode.drawBox || modeRight == Mode.zoomBox || modeRight == Mode.zoomBoxSingleShot) { // drawing boxes Point2D start = wnd.screenToDatabase((int)wnd.getStartDrag().getX(), (int)wnd.getStartDrag().getY()); Point2D end = wnd.screenToDatabase((int)wnd.getEndDrag().getX(), (int)wnd.getEndDrag().getY()); double minSelX = Math.min(start.getX(), end.getX()); double maxSelX = Math.max(start.getX(), end.getX()); double minSelY = Math.min(start.getY(), end.getY()); double maxSelY = Math.max(start.getY(), end.getY()); // determine if the user clicked on a single point to prevent unintended zoom-in // a single point is 4 lambda or less AND 10 screen pixels or less boolean onePoint = true; Rectangle2D bounds = new Rectangle2D.Double(minSelX, minSelY, maxSelX-minSelX, maxSelY-minSelY); if (bounds.getHeight() > 4 && bounds.getWidth() > 4) onePoint = false; if (Math.abs(wnd.getStartDrag().getX()-wnd.getEndDrag().getX()) > 10 || Math.abs(wnd.getStartDrag().getY()-wnd.getEndDrag().getY()) > 10) onePoint = false; if (modeRight == Mode.drawBox) { // just draw a highlight box highlighter.addArea(new Rectangle2D.Double(minSelX, minSelY, maxSelX-minSelX, maxSelY-minSelY), cell); } if (modeRight == Mode.zoomBoxSingleShot) { // zoom to box: focus on box if (!onePoint) wnd.focusScreen(bounds); WindowFrame.setListener(oldListener); if (modeLeft == Mode.zoomBoxSingleShot) modeLeft = Mode.none; } if (modeRight == Mode.zoomBox) { // zoom to box: focus on box if (onePoint) { // modeRight == Mode.zoomOut // if not zoomBox, then user meant to zoomOut double scale = wnd.getScale(); wnd.setScale(scale / 2); wnd.clearDoingAreaDrag(); wnd.getSavedFocusBrowser().saveCurrentFocus(); wnd.fullRepaint(); } else { wnd.focusScreen(bounds); } } highlighter.finished(); wnd.clearDoingAreaDrag(); wnd.repaint(); } if (modeRight == Mode.wiringFind || modeRight == Mode.stickyWiring) { // see if anything under the pointer /* int numFound = Highlight.findObject(dbMouse, wnd, false, false, false, true, false, specialSelect, true); if (numFound == 0) { // not over anything, nothing to connect to EditWindow.gridAlign(dbMouse); endObj = null; } else { // connect objects Iterator hIt = Highlight.getHighlights().iterator(); Highlight h2 = (Highlight)hIt.next(); EditWindow.gridAlign(dbMouse); endObj = h2.getElectricObject(); }*/ EditWindow.gridAlign(dbMouse); User.getUserTool().setCurrentArcProto(currentArcWhenWiringPressed); router.makeRoute(wnd, cell, startObj, endObj, dbMouse); // clear any popup cloud we had //wnd.clearShowPopupCloud(); // clear last switched to highlight wiringTarget = null; } if (modeRight == Mode.wiringConnect) { EditWindow.gridAlign(dbMouse); User.getUserTool().setCurrentArcProto(currentArcWhenWiringPressed); router.makeRoute(wnd, cell, startObj, endObj, dbMouse); wiringTarget = null; } if (modeRight == Mode.wiringToSpace) { EditWindow.gridAlign(dbMouse); User.getUserTool().setCurrentArcProto(currentArcWhenWiringPressed); router.makeRoute(wnd, cell, startObj, null, dbMouse); wiringTarget = null; } modeRight = Mode.none; } // ===== Left Mouse Release ===== if (isLeftMouse(evt)) { // ignore move if done within cancelMoveDelayMillis long curTime = evt.getWhen(); if (debug) System.out.println("Time diff between click->release is: "+(curTime - leftMousePressedTimeStamp)); if (modeLeft == Mode.move || modeLeft == Mode.stickyMove) { if ((curTime - leftMousePressedTimeStamp) < cancelMoveDelayMillis) { highlighter.setHighlightOffset(0, 0); modeLeft = Mode.none; if (moveDelta != null) highlighter.remove(moveDelta); if (moveDRC != null) highlighter.remove(moveDRC); wnd.repaint(); return; } } // if 'stickyMove' is true and we are moving stuff, ignore mouse release if (getStickyMove() && (modeLeft == Mode.move)) { // only do so if after cancel move delay /* if ((System.currentTimeMillis() - leftMousePressedTimeStamp) < dragDelayMillis) modeLeft = Mode.none; // user left mouse button single click else */ modeLeft = Mode.stickyMove; // user moving stuff in sticky mode } else { if (modeLeft == Mode.selectBox || modeLeft == Mode.drawBox || modeLeft == Mode.zoomBoxSingleShot) { // select all in box Point2D start = wnd.screenToDatabase((int)wnd.getStartDrag().getX(), (int)wnd.getStartDrag().getY()); Point2D end = wnd.screenToDatabase((int)wnd.getEndDrag().getX(), (int)wnd.getEndDrag().getY()); double minSelX = Math.min(start.getX(), end.getX()); double maxSelX = Math.max(start.getX(), end.getX()); double minSelY = Math.min(start.getY(), end.getY()); double maxSelY = Math.max(start.getY(), end.getY()); // determine if the user clicked on a single point to prevent unintended zoom-in // a single point is 4 lambda or less AND 10 screen pixels or less boolean onePoint = true; Rectangle2D bounds = new Rectangle2D.Double(minSelX, minSelY, maxSelX-minSelX, maxSelY-minSelY); if (bounds.getHeight() > 4 && bounds.getWidth() > 4) onePoint = false; if (Math.abs(wnd.getStartDrag().getX()-wnd.getEndDrag().getX()) > 10 || Math.abs(wnd.getStartDrag().getY()-wnd.getEndDrag().getY()) > 10) onePoint = false; if (modeLeft == Mode.selectBox) { if (!invertSelection) highlighter.clear(); highlighter.selectArea(wnd, minSelX, maxSelX, minSelY, maxSelY, invertSelection, specialSelect); } if (modeLeft == Mode.drawBox) { // just draw a highlight box highlighter.addArea(new Rectangle2D.Double(minSelX, minSelY, maxSelX-minSelX, maxSelY-minSelY), cell); } if (modeLeft == Mode.zoomBoxSingleShot) { // zoom to box: focus on box if (!onePoint) wnd.focusScreen(bounds); WindowFrame.setListener(oldListener); if (modeRight == Mode.zoomBoxSingleShot) modeRight = Mode.none; } highlighter.finished(); wnd.clearDoingAreaDrag(); wnd.repaint(); } if (modeLeft == Mode.move || modeLeft == Mode.stickyMove) { // moving objects if (another) dbMouse = convertToOrthogonal(new Point2D.Double(dbMoveStartX, dbMoveStartY), dbMouse); Point2D dbDelta = new Point2D.Double(dbMouse.getX() - dbMoveStartX, dbMouse.getY() - dbMoveStartY); EditWindow.gridAlign(dbDelta); if (moveDelta != null) highlighter.remove(moveDelta); if (moveDRC != null) highlighter.remove(moveDRC); if (dbDelta.getX() != 0 || dbDelta.getY() != 0) { highlighter.setHighlightOffset(0, 0); CircuitChanges.manyMove(dbDelta.getX(), dbDelta.getY()); wnd.fullRepaint(); } } modeLeft = Mode.none; } } } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -