📄 getinfooutline.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: GetInfoOutline.java * * 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.change.DatabaseChangeEvent;import com.sun.electric.database.change.DatabaseChangeListener;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.tool.Client;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;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.ui.EditWindow;import com.sun.electric.tool.user.ui.TopLevel;import java.awt.Frame;import java.awt.geom.Point2D;import javax.swing.DefaultListModel;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 "GetInfoOutline" dialog. */public class GetInfoOutline extends EModelessDialog implements HighlightListener, DatabaseChangeListener{ private NodeInst ni; private JList list; private DefaultListModel model; private boolean changingCoordinates = false; private static GetInfoOutline theDialog; public static void showOutlinePropertiesDialog() { 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.dispose(); theDialog = null; } if (theDialog == null) { JFrame jf = null; if (TopLevel.isMDIMode()) jf = TopLevel.getCurrentJFrame(); theDialog = new GetInfoOutline(jf); } theDialog.loadDialog(); if (!theDialog.isVisible()) { theDialog.pack(); theDialog.ensureProperSize(); theDialog.setVisible(true); } theDialog.toFront(); } /** Creates new form GetInfoOutline */ public GetInfoOutline(Frame parent) { super(parent, false); initComponents(); getRootPane().setDefaultButton(apply); // make all text fields select-all when entered EDialog.makeTextFieldSelectAllOnTab(xValue); EDialog.makeTextFieldSelectAllOnTab(yValue); UserInterfaceMain.addDatabaseChangeListener(this); Highlighter.addHighlightListener(this); // make a list of vertices model = new DefaultListModel(); list = new JList(model); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); pointPane.setViewportView(list); list.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { listClick(); } }); xValue.getDocument().addDocumentListener(new OutlineDocumentListener(this)); yValue.getDocument().addDocumentListener(new OutlineDocumentListener(this)); finishInitialization(); } private void loadDialog() { // presume a dead dialog apply.setEnabled(false); deletePoint.setEnabled(false); duplicatePoint.setEnabled(false); jLabel1.setEnabled(false); jLabel2.setEnabled(false); pointPane.setEnabled(false); xValue.setEditable(false); yValue.setEditable(false); // must have a node EditWindow wnd = EditWindow.getCurrent(); if (wnd == null) // not an edit window. Eg 3D ViewWindows return; ni = (NodeInst)wnd.getHighlighter().getOneElectricObject(NodeInst.class); if (ni == null) return; // node must have coordinates Point2D [] points = ni.getTrace(); if (points == null) return; // make the dialog live apply.setEnabled(true); deletePoint.setEnabled(true); duplicatePoint.setEnabled(true); jLabel1.setEnabled(true); jLabel2.setEnabled(true); pointPane.setEnabled(true); xValue.setEditable(true); yValue.setEditable(true); // load the coordinates Point2D [] dbSpacePoints = new Point2D[points.length]; for(int i=0; i<points.length; i++) { if (points[i] != null) dbSpacePoints[i] = new Point2D.Double(points[i].getX() + ni.getAnchorCenterX(), points[i].getY() + ni.getAnchorCenterY()); } loadList(dbSpacePoints, 0); listClick(); } private void loadList(Point2D [] newPoints, int index) { model.clear(); for(int i=0; i<newPoints.length; i++) model.addElement(makeLine(i, newPoints[i])); if (index >= 0) list.setSelectedIndex(index); } protected void escapePressed() { done(null); } private void listClick() { changingCoordinates = true; String line = (String)list.getSelectedValue(); Point2D clickedValue = getPointValue(line); if (clickedValue == null) { xValue.setText(""); yValue.setText(""); } else { xValue.setText(TextUtils.formatDouble(clickedValue.getX())); yValue.setText(TextUtils.formatDouble(clickedValue.getY())); } changingCoordinates = false; } private String makeLine(int index, Point2D pt) { if (pt == null) return "-------------"; return index + ": (" + TextUtils.formatDouble(pt.getX()) + ", " + TextUtils.formatDouble(pt.getY()) + ")"; } /** * Method called when the user types a new coordinate value into the edit field. */ private void coordinatesChanged() { if (changingCoordinates) return; Point2D typedValue = new Point2D.Double(TextUtils.atof(xValue.getText()), TextUtils.atof(yValue.getText())); int index = list.getSelectedIndex(); model.set(index, makeLine(index, typedValue)); } private Point2D getPointValue(String line) { double xV = 0, yV = 0; int openPos = line.indexOf('('); int commaPos = line.indexOf(',', openPos); int closePos = line.indexOf(')', commaPos); if (openPos >= 0 && commaPos >= 0 && closePos >= 0) { xV = TextUtils.atof(line.substring(openPos+1, commaPos)); yV = TextUtils.atof(line.substring(commaPos+1, closePos)); return new Point2D.Double(xV, yV); } return null; } /** * Class to handle special changes to changes to a CIF layer. */ private static class OutlineDocumentListener implements DocumentListener { private GetInfoOutline dialog; OutlineDocumentListener(GetInfoOutline dialog) { this.dialog = dialog; } public void changedUpdate(DocumentEvent e) { dialog.coordinatesChanged(); } public void insertUpdate(DocumentEvent e) { dialog.coordinatesChanged(); } public void removeUpdate(DocumentEvent e) { dialog.coordinatesChanged(); } } /** * Reloads the dialog when Highlights change */ public void highlightChanged(Highlighter which) { if (!isVisible()) return; loadDialog(); } /** * 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; loadDialog(); } /** * Respond to database changes * @param e database change event */ public void databaseChanged(DatabaseChangeEvent e) { if (!isVisible()) return; // check if we care about the changes if (e.objectChanged(ni)) loadDialog();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -