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

📄 sizelistener.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: SizeListener.java * * Copyright (c) 2004 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.DBMath;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.CircuitChangeJobs;import com.sun.electric.tool.user.Highlighter;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.dialogs.EDialog;import java.awt.Cursor;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;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.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.util.EventListener;import java.util.List;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JTextField;/** * Class to interactively resize a node. */public class SizeListener	implements MouseMotionListener, MouseListener, MouseWheelListener, KeyListener{	private Geometric stretchGeom;	private EventListener oldListener;	private Cursor oldCursor;	private Point2D farthestPoint;	private static Cursor sizeCursor = ToolBar.readCursor("CursorSize.gif", 14, 14);    private static SizeListener currentListener = null;	private SizeListener() {}	/**	 * Method to do an interactive sizing of the currently selected object.	 */	public static void sizeObjects()	{		EditWindow wnd = EditWindow.needCurrent();		if (wnd == null) return;		Highlighter highlighter = wnd.getHighlighter();		List<Geometric> geomList = highlighter.getHighlightedEObjs(true, true);		if (geomList == null) return;		if (geomList.size() != 1)		{			System.out.println("Select just one object to size");			return;		}		Geometric geom = geomList.get(0);		EventListener newListener = null;		// remember the listener that was there before		EventListener oldListener = WindowFrame.getListener();		Cursor oldCursor = TopLevel.getCurrentCursor();		System.out.println("Click to stretch " + geom);		newListener = oldListener;		if (newListener == null || !(newListener instanceof SizeListener))		{			currentListener = new SizeListener();            newListener = currentListener;            WindowFrame.setListener(newListener);        }		((SizeListener)newListener).stretchGeom = geom;        // Only store data when the previous event listener is not this one        if (!(oldListener instanceof SizeListener))        {            ((SizeListener)newListener).oldListener = oldListener;		    ((SizeListener)newListener).oldCursor = oldCursor;        }        // change the cursor		TopLevel.setCurrentCursor(sizeCursor);	}    public static void restorePreviousListener(Object toDelete)    {        if (currentListener == null) return; // nothing to restore        if (currentListener.stretchGeom == toDelete)            currentListener.restoringOriginalSetup(null);    }    /**	 * Method to present a dialog to resize all selected nodes.	 */	public static void sizeAllNodes()	{		SizeObjects dialog = new SizeObjects(TopLevel.getCurrentJFrame(), true, true);		dialog.setVisible(true);	}	/**	 * Method to present a dialog to resize all selected arcs.	 */	public static void sizeAllArcs()	{		SizeObjects dialog = new SizeObjects(TopLevel.getCurrentJFrame(), true, false);		dialog.setVisible(true);	}	/**	 * Class to handle the "Size all selected nodes/arcs" dialog.	 */	private static class SizeObjects extends EDialog	{		private JTextField xSize, ySize;		boolean nodes;		/** Creates new form Size all selected nodes/arcs */		public SizeObjects(java.awt.Frame parent, boolean modal, boolean nodes)		{			super(parent, modal);			EditWindow wnd = EditWindow.needCurrent();			if (wnd == null) return;			Highlighter highlighter = wnd.getHighlighter();			getContentPane().setLayout(new GridBagLayout());			String label = "Width:";			this.nodes = nodes;			if (nodes)			{				label = "X Size:";				setTitle("Set Node Size");				JLabel ySizeLabel = new JLabel("Y Size:");				GridBagConstraints gbc = new GridBagConstraints();				gbc.gridx = 0;				gbc.gridy = 1;				gbc.insets = new java.awt.Insets(4, 4, 4, 4);				getContentPane().add(ySizeLabel, gbc);				ySize = new JTextField();				ySize.setColumns(6);				gbc = new GridBagConstraints();				gbc.gridx = 1;				gbc.gridy = 1;				gbc.weightx = 1;				gbc.fill = GridBagConstraints.HORIZONTAL;				gbc.insets = new java.awt.Insets(4, 4, 4, 4);				getContentPane().add(ySize, gbc);			} else			{				setTitle("Set Arc Size");			}			JLabel xSizeLabel = new JLabel(label);			GridBagConstraints gbc = new GridBagConstraints();			gbc.gridx = 0;			gbc.gridy = 0;			gbc.insets = new java.awt.Insets(4, 4, 4, 4);			getContentPane().add(xSizeLabel, gbc);			xSize = new JTextField();			xSize.setColumns(6);			gbc = new GridBagConstraints();			gbc.gridx = 1;			gbc.gridy = 0;			gbc.weightx = 1;			gbc.fill = GridBagConstraints.HORIZONTAL;			gbc.insets = new java.awt.Insets(4, 4, 4, 4);			getContentPane().add(xSize, gbc);			JButton ok = new JButton("OK");			gbc = new GridBagConstraints();			gbc.gridx = 1;			gbc.gridy = 2;			gbc.insets = new java.awt.Insets(4, 4, 4, 4);			getContentPane().add(ok, gbc);			JButton cancel = new JButton("Cancel");			gbc = new GridBagConstraints();			gbc.gridx = 0;			gbc.gridy = 2;			gbc.insets = new java.awt.Insets(4, 4, 4, 4);			getContentPane().add(cancel, gbc);			addWindowListener(new WindowAdapter()			{				public void windowClosing(WindowEvent evt) { SizeObjectsClosing(evt); }			});			cancel.addActionListener(new ActionListener()			{				public void actionPerformed(ActionEvent evt) { cancel(evt); }			});			ok.addActionListener(new ActionListener()			{				public void actionPerformed(ActionEvent evt) { ok(evt); }			});			pack();			getRootPane().setDefaultButton(ok);			// determine default size			double xS = 0, yS = 0;			for(Geometric geom : highlighter.getHighlightedEObjs(true, true))			{				if (geom instanceof NodeInst && nodes)				{					NodeInst ni = (NodeInst)geom;					xS = ni.getLambdaBaseXSize();					yS = ni.getLambdaBaseYSize();				} else if (geom instanceof ArcInst && !nodes)				{					ArcInst ai = (ArcInst)geom;					xS = ai.getLambdaBaseWidth();				}			}			xSize.setText(TextUtils.formatDouble(xS));			if (nodes)				ySize.setText(TextUtils.formatDouble(yS));		}		private void cancel(java.awt.event.ActionEvent evt)		{			SizeObjectsClosing(null);		}		private void ok(java.awt.event.ActionEvent evt)		{			// resize the objects			EditWindow wnd = EditWindow.needCurrent();			if (wnd == null) return;			Highlighter highlighter = wnd.getHighlighter();			List<Geometric> highlighted = highlighter.getHighlightedEObjs(true, true);			double xS = TextUtils.atof(xSize.getText());			double yS = 0;			if (nodes)				yS = TextUtils.atof(ySize.getText());			new ResizeStuff(wnd.getCell(), highlighted, xS, yS, nodes);			SizeObjectsClosing(null);		}		private void SizeObjectsClosing(WindowEvent evt)		{			setVisible(false);			dispose();		}	}	/**	 * Class to resize objects in a new thread.	 */	private static class ResizeStuff extends Job	{		private Cell cell;		private List<Geometric> highlighted;		private double xS, yS;		private boolean nodes;		protected ResizeStuff(Cell cell, List<Geometric> highlighted, double xS, double yS, boolean nodes)		{			super("Resize Objects", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.cell = cell;			this.highlighted = highlighted;			this.xS = xS;			this.yS = yS;			this.nodes = nodes;			startJob();		}		public boolean doIt() throws JobException		{			// make sure moving the node is allowed			if (CircuitChangeJobs.cantEdit(cell, null, true, false, true) != 0) return false;			boolean didSomething = false;			for(Geometric geom : highlighted)			{				if (geom instanceof NodeInst && nodes)				{					NodeInst ni = (NodeInst)geom;					double x = xS;					double y = yS;					if (!ni.isCellInstance() && ((PrimitiveNode)ni.getProto()).isSquare())					{						if (y > x) x = y; else y = x;					}					ni.resize(x - ni.getLambdaBaseXSize(), y - ni.getLambdaBaseYSize());					didSomething = true;				} else if (geom instanceof ArcInst && !nodes)				{					ArcInst ai = (ArcInst)geom;					ai.setLambdaBaseWidth(xS);					didSomething = true;				}			}			if (!didSomething)			{				System.out.println("Could not find any " + (nodes?"nodes":"arcs") + " to resize");			}			return true;		}	}	public void mousePressed(MouseEvent evt)	{		farthestPoint = null;		showHighlight(evt, (EditWindow)evt.getSource());	}	public void mouseMoved(MouseEvent evt)	{		farthestPoint = null;		showHighlight(evt, (EditWindow)evt.getSource());		farthestPoint = null;	}

⌨️ 快捷键说明

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