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

📄 explorertree.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ExplorerTree.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.ui;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.tool.Job;import com.sun.electric.tool.cvspm.AddRemove;import com.sun.electric.tool.cvspm.CVS;import com.sun.electric.tool.cvspm.CVSLibrary;import com.sun.electric.tool.cvspm.Commit;import com.sun.electric.tool.cvspm.Edit;import com.sun.electric.tool.cvspm.Log;import com.sun.electric.tool.cvspm.State;import com.sun.electric.tool.cvspm.Update;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.io.input.EpicAnalysis;import com.sun.electric.tool.project.AddCellJob;import com.sun.electric.tool.project.AddLibraryJob;import com.sun.electric.tool.project.CancelCheckOutJob;import com.sun.electric.tool.project.CheckInJob;import com.sun.electric.tool.project.CheckOutJob;import com.sun.electric.tool.project.DeleteCellJob;import com.sun.electric.tool.project.HistoryDialog;import com.sun.electric.tool.project.Project;import com.sun.electric.tool.project.UpdateJob;import com.sun.electric.tool.simulation.AnalogSignal;import com.sun.electric.tool.simulation.Analysis;import com.sun.electric.tool.simulation.Signal;import com.sun.electric.tool.user.CellChangeJobs;import com.sun.electric.tool.user.CircuitChangeJobs;import com.sun.electric.tool.user.CircuitChanges;import com.sun.electric.tool.user.ErrorLogger;import com.sun.electric.tool.user.Resources;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ViewChanges;import com.sun.electric.tool.user.dialogs.ChangeCellGroup;import com.sun.electric.tool.user.dialogs.ChangeCurrentLib;import com.sun.electric.tool.user.dialogs.CrossLibCopy;import com.sun.electric.tool.user.dialogs.NewCell;import com.sun.electric.tool.user.menus.CellMenu;import com.sun.electric.tool.user.menus.FileMenu;import com.sun.electric.tool.user.tecEdit.Manipulate;import com.sun.electric.tool.user.waveform.Panel;import com.sun.electric.tool.user.waveform.SweepSignal;import com.sun.electric.tool.user.waveform.WaveformWindow;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Component;import java.awt.Font;import java.awt.Graphics2D;import java.awt.Point;import java.awt.Rectangle;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.dnd.DnDConstants;import java.awt.dnd.DragSource;import java.awt.dnd.DragSourceDragEvent;import java.awt.dnd.DragSourceDropEvent;import java.awt.dnd.DragSourceEvent;import java.awt.dnd.DragSourceListener;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetDragEvent;import java.awt.dnd.DropTargetDropEvent;import java.awt.dnd.DropTargetEvent;import java.awt.dnd.DropTargetListener;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.geom.AffineTransform;import java.awt.image.BufferedImage;import java.awt.image.PixelGrabber;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.TreeSet;import javax.swing.ButtonGroup;import javax.swing.Icon;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPopupMenu;import javax.swing.JRadioButtonMenuItem;import javax.swing.JTree;import javax.swing.SwingUtilities;import javax.swing.ToolTipManager;import javax.swing.TransferHandler;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.plaf.TreeUI;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.MutableTreeNode;import javax.swing.tree.TreeModel;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;/** * Class to display a cell explorer tree-view of the database. */public class ExplorerTree extends JTree implements DragSourceListener // , DragGestureListener{		private final static TreePath[] NULL_TREE_PATH_ARRAY = {};    private TreeHandler handler = null;	private final String rootNode;    private TreePath [] currentSelectedPaths = new TreePath[0];	private static class IconGroup	{		/** the icon for a normal cell */					private ImageIcon regular;		/** the icon for an old version of a cell */		private ImageIcon old;		/** the icon for a checked-in cell */				private ImageIcon available;		/** the icon for a cell checked-out to others */	private ImageIcon locked;		/** the icon for a cell checked-out to you */		private ImageIcon unlocked;	}	private static ImageIcon iconLibrary = null, iconLibraryNormal = null, iconLibraryChecked = null;	private static ImageIcon iconGroup = null;	private static ImageIcon iconJobs = null;	private static ImageIcon iconLibraries = null;	private static ImageIcon iconErrors = null;	private static ImageIcon iconErrorMsg = null;    private static ImageIcon iconWarnMsg = null;	private static ImageIcon iconSignals = null;	private static ImageIcon iconSweeps = null;	private static ImageIcon iconMeasurements = null;	private static ImageIcon iconViewMultiPageSchematics = null;	private static ImageIcon iconSpiderWeb = null;	private static ImageIcon iconLocked = null;	private static ImageIcon iconUnlocked = null;	private static ImageIcon iconAvailable = null;	/**	 * Constructor to create a new ExplorerTree.	 * @param contentNodes the tree to display.	 */	ExplorerTree(List<MutableTreeNode> contentNodes)	{		super((TreeModel)null);        setModel(new ExplorerTreeModel());        rootNode = ExplorerTreeModel.rootNode;//		ErrorLoggerTree.updateExplorerTree(model().errorExplorerNode);        redoContentTrees(contentNodes);		initDND();        // Starting Job explorer tree expanded        expandPath(new TreePath(model().jobPath));		// arbitrary selection in the explorer		getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);		// do not show top-level		setRootVisible(false);		setShowsRootHandles(true);		setToggleClickCount(3);		// enable tool tips - we'll use these to display useful info		ToolTipManager.sharedInstance().registerComponent(this);		// register our own extended renderer for custom icons and tooltips		setCellRenderer(new MyRenderer());        handler = new TreeHandler(this);		addMouseListener(handler);		addTreeSelectionListener(handler);	}	/**	 * Method to return the currently selected objects in the explorer tree.	 * @return the currently selected objects in the explorer tree.	 */	public Object [] getCurrentlySelectedObject() {        Object[] selectedObjects = new Object[numCurrentlySelectedObjects()];        for (int i = 0; i < selectedObjects.length; i++)            selectedObjects[i] = getCurrentlySelectedObject(i);        return selectedObjects;    }	/**	 * Method to return the number of currently selected objects in the explorer tree.	 * @return the number of currently selected objects in the explorer tree.	 */	public int numCurrentlySelectedObjects() { return currentSelectedPaths.length; }	/**	 * Method to return the currently selected object in the explorer tree.     * @param i index of currently selected object.	 * @return the currently selected object in the explorer tree.	 */	public Object getCurrentlySelectedObject(int i) {        if (i >= currentSelectedPaths.length) return null;        TreePath treePath = currentSelectedPaths[i];        return getObjectInTreePath(treePath);    }	/**	 * Method to get the object stored at a point in the explorer tree.	 * @param treePath the TreePath in the explorer.	 * @return the object stored there.	 */	private Object getObjectInTreePath(TreePath treePath)	{        if (treePath == null) return null;        Object obj = treePath.getLastPathComponent();        if (obj instanceof DefaultMutableTreeNode)            return ((DefaultMutableTreeNode)obj).getUserObject();        if (obj instanceof EpicAnalysis.EpicTreeNode)        {            Signal sig = EpicAnalysis.getSignal(treePath);            if (sig != null) return sig;        }        return obj;	}	/**     * Get a list of any libraries current selected.     * @return list of libraries, or empty list if none selected     */    public List<Library> getCurrentlySelectedLibraries() {        List<Library> libs = new ArrayList<Library>();        for (int i=0; i<numCurrentlySelectedObjects(); i++) {            Object obj = getCurrentlySelectedObject(i);            if (obj instanceof Library) libs.add((Library)obj);        }        return libs;    }    /**     * Get a list of any cells current selected.  Any     * cell groups selected will have their cells added.     * @return list of cells, or empty list if none selected     */    public List<Cell> getCurrentlySelectedCells() {        List<Cell> cells = new ArrayList<Cell>();        for (int i=0; i<numCurrentlySelectedObjects(); i++) {            Object obj = getCurrentlySelectedObject(i);            if (obj instanceof Cell) cells.add((Cell)obj);            if (obj instanceof Cell.CellGroup) {                Cell.CellGroup group = (Cell.CellGroup)obj;                for (Iterator<Cell> it = group.getCells(); it.hasNext(); )                    cells.add(it.next());            }        }        return cells;    }	/**	 * Method to set the currently selected object in the explorer tree.	 * param obj the currently selected object in the explorer tree.	 */	public void clearCurrentlySelectedObjects()	{		currentSelectedPaths = NULL_TREE_PATH_ARRAY;	}	/**	 * Method to return the currently selected object in the explorer tree.	 * @return the currently selected object in the explorer tree.	 */	public ExplorerTreeModel model() { return (ExplorerTreeModel)treeModel; }	/**	 * Method to force the explorer tree to show the current library or signals list.     * @param lib library to expand     * @param cell     * @param openLib true to open the current library, false to open the signals list.     */	void openLibraryInExplorerTree(Library lib, Cell cell, boolean openLib) {        int count = -1; // starts from EXPLORER node        openLibraryInExplorerTree(lib, cell, new TreePath(rootNode), openLib, count);    }    /**     * Method to count rows to given cell considering possible cell groups and versions.     * @param cell     * @param treeModel     * @param path     * @param node     * @param count     * @return     */    private int countChildrenAndExpandInPath(Cell cell, TreeModel treeModel, TreePath path, Object node, int count)    {        int numChildren = treeModel.getChildCount(node);        for (int i = 0; i < numChildren; i++)        {            DefaultMutableTreeNode child = (DefaultMutableTreeNode)treeModel.getChild(node, i);            count++;            Object obj = child.getUserObject();            if (obj == cell)                return count; // found location in library            // Obj represents the latest version of the given cell and the given cell is an older version.            // treeModel.getChildCount(child) > 0 otherwise it will go down every single version.            if (treeModel.getChildCount(child) > 0 && obj instanceof Cell && ((Cell)obj).getCellGroup() == cell.getCellGroup())            {                TreePath descentPath = path.pathByAddingChild(child);                expandPath(descentPath);                return countChildrenAndExpandInPath(cell, treeModel, descentPath, child, count);            }            // Obj represents the cell group            if (obj == cell.getCellGroup())            {                TreePath descentPath = path.pathByAddingChild(child);                expandPath(descentPath);                return countChildrenAndExpandInPath(cell, treeModel, descentPath, child, count);            }        }        return count;    }	/**	 * Method to recursively scan the explorer tree and open the current library or signals list.     * @param library the library to open     * @param cell     * @param path the current position in the explorer tree.     * @param openLib true for libraries, false for waveforms     */	private boolean openLibraryInExplorerTree(Library library, Cell cell, TreePath path, boolean openLib, int count)	{        TreeModel treeModel = model();        Object node = path.getLastPathComponent();        Object obj = node;

⌨️ 快捷键说明

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