getinfotext.java
来自「The ElectricTM VLSI Design System is an 」· Java 代码 · 共 974 行 · 第 1/2 页
JAVA
974 行
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: GetInfoText.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.dialogs;import com.sun.electric.database.change.DatabaseChangeEvent;import com.sun.electric.database.change.DatabaseChangeListener;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.tool.Client;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.io.output.Verilog;import com.sun.electric.tool.simulation.Simulation;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.User;import com.sun.electric.tool.user.UserInterfaceMain;import com.sun.electric.tool.user.menus.EMenuBar;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowFrame;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;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.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowFocusListener;import java.awt.font.GlyphVector;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.EventListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JEditorPane;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.border.BevelBorder;import javax.swing.border.EmptyBorder;import javax.swing.event.UndoableEditEvent;import javax.swing.event.UndoableEditListener;import javax.swing.text.Document;import javax.swing.text.JTextComponent;import javax.swing.undo.CannotUndoException;import javax.swing.undo.UndoManager;/** * Class to handle the Text "Properties" dialog. */public class GetInfoText extends EModelessDialog implements HighlightListener, DatabaseChangeListener { private static GetInfoText theDialog = null; private CachedTextInfo cti; private TextPropertiesFocusListener dialogFocusListener; /** * Class to hold information about the text being manipulated. */ private static class CachedTextInfo { private Highlight2 shownText; private String initialText; private Variable var; private Variable.Key varKey; private TextDescriptor td; private ElectricObject owner; private String description; private boolean instanceName; private boolean multiLineCapable; /** * Method to load the field variables from a Highlight. * @param h the Highlight of text. */ CachedTextInfo(Highlight2 h) { shownText = h; description = "Unknown text"; initialText = ""; td = null; owner = shownText.getElectricObject(); instanceName = multiLineCapable = false; NodeInst ni = null; if (owner instanceof NodeInst) { ni = (NodeInst)owner; } varKey = shownText.getVarKey(); if (varKey != null) { if (ni != null && ni.isInvisiblePinWithText() && varKey == Artwork.ART_MESSAGE) multiLineCapable = true; var = owner.getParameterOrVariable(varKey); if (var != null) { Object obj = var.getObject(); if (obj instanceof Object[]) { // unwind the array elements by hand Object[] theArray = (Object[]) obj; initialText = ""; for (int i = 0; i < theArray.length; i++) { if (i != 0) initialText += "\n"; initialText += theArray[i]; } multiLineCapable = true; } else { initialText = var.getPureValue(-1); } description = var.getFullDescription(owner); } else if (varKey == NodeInst.NODE_NAME) { description = "Name of " + ni.getProto(); varKey = NodeInst.NODE_NAME; initialText = ni.getName(); } else if (varKey == ArcInst.ARC_NAME) { ArcInst ai = (ArcInst)owner; description = "Name of " + ai.getProto(); varKey = ArcInst.ARC_NAME; initialText = ai.getName(); } else if (varKey == NodeInst.NODE_PROTO) { description = "Name of cell instance " + ni.describe(true); varKey = NodeInst.NODE_PROTO; initialText = ni.getProto().describe(true); instanceName = true; } else if (varKey == Export.EXPORT_NAME) { Export pp = (Export)owner; description = "Name of export " + pp.getName(); varKey = Export.EXPORT_NAME; initialText = pp.getName(); } } td = owner.getTextDescriptor(varKey); } /** * Method to tell whether the highlighted text is the name of a cell instance. * These cannot be edited by in-line editing. * @return true if the highlighted text is the name of a cell instance. */ public boolean isInstanceName() { return instanceName; } /** * Method to tell whether the highlighted text can be expressed with * more than 1 line of text. * This only applies to text on Invisible Pins (annotation text). * @return true if the highlighted text can have more than 1 line. */ public boolean isMultiLineCapable() { return multiLineCapable; } } /** * Method to show the Text Properties dialog. */ public static void showDialog() { if (Client.getOperatingSystem() == Client.OS.UNIX) { // JKG 07Apr2006: // On Linux, if a dialog is built, closed using setVisible(false), // and then requested again using setVisible(true), it does // not appear on top. I've tried using toFront(), requestFocus(), // but none of that works. Instead, I brute force it and // rebuild the dialog from scratch each time. if (theDialog != null) { theDialog.removeWindowFocusListener(theDialog.dialogFocusListener); theDialog.dispose(); } theDialog = null; } if (theDialog == null) { JFrame jf = null; if (TopLevel.isMDIMode()) jf = TopLevel.getCurrentJFrame(); theDialog = new GetInfoText(jf); } theDialog.loadTextInfo(); if (!theDialog.isVisible()) { theDialog.pack(); theDialog.ensureProperSize(); theDialog.setVisible(true); } theDialog.toFront(); } /** * Creates new form Text Get-Info */ private GetInfoText(Frame parent) { super(parent, false); initComponents(); getRootPane().setDefaultButton(ok); UserInterfaceMain.addDatabaseChangeListener(this); Highlighter.addHighlightListener(this); dialogFocusListener = new TextPropertiesFocusListener(); addWindowFocusListener(dialogFocusListener); loadTextInfo(); finishInitialization(); } private class TextPropertiesFocusListener implements WindowFocusListener { public synchronized void windowGainedFocus(WindowEvent e) { theText.requestFocus(); } public void windowLostFocus(WindowEvent e) {} } /** * Reloads the dialog when Highlights change */ public void highlightChanged(Highlighter which) { if (!isVisible()) return; loadTextInfo(); } /** * 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) { if (!isVisible()) return; loadTextInfo(); } public void databaseChanged(DatabaseChangeEvent e) { if (!isVisible()) return; // update dialog if (cti != null && e.objectChanged(cti.owner)) loadTextInfo(); } private void loadTextInfo() { // must have a single text selected Highlight2 textHighlight = null; EditWindow curWnd = EditWindow.getCurrent(); int textCount = 0; if (curWnd != null) { for (Highlight2 h : curWnd.getHighlighter().getHighlights()) { if (!h.isHighlightText()) continue; // ignore export text if (h.getVarKey() == Export.EXPORT_NAME) continue; textHighlight = h; textCount++; } } if (textCount > 1) textHighlight = null; boolean enabled = (textHighlight == null) ? false : true; EDialog.focusClearOnTextField(theText); // enable or disable everything for (int i = 0; i < getComponentCount(); i++) { Component c = getComponent(i); c.setEnabled(enabled); } if (!enabled) { header.setText("No Text Selected"); evaluation.setText(" "); theText.setText(""); // for some reason, the following line causes keyboard input to get ignored on SUSE Linux 9.1// theText.setEnabled(false); cti = null; textPanel.setTextDescriptor(null, null); attrPanel.setVariable(null, null); ok.setEnabled(false); apply.setEnabled(false); multiLine.setEnabled(false); return; } // cache information about the Highlight cti = new CachedTextInfo(textHighlight); // enable buttons ok.setEnabled(true); apply.setEnabled(true); header.setText(cti.description); theText.setText(cti.initialText); theText.setEditable(true); // if multiline text, make it a TextArea, otherwise it's a TextField if (cti.initialText.indexOf('\n') != -1) { // if this is the name of an object it should not be multiline if (cti.shownText != null && (cti.varKey == NodeInst.NODE_NAME || cti.varKey == ArcInst.ARC_NAME)) { multiLine.setEnabled(false); multiLine.setSelected(false); } else { multiLine.setEnabled(true); multiLine.setSelected(true); } } else { // if this is the name of an object it should not be multiline if (cti.shownText != null && (cti.varKey == NodeInst.NODE_NAME || cti.varKey == ArcInst.ARC_NAME)) { multiLine.setEnabled(false); } else { multiLine.setEnabled(true); } multiLine.setSelected(false); } // if the var is code, evaluate it evaluation.setText(" "); if (cti.var != null) { if (cti.var.isCode()) { evaluation.setText("Evaluation: " + cti.var.describe(-1)); } } // set the text edit panel textPanel.setTextDescriptor(cti.varKey, cti.owner); attrPanel.setVariable(cti.varKey, cti.owner); // do this last so everything gets packed right changeTextComponent(cti.initialText, multiLine.isSelected()); EDialog.focusOnTextField(theText); // if this is a cell instance name, disable editing if (cti.varKey == NodeInst.NODE_PROTO) { theText.setEditable(false); theText.setEnabled(false); multiLine.setEnabled(false); } } protected void escapePressed() { cancelActionPerformed(null); } /** * Method to edit text in place. */ public static void editTextInPlace() { // there must be a current edit window EditWindow curWnd = EditWindow.getCurrent(); if (curWnd == null) return; // must have a single text selected Highlight2 theHigh = null; int textCount = 0; for (Highlight2 h : curWnd.getHighlighter().getHighlights()) { if (!h.isHighlightText()) continue; theHigh = h; textCount++; } if (textCount > 1) theHigh = null; if (theHigh == null) return; // grab information about the highlighted text CachedTextInfo cti = new CachedTextInfo(theHigh); if (cti.isInstanceName()) { showDialog(); return; } // get text description Font theFont = curWnd.getFont(cti.td); if (theFont == null) { // text too small to draw (or edit), show the dialog showDialog(); return; } Point2D [] points = Highlighter.describeHighlightText(curWnd, cti.owner, cti.varKey); int lowX=0, highX=0, lowY=0, highY=0; for(int i=0; i<points.length; i++) { Point pt = curWnd.databaseToScreen(points[i]); if (i == 0) { lowX = highX = pt.x; lowY = highY = pt.y; } else { if (pt.x < lowX) lowX = pt.x; if (pt.x > highX) highX = pt.x; if (pt.y < lowY) lowY = pt.y; if (pt.y > highY) highY = pt.y; } } if (cti.td.getDispPart() != TextDescriptor.DispPos.VALUE && (cti.var == null || cti.var.getLength() == 1)) { GlyphVector gv = curWnd.getGlyphs(cti.initialText, theFont); Rectangle2D glyphBounds = gv.getLogicalBounds(); lowX = highX - (int)glyphBounds.getWidth(); } new EditInPlaceListener(cti, curWnd, theFont, lowX, lowY); } /** * Class for in-line editing a single-line piece of text. * The class exists so that it can grab the focus. */ static private class EIPTextField extends JTextField { EIPTextField(String text) { super(text); } public void paint(Graphics g) { requestFocus(); super.paint(g); } } /** * Class for in-line editing a multiple-line piece of text. * The class exists so that it can grab the focus. */ static private class EIPEditorPane extends JEditorPane { EIPEditorPane(String text) { super("text/plain", text); } public void paint(Graphics g) { requestFocus(); super.paint(g); } } /** * Class to handle edit-in-place of text. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?