📄 editwindow.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: EditWindow.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.Snapshot;import com.sun.electric.database.change.DatabaseChangeEvent;import com.sun.electric.database.change.DatabaseChangeListener;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.EDatabase;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.Nodable;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.hierarchy.Cell.CellGroup;import com.sun.electric.database.id.CellId;import com.sun.electric.database.network.Netlist;import com.sun.electric.database.network.Network;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.text.Name;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.text.TextUtils.WhatToSearch;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.RTNode;import com.sun.electric.database.variable.CodeExpression;import com.sun.electric.database.variable.EditWindow_;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.VarContext;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.Layer;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.SizeOffset;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.generator.layout.LayoutLib;import com.sun.electric.tool.io.output.PNG;import com.sun.electric.tool.user.ActivityLogger;import com.sun.electric.tool.user.Highlight2;import com.sun.electric.tool.user.HighlightListener;import com.sun.electric.tool.user.Highlighter;import com.sun.electric.tool.user.MessagesStream;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.UserInterfaceMain;import com.sun.electric.tool.user.dialogs.GetInfoText;import com.sun.electric.tool.user.dialogs.SelectObject;import com.sun.electric.tool.user.redisplay.AbstractDrawing;import com.sun.electric.tool.user.redisplay.PixelDrawing;import com.sun.electric.tool.user.redisplay.VectorCache;import com.sun.electric.tool.user.waveform.WaveformWindow;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Point;import java.awt.Polygon;import java.awt.Rectangle;import java.awt.RenderingHints;import java.awt.Toolkit;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transferable;import java.awt.dnd.DnDConstants;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetDragEvent;import java.awt.dnd.DropTargetDropEvent;import java.awt.dnd.DropTargetEvent;import java.awt.dnd.DropTargetListener;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.AdjustmentEvent;import java.awt.event.AdjustmentListener;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.font.FontRenderContext;import java.awt.font.GlyphVector;import java.awt.font.LineMetrics;import java.awt.geom.AffineTransform;import java.awt.geom.Area;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.image.BufferedImage;import java.awt.print.PageFormat;import java.awt.print.PrinterJob;import java.io.Serializable;import java.util.ArrayList;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;import java.util.logging.Level;import java.util.logging.Logger;import java.util.regex.Matcher;import java.util.regex.Pattern;import javax.print.PrintService;import javax.print.attribute.standard.ColorSupported;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.JScrollBar;import javax.swing.SwingUtilities;import javax.swing.tree.MutableTreeNode;/** * This class defines an editing window for displaying circuitry. * It implements WindowContent, which means it can be in the main part of a window * (to the right of the explorer panel). */public class EditWindow extends JPanel implements EditWindow_, WindowContent, MouseMotionListener, MouseListener, MouseWheelListener, KeyListener, HighlightListener, DatabaseChangeListener{ /** the window scale */ private double scale; /** the requested window scale */ private double scaleRequested; /** the global text scale in this window */ private double globalTextScale; /** the window offset */ private double offx = 0, offy = 0; /** the requested window offset */ private double offxRequested, offyRequested; /** the size of the window (in pixels) */ private Dimension sz; /** the display cache for this window */ private AbstractDrawing drawing; /** the half-sizes of the window (in pixels) */ private int szHalfWidth, szHalfHeight; /** the cell that is in the window */ private Cell cell; /** the page number (for multipage schematics) */ private int pageNumber; /** list of edit-in-place text in this window */ private List<GetInfoText.EditInPlaceListener> inPlaceTextObjects = new ArrayList<GetInfoText.EditInPlaceListener>(); /** true if doing down-in-place display */ private boolean inPlaceDisplay; /** transform from screen to cell (down-in-place only) */ private AffineTransform intoCell = new AffineTransform(); /** transform from cell to screen (down-in-place only) */ private AffineTransform outofCell = new AffineTransform(); /** path to cell being edited (down-in-place only) */ private List<NodeInst> inPlaceDescent = new ArrayList<NodeInst>(); /** true if repaint was requested for this editwindow */volatile boolean repaintRequest; /** full instantiate bounds for next drawing */ private Rectangle2D fullInstantiateBounds; /** Cell's VarContext */ private VarContext cellVarContext;// /** Stack of selected PortInsts */ private PortInst[] selectedPorts; /** the window frame containing this editwindow */ private WindowFrame wf; /** the overall panel with disp area and sliders */ private JPanel overall; /** the bottom scrollbar on the edit window. */ private JScrollBar bottomScrollBar; /** the right scrollbar on the edit window. */ private JScrollBar rightScrollBar; /** true if showing grid in this window */ private boolean showGrid = false; /** X spacing of grid dots in this window */ private double gridXSpacing; /** Y spacing of grid dots in this window */ private double gridYSpacing; /** true if doing object-selection drag */ private boolean doingAreaDrag = false; /** starting screen point for drags in this window */ private Point startDrag = new Point(); /** ending screen point for drags in this window */ private Point endDrag = new Point(); /** true if drawing popup cloud */ private boolean showPopupCloud = false;// /** Strings to write to popup cloud */ private List<String> popupCloudText;// /** lower left corner of popup cloud */ private Point2D popupCloudPoint; /** Highlighter for this window */ private Highlighter highlighter; /** Mouse-over Highlighter for this window */ private Highlighter mouseOverHighlighter; /** Ruler Highlighter for this window */ private Highlighter rulerHighlighter; /** selectable text in this window */ private RTNode textInCell; /** navigate through saved views */ private EditWindowFocusBrowser viewBrowser; /** synchronization lock */ private static Object lock = new Object(); /** scheduled or running rendering job */ private static RenderJob runningNow = null; /** Logger of this package. */ private static Logger logger = Logger.getLogger("com.sun.electric.tool.user.ui"); /** Class name for logging. */ private static String CLASS_NAME = EditWindow.class.getName(); private static final int SCROLLBARRESOLUTION = 200; /** for drawing selection boxes */ private static final BasicStroke selectionLine = new BasicStroke( 1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {2}, 3); /** for outlining down-hierarchy in-place bounds */ private static final BasicStroke inPlaceMarker = new BasicStroke(2); private static EditWindowDropTarget editWindowDropTarget = new EditWindowDropTarget(); // ************************************* CONSTRUCTION ************************************* // constructor private EditWindow(Cell cell, WindowFrame wf, Dimension approxSZ) { this.cell = cell; this.pageNumber = 0; this.wf = wf; setDrawingAlgorithm(); this.gridXSpacing = User.getDefGridXSpacing(); this.gridYSpacing = User.getDefGridYSpacing(); inPlaceDisplay = false; viewBrowser = new EditWindowFocusBrowser(this); sz = approxSZ; if (sz == null) sz = new Dimension(500, 500); szHalfWidth = sz.width / 2; szHalfHeight = sz.height / 2; setSize(sz.width, sz.height); setPreferredSize(sz); scale = scaleRequested = 1; textInCell = null; globalTextScale = User.getGlobalTextScale(); // the total panel in the edit window overall = new JPanel(); overall.setLayout(new GridBagLayout()); // the horizontal scroll bar int thumbSize = SCROLLBARRESOLUTION / 20; bottomScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, SCROLLBARRESOLUTION/2, thumbSize, 0, SCROLLBARRESOLUTION+thumbSize); bottomScrollBar.setBlockIncrement(SCROLLBARRESOLUTION / 5); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; overall.add(bottomScrollBar, gbc); bottomScrollBar.addAdjustmentListener(new ScrollAdjustmentListener(this)); bottomScrollBar.setValue(bottomScrollBar.getMaximum()/2); // the vertical scroll bar in the edit window rightScrollBar = new JScrollBar(JScrollBar.VERTICAL, SCROLLBARRESOLUTION/2, thumbSize, 0, SCROLLBARRESOLUTION+thumbSize); rightScrollBar.setBlockIncrement(SCROLLBARRESOLUTION / 5); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.VERTICAL; overall.add(rightScrollBar, gbc); rightScrollBar.addAdjustmentListener(new ScrollAdjustmentListener(this)); rightScrollBar.setValue(rightScrollBar.getMaximum()/2); // put this object's display up gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; gbc.weightx = gbc.weighty = 1; overall.add(this, gbc); setOpaque(true); setLayout(null); // a drop target for the signal panel new DropTarget(this, DnDConstants.ACTION_LINK, editWindowDropTarget, true); //setAutoscrolls(true); installHighlighters(); if (wf != null) { // make a highlighter for this window UserInterfaceMain.addDatabaseChangeListener(this); Highlighter.addHighlightListener(this); setCell(cell, VarContext.globalContext, null); } } private void setDrawingAlgorithm() { drawing = AbstractDrawing.createDrawing(this, drawing, cell); LayerTab layerTab = getWindowFrame().getLayersTab(); if (layerTab != null) layerTab.setDisplayAlgorithm(drawing.hasOpacity()); } private void installHighlighters() { // see if this cell is displayed elsewhere highlighter = mouseOverHighlighter = rulerHighlighter = null; for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame oWf = it.next(); if (oWf.getContent() instanceof EditWindow) { EditWindow oWnd = (EditWindow)oWf.getContent(); if (oWnd == this) continue; if (oWnd.getCell() == cell) { highlighter = oWnd.highlighter; mouseOverHighlighter = oWnd.mouseOverHighlighter; rulerHighlighter = oWnd.rulerHighlighter; break; } } } if (highlighter == null) { // not shown elsewhere: create highlighters highlighter = new Highlighter(Highlighter.SELECT_HIGHLIGHTER, wf); mouseOverHighlighter = new Highlighter(Highlighter.MOUSEOVER_HIGHLIGHTER, wf); rulerHighlighter = new Highlighter(Highlighter.RULER_HIGHLIGHTER, wf); } // add listeners --> BE SURE to remove listeners in finished() addKeyListener(this); addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); } private void uninstallHighlighters() { removeKeyListener(this); removeMouseListener(this); removeMouseMotionListener(this); removeMouseWheelListener(this); // see if the highlighters are used elsewhere boolean used = false; for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame oWf = it.next(); if (oWf.getContent() instanceof EditWindow) { EditWindow oWnd = (EditWindow)oWf.getContent(); if (oWnd == this) continue; if (oWnd.getCell() == cell) { used = true; break; } } } if (!used) { highlighter.delete(); mouseOverHighlighter.delete(); rulerHighlighter.delete(); } } /** * Factory method to create a new EditWindow with a given cell, in a given WindowFrame. * @param cell the cell in this EditWindow. * @param wf the WindowFrame that this EditWindow lives in. * @param approxSZ the approximate size of this EditWindow (in pixels). * @return the new EditWindow. */ public static EditWindow CreateElectricDoc(Cell cell, WindowFrame wf, Dimension approxSZ) { EditWindow ui = new EditWindow(cell, wf, approxSZ); return ui; } // ************************************* EVENT LISTENERS ************************************* private int lastXPosition, lastYPosition; // the MouseListener events public void mousePressed(MouseEvent evt) { requestFocus(); MessagesStream.userCommandIssued(); lastXPosition = evt.getX(); lastYPosition = evt.getY(); WindowFrame.curMouseListener.mousePressed(evt); } public void mouseReleased(MouseEvent evt) { lastXPosition = evt.getX(); lastYPosition = evt.getY(); WindowFrame.curMouseListener.mouseReleased(evt); } public void mouseClicked(MouseEvent evt) { lastXPosition = evt.getX(); lastYPosition = evt.getY();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -