changetext.java

来自「The ElectricTM VLSI Design System is an 」· Java 代码 · 共 954 行 · 第 1/3 页

JAVA
954
字号
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ChangeText.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.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.database.variable.DisplayedText;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.MutableTextDescriptor;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.technologies.Generic;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.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.Font;import java.awt.Frame;import java.awt.GraphicsEnvironment;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.Serializable;import java.util.Iterator;/** * Class to handle the "Change Text" dialog. */public class ChangeText extends EDialog{	private static boolean lastNodesSelected = false;	private static boolean lastArcsSelected = false;	private static boolean lastExportsSelected = false;	private static boolean lastAnnotationsSelected = false;	private static boolean lastInstancesSelected = false;	private static boolean lastCellsSelected = false;	private ChangeParameters cp;    private EditWindow wnd;    private static class ChangeParameters implements Serializable    {    	// which types of text are to be changed    	private boolean nodesSelected;    	private boolean arcsSelected;    	private boolean exportsSelected;    	private boolean annotationsSelected;    	private boolean instancesSelected;    	private boolean cellsSelected;    	// how much text is to be changed    	private boolean changeSelectedObjects;    	private boolean changeAllInCell;    	private boolean changeCellsWithView;    	private boolean changeAllInLibrary;    	// the type of changes to be made    	private boolean usePoints;    	private String pointSize;    	private String unitSize;    	private int selectedFontIndex;    	private String selectedFontName;    	private boolean isBold, isItalic, isUnderline;    	private String viewListSelection;    	// statistics on the existing text    	private int numToChange;    	private int lowPointSize, highPointSize;    	private double lowUnitSize, highUnitSize;    	private int numNodesChanged, numArcsChanged, numExportsChanged;    	private int numAnnotationsChanged, numInstancesChanged, numCellsChanged;    }	private void gatherTextChoices()	{		// update which types of text are to be changed		lastNodesSelected = cp.nodesSelected = changeNodeText.isSelected();		lastArcsSelected = cp.arcsSelected = changeArcText.isSelected();		lastExportsSelected  = cp.exportsSelected = changeExportText.isSelected();		lastAnnotationsSelected = cp.annotationsSelected = changeAnnotationText.isSelected();		lastInstancesSelected = cp.instancesSelected = changeInstanceText.isSelected();		lastCellsSelected = cp.cellsSelected = changeCellText.isSelected();		// update how much text is to be changed    	cp.changeSelectedObjects = changeSelectedObjects.isSelected();    	cp.changeAllInCell = changeAllInCell.isSelected();    	cp.changeCellsWithView = changeCellsWithView.isSelected();    	cp.changeAllInLibrary = changeAllInLibrary.isSelected();    	// update the type of changes to be made    	cp.usePoints = usePoints.isSelected();    	cp.pointSize = pointSize.getText();    	cp.unitSize = unitSize.getText();    	cp.selectedFontIndex = font.getSelectedIndex();    	cp.selectedFontName = (String)font.getSelectedItem();    	cp.isBold = bold.isSelected();    	cp.isItalic = italic.isSelected();    	cp.isUnderline = underline.isSelected();    	cp.viewListSelection = (String)viewList.getSelectedItem();	}    public static void changeTextDialog()	{		ChangeText dialog = new ChangeText(TopLevel.getCurrentJFrame());		dialog.setVisible(true);	}	/** Creates new form Change Text */	private ChangeText(Frame parent)	{		super(parent, true);		initComponents();		getRootPane().setDefaultButton(ok);		useUnits.setSelected(true);		changeNodeText.setSelected(lastNodesSelected);		changeArcText.setSelected(lastArcsSelected);		changeExportText.setSelected(lastExportsSelected);		changeAnnotationText.setSelected(lastAnnotationsSelected);		changeInstanceText.setSelected(lastInstancesSelected);		changeCellText.setSelected(lastCellsSelected);        wnd = EditWindow.getCurrent();		for(View view : View.getOrderedViews())		{			viewList.addItem(view.getFullName());		}		font.addItem("DEFAULT FONT");		Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();		for(int i=0; i<fonts.length; i++)			font.addItem(fonts[i].getFontName());		if ((wnd == null) || (wnd.getHighlighter().getNumHighlights() == 0))		{			changeSelectedObjects.setEnabled(false);			changeAllInCell.setSelected(true);		} else		{			changeSelectedObjects.setSelected(true);		}		cp = new ChangeParameters();		gatherTextChoices();   findSelectedText();		changeSelectedObjects.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { gatherTextChoices();   findSelectedText(); }		});		changeAllInCell.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { gatherTextChoices();   findSelectedText(); }		});		changeCellsWithView.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { gatherTextChoices();   findSelectedText(); }		});		viewList.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { gatherTextChoices();   findSelectedText(); }		});		changeAllInLibrary.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { gatherTextChoices();   findSelectedText(); }		});		changeNodeText.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { findSelectedText(); }		});		changeArcText.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { findSelectedText(); }		});		changeExportText.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { findSelectedText(); }		});		changeAnnotationText.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { findSelectedText(); }		});		changeInstanceText.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { findSelectedText(); }		});		changeCellText.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { findSelectedText(); }		});		finishInitialization();	}	protected void escapePressed() { cancelActionPerformed(null); }	/**	 * Method to scan for all relevant text.	 * This looks at the top part of the dialog to figure out which text is relevant.	 * @param change true to change the relevant text according to the bottom of the dialog;	 * false to gather the relevant text sizes for display.	 */	private void findSelectedText()	{		gatherTextChoices();		Cell cell = WindowFrame.needCurCell();		if (cell == null) return;		cp.numToChange = 0;		cp.lowPointSize = -1;		cp.lowUnitSize = -1;		if (cp.changeSelectedObjects)		{            EditWindow wnd = EditWindow.getCurrent();            if (wnd != null)            {                for(DisplayedText dt : wnd.getHighlighter().getHighlightedText(false))                {                    accumulateTextFound(cp, dt.getElectricObject(), dt.getVariableKey(), false);                }            }		} else if (cp.changeAllInCell)		{			findAllInCell(cp, cell, false);		} else if (cp.changeCellsWithView)		{			View v = View.findView(cp.viewListSelection);			if (v != null)			{				for(Iterator<Cell> it = Library.getCurrent().getCells(); it.hasNext(); )				{					Cell c = it.next();					if (c.getView() == v) findAllInCell(cp, c, false);				}			}		} else if (cp.changeAllInLibrary)		{			for(Iterator<Cell> it = Library.getCurrent().getCells(); it.hasNext(); )			{				Cell c = it.next();				findAllInCell(cp, c, false);			}		}		if (cp.numToChange == 0)		{			selectedText.setText("No text to change");		} else		{			String what = "Text runs from ";			if (cp.lowPointSize >= 0) what += cp.lowPointSize + " to " + cp.highPointSize + " points";			if (cp.lowUnitSize >= 0)			{				if (cp.lowPointSize >= 0) what += "; ";				what += cp.lowUnitSize + " to " + cp.highUnitSize + " units";			}			selectedText.setText(what);			if (cp.lowUnitSize >= 0)			{				useUnits.setSelected(true);				unitSize.setText(TextUtils.formatDouble(cp.highUnitSize));			} else			{				usePoints.setSelected(true);				pointSize.setText(Integer.toString(cp.highPointSize));			}		}	}	/**	 * Method to scan for all relevant text.	 * This looks at the top part of the dialog to figure out which text is relevant.	 * @param change true to change the relevant text according to the bottom of the dialog;	 * false to gather the relevant text sizes for display.	 */	private static void changeSelectedText(Cell cell, ChangeParameters cp)	{		if (cp.changeSelectedObjects)		{			// make sure text adjustment is allowed			if (CircuitChangeJobs.cantEdit(cell, null, true, true, true) != 0) return;            EditWindow wnd = EditWindow.getCurrent();            if (wnd != null)            {                for(DisplayedText dt : wnd.getHighlighter().getHighlightedText(false))                {                    accumulateTextFound(cp, dt.getElectricObject(), dt.getVariableKey(), true);                }            }		} else if (cp.changeAllInCell)		{

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?