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

📄 crosslibcopy.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: CrossLibCopy.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.IdMapper;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.CellChangeJobs;import com.sun.electric.tool.user.User;import java.awt.Frame;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.swing.BoundedRangeModel;import javax.swing.DefaultListModel;import javax.swing.JComboBox;import javax.swing.JList;import javax.swing.JScrollBar;import javax.swing.ListSelectionModel;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;/** * Class to handle the "Cross-Library Copy" dialog. */public class CrossLibCopy extends EDialog{	private List<Library> libList;	private List<Cell> cellListLeft, cellListRight;	private JList listLeft, listRight, listCenter;	private DefaultListModel modelLeft, modelRight, modelCenter;	private static Library curLibLeft = null, curLibRight = null;	private static boolean lastDeleteAfterCopy = false;	private static boolean lastCopyRelated = false;	private static boolean lastCopySubcells = false;	private static boolean lastUseExisting = true;	// Class to synchronize the 3 scrollbars in dialog	private class CrossLibScrollBarListener implements ChangeListener	{		private JScrollBar[] scrollBarList;        protected boolean blocked = false;		public  CrossLibScrollBarListener(JScrollBar[] bars)		{			scrollBarList = new JScrollBar[2];			System.arraycopy(bars, 0, scrollBarList, 0, bars.length);		}		public void stateChanged(ChangeEvent evt)		{            if (blocked) return;            blocked = true;			BoundedRangeModel sourceScroll = (BoundedRangeModel)evt.getSource();			int iSMin   = sourceScroll.getMinimum();			int iSMax   = sourceScroll.getMaximum();			int iSDiff  = iSMax - iSMin;			int iSVal   = sourceScroll.getValue();			int iDMin   = cellsLeft.getVerticalScrollBar().getMinimum();			int iDMax   = cellsLeft.getVerticalScrollBar().getMaximum();			int iDDiff  = iDMax - iDMin;			int iDVal = (iSDiff == iDDiff) ? iSVal : (iDDiff * iSVal) / iSDiff;			for (int i = 0; i < scrollBarList.length; i++)				scrollBarList[i].setValue(iDVal);            blocked = false;		}	}	/** Creates new form CrossLibCopy */	public CrossLibCopy(Frame parent)	{		super(parent, true);		initComponents();		// determine the two libraries to show		libList = Library.getVisibleLibraries();		if (curLibLeft == null) curLibLeft = Library.getCurrent();		if (curLibRight == null) curLibRight = Library.getCurrent();		if (curLibLeft == curLibRight)		{			for(Library lib : libList)			{				if (lib != curLibLeft)				{					curLibRight = lib;					break;				}			}		}		// setup the library popups		Library saveLeft = curLibLeft, saveRight = curLibRight;		for(Library lib : libList)		{			librariesLeft.addItem(lib.getName());			librariesRight.addItem(lib.getName());		}		int curIndex = libList.indexOf(saveLeft);		if (curIndex >= 0) librariesLeft.setSelectedIndex(curIndex);		curIndex = libList.indexOf(saveRight);		if (curIndex >= 0) librariesRight.setSelectedIndex(curIndex);		// make the left list		modelLeft = new DefaultListModel();		listLeft = new JList(modelLeft);		listLeft.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // SINGLE_SELECTION);		cellsLeft.setViewportView(listLeft);		listLeft.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { leftListClick(evt); }		});		// make the right list		modelRight = new DefaultListModel();		listRight = new JList(modelRight);		listRight.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);		cellsRight.setViewportView(listRight);		listRight.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { rightListClick(evt); }		});		// make the center list		modelCenter = new DefaultListModel();		listCenter = new JList(modelCenter);		listCenter.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);		center.setViewportView(listCenter);		listCenter.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { centerListClick(evt); }		});		showCells(false);		// show the check boxes		if (lastCopySubcells)		{			lastUseExisting = true;			useExistingSubcells.setEnabled(false);		}		deleteAfterCopy.setSelected(lastDeleteAfterCopy);		copyRelatedViews.setSelected(lastCopyRelated);		copySubcells.setSelected(lastCopySubcells);		useExistingSubcells.setSelected(lastUseExisting);		// TO syncronize scroll bars		JScrollBar[] scrollArray1 = {cellsRight.getVerticalScrollBar(), center.getVerticalScrollBar()};		cellsLeft.getVerticalScrollBar().getModel().addChangeListener(new CrossLibScrollBarListener(scrollArray1));		JScrollBar[] scrollArray2 = {cellsLeft.getVerticalScrollBar(), center.getVerticalScrollBar()};		cellsRight.getVerticalScrollBar().getModel().addChangeListener(new CrossLibScrollBarListener(scrollArray2));		JScrollBar[] scrollArray3 = {cellsLeft.getVerticalScrollBar(), cellsRight.getVerticalScrollBar()};		center.getVerticalScrollBar().getModel().addChangeListener(new CrossLibScrollBarListener(scrollArray3));		finishInitialization();	}	private void leftListClick(MouseEvent evt)	{        int[] indices = listLeft.getSelectedIndices();        listCenter.setSelectedIndices(indices);        listRight.setSelectedIndices(indices);	}	private void rightListClick(MouseEvent evt)	{        int[] indices = listRight.getSelectedIndices();        listLeft.setSelectedIndices(indices);        listCenter.setSelectedIndices(indices);	}	private void centerListClick(MouseEvent evt)	{        int[] indices = listCenter.getSelectedIndices();        listLeft.setSelectedIndices(indices);        listRight.setSelectedIndices(indices);	}	private void showCells(boolean report)	{		if (modelLeft == null || modelRight == null || modelCenter == null) return;		cellListLeft = new ArrayList<Cell>();		for (Iterator<Cell> it = curLibLeft.getCells(); it.hasNext(); ) cellListLeft.add(it.next());		cellListRight = new ArrayList<Cell>();		for (Iterator<Cell> it = curLibRight.getCells(); it.hasNext(); ) cellListRight.add(it.next());		modelLeft.clear();		modelRight.clear();		modelCenter.clear();        boolean examineContents = compareContent.isSelected();		// put out the parallel list of cells in the two libraries		int leftPos = 0, rightPos = 0;		int leftCount = cellListLeft.size();		int rightCount = cellListRight.size();		for(;;)		{			int op;			if (leftPos >= leftCount && rightPos >= rightCount) break;			if (leftPos >= leftCount) op = 2; else				if (rightPos >= rightCount) op = 1; else			{				Cell leftCell = cellListLeft.get(leftPos);				Cell rightCell = cellListRight.get(rightPos);                int j = leftCell.getCellName().compareTo(rightCell.getCellName());				if (j < 0) op = 1; else					if (j > 0) op = 2; else						op = 3;			}			String leftName = " ";			Cell leftCell = null;			if (op == 1 || op == 3)			{				leftCell = cellListLeft.get(leftPos++);				leftName = leftCell.noLibDescribe();			}			modelLeft.addElement(leftName);			String rightName = " ";			Cell rightCell = null;			if (op == 2 || op == 3)			{				rightCell = cellListRight.get(rightPos++);				rightName = rightCell.noLibDescribe();			}			modelRight.addElement(rightName);			String pt = " ";			if (op == 3)			{				int compare = leftCell.getRevisionDate().compareTo(rightCell.getRevisionDate());				StringBuffer buffer = null;				boolean result = true; String message = "";				if (examineContents)				{					if (report) buffer = new StringBuffer("\n");					result = leftCell.compare(rightCell, buffer);                    // This message is only valid if the content is compared.                    message = (result) ? "(but contents are the same)" : "(and contents are different)";				}				if (compare > 0)				{					pt = (result) ? "<-New" : "<-New/Diff";					if (report) System.out.println(curLibLeft.getName() + ":" + leftName + " NEWER THAN " +						curLibRight.getName() + ":" + rightName + message + ":" + ((buffer != null) ? buffer.toString() : "\n"));				} else if (compare < 0)				{					pt = (result) ? "  New->" : " Diff/New->";					if (report) System.out.println(curLibRight.getName() + ":" + rightName + " NEWER THAN " +						curLibLeft.getName() + ":" + leftName + message + ":" + ((buffer != null) ? buffer.toString() : "\n"));				} else				{					pt = (result) ? "-Same-" : "-Diff -";					if (!result && report) System.out.println(curLibLeft.getName() + ":" + leftName + " DIFFERS FROM " +						curLibRight.getName() + ":" + rightName + ":" + ((buffer != null) ? buffer.toString() : "\n"));				}			}			modelCenter.addElement(pt);		}	}//	// Class to compare two cells//	private static class CrossLibraryExamineJob extends Job//	{//		private Cell leftC;//		private Cell rightC;//		private boolean reportResults; // to report to std output the comparison//		private boolean result;//		private StringBuffer buffer;////        private CrossLibraryExamineJob(Cell left, Cell right, boolean report)//		{//			super("Cross-Library examine", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER);//			this.leftC = left;//			this.rightC = right;//			this.reportResults = report;//			startJob();//		}////		public boolean doIt() throws JobException//		{//			if (reportResults)//				buffer = new StringBuffer("Cells '" + leftC.libDescribe() + "' and '" + rightC.libDescribe() + ":");//			result = (leftC != null && leftC.compare(rightC, buffer));////			if (reportResults)//			{//				if (result)//					buffer.append("Do not differ");//				System.out.println(buffer);//			}//			return (true);//		}//		public boolean getResult() { return (result); }//		public StringBuffer getDifference() { return (buffer); }//	}	public static class CrossLibraryCopyJob extends Job	{		private List<Cell> fromCells;		private Library toLibrary;		private transient CrossLibCopy dialog;		private boolean deleteAfter, copyRelated, copySubs, useExisting;		private int index;        private IdMapper idMapper; 		public CrossLibraryCopyJob(List<Cell> fromCells, Library toLibrary, CrossLibCopy dialog, boolean deleteAfter,			boolean copyRelated, boolean copySubs, boolean useExisting)		{			super("Cross-Library copy", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.fromCells = fromCells;			this.toLibrary = toLibrary;			this.dialog = dialog;			this.deleteAfter = deleteAfter;			this.copyRelated = copyRelated;			this.copySubs = copySubs;			this.useExisting = useExisting;			// remember the selection line            if (dialog != null)                index = dialog.listLeft.getSelectedIndex();            else                index = -1; // use from the ExplorerTree            startJob();		}		public boolean doIt() throws JobException		{			// do the copy			idMapper = CellChangeJobs.copyRecursively(fromCells, toLibrary, true, deleteAfter, copyRelated, copySubs, useExisting);            fieldVariableChanged("idMapper");			return true;		}        public void terminateOK()        {            User.fixStaleCellReferences(idMapper);            if (dialog == null) return; // from ExplorerTree                        // reload the dialog			dialog.showCells(false);			// reselect the last selected line			dialog.listLeft.setSelectedIndex(index);			dialog.listRight.setSelectedIndex(index);

⌨️ 快捷键说明

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