⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 componentmenu.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ComponentMenuTab.java * * Copyright (c) 2007 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.Library;import com.sun.electric.database.text.TextUtils;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.technology.Xml;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.tecEdit.Info;import com.sun.electric.tool.user.ui.TopLevel;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.font.FontRenderContext;import java.awt.font.GlyphVector;import java.awt.font.LineMetrics;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.swing.DefaultListModel;import javax.swing.JButton;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JSeparator;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;/** * Class to handle the "Component Menu" dialog. * This panel appears either in a Preferences tab or stand-alone in the technology editor. */public class ComponentMenu extends EDialog{	private JList listNodes, listArcs, listCells, listSpecials, listPopup;	private DefaultListModel modelNodes, modelArcs, modelCells, modelSpecials, modelPopup;	private int menuWid, menuHei, menuSelectedX, menuSelectedY;	private int lastListSelected = -1;	private Object [][] menuArray;	private Object [][] factoryMenuArray;	private MenuView menuView;	private String techName;	private Xml.Technology xTech;	private boolean changingNodeFields = false;	private boolean changed;	/**	 * Method to display a dialog for showing the component menu.	 * Called only from the technology editor.	 */	public static void showComponentMenuDialog(String techName, Xml.MenuPalette xmp,		List<Xml.PrimitiveNode> nodes, List<Xml.ArcProto> arcs)	{		ComponentMenu dialog = new ComponentMenu(TopLevel.getCurrentJFrame(), true);		dialog.setTitle("Technology Edit: Component Menu Layout");		Xml.Technology xTech = new Xml.Technology();		for(Xml.PrimitiveNode xnp : nodes)			xTech.nodes.add(xnp);		for(Xml.ArcProto xap : arcs)			xTech.arcs.add(xap);		xTech.menuPalette = xmp;		int menuWid = xmp.numColumns;		int menuHei = xmp.menuBoxes.size() / menuWid;		Object[][] menuArray = new Object[menuHei][menuWid];		int i = 0;		for(int y=0; y<menuHei; y++)		{			for(int x=0; x<menuWid; x++)			{				Object obj = xmp.menuBoxes.get(i++);				if (obj instanceof List)				{					List l = (List)obj;					if (l.size() == 0) obj = null; else						if (l.size() == 1) obj = l.get(0);				}				menuArray[y][x] = obj;			}		}		dialog.showTechnology(techName, xTech, menuArray, menuArray);		dialog.finishInitialization();		dialog.setVisible(true);	}	/** Creates new form ComponentMenu */	public ComponentMenu(Frame parent, boolean techEdit)	{		super(parent, true);		initComponents();		menuView = new MenuView();		GridBagConstraints gbc = new GridBagConstraints();		gbc.gridx = 0;       gbc.gridy = 1;		gbc.gridwidth = 1;   gbc.gridheight = 8;		gbc.fill = GridBagConstraints.BOTH;		gbc.weightx = 0.5;   gbc.weighty = 0.9;		gbc.insets = new Insets(1, 4, 4, 4);		Top.add(menuView, gbc);		// load the node function combobox		List<PrimitiveNode.Function> funs = PrimitiveNode.Function.getFunctions();		for(PrimitiveNode.Function fun : funs)			nodeFunction.addItem(fun.getName());		// make the nodes, arcs, specials, and popup lists		modelNodes = new DefaultListModel();		listNodes = new JList(modelNodes);		nodeListPane.setViewportView(listNodes);		listNodes.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { selectList(0); }		});		modelArcs = new DefaultListModel();		listArcs = new JList(modelArcs);		arcListPane.setViewportView(listArcs);		listArcs.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { selectList(1); }		});		modelCells = new DefaultListModel();		listCells = new JList(modelCells);		cellListPane.setViewportView(listCells);		listCells.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { selectList(2); }		});		for(Library lib : Library.getVisibleLibraries())			libraryName.addItem(lib.getName());		libraryName.setSelectedItem(Library.getCurrent());		libraryChanged();		libraryName.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { libraryChanged(); }		});		modelSpecials = new DefaultListModel();		modelSpecials.addElement(Technology.SPECIALMENUCELL);		modelSpecials.addElement(Technology.SPECIALMENUEXPORT);		modelSpecials.addElement(Technology.SPECIALMENUMISC);		modelSpecials.addElement(Technology.SPECIALMENUPURE);		modelSpecials.addElement(Technology.SPECIALMENUSPICE);		listSpecials = new JList(modelSpecials);		specialListPane.setViewportView(listSpecials);		listSpecials.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { selectList(3); }		});		modelPopup = new DefaultListModel();		listPopup = new JList(modelPopup);		popupListPane.setViewportView(listPopup);		listPopup.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { showSelectedPopup(); }		});		// setup listeners for the node detail fields		nodeAngle.getDocument().addDocumentListener(new NodeFieldDocumentListener());		nodeName.getDocument().addDocumentListener(new NodeFieldDocumentListener());		nodeTextSize.getDocument().addDocumentListener(new NodeFieldDocumentListener());		nodeFunction.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { nodeInfoChanged(); }		});		if (techEdit)		{			JButton OK = new JButton("OK");			gbc = new GridBagConstraints();			gbc.gridx = 0;       gbc.gridy = 4;			gbc.insets = new Insets(25, 4, 4, 4);			lowerRight.add(OK, gbc);			OK.addActionListener(new ActionListener() {				public void actionPerformed(ActionEvent evt) { saveChanges();   closeDialog(null); }			});			JButton cancel = new JButton("Cancel");			gbc = new GridBagConstraints();			gbc.gridx = 1;       gbc.gridy = 4;			gbc.insets = new Insets(25, 4, 4, 4);			lowerRight.add(cancel, gbc);			cancel.addActionListener(new ActionListener() {				public void actionPerformed(ActionEvent evt) { closeDialog(null); }			});		}	}	/**	 * Method to load the dialog with menu information.	 */	public void showTechnology(String name, Xml.Technology xt, Object [][] theArray, Object [][] factoryArray)	{		techName = name;		xTech = xt;		menuArray = theArray;		factoryMenuArray = factoryArray;		menuHei = menuArray.length;		menuWid = menuArray[0].length;		modelNodes.clear();		for(Xml.PrimitiveNode pnp : xTech.nodes)		{			modelNodes.addElement(pnp.name);		}		modelArcs.clear();		for(Xml.ArcProto ap : xTech.arcs)		{			modelArcs.addElement(ap.name);		}		// display the menu		showMenuSize();		showSelected();		menuView.repaint();		changed = false;	}	public void factoryReset()	{		menuHei = factoryMenuArray.length;		menuWid = factoryMenuArray[0].length;		menuArray = new Object[menuHei][];		for(int y=0; y<menuHei; y++)		{			menuArray[y] = new Object[menuWid];			for(int x=0; x<menuWid; x++) menuArray[y][x] = factoryMenuArray[y][x];		}		menuSelectedY = menuSelectedX = 0;		showMenuSize();		showSelected();		menuView.repaint();		changed = true;	}	/** return the name of this preferences tab. */	public String getName() { return "Component Menu"; }	/** return the panel to use for this preferences tab. */	public JPanel getPanel() { return Top; }	protected void escapePressed() { closeDialog(null); }	public boolean isChanged() { return changed; }	public Object[][] getMenuInfo() { return menuArray; }	/**	 * Method called when the "OK" button is hit.	 */	private void saveChanges()	{		if (!changed) return;		Xml.MenuPalette xmp = new Xml.MenuPalette();		xmp.numColumns = menuWid;		xmp.menuBoxes = new ArrayList<List<Object>>();		for(int y=0; y<menuHei; y++)		{			for(int x=0; x<menuWid; x++)			{				Object item = null;				if (menuArray[y] != null)					item = menuArray[y][x];				if (item instanceof List)				{					xmp.menuBoxes.add((List)item);				} else				{					List<Object> subList = new ArrayList<Object>();					if (item != null) subList.add(item);					xmp.menuBoxes.add(subList);				}			}		}		new SetMenuJob(xmp.writeXml());	}	/**	 * Class to store the updated component menu on the Technology Library.	 */	private static class SetMenuJob extends Job	{		private String menuXML;		private SetMenuJob(String menuXML)		{			super("Set Technology Library Component Menu", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.menuXML = menuXML;			startJob();		}		public boolean doIt() throws JobException		{			Library.getCurrent().newVar(Info.COMPMENU_KEY, menuXML);			return true;

⌨️ 快捷键说明

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