📄 selectobject.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: SelectObject.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.network.Netlist;import com.sun.electric.database.network.Network;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.tool.user.Highlighter;import com.sun.electric.tool.user.KeyBindingManager;import com.sun.electric.tool.user.UserInterfaceMain;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowContent;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.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.List;import java.util.regex.Matcher;import java.util.regex.Pattern;import javax.swing.ActionMap;import javax.swing.DefaultListModel;import javax.swing.InputMap;import javax.swing.JFrame;import javax.swing.JList;import javax.swing.ListSelectionModel;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;/** * Class to handle the "Select Object" dialog. */public class SelectObject extends EModelessDialog implements DatabaseChangeListener{ private static SelectObject theDialog = null; private static final int NODES = 1; private static final int ARCS = 2; private static final int EXPORTS = 3; private static final int NETS = 4; private static int what = NODES; private Cell cell; private JList list; private DefaultListModel model; private Highlighter highlighter; public static void selectObjectDialog(Cell thisCell, boolean updateOnlyIfVisible) { if (theDialog == null) { if (updateOnlyIfVisible) return; // it is not previously open JFrame jf = null; if (TopLevel.isMDIMode()) jf = TopLevel.getCurrentJFrame(); theDialog = new SelectObject(jf); } if (updateOnlyIfVisible && !theDialog.isVisible()) return; // it is not previously visible theDialog.setVisible(true); theDialog.buttonClicked(thisCell); theDialog.toFront(); } /** Creates new form SelectObject */ private SelectObject(Frame parent) { super(parent, false); initComponents(); getRootPane().setDefaultButton(done); UserInterfaceMain.addDatabaseChangeListener(this); switch (what) { case NODES: nodes.setSelected(true); break; case ARCS: arcs.setSelected(true); break; case EXPORTS: exports.setSelected(true); break; case NETS: networks.setSelected(true); break; } model = new DefaultListModel(); list = new JList(model); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); objectPane.setViewportView(list); list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { listClicked(); } }); done.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { closeDialog(null); } }); nodes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonClicked(null); } }); arcs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonClicked(null); } }); exports.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonClicked(null); } }); networks.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { buttonClicked(null); } }); searchText.getDocument().addDocumentListener(new SelecdtObjectDocumentListener(this)); // special case for this dialog: allow Electric quick-keys to pass-through TopLevel top = TopLevel.getCurrentJFrame(); if (top != null && top.getTheMenuBar() != null) { KeyBindingManager.KeyMaps km = top.getEMenuBar().getKeyMaps(); InputMap im = km.getInputMap(); ActionMap am = km.getActionMap(); getRootPane().getInputMap().setParent(im); getRootPane().getActionMap().setParent(am); findText.getInputMap().setParent(im); findText.getActionMap().setParent(am); list.getInputMap().setParent(im); list.getActionMap().setParent(am); } finishInitialization(); } protected void escapePressed() { closeDialog(null); } /** * Respond to database changes and reload the list. * @param e database change event */ public void databaseChanged(DatabaseChangeEvent e) { if (!isVisible()) return; buttonClicked(null); } private void listClicked() { int [] si = list.getSelectedIndices(); if (si.length > 0) highlighter.clear(); Netlist netlist = cell.acquireUserNetlist(); if (netlist == null) { System.out.println("Sorry, a deadlock aborted selection (network information unavailable). Please try again"); return; } for(int i=0; i<si.length; i++) { int index = si[i]; String s = (String)model.get(index); if (nodes.isSelected()) { // find nodes for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (s.equals(ni.getName())) { highlighter.addElectricObject(ni, cell); break; } } } else if (arcs.isSelected()) { // find arcs for(Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst ai = it.next(); if (s.equals(ai.getName())) { highlighter.addElectricObject(ai, cell); break; } } } else if (exports.isSelected()) { // find exports for(Iterator<PortProto> it = cell.getPorts(); it.hasNext(); ) { Export pp = (Export)it.next(); if (s.equals(pp.getName())) { highlighter.addText(pp, cell, Export.EXPORT_NAME); break; } } } else { // find networks for(Iterator<Network> it = netlist.getNetworks(); it.hasNext(); ) { Network net = it.next(); String netName = net.describe(false); if (netName.length() == 0) continue; if (s.equals(netName)) { highlighter.addNetwork(net, cell); break; } } } } if (si.length > 0) { highlighter.ensureHighlightingSeen(); highlighter.finished(); } } /** * Method to load the dialog depending on cell selected. * It is not getCurrentCell because of down/up hierarchy calls. * @param thisCell */ private void buttonClicked(Cell thisCell) { model.clear(); cell = (thisCell != null) ? thisCell: WindowFrame.getCurrentCell(); if (cell == null) return; WindowFrame wf = WindowFrame.getCurrentWindowFrame(); if (wf == null) return; WindowContent wc = wf.getContent(); if (wc == null) return; highlighter = wc.getHighlighter(); if (highlighter == null) return; List<String> allNames = new ArrayList<String>(); if (nodes.isSelected()) { // show all nodes what = NODES; for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -