📄 specialproperties.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: SpecialProperties.java * 2572968, exp 6/5/5 * Copyright (c) 2005 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.prototype.PortCharacteristic;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.variable.CodeExpression;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ui.EditWindow;import java.awt.Dimension;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.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Iterator;import java.util.List;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JTextField;/** * Class to handle special dialogs for specific nodes. */public class SpecialProperties{ /** * Method to handle special dialogs that are associated with double-clicking on a node. * @param wnd the EditWindow in which the click occurred. * @param ni the NodeInst that was double-clicked. * @return 1 if the double-click has been handled. * 0 if text edit in-place should be done. * -1 indicates that a general "node properties" dialog should be shown. */ public static int doubleClickOnNode(EditWindow wnd, NodeInst ni) { // if double-clicked on a schematic resistor, show special dialog if (ni.getProto() == Schematics.tech().resistorNode) { NodePropertiesDialog npd = new NodePropertiesDialog(wnd, ni, "Resistance", "Ohms", Schematics.SCHEM_RESISTANCE); if (npd.wantMore()) return -1; return 1; } // if double-clicked on a schematic capacitor, show special dialog if (ni.getProto() == Schematics.tech().capacitorNode) { NodePropertiesDialog npd = new NodePropertiesDialog(wnd, ni, "Capacitance", "Farads", Schematics.SCHEM_CAPACITANCE); if (npd.wantMore()) return -1; return 1; } // if double-clicked on a schematic inductor, show special dialog if (ni.getProto() == Schematics.tech().inductorNode) { NodePropertiesDialog npd = new NodePropertiesDialog(wnd, ni, "Inductance", "Henrys", Schematics.SCHEM_INDUCTANCE); if (npd.wantMore()) return -1; return 1; } // if double-clicked on a schematic diode, show special dialog if (ni.getProto() == Schematics.tech().diodeNode) { NodePropertiesDialog npd = new NodePropertiesDialog(wnd, ni, "Diode area", null, Schematics.SCHEM_DIODE); if (npd.wantMore()) return -1; return 1; } // if double-clicked on a schematic transistor, show special dialog if (ni.getProto() == Schematics.tech().transistorNode || ni.getProto() == Schematics.tech().transistor4Node) { PrimitiveNode.Function fun = ni.getFunction(); if (fun == PrimitiveNode.Function.TRA4NPN || fun == PrimitiveNode.Function.TRA4PNP || fun == PrimitiveNode.Function.TRANPN || fun == PrimitiveNode.Function.TRAPNP) { // show just the area value for NPN and PNP transistors NodePropertiesDialog npd = new NodePropertiesDialog(wnd, ni, "Transistor area", null, Schematics.ATTR_AREA); if (npd.wantMore()) return -1; return 1; } // show length and width for other transistors TransistorPropertiesDialog tpd = new TransistorPropertiesDialog(wnd, ni); if (tpd.wantMore()) return -1; return 1; } // if double-clicked on a schematic global, show special dialog if (ni.getProto() == Schematics.tech().globalNode) { GlobalPropertiesDialog gpd = new GlobalPropertiesDialog(wnd, ni); if (gpd.wantMore()) return -1; return 1; } return 0; } private static TextUtils.UnitScale getUnit(String str) { TextUtils.UnitScale [] scales = TextUtils.UnitScale.getUnitScales(); for (int i=0; i<scales.length; i++) { TextUtils.UnitScale u = scales[i]; String postfix = u.getPostFix(); if (postfix.equals("")) continue; // ignore the NONE suffix case if (postfix.length() >= str.length()) continue; // postfix is same length or longer than string String sSuffix = str.substring(str.length()-postfix.length(), str.length()); if (sSuffix.equalsIgnoreCase(postfix)) return u; } return TextUtils.UnitScale.NONE; } /** * This class displays a dialog for handling special node properties. */ private static class NodePropertiesDialog extends EDialog { private JTextField value; private JComboBox combo; private boolean cancelHit; private boolean moreHit; /** Creates new special node properties object */ private NodePropertiesDialog(EditWindow wnd, NodeInst ni, String title, String units, Variable.Key key) { super(null, true); TextUtils.UnitScale [] scales = TextUtils.UnitScale.getUnitScales(); String [] theScales = new String[scales.length]; for(int i=0; i<scales.length; i++) theScales[i] = scales[i].toString(); double num = 0; TextUtils.UnitScale scale = TextUtils.UnitScale.NONE; Variable var = ni.getVar(key); if (var != null) { String val = var.getObject().toString(); scale = getUnit(val); String postFix = scale.getPostFix(); if (postFix.length() > 0) val = val.substring(0, val.length()-postFix.length()); num = TextUtils.atof(val); } initComponents(wnd, ni, title, TextUtils.formatDouble(num), theScales, scale.getName(), units); cancelHit = moreHit = false; setVisible(true); toFront(); // all done: see if value should be updated if (!cancelHit) { String newValue = value.getText(); if (units != null) { int newScale = combo.getSelectedIndex(); newValue += scales[newScale].getPostFix(); } new ModifyNodeProperties(ni, key, newValue); } } protected void escapePressed() { exit(false); } private boolean wantMore() { return moreHit; } private void exit(boolean goodButton) { cancelHit = !goodButton; setVisible(false); dispose(); } private void moreButton() { moreHit = true; exit(true); } private void initComponents(EditWindow wnd, NodeInst ni, String title, String initialValue, String [] theScales, String initialScale, String units) { getContentPane().setLayout(new GridBagLayout()); setTitle(title); setName(""); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { exit(false); } }); // special information value = new JTextField(initialValue); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; if (units == null) gbc.gridwidth = 4; else gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = .5; gbc.insets = new Insets(4, 4, 4, 4); getContentPane().add(value, gbc); EDialog.makeTextFieldSelectAllOnTab(value); value.selectAll(); if (units != null) { combo = new JComboBox(); int selected = 0; for(int k=0; k<theScales.length; k++) { String sca = theScales[k]; if (sca.equalsIgnoreCase(initialScale)) selected = k; if (sca.length() == 0) combo.addItem(units); else combo.addItem(sca + "-" + units.toLowerCase()); } combo.setSelectedIndex(selected); gbc = new GridBagConstraints(); gbc.gridx = 2; gbc.gridy = 0; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = .5; gbc.insets = new Insets(4, 4, 4, 4); getContentPane().add(combo, gbc); } // OK, More, and Cancel JButton cancel = new JButton("Cancel"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(4, 4, 4, 4); getContentPane().add(cancel, gbc); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exit(false); } }); JButton more = new JButton("More..."); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(4, 4, 4, 4); getContentPane().add(more, gbc); more.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { moreButton(); } }); JButton ok = new JButton("OK"); gbc = new GridBagConstraints(); gbc.gridx = 3; gbc.gridy = 1; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(4, 4, 4, 4); getContentPane().add(ok, gbc); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exit(true); } }); getRootPane().setDefaultButton(ok); pack(); // now make the dialog appear over a node Point ew = wnd.getLocationOnScreen(); Point locInWnd = wnd.databaseToScreen(ni.getAnchorCenterX(), ni.getAnchorCenterY()); Point textfield = value.getLocation(); Dimension textSize = value.getSize(); setLocation(locInWnd.x+ew.x-(textfield.x+textSize.width/2), locInWnd.y+ew.y-(textfield.y+textSize.height/2+20)); } } /** * Class for saving changes in the special dialog. */ private static class ModifyNodeProperties extends Job { private NodeInst ni; private Variable.Key key; private String newValue, newValueLen; private CodeExpression.Code newCode, newCodeLen; private int newBits; private ModifyNodeProperties(NodeInst ni, Variable.Key key, String newValue) { super("Change Node Value", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.ni = ni; this.key = key; this.newValue = newValue; this.newBits = -1; startJob(); } private ModifyNodeProperties(NodeInst ni, Variable.Key key, String newValue, int newBits) { super("Change Node Value", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.ni = ni; this.key = key; this.newValue = newValue; this.newBits = newBits; startJob(); } private ModifyNodeProperties(NodeInst ni, String newWid, CodeExpression.Code newWidCode, String newLen, CodeExpression.Code newLenCode) { super("Change Node Value", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.ni = ni; this.key = null; this.newValue = newWid; this.newCode = newWidCode; this.newValueLen = newLen; this.newCodeLen = newLenCode; startJob(); } public boolean doIt() throws JobException { if (key == null) { // update length/width on transistor Variable oldWid = ni.getVar(Schematics.ATTR_WIDTH); TextDescriptor wtd = oldWid != null ? oldWid.getTextDescriptor() : TextDescriptor.getNodeTextDescriptor();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -