📄 change.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: Change.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.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.network.Netlist;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Connection;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.technology.ArcProto;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.Client;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.CircuitChangeJobs;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.ui.EditWindow;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowFrame;import java.awt.Frame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.geom.Point2D;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.regex.Matcher;import java.util.regex.Pattern;import javax.swing.DefaultListModel;import javax.swing.JFrame;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JRadioButton;import javax.swing.ListSelectionModel;import javax.swing.SwingUtilities;/** * Class to handle the "Change" dialog. */public class Change extends EModelessDialog implements HighlightListener{ /** Change selected only. */ private static final int CHANGE_SELECTED = 1; /** Change all connected to this. */ private static final int CHANGE_CONNECTED = 2; /** Change all in this cell. */ private static final int CHANGE_CELL = 3; /** Change all in this Library. */ private static final int CHANGE_LIBRARY = 4; /** Change all in all Libraries. */ private static final int CHANGE_EVERYWHERE = 5; private static Change theDialog = null; private static boolean lastChangeNodesWithArcs = false; private static boolean lastIgnorePortNames = false; private static boolean lastAllowMissingPorts = false; private static int whatToChange = CHANGE_SELECTED; private static String libSelected = null; private List<Geometric> geomsToChange; // List of Geometrics to change private JList changeList; private DefaultListModel changeListModel; private List<NodeProto> changeNodeProtoList; private EditWindow wnd; public static void showChangeDialog() { if (Client.getOperatingSystem() == Client.OS.UNIX && theDialog != null) { // 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. theDialog.closeDialog(null); } if (theDialog == null) { JFrame jf = null; if (TopLevel.isMDIMode()) jf = TopLevel.getCurrentJFrame(); theDialog = new Change(jf); } theDialog.loadInfo(true); theDialog.setVisible(true); theDialog.toFront(); } /** Creates new form Change */ private Change(Frame parent) { super(parent, false); initComponents(); getRootPane().setDefaultButton(done); apply.setMnemonic('A'); done.setMnemonic('D'); // build the change list changeListModel = new DefaultListModel(); changeList = new JList(changeListModel); changeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listPane.setViewportView(changeList); changeNodeProtoList = new ArrayList<NodeProto>(); changeList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) apply(null); } }); // make a popup of libraries List<Library> libList = Library.getVisibleLibraries(); int curIndex = libList.indexOf(Library.getCurrent()); for(Library lib: libList) { librariesPopup.addItem(lib.getName()); if (lib.getName().equals(libSelected)) { curIndex = -1; // won't set to current library now librariesPopup.setSelectedItem(libSelected); } } if (curIndex >= 0) librariesPopup.setSelectedIndex(curIndex); librariesPopup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { reload(false); } }); // restore defaults ignorePortNames.setSelected(lastIgnorePortNames); allowMissingPorts.setSelected(lastAllowMissingPorts); ignorePortNames.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { rememberState(); } }); allowMissingPorts.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { rememberState(); } }); showPrimitives.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { reload(false); } }); showCells.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { reload(false); } }); changeNodesWithArcs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { reload(false); } }); // setup the radio buttons that select what to change changeSelected.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { whatToChangeChanged(evt); } }); changeConnected.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { whatToChangeChanged(evt); } }); changeInCell.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { whatToChangeChanged(evt); } }); changeInLibrary.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { whatToChangeChanged(evt); } }); changeEverywhere.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { whatToChangeChanged(evt); } }); switch (whatToChange) { case CHANGE_SELECTED: changeSelected.setSelected(true); break; case CHANGE_CONNECTED: changeConnected.setSelected(true); break; case CHANGE_CELL: changeInCell.setSelected(true); break; case CHANGE_LIBRARY: changeInLibrary.setSelected(true); break; case CHANGE_EVERYWHERE: changeEverywhere.setSelected(true); break; } finishInitialization(); Highlighter.addHighlightListener(this); } /** * Reloads the dialog when Highlights change */ public void highlightChanged(Highlighter which) { if (!isVisible()) return; loadInfo(true); } /** * 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; loadInfo(false); } protected void escapePressed() { done(null); } private void whatToChangeChanged(ActionEvent evt) { JRadioButton src = (JRadioButton)evt.getSource(); if (src == changeSelected) whatToChange = CHANGE_SELECTED; else if (src == changeConnected) whatToChange = CHANGE_CONNECTED; else if (src == changeInCell) whatToChange = CHANGE_CELL; else if (src == changeInLibrary) whatToChange = CHANGE_LIBRARY; else if (src == changeEverywhere) whatToChange = CHANGE_EVERYWHERE; Geometric geomToChange = geomsToChange.get(0); if (whatToChange == CHANGE_EVERYWHERE) { if (geomToChange instanceof ArcInst) { if (changeNodesWithArcs.isSelected()) { changeNodesWithArcs.setSelected(false); reload(false); } changeNodesWithArcs.setEnabled(false); } } else { if (geomToChange instanceof ArcInst) changeNodesWithArcs.setEnabled(true); } } private static final Pattern dummyName = Pattern.compile("(.*?)FROM(.*?)\\{(.*)"); /** * Method called when the current selection has changed. * Makes sure displayed options are correct. */ private void loadInfo(boolean showHighlighted) { // update current window EditWindow curWnd = EditWindow.getCurrent(); if (curWnd != null) wnd = curWnd; // find out what is going to be changed geomsToChange = new ArrayList<Geometric>(); if (wnd != null) { List<Geometric> highs = wnd.getHighlighter().getHighlightedEObjs(true, true); boolean hasArcs = false, hasCells = false, hasPrimitives = false; for (Geometric geom : highs) { geomsToChange.add(geom); if (geom instanceof ArcInst) hasArcs = true; else if (geom instanceof NodeInst) { NodeInst ni = (NodeInst)geom; if (ni.isCellInstance()) hasCells = true; else hasPrimitives = true; } } if (hasArcs && hasCells) { System.out.println("The 'Change' dialog cannot handle selection of both arcs and cells"); geomsToChange.clear(); } else if (hasArcs && hasPrimitives) { System.out.println("The 'Change' dialog cannot handle selection of both arcs and primitives"); geomsToChange.clear(); } else if (hasCells && hasPrimitives) { System.out.println("The 'Change' dialog cannot handle selection of both cells and primitives"); geomsToChange.clear(); } } if (geomsToChange.size() == 0) { librariesPopup.setEnabled(false); ignorePortNames.setEnabled(false); allowMissingPorts.setEnabled(false); showPrimitives.setEnabled(false); showCells.setEnabled(false); changeNodesWithArcs.setEnabled(false); apply.setEnabled(false); changeSelected.setEnabled(false); changeConnected.setEnabled(false); changeInCell.setEnabled(false); changeInLibrary.setEnabled(false); changeEverywhere.setEnabled(false); return; } apply.setEnabled(true); changeSelected.setEnabled(true); changeConnected.setEnabled(true); changeInCell.setEnabled(true); changeInLibrary.setEnabled(true); changeEverywhere.setEnabled(true); Geometric geomToChange = geomsToChange.get(0); if (geomToChange instanceof NodeInst) { librariesPopup.setEnabled(true); ignorePortNames.setEnabled(true); allowMissingPorts.setEnabled(true); showPrimitives.setEnabled(true); showCells.setEnabled(true); NodeInst ni = (NodeInst)geomToChange; if (ni.isCellInstance()) { showCells.setSelected(true); } else { showPrimitives.setSelected(true); } changeNodesWithArcs.setSelected(false); changeNodesWithArcs.setEnabled(false); } else { librariesPopup.setEnabled(false); ignorePortNames.setEnabled(false); allowMissingPorts.setEnabled(false); showPrimitives.setEnabled(false); showCells.setEnabled(false); changeNodesWithArcs.setEnabled(true); changeNodesWithArcs.setSelected(lastChangeNodesWithArcs); } reload(true); } private void rememberState() { lastIgnorePortNames = ignorePortNames.isSelected();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -