📄 clickzoomwirelistener.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ClickDragZoomListener.java * * Copyright (c) 2003 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user.ui;import com.sun.electric.database.geometry.Dimension2D;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.network.Netlist;import com.sun.electric.database.network.Network;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.topology.RTBounds;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.DRCTemplate;import com.sun.electric.technology.Layer;import com.sun.electric.technology.Technology;import com.sun.electric.tool.Client;import com.sun.electric.tool.drc.DRC;import com.sun.electric.tool.routing.InteractiveRouter;import com.sun.electric.tool.routing.SimpleWirer;import com.sun.electric.tool.user.CircuitChanges;import com.sun.electric.tool.user.Highlight2;import com.sun.electric.tool.user.Highlighter;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.menus.EditMenu;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseWheelEvent;import java.awt.event.MouseWheelListener;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.EventListener;import java.util.Iterator;import java.util.List;import java.util.prefs.Preferences;import javax.swing.JMenuItem;import javax.swing.JPopupMenu;/** * Handles Selection, Zooming, and Wiring. * <p>The Left Mouse Button handles Selection and Moving * <p>The Right Mouse Button handles Zooming and Wiring * <p>The Mouse Wheel handles panning * * User: gainsley * Date: Feb 19, 2004 * Time: 2:53:33 PM */public class ClickZoomWireListener implements MouseMotionListener, MouseListener, MouseWheelListener, KeyListener, ActionListener{ private static Preferences prefs = Preferences.userNodeForPackage(ClickZoomWireListener.class); private static long cancelMoveDelayMillis; /* cancel move delay in milliseconds */ private static long zoomInDelayMillis; /* zoom in delay in milliseconds */ private static final boolean debug = false; /* for debugging */ public static ClickZoomWireListener theOne = new ClickZoomWireListener(); private int clickX, clickY; /* current mouse pressed coords in screen space */ private int lastX, lastY; /* last mouse pressed coords in screen space (for panning) */ private Cell startCell; private double dbMoveStartX, dbMoveStartY; /* left mouse pressed coords for move in database space */ private double lastdbMouseX, lastdbMouseY; /* last location of mouse */ private Mode modeLeft = Mode.none; /* left mouse button context mode */ private Mode modeRight = Mode.none; /* right mouse button context mode */ private boolean specialSelect = false; /* if hard-to-select objects are to be selected */ private boolean invertSelection = false; /* if invert selection */ private boolean another; //private List underCursor = null; /* objects in popupmenu */ //private String lastPopupMenu = null; /* last used popupmenu */ private long leftMousePressedTimeStamp; /* log of last left mouse pressed time */ private long rightMousePressedTimeStamp; /* log of last left mouse pressed time */ private ElectricObject wiringTarget; /* last highlight user switched to possibly wire to */ // wiring stuff private InteractiveRouter router; /* router used to connect objects */ private ElectricObject startObj; /* object routing from */ private ElectricObject endObj; /* object routing to */ private ArcProto currentArcWhenWiringPressed; /* current arc proto when mouse pressed to draw wire: later actions of this tool may change current arc */ private int mouseX, mouseY; /* last known location of mouse */ private Highlight2 moveDelta; /* highlight to display move delta */ private Highlight2 moveDRC; /* highlight to display design rules during a move */ private EventListener oldListener; /* used when swtiching back to old listener */ // mac stuff private static final boolean isMac = Client.isOSMac(); /** Class Mode lets us set a common mode over several types of events, * letting initial events (like a right mouse click) set the context for * later events (such as pressing the CTRL button). */ private static class Mode { private final String name; public Mode(String name) { this.name = name; } public String toString() { return name; } public static final Mode none = new Mode("none"); // no context public static final Mode move = new Mode("move"); // moving objects public static final Mode stickyMove = new Mode("stickyMove"); // second move mode public static final Mode drawBox = new Mode("drawBox"); // drawing a box public static final Mode zoomBox = new Mode("zoomBox"); // drawing a box to zoom to public static final Mode zoomBoxSingleShot = new Mode("zoomBoxSingleShot"); // drawing a box to zoom to public static final Mode zoomIn = new Mode("zoomIn"); // zoom in mode public static final Mode zoomOut = new Mode("zoomOut"); // zoom in mode public static final Mode selectBox = new Mode("selectBox"); // box for selection public static final Mode wiringConnect = new Mode("wiring"); // drawing a wire between two objects public static final Mode wiringFind = new Mode("wiringFind"); // drawing wire with unknown end point public static final Mode wiringToSpace = new Mode("wiringToSpace"); // only draw wire to space, not objects public static final Mode stickyWiring = new Mode("stickyWiring"); // sticky mode wiring } /** Constructor is private */ private ClickZoomWireListener() { router = new SimpleWirer(); router.setTool(User.getUserTool()); readPrefs(); } /** Set ClickZoomWireListener to include hard to select objects */ public void setSpecialSelect() { specialSelect = true; } /** Set ClickZoomWireListener to exclude hard to select objects */ public void clearSpecialSelect() { specialSelect = false; } /** * Returns state of 'stickyMove'. * If sticky move is true, after the user clicks and drags to * move an object, the user can release the mouse button and the * object will continue to move with the mouse. Clicking the * select mouse key again will place the object. * If sticky move is false, the user must hold and drag to move * the object. Letting go of the select mouse key will place the * object. This is the C-Electric style. * @return state of preference 'stickyMove' */ public boolean getStickyMove() { // for now just return true. // TODO: make it a preference return false; } public void setRouter(InteractiveRouter router) { this.router = router; } /** * Returns state of 'stickyWiring'. * If sticky wiring is true, after the user clicks and drags to * draw a wire, the user can release the mouse button and the UI * will remain in wire-draw mode. Click the mouse button again * will draw the wire. * If sticky wiring is false, the user must hold and drag to * draw the tentative wire, and the wire gets drawn when the * user releases the mouse button. This is C-Electric style. * @return state of preference 'stickyWiring' */ public boolean getStickyWiring() { // for now just return true // TODO: make it a preference return true; } /** * Return the last known location of the mouse. Note that these are * screen coords, and are in the coordinate system of the current container(?). * @return a Point2D containing the last mouse coords. */ public Point2D getLastMouse() { return new Point2D.Double(mouseX, mouseY); } /** * Sets the mode to zoom box for the next right click only. */ public void zoomBoxSingleShot(EventListener oldListener) { modeRight = Mode.zoomBoxSingleShot; modeLeft = Mode.zoomBoxSingleShot; this.oldListener = oldListener; } /** * See if event is a left mouse click. Platform independent. */ private boolean isLeftMouse(MouseEvent evt) { if (isMac) { if (!evt.isMetaDown()) { if ((evt.getModifiers() & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) return true; } } else { if ((evt.getModifiers() & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) return true; } return false; } /** * See if event is a right mouse click. Platform independent. * One-button macs: Command + click == right mouse click. */ public static boolean isRightMouse(InputEvent evt) { if (isMac) { if (evt.isMetaDown()) { if ((evt.getModifiers() & MouseEvent.BUTTON1_MASK) == MouseEvent.BUTTON1_MASK) return true; } if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) == MouseEvent.BUTTON3_MASK) return true; } else { if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) == MouseEvent.BUTTON3_MASK) return true; } return false; } /** * See if event is a middle mouse click. Platform independent. */ public static boolean isMiddleMouse(InputEvent evt) { if ((evt.getModifiers() & MouseEvent.BUTTON2_MASK) == MouseEvent.BUTTON2_MASK) return true; return false; } /** Handle mouse press events. * <p>Left Mouse Click: Select * <p>Left Mouse Drag: Move Objects (or select area if not on object) * <p>Left Mouse Double-Click: Get Info * <p>CTRL + Left Mouse Click: Cycle through select * <p>SHIFT + Left Mouse Click: invert selection * <p>Right Mouse Click/Drag: Connect wire * <p>SHIFT + Right Mouse Click: zoom out * <p>SHIFT + Right Mouse Drag: zoom in * <p>CTRL + SHIFT + Right Mouse Click: draw box * @param evt the MouseEvent * */ public void mousePressed(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(); startCell = wnd.getCell(); if (startCell == null) return; clickX = evt.getX(); clickY = evt.getY(); Point2D dbClick = wnd.screenToDatabase(clickX, clickY); lastdbMouseX = dbClick.getX(); lastdbMouseY = dbClick.getY(); boolean another = (evt.getModifiersEx()&MouseEvent.CTRL_DOWN_MASK) != 0; invertSelection = (evt.getModifiersEx()&MouseEvent.SHIFT_DOWN_MASK) != 0; specialSelect = ToolBar.isSelectSpecial(); // ===== right mouse clicks ===== if (isRightMouse(evt)) { rightMousePressedTimeStamp = currentTime;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -