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

📄 colorpatternpanel.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: ColorPatternPanel.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.dialogs;import com.sun.electric.database.geometry.EGraphics;import com.sun.electric.database.geometry.EGraphics.Outline;import com.sun.electric.database.text.Pref;import com.sun.electric.database.text.TextUtils;import com.sun.electric.tool.Job;import com.sun.electric.tool.user.Resources;import com.sun.electric.tool.user.User;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.image.BufferedImage;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JColorChooser;import javax.swing.JComboBox;import javax.swing.JPanel;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;/*** A Panel to display color and pattern information.* Used in the "Layers" tab of the "Edit Options" dialog.* Used in the "Artwork Look" dialog.*/public class ColorPatternPanel extends JPanel{	/**	 * Class to define the information on a color pattern panel.	 */	public static class Info	{		public EGraphics graphics;		public int [] pattern;		public boolean useStippleDisplay;		public Outline outlinePatternDisplay;		public boolean useStipplePrinter;		public int transparentLayer;		public int red, green, blue;        public Pref theColor;  // theColor to remember the factory color for special layers		public double opacity;		public boolean justColor;		/**		 * Constructor to load a color described by an EGraphics object.		 */		public Info(EGraphics graphics)		{			this.graphics = graphics;			this.pattern = new int[16];			int [] pattern = graphics.getPattern();			for(int i=0; i<16; i++) this.pattern[i] = pattern[i];			useStippleDisplay = graphics.isPatternedOnDisplay();			outlinePatternDisplay = graphics.getOutlined();			useStipplePrinter = graphics.isPatternedOnPrinter();			transparentLayer = graphics.getTransparentLayer();			int color = graphics.getColor().getRGB();			red = (color >> 16) & 0xFF;			green = (color >> 8) & 0xFF;			blue = color & 0xFF;			opacity = graphics.getOpacity();			justColor = false; theColor = null;		}		/**		 * Constructor for class to load a pure color.		 * Used for special colors (like background, etc.)		 */		public Info(Pref colorPref)		{            int color = colorPref.getInt();            red = (color >> 16) & 0xFF;			green = (color >> 8) & 0xFF;			blue = color & 0xFF;            theColor = colorPref;            justColor = true;		}		/**		 * Method to update the EGraphics object that is being displayed in this dialog panel.		 * @return true if the EGraphics object changed.		 */		public boolean updateGraphics(EGraphics setGraphics)		{			if (justColor) return false;			boolean changed = false;			int [] origPattern = setGraphics.getPattern();			for(int i=0; i<16; i++) if (pattern[i] != origPattern[i]) changed = true;			if (changed)				setGraphics.setPattern(pattern);			// check the pattern and outline factors			if (useStippleDisplay != setGraphics.isPatternedOnDisplay())			{				setGraphics.setPatternedOnDisplay(useStippleDisplay);				changed = true;			}			if (outlinePatternDisplay != setGraphics.getOutlined())			{				setGraphics.setOutlined(outlinePatternDisplay);				changed = true;			}			if (useStipplePrinter != setGraphics.isPatternedOnPrinter())			{				setGraphics.setPatternedOnPrinter(useStipplePrinter);				changed = true;			}			// check the color values			int color = (red << 16) | (green << 8) | blue;			Color colorObj = null;			if (color != (setGraphics.getColor().getRGB() & 0xFFFFFF))			{				colorObj = new Color(color);				setGraphics.setColor(colorObj);				changed = true;			}			if (opacity != setGraphics.getOpacity())			{				setGraphics.setOpacity(opacity);				changed = true;			}			if (transparentLayer != setGraphics.getTransparentLayer())			{				setGraphics.setTransparentLayer(transparentLayer);				changed = true;			}			return changed;		}	}	private PatternView patternView;	private PatternChoices patternIcon;	private Info currentLI;	private boolean dataChanging = false;	private boolean showPrinter;	private Color [] colorMap;	private JColorChooser colorChooser;	private MyPreviewPanel colorPreviewPanel;	private boolean warnedOfTransparentLayerSharing;	private String otherTransparentLayers;    private Map<Outline,ImageIcon> outlineImageIcons = new HashMap<Outline,ImageIcon>();	/**	 * Create a Panel for editing color and pattern information.	 */	public ColorPatternPanel(boolean showPrinter)	{		initComponents();		this.showPrinter = showPrinter;		warnedOfTransparentLayerSharing = false;		useStipplePatternDisplay.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { layerInfoChanged(); }		});		for(Outline o : Outline.getOutlines())		{            ImageIcon imageIcon = getSample(o);            outlineImageIcons.put(o, imageIcon);			outlinePattern.addItem(imageIcon);		}		outlinePattern.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { layerInfoChanged(); }		});		transparentLayer.addActionListener(new ActionListener()		{			public void actionPerformed(ActionEvent evt) { transparentLayerChanged(); }		});		transparentLayer.addItem("NOT TRANSPARENT");		int [] transLayers = EGraphics.getTransparentColorIndices();		for(int i=0; i<transLayers.length; i++)			transparentLayer.addItem(EGraphics.getColorIndexName(transLayers[i]));		patternView = new PatternView(currentLI, useStipplePatternDisplay, outlinePattern);		GridBagConstraints gbc = new GridBagConstraints();		gbc.gridx = 0;       gbc.gridy = 1;		gbc.gridwidth = 3;   gbc.gridheight = 1;		gbc.insets = new Insets(0, 4, 4, 4);		pattern.add(patternView, gbc);		patternIcon = new PatternChoices();		gbc = new GridBagConstraints();		gbc.gridx = 0;   gbc.gridy = 3;		gbc.gridwidth = 3;   gbc.gridheight = 1;		gbc.insets = new Insets(0, 4, 2, 4);		pattern.add(patternIcon, gbc);		colorChooser = new JColorChooser();		gbc = new GridBagConstraints();		gbc.gridx = 0;   gbc.gridy = 1;		gbc.gridwidth = 2;		color.add(colorChooser, gbc);		colorChooser.getSelectionModel().addChangeListener(new ChangeListener()		{			public void stateChanged(ChangeEvent e) { colorChanged(); }		});		colorChooser.setPreviewPanel(new JPanel());		colorPreviewPanel = new MyPreviewPanel(this);		gbc = new GridBagConstraints();		gbc.gridx = 0;   gbc.gridy = 2;		gbc.gridwidth = 2;		gbc.insets = new Insets(4, 4, 4, 4);		color.add(colorPreviewPanel, gbc);		if (showPrinter)		{			useStipplePatternPrinter.addActionListener(new ActionListener()			{				public void actionPerformed(ActionEvent evt) { layerInfoChanged(); }			});			opacity.getDocument().addDocumentListener(new LayerColorDocumentListener());		} else		{			pattern.remove(useStipplePatternPrinter);			pattern.remove(jLabel1);			pattern.remove(jLabel2);			pattern.remove(opacityLabel);			pattern.remove(opacity);		}	}	/**	 * Class to provide an alternative preview panel for JColorChooser.	 */	public class MyPreviewPanel extends JButton	{		private static final int XSIZE = 288;		private static final int YSIZE = 48;		private static final int BORDER = 10;		private ColorPatternPanel dia;		Color curColor = Color.BLACK;   		public MyPreviewPanel(ColorPatternPanel dia)		{			this.dia = dia;			setPreferredSize(new Dimension(XSIZE+BORDER*2, YSIZE+BORDER*2));		}		public void setPreviewColor(Color color)		{			curColor = color;		}		public void paint(Graphics g)		{			// clear background			g.setColor(new Color(User.getColor(User.ColorPrefType.BACKGROUND)));			g.fillRect(0, 0, getWidth(), getHeight());			if (currentLI == null) return;			if (dia.useStipplePatternDisplay.isSelected())			{				// stippled: construct an image				BufferedImage im = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);				for(int y=0; y<16; y++)				{					int line = currentLI.pattern[y];					for(int x=0; x<16; x++)					{						if ((line & (1<<(15-x))) != 0) im.setRGB(x, y, curColor.getRGB()); else							im.setRGB(x, y, User.getColor(User.ColorPrefType.BACKGROUND));					}				}				// draw the image to fill the preview				for(int y=0; y<YSIZE; y+=16)					for(int x=0; x<XSIZE; x+=16)						g.drawImage(im, x+BORDER, y+BORDER, null, null);				// draw an outline if requested				List<Outline> outlines = Outline.getOutlines();				Outline o = outlines.get(dia.outlinePattern.getSelectedIndex());				if (o != Outline.NOPAT)				{					g.setColor(curColor);					for(int t=0; t<o.getThickness(); t++)					{						if (o.isSolidPattern())						{							g.drawLine(BORDER+t, BORDER+t, XSIZE+BORDER-1-t, BORDER+t);							g.drawLine(XSIZE+BORDER-1-t, BORDER+t, XSIZE+BORDER-1-t, YSIZE+BORDER-1-t);							g.drawLine(XSIZE+BORDER-1-t, YSIZE+BORDER-1-t, BORDER+t, YSIZE+BORDER-1-t);							g.drawLine(BORDER+t, YSIZE+BORDER-1-t, BORDER+t, BORDER+t);						} else						{							int pattern = o.getPattern();							int len = o.getLen();							// draw the top and bottom lines							int patPos = 0;							for(int x=0; x<XSIZE; x++)							{								if ((pattern & (1<<patPos)) != 0)								{									g.fillRect(BORDER+x, BORDER+t, 1, 1);									g.fillRect(BORDER+x, YSIZE+BORDER-1-t, 1, 1);								}								patPos++;								if (patPos >= len) patPos = 0;							}							// draw the left and right lines							patPos = 0;							for(int y=0; y<YSIZE; y++)							{								if ((pattern & (1<<patPos)) != 0)								{									g.fillRect(BORDER+t, BORDER+y, 1, 1);									g.fillRect(XSIZE+BORDER-1-t, BORDER+y, 1, 1);								}								patPos++;								if (patPos >= len) patPos = 0;							}						}					}				}			} else			{				// not stippled, just fill it				g.setColor(curColor);				g.fillRect(BORDER, BORDER, XSIZE, YSIZE);			}	   }   }	/**	 * Method to update the panel to reflect the given color map.	 * @param map the color map to be used.	 */	public void setColorMap(Color [] map)	{		colorMap = map;		int curTrans = transparentLayer.getSelectedIndex();		int [] transLayers = EGraphics.getTransparentColorIndices();		transparentLayer.removeAllItems();		transparentLayer.addItem("NOT TRANSPARENT");		int maxTrans = Math.min(transLayers.length, map.length);        if (maxTrans > 0)  // zero for generic at least        {            for(int i=0; i<maxTrans; i++)                transparentLayer.addItem(EGraphics.getColorIndexName(transLayers[i]));            transparentLayer.setSelectedIndex(curTrans);        }	}	public void setOtherTransparentLayerNames(String names) { otherTransparentLayers = names; }	/**	 * Method to update the panel to reflect the given Info.	 * @param li the Info structure with data for this panel.	 * The Info structure contains color, texture, and other appearance-related factors for drawing.	 */	public void setColorPattern(Info li)	{		currentLI = li;		patternView.setLayerInfo(li);		if (li == null)		{			useStipplePatternDisplay.setEnabled(false);			outlinePattern.setEnabled(false);			useStipplePatternPrinter.setEnabled(false);			transparentLayer.setEnabled(false);			colorChooser.setEnabled(false);			return;		}		colorChooser.setEnabled(true);		if (li.justColor)		{			useStipplePatternDisplay.setEnabled(false);			outlinePattern.setEnabled(false);			useStipplePatternPrinter.setEnabled(false);

⌨️ 快捷键说明

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