📄 clipboard.java
字号:
urcorner = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()); continue; } if (bounds.getMinX() < llcorner.getX()) llcorner.setLocation(bounds.getMinX(), llcorner.getY()); if (bounds.getMinY() < llcorner.getY()) llcorner.setLocation(llcorner.getX(), bounds.getMinY()); if (bounds.getMaxX() > urcorner.getX()) urcorner.setLocation(bounds.getMaxX(), urcorner.getY()); if (bounds.getMaxY() > urcorner.getY()) urcorner.setLocation(urcorner.getX(), bounds.getMaxY()); } for(Geometric geom : geomList) { if (geom instanceof NodeInst) { NodeInst ni = (NodeInst)geom; Point2D pt = ni.getAnchorCenter(); if (llcorner == null) { llcorner = new Point2D.Double(pt.getX(), pt.getY()); urcorner = new Point2D.Double(pt.getX(), pt.getY()); continue; } if (pt.getX() < llcorner.getX()) llcorner.setLocation(pt.getX(), llcorner.getY()); if (pt.getY() < llcorner.getY()) llcorner.setLocation(llcorner.getX(), pt.getY()); if (pt.getX() > urcorner.getX()) urcorner.setLocation(pt.getX(), urcorner.getY()); if (pt.getY() > urcorner.getY()) urcorner.setLocation(urcorner.getX(), pt.getY()); } else { ArcInst ai = (ArcInst)geom; Poly poly = ai.makeLambdaPoly(ai.getGridBaseWidth(), Poly.Type.FILLED); Rectangle2D bounds = poly.getBounds2D(); if (llcorner == null) { llcorner = new Point2D.Double(bounds.getMinX(), bounds.getMinY()); urcorner = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()); continue; } if (bounds.getMinX() < llcorner.getX()) llcorner.setLocation(bounds.getMinX(), llcorner.getY()); if (bounds.getMinY() < llcorner.getY()) llcorner.setLocation(llcorner.getX(), bounds.getMinY()); if (bounds.getMaxX() > urcorner.getX()) urcorner.setLocation(bounds.getMaxX(), urcorner.getY()); if (bounds.getMaxY() > urcorner.getY()) urcorner.setLocation(urcorner.getX(), bounds.getMaxY()); } } // figure bounds double width = urcorner.getX() - llcorner.getX(); double height = urcorner.getY() - llcorner.getY(); Rectangle2D bounds = new Rectangle2D.Double(llcorner.getX(), llcorner.getY(), width, height); return bounds; } /****************************** PASTE LISTENER ******************************/ /** * Class to handle the interactive drag after a paste. */ private static class PasteListener implements MouseMotionListener, MouseListener, MouseWheelListener, KeyListener { private EditWindow wnd; private List<Geometric> geomList; private List<DisplayedText> textList; private EventListener currentListener; private Rectangle2D pasteBounds; private double translateX; private double translateY; private Point2D lastMouseDB; // last point where mouse was (in db units) private JPopupMenu popup; private AffineTransform inPlace; private Orientation inPlaceOrient; /** paste anchor types */ /** * Create a new paste listener * @param wnd Controlling window * @param pasteList list of objects to paste * @param currentListener listener to restore when done */ private PasteListener(EditWindow wnd, List<Geometric> geomList, List<DisplayedText> textList, EventListener currentListener, AffineTransform inPlace, Orientation inPlaceOrient, boolean dup) { this.wnd = wnd; this.geomList = geomList; this.textList = textList; this.currentListener = currentListener; this.inPlace = inPlace; this.inPlaceOrient = inPlaceOrient; this.pasteBounds = getPasteBounds(geomList, textList, wnd); translateX = translateY = 0; initPopup(); // get starting point from current mouse location Point2D mouse = ClickZoomWireListener.theOne.getLastMouse(); Point2D mouseDB = wnd.screenToDatabase((int)mouse.getX(), (int)mouse.getY()); if (dup) { pasteBounds.setRect(pasteBounds.getMinX()+mouseDB.getX()-pasteBounds.getCenterX(), pasteBounds.getMinY()+mouseDB.getY()-pasteBounds.getCenterY(), pasteBounds.getWidth(), pasteBounds.getHeight()); } Point2D delta = getDelta(mouseDB, false); wnd.getHighlighter().pushHighlight(); showList(delta); } /** * Gets grid-aligned delta translation for nodes based on mouse location * @param mouseDB the location of the mouse * @param orthogonal if the translation is orthogonal only * @return a grid-aligned delta */ private Point2D getDelta(Point2D mouseDB, boolean orthogonal) { // mouseDB == null if you press arrow keys before placing the new copy if (mouseDB == null) return null; Dimension2D alignment = User.getAlignmentToGrid(); DBMath.gridAlign(mouseDB, alignment); // this is the point on the clipboard cell that will be pasted at the mouse location Point2D refPastePoint = new Point2D.Double(pasteBounds.getCenterX() + translateX, pasteBounds.getCenterY() + translateY); double deltaX = mouseDB.getX() - refPastePoint.getX(); double deltaY = mouseDB.getY() - refPastePoint.getY(); // if orthogonal is true, convert to orthogonal if (orthogonal) { // Attempt to fix bug #1748// double distanceX = deltaX;// double distanceY = deltaY;//// // deciding direction for the move// if (lastMouseDB != null)// {// distanceX = mouseDB.getX() - lastMouseDB.getX();// distanceY = mouseDB.getY() - lastMouseDB.getY();// } // If the mouse is within the X and Y extent of the object use X and Y only // If the mouse is not confined to either extent then use the 45 degree rule // Arguably we can change it to x degree rule where x is defined by the ratio of the widths if (mouseDB.getX() > pasteBounds.getMinX() && mouseDB.getX() < pasteBounds.getMaxX()) { deltaX = 0; } else if (mouseDB.getY() > pasteBounds.getMinY() && mouseDB.getY() < pasteBounds.getMaxY()) { deltaY = 0; } else {// // only use delta in direction that has larger delta if (Math.abs(deltaX) > Math.abs(deltaY))// if (Math.abs(distanceX) > Math.abs(distanceY)) deltaY = 0; else deltaX = 0; } } // this is now a delta, not a point refPastePoint.setLocation(deltaX, deltaY); DBMath.gridAlign(refPastePoint, alignment); return refPastePoint; } /** * Show the objects to paste with the anchor point at 'mouseDB' * @param delta the translation for the highlights */ private void showList(Point2D delta) { // if delta==null, problems to get mouseDB pointer if (delta == null) return; // find offset of highlights double oX = delta.getX(); double oY = delta.getY(); Cell cell = wnd.getCell(); Highlighter highlighter = wnd.getHighlighter(); highlighter.clear(); for(Geometric geom : geomList) { if (geom instanceof ArcInst) { ArcInst ai = (ArcInst)geom; Poly poly = ai.makeLambdaPoly(ai.getGridBaseWidth(), Poly.Type.CLOSED); if (inPlace != null) poly.transform(inPlace); Point2D [] points = poly.getPoints(); showPoints(points, oX, oY, cell, highlighter); continue; } NodeInst ni = (NodeInst)geom; if (ni.isInvisiblePinWithText()) { // find text on the invisible pin boolean found = false; for(Iterator<Variable> vIt = ni.getVariables(); vIt.hasNext(); ) { Variable var = vIt.next(); if (var.isDisplay()) { Point2D [] points = Highlighter.describeHighlightText(wnd, geom, var.getKey()); if (inPlace != null) inPlace.transform(points, 0, points, 0, points.length); showPoints(points, oX, oY, cell, highlighter); found = true; break; } } if (found) continue; } Poly poly = ni.getBaseShape();// SizeOffset so = ni.getSizeOffset();// AffineTransform trans = ni.rotateOutAboutTrueCenter();// double nodeLowX = ni.getTrueCenterX() - ni.getXSize()/2 + so.getLowXOffset();// double nodeHighX = ni.getTrueCenterX() + ni.getXSize()/2 - so.getHighXOffset();// double nodeLowY = ni.getTrueCenterY() - ni.getYSize()/2 + so.getLowYOffset();// double nodeHighY = ni.getTrueCenterY() + ni.getYSize()/2 - so.getHighYOffset();// double nodeX = (nodeLowX + nodeHighX) / 2;// double nodeY = (nodeLowY + nodeHighY) / 2;// Poly poly = new Poly(nodeX, nodeY, nodeHighX-nodeLowX, nodeHighY-nodeLowY); if (inPlace != null) poly.transform(inPlace);// poly.transform(trans); showPoints(poly.getPoints(), oX, oY, cell, highlighter); } // show delta from original Rectangle2D bounds = wnd.getDisplayedBounds(); highlighter.addMessage(cell, "("+(int)oX+","+(int)oY+")", new Point2D.Double(bounds.getCenterX(),bounds.getCenterY())); // also draw arrow if user has moved highlights off the screen double halfWidth = 0.5*pasteBounds.getWidth(); double halfHeight = 0.5*pasteBounds.getHeight(); if (Math.abs(translateX) > halfWidth || Math.abs(translateY) > halfHeight) { Rectangle2D transBounds = new Rectangle2D.Double(pasteBounds.getX()+oX, pasteBounds.getY()+oY, pasteBounds.getWidth(), pasteBounds.getHeight()); Poly p = new Poly(transBounds); if (inPlace != null) p.transform(inPlace); Point2D endPoint = p.closestPoint(lastMouseDB); // draw arrow highlighter.addLine(lastMouseDB, endPoint, cell); int angle = GenMath.figureAngle(lastMouseDB, endPoint); angle += 1800; int angleOfArrow = 300; // 30 degrees int backAngle1 = angle - angleOfArrow; int backAngle2 = angle + angleOfArrow; Point2D p1 = new Point2D.Double(endPoint.getX() + DBMath.cos(backAngle1), endPoint.getY() + DBMath.sin(backAngle1)); Point2D p2 = new Point2D.Double(endPoint.getX() + DBMath.cos(backAngle2), endPoint.getY() + DBMath.sin(backAngle2)); highlighter.addLine(endPoint, p1, cell); highlighter.addLine(endPoint, p2, cell); } highlighter.finished(); } private void showPoints(Point2D [] points, double oX, double oY, Cell cell, Highlighter highlighter) { for(int i=0; i<points.length; i++) { int lastI = i - 1; if (lastI < 0) lastI = points.length - 1; double fX = points[lastI].getX(); double fY = points[lastI].getY(); double tX = points[i].getX(); double tY = points[i].getY(); highlighter.addLine(new Point2D.Double(fX+oX, fY+oY), new Point2D.Double(tX+oX, tY+oY), cell); } } public void mousePressed(MouseEvent e) { if (e.isMetaDown()) { // right click popup.show(e.getComponent(), e.getX(), e.getY()); } } public void mouseDragged(MouseEvent evt) { mouseMoved(evt); } public void mouseReleased(MouseEvent evt) { if (evt.isMetaDown()) { // right click return; } boolean ctrl = (evt.getModifiersEx()&MouseEvent.CTRL_DOWN_MASK) != 0; Point2D mouseDB = wnd.screenToDatabase(evt.getX(), evt.getY()); Point2D delta = getDelta(mouseDB, ctrl); showList(delta); WindowFrame.setListener(currentListener); wnd.getHighlighter().popHighlight(); Cell cell = WindowFrame.needCurCell(); if (cell != null) new PasteObjects(cell, geomList, textList, delta.getX(), delta.getY(), User.getAlignmentToGrid(), User.isDupCopiesExports(), User.isArcsAutoIncremented(), inPlace, inPlaceOrient); } public void mouseMoved(MouseEvent evt) { boolean ctrl = (evt.getModifiersEx()&MouseEvent.CTRL_DOWN_MASK) != 0; Point2D mouseDB = wnd.screenToDatabase(evt.getX(), evt.getY()); Point2D delta = getDelta(mouseDB, ctrl); lastMouseDB = mouseDB; showList(delta); wnd.repaint(); } public void mouseClicked(MouseEvent evt) {} public void mouseEntered(MouseEvent evt) {} public void mouseExited(MouseEvent evt) {} public void mouseWheelMoved(MouseWheelEvent e) {} public void keyPressed(KeyEvent evt) { int chr = evt.getKeyCode(); if (chr == KeyEvent.VK_ESCAPE) { // abort on ESC abort(); } else if (chr == KeyEvent.VK_UP) { moveObjectsUp(); } else if (chr == KeyEvent.VK_DOWN) { moveObjectsDown(); } else if (chr == KeyEvent.VK_LEFT) { moveObjectsLeft(); } else if (chr == KeyEvent.VK_RIGHT) { moveObjectsRight(); } } public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) {} private void abort() { wnd.getHighlighter().clear(); wnd.getHighlighter().finished(); WindowFrame.setListener(currentListener); wnd.repaint(); } private void initPopup() { popup = new JPopupMenu(); JMenuItem m; m = new JMenuItem("Move objects left"); m.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)); m.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { moveObjectsLeft(); } }); popup.add(m); m = new JMenuItem("Move objects right"); m.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); m.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { moveObjectsRight(); } }); popup.add(m); m = new JMenuItem("Move objects up"); m.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)); m.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { moveObjectsUp(); } }); popup.add(m); m = new JMenuItem("Move objects down"); m.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)); m.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { moveObjectsDown(); } }); popup.add(m); m = new JMenuItem("Abort"); m.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); m.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { abort(); } }); popup.add(m); } private void moveObjectsLeft() { translateX += 0.5*pasteBounds.getWidth(); Point2D delta = getDelta(lastMouseDB, false); showList(delta); } private void moveObjectsRight() { translateX -= 0.5*pasteBounds.getWidth(); Point2D delta = getDelta(lastMouseDB, false); showList(delta); } private void moveObjectsUp() { translateY -= 0.5*pasteBounds.getHeight(); Point2D delta = getDelta(lastMouseDB, false); showList(delta); } private void moveObjectsDown() { translateY += 0.5*pasteBounds.getHeight(); Point2D delta = getDelta(lastMouseDB, false); showList(delta); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -