📄 abstracttextdescriptor.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: AbstractTextDescriptor.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.database.variable;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.text.Pref;import com.sun.electric.tool.user.User;import java.awt.Font;import java.awt.font.FontRenderContext;import java.awt.font.GlyphVector;import java.io.Serializable;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;/** * This class describes how variable text appears. * <P> * This class should be thread-safe */abstract class AbstractTextDescriptor implements Serializable{ /*private*/ static final long VTPOSITION = 017L; /* 0: position of text relative to point */ /*private*/ static final int VTPOSITIONSH = 0; /* 0: right shift of VTPOSITION */ /*private*/ static final int VTPOSCENT = 0; /* 0: text centered about point */ /*private*/ static final int VTPOSUP = 1; /* 0: text centered above point */ /*private*/ static final int VTPOSDOWN = 2; /* 0: text centered below point */ /*private*/ static final int VTPOSLEFT = 3; /* 0: text centered to left of point */ /*private*/ static final int VTPOSRIGHT = 4; /* 0: text centered to right of point */ /*private*/ static final int VTPOSUPLEFT = 5; /* 0: text centered to upper-left of point */ /*private*/ static final int VTPOSUPRIGHT = 6; /* 0: text centered to upper-right of point */ /*private*/ static final int VTPOSDOWNLEFT = 7; /* 0: text centered to lower-left of point */ /*private*/ static final int VTPOSDOWNRIGHT = 8; /* 0: text centered to lower-right of point */ /*private*/ static final int VTPOSBOXED = 9; /* 0: text centered and limited to object size */ /*private*/ static final long VTDISPLAYPART = 060L; /* 0: bits telling what to display */ /*private*/ static final int VTDISPLAYPARTSH = 4; /* 0: right shift of VTDISPLAYPART */ /*private*/ static final int VTDISPLAYVALUE = 0; /* 0: display value */ /*private*/ static final int VTDISPLAYNAMEVALUE = 2; /* 0: display name and value */ /*private*/ static final int VTDISPLAYNAMEVALINH = 1; /* 0: display name, value, 1-level inherit */ /*private*/ static final int VTDISPLAYNAMEVALINHALL = 3; /* 0: display name, value, any inherit */ /*private*/ static final long VTITALIC = 0100L; /* 0: set for italic text */ /*private*/ static final long VTBOLD = 0200L; /* 0: set for bold text */ /*private*/ static final long VTUNDERLINE = 0400L; /* 0: set for underline text */ /*private*/ static final long VTISPARAMETER = 01000L; /* 0: attribute is parameter (nodeinst only) */ /*private*/ static final long VTINTERIOR = 02000L; /* 0: text only appears inside cell */ /*private*/ static final long VTINHERIT = 04000L; /* 0: set to inherit value from proto to inst */ /*private*/ static final long VTXOFF = 07770000L; /* 0: X offset of text */ /*private*/ static final int VTXOFFSH = 12; /* 0: right shift of VTXOFF */ /*private*/ static final long VTXOFFNEG = 010000000L; /* 0: set if X offset is negative */ /*private*/ static final long VTYOFF = 017760000000L; /* 0: Y offset of text */ /*private*/ static final int VTYOFFSH = 22; /* 0: right shift of VTYOFF */ /*private*/ static final long VTYOFFNEG = 020000000000L; /* 0: set if Y offset is negative */ /*private*/ static final int VTOFFMASKWID = 9; /* 0: Width of VTXOFF and VTYOFF */ /*private*/ static final long VTSIZE = 077777L << 32; /* 1: size of text */ /*private*/ static final int VTSIZESH = 0 + 32; /* 1: right shift of VTSIZE */ /*private*/ static final long VTFACE = 017700000L << 32; /* 1: face of text */ /*private*/ static final int VTFACESH = 15 + 32; /* 1: right shift of VTFACE */ /*private*/ static final int VTMAXFACE = 127; /* 1: maximum value of VTFACE field */ /*private*/ static final long VTROTATION = 060000000L << 32; /* 1: rotation of text */ /*private*/ static final int VTROTATIONSH = 22 + 32; /* 1: right shift of VTROTATION */ /*private*/ static final long VTOFFSCALE = 03700000000L << 32; /* 1: scale of text offset */ /*private*/ static final int VTOFFSCALESH = 24 + 32; /* 1: right shift of VTOFFSCALE */ /*private*/ static final long VTUNITS = 034000000000L << 32; /* 1: units of text */ /*private*/ static final int VTUNITSHMASK = 07; /* 1: mask of this value after being shifted down */ /*private*/ static final int VTUNITSSH = 29 + 32; /* 1: right shift of VTUNITS */ /*private*/ static final int VTUNITSNONE = 0; /* 1: units: none */ /*private*/ static final int VTUNITSRES = 1; /* 1: units: resistance */ /*private*/ static final int VTUNITSCAP = 2; /* 1: units: capacitance */ /*private*/ static final int VTUNITSIND = 3; /* 1: units: inductance */ /*private*/ static final int VTUNITSCUR = 4; /* 1: units: current */ /*private*/ static final int VTUNITSVOLT = 5; /* 1: units: voltage */ /*private*/ static final int VTUNITSDIST = 6; /* 1: units: distance */ /*private*/ static final int VTUNITSTIME = 7; /* 1: units: time */ /*private*/ static final int VTOFFMAX = (1 << VTOFFMASKWID) - 1; /* 0: Maximal value of unshifted VTXOFF and VTYOFF */ /** Semantic bits - those bits which are meaningful in non-displayable text descriptors. */ static long VTSEMANTIC = VTISPARAMETER | VTINTERIOR | VTINHERIT | VTUNITS; // Variable flags in C Electric /** display variable (uses textdescript field) */ /*private*/ static final int VDISPLAY = 0100; /** enumeration which represents text visibility .*/ public enum Display { /** Non-displayable variable */ NONE, /** Displayable variable which is temporary hidden */ HIDDEN, /** Displayable variable which is shown */ SHOWN; }; /** * Position is a typesafe enum class that describes the text position of a Variable. * The Position describes the "anchor point" of the text, * which is the point on the text that is attached to the object and does not move. * For example, when the Position is CENT, then the center of the text is fixed, * and as the text grows, it expands uniformly about the center. * When the Position is UP, the text is centered above the anchor point, and as the text grows * it expands upward from the bottom-center point. */ public static class Position { private final String name; private final int index; private final Poly.Type pt; private static final List<Position> positions = new ArrayList<Position>(); private Position(String name, int index, Poly.Type pt) { this.name = name; this.index = index; this.pt = pt; positions.add(index, this); } /** * Method to return the integer equivalent of this Position. * @return the integer equivalent of this Position. */ public int getIndex() { return index; } /** * Method to return the Poly.Type to use for this Position. * The Poly.Type will vary through the 9 "anchor point" locations: * center, left, right, up, down, up-left, up-right, down-left, down-right. * @return the Poly.Type to use for this Position. */ public Poly.Type getPolyType() { return pt; } /** * Return Position moved in specified direction. * @param dx if positive move right, if negative move left. * @param dy if positive move up, if negative move down. * @return the moved position. */ public Position align(int dx, int dy) { Position p = this; if (dx > 0) { if (p == CENT || p == RIGHT || p == LEFT) p = RIGHT; else if (p == UP || p == UPRIGHT || p == UPLEFT) p = UPRIGHT; else if (p == DOWN || p == DOWNRIGHT || p == DOWNLEFT) p = DOWNRIGHT; } else if (dx < 0) { if (p == CENT || p == RIGHT || p == LEFT) p = LEFT; else if (p == UP || p == UPRIGHT || p == UPLEFT) p = UPLEFT; else if (p == DOWN || p == DOWNRIGHT || p == DOWNLEFT) p = DOWNLEFT; } if (dy > 0) { if (p == CENT || p == UP || p == DOWN) p = UP; else if (p == RIGHT || p == UPRIGHT || p == DOWNRIGHT) p = UPRIGHT; else if (p == LEFT || p == UPLEFT || p == DOWNLEFT) p = UPLEFT; } else if (dy < 0) { if (p == CENT || p == UP || p == DOWN) p = DOWN; else if (p == RIGHT || p == UPRIGHT || p == DOWNRIGHT) p = DOWNRIGHT; else if (p == LEFT || p == UPLEFT || p == DOWNLEFT) p = DOWNLEFT; } return p; } /** * Method to return the Position to use for the given Poly.Type. * The Poly.Type will vary through the 9 "anchor point" locations: * center, left, right, up, down, up-left, up-right, down-left, down-right. * @return the Position to use for the given Poly.Type. */ public static Position getPosition(Poly.Type type) { for(Position pos : positions) { if (type == pos.pt) return pos; } return CENT; } /** * Method to return the number Positions. * @return the number of Positions. */ public static int getNumPositions() { return positions.size(); } /** * Method to return the Position at a given index. * @param index the Position number desired. * @return the Position at a given index. */ public static Position getPositionAt(int index) { return positions.get(index); } /** * Get an iterator over all Positions */ public static Iterator<Position> getPositions() { return Collections.unmodifiableList(positions).iterator(); } /** * Returns a printable version of this Position. * @return a printable version of this Position. */ public String toString() { return name; } /** * Describes text centered at a point. */ public static final Position CENT = new Position("centered", VTPOSCENT, Poly.Type.TEXTCENT); /** * Describes text centered above a point. */ public static final Position UP = new Position("bottom", VTPOSUP, Poly.Type.TEXTBOT); /** * Describes text centered below a point. */ public static final Position DOWN = new Position("top", VTPOSDOWN, Poly.Type.TEXTTOP); /** * Describes text centered to left of a point. */ public static final Position LEFT = new Position("right", VTPOSLEFT, Poly.Type.TEXTRIGHT); /** * Describes text centered to right of a point. */ public static final Position RIGHT = new Position("left", VTPOSRIGHT, Poly.Type.TEXTLEFT); /** * Describes text centered to upper-left of a point. */ public static final Position UPLEFT = new Position("lower-right", VTPOSUPLEFT, Poly.Type.TEXTBOTRIGHT); /** * Describes text centered to upper-right of a point. */ public static final Position UPRIGHT = new Position("lower-left", VTPOSUPRIGHT, Poly.Type.TEXTBOTLEFT); /** * Describes text centered to lower-left of a point. */ public static final Position DOWNLEFT = new Position("upper-right", VTPOSDOWNLEFT, Poly.Type.TEXTTOPRIGHT); /** * Describes text centered to lower-right of a point. */ public static final Position DOWNRIGHT = new Position("upper-left", VTPOSDOWNRIGHT, Poly.Type.TEXTTOPLEFT); /** * Describes text centered and limited to the object size. * This means that the text may shrink in size or clip letters if necessary. */ public static final Position BOXED = new Position("boxed", VTPOSBOXED, Poly.Type.TEXTBOX); } /** * DispPos is a typesafe enum class that describes text's display position on a Variable. */ public static class DispPos { private final String name; private final int index; private static final List<DispPos> positions = new ArrayList<DispPos>(); private DispPos(String name, int index) { this.name = name; this.index = index; positions.add(this); } /** * Method to return the integer equivalent of this DispPos. * @return the integer equivalent of this DispPos. */ public int getIndex() { return index; } /** * Method to return the name of this DispPos. * It is used in popup menus. * @return the name of this DispPos. */ public String getName() { return name; } /** * Method to return the number DispPos. * @return the number DispPos. */ public static int getNumShowStyles() { return positions.size(); } /** * Method to return the DispPos at a given index. * @param index the DispPos number desired. * @return the DispPos at a given index. */ public static DispPos getShowStylesAt(int index) { for (DispPos d : positions) { if (d.index == index) return d; } return NAMEVALUE; } /** * Get an iterator over all show styles. * @return an iterator over the list of show styles */ public static Iterator<DispPos> getShowStyles() { return Collections.unmodifiableList(positions).iterator(); } /** * Returns a printable version of this DispPos. * @return a printable version of this DispPos. */ public String toString() { return name; } /** * Describes a Variable that displays its value. */ public static final DispPos VALUE = new DispPos("value", VTDISPLAYVALUE); /** * Describes a Variable that displays its name, value, 1-level inherit. * The form of the display is "ATTR=VALUE;def=DEFAULT"; */ //public static final DispPos NAMEVALINH = new DispPos("name=inherit;def=value", VTDISPLAYNAMEVALINH); /** * Describes a Variable that displays its name and value. * The form of the display is "ATTR=VALUE"; */ public static final DispPos NAMEVALUE = new DispPos("name=value", VTDISPLAYNAMEVALUE); /** * Describes a Variable that displays its name, value, any inherit. * The form of the display is "ATTR=VALUE;def=DEFAULT"; */ //public static final DispPos NAMEVALINHALL = new DispPos("name=inheritAll;def=value", VTDISPLAYNAMEVALINHALL); } /** * Size is a class that describes text's size on a Variable. * Text size can be absolute (in points) or relative (in quarter grid units). */ public static class Size { /** The minimu size of text (in points). */ public static final int TXTMINPOINTS = 1; /** The maximum size of text (in points). */ public static final int TXTMAXPOINTS = 63; /** The minimu size of text (in grid units). */ public static final double TXTMINQGRID = 0.25; /** The maximum size of text (in grid units). */ public static final double TXTMAXQGRID = 127.75; /** Default font size. */ private static final int DEFAULT_FONT_SIZE = 14; /*private*/ static final int TXTQGRIDSH = 6; private final boolean absolute; private final double size; private final int bits; private Size(double size, boolean absolute) { this.size = size; this.absolute = absolute; if (absolute) { this.bits = (int)size; } else { this.bits = ((int)(size*4.0)) << TXTQGRIDSH; } } /** * Method to return bits associated with this text Size. * @return bits associated with this text Size.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -