📄 clickzoomwirelistener.java
字号:
if (modeRight == Mode.zoomBoxSingleShot) { // We will zoom to box wnd.setStartDrag(clickX, clickY); wnd.setEndDrag(clickX, clickY); wnd.setDoingAreaDrag(); return; } // draw possible wire connection if (!invertSelection) { // ignore anything that can't have a wire drawn to it // (everything except nodes, ports, and arcs) List<Highlight2> highlights = new ArrayList<Highlight2>(); for (Highlight2 h : highlighter.getHighlights()) { if (h.isHighlightEOBJ()) { ElectricObject eobj = h.getElectricObject(); if (eobj instanceof PortInst || eobj instanceof NodeInst || eobj instanceof ArcInst) highlights.add(h); } } Iterator<Highlight2> hIt = highlights.iterator(); // if already 2 objects, wire them up if (highlights.size() == 2) { Highlight2 h1 = hIt.next(); Highlight2 h2 = hIt.next(); ElectricObject eobj1 = h1.getElectricObject(); ElectricObject eobj2 = h2.getElectricObject(); if (eobj1 != null && eobj2 != null) { modeRight = Mode.wiringConnect; wiringTarget = null; startObj = h1.getElectricObject(); endObj = h2.getElectricObject(); currentArcWhenWiringPressed = User.getUserTool().getCurrentArcProto(); EditWindow.gridAlign(dbClick); router.highlightRoute(wnd, startCell, h1.getElectricObject(), h2.getElectricObject(), dbClick); return; } } // if one object, put into wire find mode // which will draw possible wire route. if (highlights.size() == 1) { Highlight2 h1 = hIt.next(); ElectricObject eobj1 = h1.getElectricObject(); if (eobj1 != null) { modeRight = Mode.wiringFind; endObj = null; wiringTarget = null; startObj = h1.getElectricObject(); router.startInteractiveRoute(wnd); // look for stuff under the mouse Highlight2 h2 = highlighter.findObject(dbClick, wnd, false, false, false, true, false, specialSelect, false); if (h2 == null) { // not over anything, nothing to connect to endObj = null; wiringTarget = null; } else {// Highlight2 h2 = highlighter.getHighlights().iterator().next(); endObj = h2.getElectricObject(); } currentArcWhenWiringPressed = User.getUserTool().getCurrentArcProto(); EditWindow.gridAlign(dbClick); router.highlightRoute(wnd, startCell, h1.getElectricObject(), endObj, dbClick); return; } } System.out.println("Must start new arc from one node or arc; or wire two node/arcs together"); modeRight = Mode.none; return; } // drawing some sort of box wnd.setStartDrag(clickX, clickY); wnd.setEndDrag(clickX, clickY); wnd.setDoingAreaDrag(); // zoom out and zoom to box mode if (invertSelection && !another) { // A single click zooms out, but a drag box zooms to box // The distinction is if the user starts dragging a box, // which we check for in mouseDragged after a set time delay modeRight = Mode.zoomOut; } // draw box if (another && invertSelection) { // the box we are going to draw is a highlight highlighter.clear(); modeRight = Mode.drawBox; } return; } // ===== left mouse clicks ====== if (isLeftMouse(evt)) { if (modeLeft == Mode.zoomBoxSingleShot) { // We will zoom to box wnd.setStartDrag(clickX, clickY); wnd.setEndDrag(clickX, clickY); wnd.setDoingAreaDrag(); return; } // if doing sticky move place objects now if (modeLeft == Mode.stickyMove) { // moving objects if (another) dbClick = convertToOrthogonal(new Point2D.Double(dbMoveStartX, dbMoveStartY), dbClick); Point2D dbDelta = new Point2D.Double(dbClick.getX() - dbMoveStartX, dbClick.getY() - dbMoveStartY); EditWindow.gridAlign(dbDelta); if (dbDelta.getX() != 0 || dbDelta.getY() != 0) { highlighter.setHighlightOffset(0, 0); CircuitChanges.manyMove(dbDelta.getX(), dbDelta.getY()); wnd.fullRepaint(); } modeLeft = Mode.none; return; } // new time stamp must occur after checking for sticky move leftMousePressedTimeStamp = evt.getWhen(); // ----- double-click responses ----- if (evt.getClickCount() == 2) { /* if CTRL is being held, user wants to cycle through what's under the cursor--pop up menu to let them select */ /* if (another) { Rectangle2D bounds = new Rectangle2D.Double(clickX, clickY, 0, 0); underCursor = Highlight.findAllInArea(cell, false, another, true, specialSelect, true, bounds, wnd); JPopupMenu popup = selectPopupMenu(underCursor); popup.show(wnd, clickX, clickY); return; } */ /* if no modifiers, do "get info" */ if (!another && !invertSelection) { if (highlighter.getNumHighlights() >= 1) { EditMenu.getInfoCommand(true); return; } } } // ----- single click responses ----- // if toolbar is in select mode, draw box if (ToolBar.getSelectMode() == ToolBar.SelectMode.AREA) { // select area // area selection: just drag out a rectangle wnd.setStartDrag(clickX, clickY); wnd.setEndDrag(clickX, clickY); wnd.setDoingAreaDrag(); highlighter.clear(); modeLeft = Mode.drawBox; return; } // if already over highlighted object, move it if (!another && !invertSelection && highlighter.overHighlighted(wnd, clickX, clickY) != null) { highlighter.finished(); // over something, user may want to move objects dbMoveStartX = dbClick.getX(); dbMoveStartY = dbClick.getY(); moveDelta = moveDRC = null; modeLeft = Mode.move; } else { // findObject handles cycling through objects (another) // and inverting selection (invertSelection) // and selection special objects (specialSelection) Highlight2 h = highlighter.findObject(dbClick, wnd, false, another, invertSelection, true, false, specialSelect, true); if (h == null) { // not over anything: drag out a selection rectangle wnd.setStartDrag(clickX, clickY); wnd.setEndDrag(clickX, clickY); wnd.setDoingAreaDrag(); modeLeft = Mode.selectBox; } else { // over something, user may want to move objects dbMoveStartX = dbClick.getX(); dbMoveStartY = dbClick.getY(); moveDelta = moveDRC = null; modeLeft = Mode.move; } mouseOver(dbClick, wnd); } return; } if (isMiddleMouse(evt)) { // We will pan the screen lastX = evt.getX(); lastY = evt.getY(); return; } } } /** Handle mouse dragged event. * <p>Left Mouse Drag: Move Objects (or select area if not on object) * <p>Right Mouse Click/Drag: Connect wire * <p>Right Mouse Drag + (later) CTRL: Connect wire in space (ignore objects) * <p>SHIFT + Right Mouse Drag: zoom box * <p>CTRL + Right Mouse Drag: draw box * @param evt the MouseEvent */ public void mouseDragged(MouseEvent evt) { if (debug) System.out.println(" ["+modeLeft+","+modeRight+"] "+evt.paramString()); long currentTime = System.currentTimeMillis(); if (evt.getSource() instanceof EditWindow) { EditWindow wnd = (EditWindow)evt.getSource(); Highlighter highlighter = wnd.getHighlighter(); Cell cell = wnd.getCell(); if (cell == null) return; int mouseX = evt.getX(); int mouseY = evt.getY(); Point2D dbMouse = wnd.screenToDatabase(mouseX, mouseY); lastdbMouseX = (int)dbMouse.getX(); lastdbMouseY = (int)dbMouse.getY(); boolean another = (evt.getModifiersEx()&MouseEvent.CTRL_DOWN_MASK) != 0; specialSelect = ToolBar.isSelectSpecial(); // ===== Right mouse drags ===== if (isRightMouse(evt)) { if (modeRight == Mode.zoomBoxSingleShot) { // We will zoom to box if (!wnd.isDoingAreaDrag()) { wnd.setStartDrag(mouseX, mouseY); wnd.setEndDrag(mouseX, mouseY); wnd.setDoingAreaDrag(); } wnd.setEndDrag(mouseX, mouseY); } if (modeRight == Mode.zoomOut) { // switch to zoomBox mode if the user is really dragging a box // otherwise, we zoom out after specified delay if ((currentTime - rightMousePressedTimeStamp) > zoomInDelayMillis) modeRight = Mode.zoomBox; } if (modeRight == Mode.drawBox || modeRight == Mode.zoomBox) { // draw a box wnd.setEndDrag(mouseX, mouseY); } if (modeRight == Mode.wiringFind || modeRight == Mode.stickyWiring) { // see if anything under the pointer Highlight2 h3 = highlighter.findObject(dbMouse, wnd, false, false, false, true, false, specialSelect, false); if (h3 == null) { // not over anything, nothing to connect to EditWindow.gridAlign(dbMouse); endObj = null; wiringTarget = null; } else { // The user can switch between wiring targets under the cursor using a key stroke // if wiring target non-null, and still under cursor, use that endObj = null; if (wiringTarget != null) { // check if still valid target EditWindow.gridAlign(dbMouse); List<Highlight2> underCursor = Highlighter.findAllInArea(highlighter, cell, false, true, true, false, specialSelect, false, new Rectangle2D.Double(dbMouse.getX(), dbMouse.getY(), 0, 0), wnd); for (Highlight2 h : underCursor) { ElectricObject eobj = h.getElectricObject(); if (eobj == wiringTarget) { endObj = wiringTarget; break; } } // wiringTarget is no longer valid, reset it if (endObj == null) wiringTarget = null; } // if target is null, find new target if (endObj == null) { Iterator<Highlight2> hIt = highlighter.getHighlights().iterator(); if (hIt.hasNext()){ Highlight2 h2 = hIt.next(); endObj = h2.getElectricObject(); } } EditWindow.gridAlign(dbMouse); } User.getUserTool().setCurrentArcProto(currentArcWhenWiringPressed); router.highlightRoute(wnd, cell, startObj, endObj, dbMouse); // clear any previous popup cloud /* wnd.clearShowPopupCloud(); // popup list of stuff under mouse to connect to if more than one List underCursor = Highlight.findAllInArea(cell, false, true, true, false, specialSelect, false, new Rectangle2D.Double(dbMouse.getX(), dbMouse.getY(), 0, 0), wnd); if (underCursor.size() > 1) { ArrayList text = new ArrayList(); ArrayList portList = new ArrayList(); text.add("Connect to:"); int num = 1; for (int i=0; i<underCursor.size(); i++) { Highlight h = underCursor.get(i); ElectricObject obj = h.getElectricObject(); if (num == 10) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -