📄 editwindow.java
字号:
WindowFrame.curMouseListener.mouseClicked(evt); } public void mouseEntered(MouseEvent evt) { lastXPosition = evt.getX(); lastYPosition = evt.getY(); showCoordinates(evt); WindowFrame.curMouseListener.mouseEntered(evt); } public void mouseExited(MouseEvent evt) { lastXPosition = evt.getX(); lastYPosition = evt.getY(); WindowFrame.curMouseListener.mouseExited(evt); } // the MouseMotionListener events public void mouseMoved(MouseEvent evt) { lastXPosition = evt.getX(); lastYPosition = evt.getY(); showCoordinates(evt); WindowFrame.curMouseMotionListener.mouseMoved(evt); } public void mouseDragged(MouseEvent evt) { lastXPosition = evt.getX(); lastYPosition = evt.getY(); showCoordinates(evt); WindowFrame.curMouseMotionListener.mouseDragged(evt); } private void showCoordinates(MouseEvent evt) { EditWindow wnd = (EditWindow)evt.getSource(); if (wnd.getCell() == null) StatusBar.setCoordinates(null, wnd.wf); else { Point2D pt = wnd.screenToDatabase(evt.getX(), evt.getY()); EditWindow.gridAlign(pt); if (User.isShowHierarchicalCursorCoordinates()) { // if the current VarContext is not the global one, user is "down hierarchy" String path = null; if (cellVarContext != VarContext.globalContext) { Point2D ptPath = new Point2D.Double(pt.getX(), pt.getY()); VarContext vc = cellVarContext; boolean validPath = true; boolean first = true; NodeInst ni = null; path = ""; while (vc != VarContext.globalContext) { Nodable no = vc.getNodable(); if (!(no instanceof NodeInst)) { validPath = false; break; } ni = (NodeInst)no; path = ni.getParent().getName() + "[" + ni.getName() + "]" + (first? "" : " / ") + path; if (first) first = false; AffineTransform trans = ni.translateOut(ni.rotateOut()); trans.transform(ptPath, ptPath); vc = vc.pop(); } if (validPath) { if (ni.getParent().isSchematic()) { path = "Location is " + ni.getParent() + " / " + path; } else { path = "Location in " + ni.getParent() + " / " + path + " is (" + TextUtils.formatDouble(ptPath.getX(), 2) + ", " + TextUtils.formatDouble(ptPath.getY(), 2) + ")"; } } else path = null; } StatusBar.setHierarchicalCoordinates(path, wnd.wf); } StatusBar.setCoordinates("(" + TextUtils.formatDouble(pt.getX(), 2) + ", " + TextUtils.formatDouble(pt.getY(), 2) + ")", wnd.wf); } } // the MouseWheelListener events public void mouseWheelMoved(MouseWheelEvent evt) { WindowFrame.curMouseWheelListener.mouseWheelMoved(evt); } // the KeyListener events public void keyPressed(KeyEvent evt) { MessagesStream.userCommandIssued(); WindowFrame.curKeyListener.keyPressed(evt); } public void keyReleased(KeyEvent evt) { WindowFrame.curKeyListener.keyReleased(evt); } public void keyTyped(KeyEvent evt) { WindowFrame.curKeyListener.keyTyped(evt); } public void highlightChanged(Highlighter which) { repaint(); } /** * Called when by a Highlighter when it loses focus. The argument * is the Highlighter that has gained focus (may be null). * @param highlighterGainedFocus the highlighter for the current window (may be null). */ public void highlighterLostFocus(Highlighter highlighterGainedFocus) {} public Point getLastMousePosition() { return new Point(lastXPosition, lastYPosition); } // ************************************* WHEN DROPPING A CELL NAME FROM THE EXPLORER TREE ************************************* /** * Method to figure out which cell in a cell group should be used when dragging the group * onto this EditWindow. * @param group the cell group dragged. * @return the Cell in the group to drag into this EditWindow. */ private Cell whichCellInGroup(CellGroup group) { if (cell == null) return null; for(Iterator<Cell> it = group.getCells(); it.hasNext(); ) { Cell c = it.next(); View cV = c.getView(); if (cV == View.DOC) continue; // skip document if (cV == View.ICON) { if (cell.getView() == View.SCHEMATIC || cell.getView() == View.ICON) return c; } else if (cV != View.SCHEMATIC) { if (cell.getView() != View.SCHEMATIC && cell.getView() != View.ICON) return c; } } return null; } /** * Method to set the highlight to show the outline of a node that will be placed in this EditWindow. * @param toDraw the object to draw (a NodeInst or a NodeProto). * @param oldx the X position (on the screen) of the outline. * @param oldy the Y position (on the screen) of the outline. */ public void showDraggedBox(Object toDraw, int oldx, int oldy) { // undraw it Highlighter highlighter = getHighlighter(); highlighter.clear(); // draw it Point2D drawnLoc = screenToDatabase(oldx, oldy); EditWindow.gridAlign(drawnLoc); NodeProto np = null; if (toDraw instanceof CellGroup) { // figure out which cell in the group should be dragged np = whichCellInGroup((CellGroup)toDraw); } if (toDraw instanceof NodeInst) { NodeInst ni = (NodeInst)toDraw; np = ni.getProto(); } if (toDraw instanceof NodeProto) { np = (NodeProto)toDraw; } int defAngle = 0; if (toDraw instanceof NodeInst) { NodeInst ni = (NodeInst)toDraw; defAngle = ni.getAngle(); } if (toDraw instanceof PrimitiveNode) { defAngle = User.getNewNodeRotation(); } if (np != null) { // zoom the window to fit the placed node (if appropriate) zoomWindowToFitCellInstance(np); Poly poly = null; Orientation orient = Orientation.fromJava(defAngle, defAngle >= 3600, false); if (np instanceof Cell) { Cell placeCell = (Cell)np; Rectangle2D cellBounds = placeCell.getBounds(); poly = new Poly(cellBounds); AffineTransform rotate = orient.pureRotate(); AffineTransform translate = new AffineTransform(); translate.setToTranslation(drawnLoc.getX(), drawnLoc.getY()); rotate.concatenate(translate); poly.transform(rotate); } else { SizeOffset so = np.getProtoSizeOffset(); double trueSizeX = np.getDefWidth() - so.getLowXOffset() - so.getHighXOffset(); double trueSizeY = np.getDefHeight() - so.getLowYOffset() - so.getHighYOffset(); double dX = (so.getHighXOffset() - so.getLowXOffset())/2; double dY = (so.getHighYOffset() - so.getLowYOffset())/2; poly = new Poly(drawnLoc.getX()-dX, drawnLoc.getY()-dY, trueSizeX, trueSizeY); AffineTransform trans = orient.rotateAbout(drawnLoc.getX(), drawnLoc.getY()); poly.transform(trans); } Point2D [] points = poly.getPoints(); for(int i=0; i<points.length; i++) { int last = i-1; if (i == 0) last = points.length - 1; highlighter.addLine(points[last], points[i], getCell()); } repaint(); } highlighter.finished(); } /** * Method to zoom this window to fit a placed node (if appropriate). * If the placed object is a cell instance that is larger than the window, * and the window is empty, zoom out to fit. * @param np the node being placed. */ public void zoomWindowToFitCellInstance(NodeProto np) { Cell parent = getCell(); if (parent == null) return; boolean empty = true; if (parent.getNumArcs() > 0) empty = false; if (parent.getNumNodes() > 1) empty = false; else { if (parent.getNumNodes() == 1) { NodeInst onlyNi = parent.getNode(0); if (onlyNi.getProto() != Generic.tech().cellCenterNode) empty = false; } } if (empty && np instanceof Cell) { // placing instance of cell into empty cell: see if scaling is necessary Rectangle2D cellBounds = ((Cell)np).getBounds(); Rectangle2D screenBounds = displayableBounds(); if (cellBounds.getWidth() > screenBounds.getWidth() || cellBounds.getHeight() > screenBounds.getHeight()) { double scaleX = cellBounds.getWidth() / (screenBounds.getWidth() * 0.9); double scaleY = cellBounds.getHeight() / (screenBounds.getHeight() * 0.9); double scale = Math.max(scaleX, scaleY); setScale(getScale() / scale); } } } /** * Class to define a custom data flavor that packages a NodeProto to create. */ public static class NodeProtoDataFlavor extends DataFlavor { private Cell cell; private Cell.CellGroup group; private ExplorerTree originalTree; NodeProtoDataFlavor(Cell cell, Cell.CellGroup group, ExplorerTree originalTree) { super(NodeProto.class, "electric/instance"); this.cell = cell; this.group = group; this.originalTree = originalTree; } public Object getFlavorObject() { if (cell != null) return cell; return group; } public ExplorerTree getOriginalTree() { return originalTree; } } /** * Class to define a custom transferable that packages a Cell or Group. */ public static class NodeProtoTransferable implements Transferable { private Cell cell; private Cell.CellGroup group; private NodeProtoDataFlavor df; public NodeProtoTransferable(Object obj, ExplorerTree tree) { if (obj instanceof Cell) { cell = (Cell)obj; group = cell.getCellGroup(); } else if (obj instanceof Cell.CellGroup) { group = (Cell.CellGroup)obj; } df = new NodeProtoDataFlavor(cell, group, tree); } public boolean isValid() { return group != null; } public DataFlavor[] getTransferDataFlavors() { DataFlavor [] it = new DataFlavor[1]; it[0] = df; return it; } public boolean isDataFlavorSupported(DataFlavor flavor) { if (flavor == df) return true; return false; } public Object getTransferData(DataFlavor flavor) { if (flavor != df) return null; if (cell != null) return cell; return group; } } /** * Class for catching drags into the edit window. * These drags come from the Explorer tree (when a cell name is dragged to place an instance). */ private static class EditWindowDropTarget implements DropTargetListener { public void dragEnter(DropTargetDragEvent e) { dragAction(e); } public void dragOver(DropTargetDragEvent e) { dragAction(e); } private Object getDraggedObject(DataFlavor [] flavors) { if (flavors.length > 0) { if (flavors[0] instanceof NodeProtoDataFlavor) { NodeProtoDataFlavor npdf = (NodeProtoDataFlavor)flavors[0]; Object obj = npdf.getFlavorObject(); return obj; } } return null; } private void dragAction(DropTargetDragEvent e) { Object obj = getDraggedObject(e.getCurrentDataFlavors()); if (obj != null) { e.acceptDrag(e.getDropAction()); // determine the window DropTarget dt = (DropTarget)e.getSource(); if (dt.getComponent() instanceof JPanel) { EditWindow wnd = (EditWindow)dt.getComponent(); wnd.showDraggedBox(obj, e.getLocation().x, e.getLocation().y); } return; } } public void dropActionChanged(DropTargetDragEvent e) { e.acceptDrag(e.getDropAction()); } public void dragExit(DropTargetEvent e) {} public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_LINK); Object obj = getDraggedObject(dtde.getCurrentDataFlavors()); if (obj == null) { dtde.dropComplete(false); return; } // determine the window DropTarget dt = (DropTarget)dtde.getSource(); if (!(dt.getComponent() instanceof JPanel))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -