📄 newarcstab.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: NewArcsTab.java * * Copyright (c) 2004 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.options;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.TextUtils;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.dialogs.EDialog;import com.sun.electric.tool.user.ui.TopLevel;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;/** * Class to handle the "New Arcs" tab of the Preferences dialog. */public class NewArcsTab extends PreferencePanel{ /** Creates new form NewArcsTab */ public NewArcsTab(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); // make all text fields select-all when entered EDialog.makeTextFieldSelectAllOnTab(arcWidth); EDialog.makeTextFieldSelectAllOnTab(arcAngle); } /** return the panel to use for this preferences tab. */ public JPanel getPanel() { return newArc; } /** return the name of this preferences tab. */ public String getName() { return "Arcs"; } private static class PrimArcInfo { boolean initialRigid, rigid; boolean initialFixedAngle, fixedAngle; boolean initialSlidable, slidable; boolean initialDirectional, directional; boolean initialEndsExtend, endsExtend; double initialWid, wid; int initialAngleIncrement, angleIncrement; PrimitiveNode initialPin, pin; } private Map<ArcProto,PrimArcInfo> initialNewArcsPrimInfo; private boolean newArcsDataChanging = false; private Technology selectedTech; /** * Method called at the start of the dialog. * Caches current values and displays them in the New Arcs tab. */ public void init() { // gather information about the ArcProtos in the current Technology initialNewArcsPrimInfo = new HashMap<ArcProto,PrimArcInfo>(); for(Iterator<Technology> tIt = Technology.getTechnologies(); tIt.hasNext(); ) { Technology tech = tIt.next(); technologySelection.addItem(tech.getTechName()); for(Iterator<ArcProto> it = tech.getArcs(); it.hasNext(); ) { ArcProto ap = it.next(); PrimArcInfo pai = new PrimArcInfo(); pai.initialRigid = pai.rigid = ap.isRigid(); pai.initialFixedAngle = pai.fixedAngle = ap.isFixedAngle(); pai.initialSlidable = pai.slidable = ap.isSlidable(); pai.initialDirectional = pai.directional = ap.isDirectional(); pai.initialEndsExtend = pai.endsExtend = ap.isExtended(); pai.initialWid = pai.wid = ap.getDefaultLambdaBaseWidth(); pai.initialAngleIncrement = pai.angleIncrement = ap.getAngleIncrement(); pai.initialPin = pai.pin = ap.findOverridablePinProto(); initialNewArcsPrimInfo.put(ap, pai); } } technologySelection.setSelectedItem(Technology.getCurrent().getTechName()); selectedTech = null; newArcsPrimPopupChanged(); // setup listeners to react to a change of the selected arc technologySelection.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimPopupChanged(); } }); arcProtoList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimPopupChanged(); } }); // setup listeners to react to any changes to the arc values arcRigid.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimDataChanged(); } }); arcFixedAngle.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimDataChanged(); } }); arcSlidable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimDataChanged(); } }); arcDirectional.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimDataChanged(); } }); arcEndsExtend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimDataChanged(); } }); arcWidth.getDocument().addDocumentListener(new NewArcDocumentListener(this)); arcAngle.getDocument().addDocumentListener(new NewArcDocumentListener(this)); arcPin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newArcsPrimDataChanged(); } }); playClickSounds.setSelected(User.isPlayClickSoundsWhenCreatingArcs()); incrementArcNames.setSelected(User.isArcsAutoIncremented()); } /** * Method called when the primitive arc popup is changed. */ private void newArcsPrimPopupChanged() { String techName = (String)technologySelection.getSelectedItem(); Technology tech = Technology.findTechnology(techName); if (tech == null) return; if (tech != selectedTech) { // reload the arcs selectedTech = tech; arcProtoList.removeAllItems(); arcPin.removeAllItems(); for(Iterator<ArcProto> it = tech.getArcs(); it.hasNext(); ) { ArcProto ap = it.next(); arcProtoList.addItem(ap.getName()); } // setup popup of possible pins for(Iterator<PrimitiveNode> it = tech.getNodes(); it.hasNext(); ) { PrimitiveNode np = it.next(); arcPin.addItem(np.getName()); } } String primName = (String)arcProtoList.getSelectedItem(); ArcProto ap = tech.findArcProto(primName); PrimArcInfo pai = initialNewArcsPrimInfo.get(ap); if (pai == null) return; newArcsDataChanging = true; arcRigid.setSelected(pai.rigid); arcFixedAngle.setSelected(pai.fixedAngle); arcSlidable.setSelected(pai.slidable); arcDirectional.setSelected(pai.directional); arcEndsExtend.setSelected(pai.endsExtend); arcWidth.setText(TextUtils.formatDouble(pai.wid)); arcAngle.setText(Integer.toString(pai.angleIncrement)); arcPin.setSelectedItem(pai.pin.getName()); newArcsDataChanging = false; } /** * Class to handle special changes to per-primitive arc options. */ private static class NewArcDocumentListener implements DocumentListener { NewArcsTab dialog; NewArcDocumentListener(NewArcsTab dialog) { this.dialog = dialog; } public void changedUpdate(DocumentEvent e) { dialog.newArcsPrimDataChanged(); } public void insertUpdate(DocumentEvent e) { dialog.newArcsPrimDataChanged(); } public void removeUpdate(DocumentEvent e) { dialog.newArcsPrimDataChanged(); } } /** * Method called when any of the primitive data changes. * Caches all values for the selected primitive arc. */ private void newArcsPrimDataChanged() { if (newArcsDataChanging) return; String techName = (String)technologySelection.getSelectedItem(); Technology tech = Technology.findTechnology(techName); if (tech == null) return; String primName = (String)arcProtoList.getSelectedItem(); ArcProto ap = tech.findArcProto(primName); PrimArcInfo pai = initialNewArcsPrimInfo.get(ap); if (pai == null) return; pai.rigid = arcRigid.isSelected(); pai.fixedAngle = arcFixedAngle.isSelected(); pai.slidable = arcSlidable.isSelected(); pai.directional = arcDirectional.isSelected(); pai.endsExtend = arcEndsExtend.isSelected(); pai.wid = TextUtils.atof(arcWidth.getText()); pai.angleIncrement = TextUtils.atoi(arcAngle.getText()); pai.pin = tech.findNodeProto((String)arcPin.getSelectedItem()); PortProto pp = pai.pin.getPorts().next(); if (!pp.connectsTo(ap)) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Cannot use " + pai.pin.getName() + " as a pin because it does not connect to " + ap.getName() + " arcs"); pai.pin = pai.initialPin; arcPin.setSelectedItem(pai.pin.getName()); } } /** * Method called when the "OK" panel is hit. * Updates any changed fields in the New Arcs tab. */ public void term() { for(Iterator<Technology> tIt = Technology.getTechnologies(); tIt.hasNext(); ) { Technology tech = tIt.next(); for(Iterator<ArcProto> it = tech.getArcs(); it.hasNext(); ) { ArcProto ap = it.next(); PrimArcInfo pai = initialNewArcsPrimInfo.get(ap); if (pai.rigid != pai.initialRigid) ap.setRigid(pai.rigid); if (pai.fixedAngle != pai.initialFixedAngle) ap.setFixedAngle(pai.fixedAngle); if (pai.slidable != pai.initialSlidable) ap.setSlidable(pai.slidable); if (pai.directional != pai.initialDirectional) ap.setDirectional(pai.directional); if (pai.endsExtend != pai.initialEndsExtend) ap.setExtended(pai.endsExtend); if (pai.wid != pai.initialWid) ap.setDefaultLambdaBaseWidth(pai.wid); if (pai.angleIncrement != pai.initialAngleIncrement) ap.setAngleIncrement(pai.angleIncrement); if (pai.pin != pai.initialPin) { ap.setPinProto(pai.pin); } } } boolean currBoolean = playClickSounds.isSelected(); if (currBoolean != User.isPlayClickSoundsWhenCreatingArcs()) User.setPlayClickSoundsWhenCreatingArcs(currBoolean); currBoolean = incrementArcNames.isSelected(); if (currBoolean != User.isArcsAutoIncremented()) User.setArcsAutoIncremented(currBoolean); } /** * Method called when the factory reset is requested. */ public void reset() { for(Iterator<Technology> tIt = Technology.getTechnologies(); tIt.hasNext(); )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -