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

📄 egraphics.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: EGraphics.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.geometry;import com.sun.electric.database.text.Pref;import com.sun.electric.database.text.TextUtils;import com.sun.electric.technology.Layer;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.user.Resources;import java.awt.Color;import java.io.Serializable;import java.lang.reflect.Method;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Observable;/** * Class to define the appearance of a piece of geometry. */public class EGraphics extends Observable implements Cloneable, Serializable{	private static Map<String,Outline> outlineNames = new HashMap<String,Outline>();	/**	 * Class to define the type of outline around a stipple pattern.	 */	public static enum Outline	{		/** Draw stipple pattern with no outline. */		NOPAT("None", 0, 32, 1),		/** Draw stipple pattern with solid outline. */		PAT_S("Solid", -1, 32, 1),		/** Draw stipple pattern with solid thick outline. */		PAT_T1("Solid-Thick", -1, 32, 3),		/** Draw stipple pattern with solid thicker outline. */		PAT_T2("Solid-Thicker", -1, 32, 5),		/** Draw stipple pattern with close dotted outline. */		PAT_DO1("Dotted-Close", 0x55, 8, 1),		/** Draw stipple pattern with far dotted outline. */		PAT_DO2("Dotted-Far", 0x11, 8, 1),		/** Draw stipple pattern with short dashed outline. */		PAT_DA1("Dashed-Short", 0x33, 8, 1),		/** Draw stipple pattern with long dashed outline. */		PAT_DA2("Dashed-Long", 0xF, 6, 1),		/** Draw stipple pattern with short dotted-dashed outline. */		PAT_DD1("Dotted-Dashed-Short", 0x39, 8, 1),		/** Draw stipple pattern with long dotted-dashed outline. */		PAT_DD2("Dotted-Dashed-Long", 0xF3, 10, 1),		/** Draw stipple pattern with close dotted thick outline. */		PAT_DO1_T1("Dotted-Close-Thick", 0xF, 6, 3),		/** Draw stipple pattern with far dotted thick outline. */		PAT_DO2_T1("Dotted-Far-Thick", 0xF, 8, 3),		/** Draw stipple pattern with dashed thick outline. */		PAT_DA1_T1("Dashed-Thick", 0x1FFFF, 19, 3),		/** Draw stipple pattern with close dotted thicker outline. */		PAT_DO1_T2("Dotted-Close-Thicker", 0x1F, 8, 5),		/** Draw stipple pattern with far dotted thicker outline. */		PAT_DO2_T2("Dotted-Far-Thicker", 0x7F, 9, 5);		private String name;		private int pattern, len;		private int thickness;		private boolean solid;		private Outline(String name, int pattern, int len, int thickness)		{			this.name = name;			outlineNames.put(name, this);			this.pattern = pattern;			this.len = len;			this.thickness = thickness;			this.solid = (pattern == -1);		}		public String getName() { return name; }		public String getConstName() { return name(); }		public int getIndex() { return ordinal(); }		public boolean isSolidPattern() { return solid; }		public int getPattern() { return pattern; }		public int getLen() { return len; }		public int getThickness() { return thickness; }		public static Outline findOutline(int index)		{			return Outline.class.getEnumConstants()[index];		}		public static Outline findOutline(String name)		{			// return valueOf(name);			return outlineNames.get(name);		}		public static List<Outline> getOutlines() { return Arrays.asList(Outline.class.getEnumConstants()); }		public String toString() { return name; }	}	/** the Layer associated with this graphics. */			private Layer layer;	/** display: true to use patterns; false for solid */	private boolean displayPatterned;	/** printer: true to use patterns; false for solid */	private boolean printPatterned;	/** the outline pattern */								private Outline patternOutline;	/** transparent layer to use (0 for none) */			private int transparentLayer;	/** color to use */										private int red, green, blue;	/** opacity (0 to 1) of color */						private double opacity;	/** whether to draw color in foregound */				private boolean foreground;	/** stipple pattern to draw */							private int [] pattern;	/** stipple pattern to draw with proper bit order */	private int [] reversedPattern;	/** 3D appearance */									private Object appearance3D;	private static Map<Layer,Pref> usePatternDisplayMap = new HashMap<Layer,Pref>();	private static Map<Layer,Pref> usePatternPrinterMap = new HashMap<Layer,Pref>();	private static Map<Layer,Pref> outlinePatternMap = new HashMap<Layer,Pref>();	private static Map<Layer,Pref> transparentLayerMap = new HashMap<Layer,Pref>();	private static Map<Layer,Pref> opacityMap = new HashMap<Layer,Pref>();	private static Map<Layer,Pref> colorMap = new HashMap<Layer,Pref>();	private static Map<Layer,Pref> patternMap = new HashMap<Layer,Pref>();	/**	 * There are 3 ways to encode color in an integer.	 * If the lowest bit (FULLRGBBIT) is set, this is a full RGB color in the high 3 bytes.	 * If the next lowest bit (OPAQUEBIT) is set, this is an "old C Electric" opaque color	 * (such as WHITE, BLACK, etc., listed below).	 * If neither of these bits is set, this is a transparent layer	 * (LAYERT1, LAYERT2, etc., listed below).	 */	/** Describes the full RGB escape bit. */				public final static int FULLRGBBIT = 01;	/** Describes opaque color escape bit. */				public final static int OPAQUEBIT =  02;	// the opaque colors (all have the OPAQUEBIT set in them)	/** Describes the color white. */						public final static int WHITE =    0002;	/** Describes the color black. */						public final static int BLACK =    0006;	/** Describes the color red. */							public final static int RED =      0012;	/** Describes the color blue. */						public final static int BLUE =     0016;	/** Describes the color green. */						public final static int GREEN =    0022;	/** Describes the color cyan. */						public final static int CYAN =     0026;	/** Describes the color magenta. */						public final static int MAGENTA =  0032;	/** Describes the color yellow. */						public final static int YELLOW =   0036;	/** Describes the cell and port names. */				public final static int CELLTXT =  0042;	/** Describes the cell outline. */						public final static int CELLOUT =  0046;	/** Describes the window border color. */				public final static int WINBOR =   0052;	/** Describes the highlighted window border color. */	public final static int HWINBOR =  0056;	/** Describes the menu border color. */					public final static int MENBOR =   0062;	/** Describes the highlighted menu border color. */		public final static int HMENBOR =  0066;	/** Describes the menu text color. */					public final static int MENTXT =   0072;	/** Describes the menu glyph color. */					public final static int MENGLY =   0076;	/** Describes the cursor color. */						public final static int CURSOR =   0102;	/** Describes the color gray. */						public final static int GRAY =     0106;	/** Describes the color orange. */						public final static int ORANGE =   0112;	/** Describes the color purple. */						public final static int PURPLE =   0116;	/** Describes the color brown. */						public final static int BROWN =    0122;	/** Describes the color light gray. */					public final static int LGRAY =    0126;	/** Describes the color dark gray. */					public final static int DGRAY =    0132;	/** Describes the color light red. */					public final static int LRED =     0136;	/** Describes the color dark red. */					public final static int DRED =     0142;	/** Describes the color light green. */					public final static int LGREEN =   0146;	/** Describes the color dark green. */					public final static int DGREEN =   0152;	/** Describes the color light blue. */					public final static int LBLUE =    0156;	/** Describes the color dark blue. */					public final static int DBLUE =    0162;	// the transparent layers	/** Describes transparent layer 1. */					public final static int LAYERT1 =      04;	/** Describes transparent layer 2. */					public final static int LAYERT2 =     010;	/** Describes transparent layer 3. */					public final static int LAYERT3 =     020;	/** Describes transparent layer 4. */					public final static int LAYERT4 =     040;	/** Describes transparent layer 5. */					public final static int LAYERT5 =    0100;	/** Describes transparent layer 6. */					public final static int LAYERT6 =    0200;	/** Describes transparent layer 7. */					public final static int LAYERT7 =    0400;	/** Describes transparent layer 8. */					public final static int LAYERT8 =   01000;	/** Describes transparent layer 9. */					public final static int LAYERT9 =   02000;	/** Describes transparent layer 10. */					public final static int LAYERT10 =  04000;	/** Describes transparent layer 11. */					public final static int LAYERT11 = 010000;	/** Describes transparent layer 12. */					public final static int LAYERT12 = 020000;	// Constants used in technologies and in creating an EGraphics	/** defines the 1st transparent layer. */				public static final int TRANSPARENT_1  =  1;	/** defines the 2nd transparent layer. */				public static final int TRANSPARENT_2  =  2;	/** defines the 3rd transparent layer. */				public static final int TRANSPARENT_3  =  3;	/** defines the 4th transparent layer. */				public static final int TRANSPARENT_4  =  4;	/** defines the 5th transparent layer. */				public static final int TRANSPARENT_5  =  5;	/** defines the 6th transparent layer. */				public static final int TRANSPARENT_6  =  6;	/** defines the 7th transparent layer. */				public static final int TRANSPARENT_7  =  7;	/** defines the 8th transparent layer. */				public static final int TRANSPARENT_8  =  8;	/** defines the 9th transparent layer. */				public static final int TRANSPARENT_9  =  9;	/** defines the 10th transparent layer. */				public static final int TRANSPARENT_10 = 10;	/** defines the 11th transparent layer. */				public static final int TRANSPARENT_11 = 11;	/** defines the 12th transparent layer. */				public static final int TRANSPARENT_12 = 12;	/**	 * Method to create a graphics object.	 * @param displayPatterned true if drawn with a pattern on the display.	 * @param printPatterned true if drawn with a pattern on a printer.	 * @param outlineWhenPatterned the outline texture to use when patterned.	 * @param transparentLayer the transparent layer number (0 for none).	 * @param red the red component of this EGraphics.	 * @param green the green component of this EGraphics.	 * @param blue the blue component of this EGraphics.	 * @param opacity the opacity of this EGraphics (1 for opaque, 0 for transparent).	 * @param foreground the foreground factor of this EGraphics (1 for to be in foreground).	 * @param pattern the 16x16 stipple pattern of this EGraphics (16 integers).	 */	public EGraphics(boolean displayPatterned, boolean printPatterned, Outline outlineWhenPatterned,		int transparentLayer, int red, int green, int blue, double opacity, boolean foreground, int[] pattern)	{		this.layer = null;		this.displayPatterned = displayPatterned;		this.printPatterned = printPatterned;		this.patternOutline = (outlineWhenPatterned != null) ? outlineWhenPatterned : Outline.NOPAT;		this.transparentLayer = transparentLayer;		this.red = red;		this.green = green;		this.blue = blue;		this.opacity = validateOpacity(opacity);		this.foreground = foreground;		setPatternLow(pattern);		if (transparentLayer < 0 || transparentLayer > TRANSPARENT_12)		{			System.out.println("Graphics transparent color bad: " + transparentLayer);		}		if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)		{			System.out.println("Graphics color bad: (" + red + "," + green + "," + blue + ")");		}	}	/**	 * Method to easily copy graphics between similar layers	 * @param g graphics to copy data from	 */	public EGraphics(EGraphics g)	{		this.layer = null;		this.displayPatterned = g.isPatternedOnDisplay();		this.printPatterned = g.isPatternedOnPrinter();		this.patternOutline = g.getOutlined();		this.transparentLayer = g.getTransparentLayer();		Color gColor = g.getColor();		this.red = gColor.getRed();		this.green = gColor.getGreen();		this.blue = gColor.getBlue();		this.opacity = g.getOpacity();		this.foreground = g.getForeground();		setPatternLow(g.getPattern().clone());		if (transparentLayer < 0 || transparentLayer > TRANSPARENT_12)		{			System.out.println("Graphics transparent color bad: " + transparentLayer);		}		if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)		{			System.out.println("Graphics color bad: (" + red + "," + green + "," + blue + ")");		}	}//	private static void setPattern() {}	/**	 * Method to return the Layer associated with this EGraphics.	 * @return the Layer associated with this EGraphics.	 */	public Layer getLayer() { return layer; }	/**	 * Method to set which Layer is associated with this EGraphics.	 * Since this is called only during initialization, it also examines preferences	 * and uses them to override the graphics information.	 * @param layer the Layer to associate with this EGraphics.	 */	public void setLayer(Layer layer)	{		this.layer = layer;		Technology tech = layer.getTechnology();		if (tech == null || layer.getIndex() < 0) return;		String layerTechMsg = layer.getName() + "In" + tech.getTechName();		Pref usePatternDisplayPref = Pref.makeBooleanPref("UsePatternDisplayFor" + layerTechMsg,			tech.getTechnologyPreferences(), displayPatterned);		displayPatterned = usePatternDisplayPref.getBoolean();		usePatternDisplayMap.put(layer, usePatternDisplayPref);		Pref usePatternPrinterPref = Pref.makeBooleanPref("UsePatternPrinterFor" + layerTechMsg,			tech.getTechnologyPreferences(), printPatterned);		printPatterned = usePatternPrinterPref.getBoolean();		usePatternPrinterMap.put(layer, usePatternPrinterPref);		// read any previous outline information and apply it		Pref oldOutlinePatternDisplayPref = Pref.makeBooleanPref("OutlinePatternDisplayFor" + layerTechMsg,			tech.getTechnologyPreferences(), false);		if (oldOutlinePatternDisplayPref.getBoolean()) patternOutline = Outline.PAT_S;		Pref outlinePatternPref = Pref.makeIntPref("OutlinePatternFor" + layerTechMsg,				tech.getTechnologyPreferences(), patternOutline.getIndex());		patternOutline = Outline.findOutline(outlinePatternPref.getInt());		outlinePatternMap.put(layer, outlinePatternPref);		Pref transparentLayerPref = Pref.makeIntPref("TransparentLayerFor" + layerTechMsg,			tech.getTechnologyPreferences(), transparentLayer);		transparentLayer = transparentLayerPref.getInt();		transparentLayerMap.put(layer, transparentLayerPref);		Pref opacityPref = Pref.makeDoublePref("OpacityFor" + layerTechMsg,			tech.getTechnologyPreferences(), opacity);		opacity = validateOpacity(opacityPref.getDouble());		opacityMap.put(layer, opacityPref);		Pref colorPref = Pref.makeIntPref("ColorFor" + layerTechMsg,			tech.getTechnologyPreferences(), (red<<16) | (green << 8) | blue);		int color = colorPref.getInt();		red = (color >> 16) & 0xFF;		green = (color >> 8) & 0xFF;		blue = color & 0xFF;		colorMap.put(layer, colorPref);		String pat = makePatString(pattern);		Pref patternPref = Pref.makeStringPref("PatternFor" + layerTechMsg,			tech.getTechnologyPreferences(), pat);		pat = patternPref.getString();		parsePatString(pat, pattern);		setPatternLow(pattern);		patternMap.put(layer, patternPref);	}	/**	 * Method to recache the graphics information from the preferences.	 * Called after new preferences have been imported.	 */	public void recachePrefs()	{		Technology tech = layer.getTechnology();		if (tech == null) return;		Pref usePatternDisplayPref = usePatternDisplayMap.get(layer);		displayPatterned = usePatternDisplayPref.getBoolean();		Pref usePatternPrinterPref = usePatternPrinterMap.get(layer);		printPatterned = usePatternPrinterPref.getBoolean();		Pref outlinePatternPref = outlinePatternMap.get(layer);		patternOutline = Outline.findOutline(outlinePatternPref.getInt());

⌨️ 快捷键说明

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