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

📄 textinfopanel.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: TextInfoPanel.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.geometry.DBMath;import com.sun.electric.database.geometry.EGraphics;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.MutableTextDescriptor;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.user.ui.WindowFrame;import java.awt.Color;import java.awt.Font;import java.awt.GraphicsEnvironment;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.util.Arrays;import java.util.Iterator;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;/** * A Panel to display and edit Text Display options for a Variable. * Does not display attribute specific options such as Code or Show Style. */public class TextInfoPanel extends javax.swing.JPanel{	private boolean updateChangesInstantly;	private boolean loading = false;    private TextDescriptor.Position initialPos;    private TextDescriptor.Size initialSize;    private TextDescriptor.Rotation initialRotation;    private boolean initialItalic, initialBold, initialUnderline;    private boolean initialInvisibleOutsideCell;    private int initialFont;    private double initialXOffset, initialYOffset;    private double initialBoxedWidth, initialBoxedHeight;    private int initialColorIndex;    private TextDescriptor td;    private Variable.Key varKey;    private ElectricObject owner;    private NodeInst unTransformNi;    /**     * Create a new TextInfoPanel that can be used to edit     * the Text Display options of a Variable.     */    public TextInfoPanel(boolean updateChangesInstantly, boolean paramDialog)    {    	this.updateChangesInstantly = updateChangesInstantly;        initComponents();		// make all text fields select-all when entered	    EDialog.makeTextFieldSelectAllOnTab(pointsSize);	    EDialog.makeTextFieldSelectAllOnTab(unitsSize);	    EDialog.makeTextFieldSelectAllOnTab(xOffset);	    EDialog.makeTextFieldSelectAllOnTab(yOffset);	    EDialog.makeTextFieldSelectAllOnTab(boxedHeight);	    EDialog.makeTextFieldSelectAllOnTab(boxedWidth);        // pure "parameters" dialog doesn't have "Highlight Owner" button        if (paramDialog) remove(seeNode);        font.addItem("DEFAULT FONT");        Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();        for(int i=0; i<fonts.length; i++) {            font.addItem(fonts[i].getFontName());        }        // populate Rotations combo box        for (int i=0; i<TextDescriptor.Rotation.getNumRotations(); i++) {            TextDescriptor.Rotation rot = TextDescriptor.Rotation.getRotationAt(i);            // rotations stored as integers, retrieve by Rotation.getIndex()            rotation.addItem(new Integer(rot.getAngle()));        }        // populate Anchor combo box        for (Iterator<TextDescriptor.Position> it = TextDescriptor.Position.getPositions(); it.hasNext(); ) {            TextDescriptor.Position pos = it.next();            textAnchor.addItem(pos);        }        // populate color combo box        int [] colorIndices = EGraphics.getColorIndices();        textColorComboBox.addItem("DEFAULT COLOR");        for (int i=0; i<colorIndices.length; i++) {            String str = EGraphics.getColorIndexName(colorIndices[i]);            textColorComboBox.addItem(str);        }        // default settings        // offset        initialXOffset = initialYOffset = 0;        xOffset.setText("0"); yOffset.setText("0");        // invisible outside cell        initialInvisibleOutsideCell = false;        invisibleOutsideCell.setSelected(initialInvisibleOutsideCell);        // size        unitsButton.setText("Units (min " + TextDescriptor.Size.TXTMINQGRID + ", max " + TextDescriptor.Size.TXTMAXQGRID + ")");        initialSize = TextDescriptor.Size.newRelSize(1.0);        unitsButton.setSelected(true);        unitsSize.setText("1.0");        pointsButton.setText("Points (min " + TextDescriptor.Size.TXTMINPOINTS + ", max " + TextDescriptor.Size.TXTMAXPOINTS + ")");        // position        initialPos = TextDescriptor.Position.CENT;        textAnchor.setSelectedItem(initialPos);        // font        initialFont = 0;        font.setSelectedIndex(initialFont);        // italic/bold/underline        initialItalic = false; italic.setEnabled(false);        initialBold = false; bold.setEnabled(false);        initialUnderline = false; underline.setEnabled(false);        // rotation        initialRotation = TextDescriptor.Rotation.ROT0;        rotation.setSelectedItem(initialRotation);        // color        initialColorIndex = 0; // Zero is the default font        setTextDescriptor(null, null);        // listeners        unitsSize.getDocument().addDocumentListener(new TextInfoDocumentListener(this));        pointsSize.getDocument().addDocumentListener(new TextInfoDocumentListener(this));        xOffset.getDocument().addDocumentListener(new TextInfoDocumentListener(this));        yOffset.getDocument().addDocumentListener(new TextInfoDocumentListener(this));        boxedWidth.getDocument().addDocumentListener(new TextInfoDocumentListener(this));        boxedHeight.getDocument().addDocumentListener(new TextInfoDocumentListener(this));        unitsButton.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        pointsButton.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        italic.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        bold.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        underline.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        invisibleOutsideCell.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        rotation.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        textAnchor.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        font.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });        textColorComboBox.addActionListener(new java.awt.event.ActionListener()        {            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }        });    }    public void setOffsets(Point2D offset)    {        loading = true;        xOffset.setText(TextUtils.formatDouble(offset.getX()));        yOffset.setText(TextUtils.formatDouble(offset.getY()));        loading = false;    }    /**     * Set what the dialog displays: It can display and allow editing of the settings     * for an existing text descriptor, or it can display and allow editing of default values     * for a text descriptor of a variable that has not yet been created.     * <p>if owner.getTextDescriptor(varKey) returns non-null td, display and allow editing of the td text options     * <p>else if varKey is non-null, display and allow editing of default values.     * <p>if varKey is null, disable entire panel     * @param varKey the key a variable that will be created later.     * @param owner the object the variable is on.     */    public synchronized void setTextDescriptor(Variable.Key varKey, ElectricObject owner)    {        // do not allow empty names for future vars        if (varKey != null) {            if (varKey.getName().trim().equals("")) varKey = null;        }        this.varKey = varKey;        this.owner = owner;        boolean enabled = owner != null && varKey != null;        // update enabled state of everything        // can't just enable all children because objects might be inside JPanel        pointsSize.setEnabled(enabled);        unitsSize.setEnabled(enabled);        pointsButton.setEnabled(enabled);        unitsButton.setEnabled(enabled);        xOffset.setEnabled(enabled);        yOffset.setEnabled(enabled);        font.setEnabled(enabled);        textAnchor.setEnabled(enabled);        rotation.setEnabled(enabled);        bold.setEnabled(enabled);        italic.setEnabled(enabled);        underline.setEnabled(enabled);        invisibleOutsideCell.setEnabled(enabled);        seeNode.setEnabled(enabled && !(owner instanceof Cell));        boxedWidth.setEnabled(false);               // only enabled when boxed anchor is selected        boxedHeight.setEnabled(false);               // only enabled when boxed anchor is selected        textColorComboBox.setEnabled(enabled);        if (!enabled) return;        // if td is null and we are going to apply value to future var,        // use current panel settings.		td = owner.getTextDescriptor(varKey);        if (td == null) return;        loading = true;        NodeInst ni = null;        // use location of owner if it is a generic invisible pin, because        // this is the location of the text on the cell        if (owner != null)        {            if (owner instanceof NodeInst)            {                ni = (NodeInst)owner;                if (ni.getProto() != Generic.tech().invisiblePinNode)                {                    ni = null;                  // ni is null unless owner is invisible pin                }            }        }        // find the node that this is sitting on, to handle offsets and rotations        unTransformNi = null;        if (owner != null)        {        	if (owner instanceof NodeInst) unTransformNi = (NodeInst)owner; else        		if (owner instanceof Export) unTransformNi = ((Export)owner).getOriginalPort().getNodeInst();        }        // set the offset        if (ni != null)        {            initialXOffset = ni.getAnchorCenterX();            initialYOffset = ni.getAnchorCenterY();        } else        {            initialXOffset = td.getXOff();            initialYOffset = td.getYOff();        	if (unTransformNi != null)        	{        		Point2D off = new Point2D.Double(initialXOffset, initialYOffset);        		AffineTransform trans = unTransformNi.pureRotateOut();        		trans.transform(off, off);        		initialXOffset = off.getX();        		initialYOffset = off.getY();

⌨️ 快捷键说明

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