📄 layertab.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: LayerTab.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.text.TextUtils;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.Layer;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.tool.user.User;import java.awt.Color;import java.awt.Graphics2D;import java.awt.Rectangle;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.dnd.DnDConstants;import java.awt.dnd.DragGestureEvent;import java.awt.dnd.DragGestureListener;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.MouseAdapter;import java.awt.event.MouseEvent;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.swing.DefaultListModel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.ListSelectionModel;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;/** * Class to handle the "Layers tab" of a window. */public class LayerTab extends JPanel implements DragSourceListener, DragGestureListener{ private JList layerList; private DefaultListModel layerListModel; private Map<Layer,Boolean> highlighted; private List<Layer> layersInList; private DragSource dragSource; private boolean loading; private boolean layerDrawing; private static Map<Layer,Boolean> visibility; /** * Constructor creates a new panel for the Layers tab. */ public LayerTab(WindowFrame wf) { initComponents(); // build the change list layerListModel = new DefaultListModel(); layerList = new JList(layerListModel); layerList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); layerPane.setViewportView(layerList); layerList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { apply(e); } }); // setup drag-and-drop in the layers tab dragSource = new DragSource(); dragSource.createDefaultDragGestureRecognizer(layerList, DnDConstants.ACTION_COPY, this); new DropTarget(layerList, DnDConstants.ACTION_LINK, new LayerTabTreeDropTarget(), true); nodeText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); arcText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); portText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); exportText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); annotationText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); instanceNames.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); cellText.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { update(); } }); opacitySlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { sliderChanged(); } }); technology.setLightWeightPopupEnabled(false); // Getting default tech stored loadTechnologies(true); updateLayersTab(); technology.addActionListener(new WindowFrame.CurTechControlListener(wf)); } /** * Free allocated resources before closing. */ public void finished() { // making memory available for GC layersInList.clear(); layersInList = null; highlighted.clear(); highlighted = null; } /** * Method to update the technology popup selector in the Layers tab. * Called at initialization or when a new technology has been created. */ public void loadTechnologies(boolean makeCurrent) { Technology cur = Technology.getCurrent(); if (!makeCurrent || cur == null) cur = Technology.findTechnology((String)technology.getSelectedItem()); loading = true; technology.removeAllItems(); visibility = new HashMap<Layer,Boolean>(); for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next();// if (tech == Generic.tech() && !Job.getDebug()) continue; technology.addItem(tech.getTechName()); for(Iterator<Layer> lIt = tech.getLayers(); lIt.hasNext(); ) { Layer layer = lIt.next(); if (layer.isPseudoLayer()) continue; visibility.put(layer, Boolean.valueOf(layer.isVisible())); } } visibility.put(Generic.tech().drcLay, Boolean.valueOf(Generic.tech().drcLay.isVisible())); visibility.put(Generic.tech().afgLay, Boolean.valueOf(Generic.tech().afgLay.isVisible())); setSelectedTechnology(cur); loading = false; } /** * Method to set the technology in the pull down menu of this Layers tab. * @param tech the technology to set. */ public void setSelectedTechnology(Technology tech) { if (tech == null) System.out.println("Selecting a null technology"); else technology.setSelectedItem(tech.getTechName()); } public void setDisplayAlgorithm(boolean layerDrawing) { boolean changed = this.layerDrawing != layerDrawing; this.layerDrawing = layerDrawing; if (changed) updateLayersTab(); } /** * Method to update this LayersTab. * Called when any of the values in the tab have changed. */ public void updateLayersTab() { if (loading) return; // initialize text visibility checkboxes nodeText.setSelected(User.isTextVisibilityOnNode()); arcText.setSelected(User.isTextVisibilityOnArc()); portText.setSelected(User.isTextVisibilityOnPort()); exportText.setSelected(User.isTextVisibilityOnExport()); annotationText.setSelected(User.isTextVisibilityOnAnnotation()); instanceNames.setSelected(User.isTextVisibilityOnInstance()); cellText.setSelected(User.isTextVisibilityOnCell()); // cache dimming boolean noDimming = true; for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); for(Iterator<Layer> lIt = tech.getLayers(); lIt.hasNext(); ) { Layer layer = lIt.next(); if (layer.isDimmed()) noDimming = false; } } // cache highlighting highlighted = new HashMap<Layer,Boolean>(); for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); for(Iterator<Layer> lIt = tech.getLayers(); lIt.hasNext(); ) { Layer layer = lIt.next(); if (layer.isPseudoLayer()) continue; if (noDimming) highlighted.put(layer, Boolean.FALSE); else highlighted.put(layer, Boolean.valueOf(!layer.isDimmed())); } } Technology tech = Technology.getCurrent(); setSelectedTechnology(tech); layerListModel.clear(); layersInList = new ArrayList<Layer>(); if (tech != null) { // see if a preferred order has been saved List<Layer> savedOrder = tech.getSavedLayerOrder(); List<Layer> allLayers = tech.getLayersSortedByHeight(); // put the dummy layers at the end of the list List<Layer> dummyLayers = new ArrayList<Layer>(); for(Layer lay : allLayers) { if (lay.getFunction().isDummy() || lay.getFunction().isDummyExclusion()) dummyLayers.add(lay); } for(Layer lay : dummyLayers) allLayers.remove(lay); for(Layer lay : dummyLayers) allLayers.add(lay); // add special layers in layout technologies if (tech.isLayout()) { allLayers.add(Generic.tech().drcLay); allLayers.add(Generic.tech().afgLay); } if (savedOrder == null) savedOrder = allLayers; for(Layer layer : savedOrder) { if (layer.getTechnology() != Generic.tech() && layer.isPseudoLayer()) continue; layersInList.add(layer); layerListModel.addElement(lineName(layer)); } // add any layers not saved for(Layer layer : allLayers) { if (savedOrder.contains(layer)) continue; if (layer.getTechnology() != Generic.tech() && layer.isPseudoLayer()) continue; layersInList.add(layer); layerListModel.addElement(lineName(layer)); } layerList.setSelectedIndex(0); } opacitySlider.setVisible(layerDrawing); resetOpacity.setVisible(layerDrawing); } private String lineName(Layer layer) { StringBuffer layerName = new StringBuffer(); Boolean layerVisible = visibility.get(layer); if (layerVisible != null && layerVisible.booleanValue()) layerName.append("\u2713 "); else layerName.append(" "); if (layer.isPseudoLayer()) layerName.append(" (for pins)"); Boolean layerHighlighted = highlighted.get(layer); layerName.append(layer.getName()); if (layerHighlighted.booleanValue()) layerName.append(" (HIGHLIGHTED)"); if (layerDrawing) layerName.append(" (" + TextUtils.formatDouble(layer.getGraphics().getOpacity(),2) + ")"); return layerName.toString(); } /** * Method called when the user clicks on an element of the list. * @param e Event information. */ private void apply(MouseEvent e) { int [] indices = layerList.getSelectedIndices(); if (indices.length == 1) { // single layer selected: show opacity if (/*Job.getDebug()*/layerDrawing) { Layer layer = getSelectedLayer(indices[0]); if (layer != null) { double opacity = layer.getGraphics().getOpacity(); double range = opacitySlider.getMaximum() - opacitySlider.getMinimum(); int newValue = opacitySlider.getMinimum() + (int)(range * opacity); opacitySlider.setValue(newValue); } } } if (e.getClickCount() == 2) { for(int i=0; i<indices.length; i++) { int line = indices[i]; setVisibility(line, !isLineChecked(line), true); } } } /** * Method called when the opacity slider is changed. */ private void sliderChanged() { // single layer selected: show opacity int [] indices = layerList.getSelectedIndices(); if (indices.length != 1) return; Layer layer = getSelectedLayer(indices[0]); if (layer == null) return; int sliderValue = opacitySlider.getValue() - opacitySlider.getMinimum(); double range = opacitySlider.getMaximum() - opacitySlider.getMinimum(); double newOpacity = sliderValue / range; layer.getGraphics().setOpacity(newOpacity); layerListModel.set(indices[0], lineName(layer));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -