📄 paletteframe.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: PaletteFrame.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.geometry.EPoint;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.Highlighter;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.dialogs.NewExport;import com.sun.electric.tool.user.tecEdit.Info;import com.sun.electric.tool.user.tecEdit.Manipulate;import java.awt.Container;import java.awt.Cursor;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.MouseWheelEvent;import java.awt.event.MouseWheelListener;import java.awt.geom.Point2D;import java.util.EventListener;import java.util.Iterator;import javax.swing.JComboBox;import javax.swing.JOptionPane;import javax.swing.JPanel;/** * This class defines a component window in the side bar. */public class PaletteFrame implements MouseListener{ /** the palette window panel. */ private JPanel topPanel; /** the technology palette */ private TechPalette techPalette; /** the popup that selects technologies. */ private JComboBox techSelector; // constructor private PaletteFrame() {} /** * Method to create a new window on the screen that displays the component menu. * @return the PaletteFrame that shows the component menu. */ public static PaletteFrame newInstance(WindowFrame ww) { PaletteFrame palette = new PaletteFrame(); palette.topPanel = new JPanel(); // initialize all components palette.initComponents(ww); return palette; } /** * Method to update the technology popup selector. * Called at initialization or when a new technology has been created. * @param makeCurrent true to keep the current technology selected, * false to set to the current technology. */ public void loadTechnologies(boolean makeCurrent) { Technology cur = Technology.getCurrent(); if (!makeCurrent) cur = Technology.findTechnology((String)techSelector.getSelectedItem()); techSelector.removeAllItems(); for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); if (tech == Generic.tech()) continue; techSelector.addItem(tech.getTechName()); } if (cur != null) setSelectedItem(cur.getTechName()); } /** * Public function to set selected item in techSelector * @param anObject */ public void setSelectedItem(Object anObject) { techSelector.setSelectedItem(anObject); } private void initComponents(WindowFrame wf) { Container content = topPanel; // layout the Buttons and Combo boxes that control the palette content.setLayout(new GridBagLayout()); GridBagConstraints gridBagConstraints; techSelector = new JComboBox(); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new Insets(0, 0, 0, 0); content.add(techSelector, gridBagConstraints); // this panel will switch between the different palettes techPalette = new TechPalette(); techPalette.setFocusable(true); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.gridwidth = 2; gridBagConstraints.gridheight = 2; gridBagConstraints.insets = new Insets(0, 0, 0, 0); content.add(techPalette, gridBagConstraints); techSelector.setLightWeightPopupEnabled(false); // Getting default tech stored loadTechnologies(true); techSelector.addActionListener(new WindowFrame.CurTechControlListener(wf)); } /** * Method to set the cursor that is displayed in the PaletteFrame. * @param cursor the cursor to display here. */ public void setCursor(Cursor cursor) { techPalette.setCursor(cursor); } public JPanel getTechPalette() { return topPanel; } public void arcProtoChanged() { techPalette.repaint(); } /** * Set the Technology Palette to the current technology. */ public void loadForTechnology(Technology tech, WindowFrame ww) { techSelector.setSelectedItem(tech.getTechName()); Dimension size = techPalette.loadForTechnology(tech, ww.getContent().getCell()); if (techPalette.isVisible()) { setSize(size); } } private void setSize(Dimension size) { topPanel.setSize(size); } public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) { if (e.isShiftDown() || e.isControlDown() || e.isAltDown()) return; } /** * Interface for a Palette object that can be added to the Palette frame */ public static interface PlaceNodeEventListener { /** * Called when the placeNodeListener is started, and the requested Object nodeToBePlaced * is in the process of being placed * @param nodeToBePlaced the node that will be placed */ public void placeNodeStarted(Object nodeToBePlaced); /** * Called when the placeNodeListener has finished. * @param cancelled true if process aborted and nothing place, false otherwise. */ public void placeNodeFinished(boolean cancelled); } /** * Method to interactively place an instance of a node. * @param obj the node to create. * If this is a NodeProto, one of these types is created. * If this is a NodeInst, one of these is created, and the specifics of this instance are copied. * @param palette if not null, is notified of certain events during the placing of the node * If this is null, then the request did not come from the palette. */ public static PlaceNodeListener placeInstance(Object obj, PlaceNodeEventListener palette, boolean export) { NodeProto np = null; NodeInst ni = null; String placeText = null; String whatToCreate = null; // make sure current cell is not null Cell curCell = WindowFrame.needCurCell(); if (curCell == null) return null; if (obj instanceof String) { placeText = (String)obj; whatToCreate = Variable.betterVariableName(placeText); obj = Generic.tech().invisiblePinNode; } if (obj instanceof NodeProto) { np = (NodeProto)obj; if (np instanceof Cell) { // see if a contents is requested when it should be an icon Cell cell = (Cell)np; Cell iconCell = cell.iconView(); if (iconCell != null && iconCell != cell) { int response = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(), "Don't you really want to place the icon " + iconCell.describe(true) + "?"); if (response == JOptionPane.CANCEL_OPTION) return null; if (response == JOptionPane.YES_OPTION) obj = np = iconCell; } } } else if (obj instanceof NodeInst) { ni = (NodeInst)obj; np = ni.getProto(); whatToCreate = ni.getFunction() + " node"; } if (np != null) { // remember the listener that was there before EventListener oldListener = WindowFrame.getListener(); Cursor oldCursor = TopLevel.getCurrentCursor(); if (whatToCreate != null) System.out.println("Click to create " + whatToCreate); else { if (np instanceof Cell) System.out.println("Click to create an instance of " + np); else System.out.println("Click to create " + np); } EventListener newListener = oldListener; if (newListener != null && newListener instanceof PlaceNodeListener) { // It has to be obj so it would remember if element from list was selected. ((PlaceNodeListener)newListener).setParameter(obj); ((PlaceNodeListener)newListener).makePortWhenCreated(export); } else { newListener = new PlaceNodeListener(obj, oldListener, oldCursor, palette); ((PlaceNodeListener)newListener).makePortWhenCreated(export); WindowFrame.setListener(newListener); } if (placeText != null) ((PlaceNodeListener)newListener).setTextNode(placeText); if (palette != null) palette.placeNodeStarted(obj); // change the cursor TopLevel.setCurrentCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // zoom the window to fit the placed node (if appropriate) EditWindow wnd = EditWindow.getCurrent(); if (wnd != null) { wnd.requestFocus(); wnd.zoomWindowToFitCellInstance(np);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -