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

📄 jthreedtab.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: JThreeDTab.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.plugins.j3d.ui;import com.sun.electric.database.geometry.GenMath;import com.sun.electric.database.text.TextUtils;import com.sun.electric.plugins.j3d.View3DWindow;import com.sun.electric.plugins.j3d.utils.J3DAppearance;import com.sun.electric.plugins.j3d.utils.J3DUtils;import com.sun.electric.technology.Layer;import com.sun.electric.tool.user.dialogs.options.ThreeDTab;import java.awt.GridBagConstraints;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.media.j3d.TransparencyAttributes;import javax.swing.DefaultListModel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.ListSelectionModel;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import javax.vecmath.Vector3f;/** * Class to handle the "3D" tab of the Preferences dialog. * @author  Gilda Garreton * @version 0.1 */public class JThreeDTab extends ThreeDTab{	/** Creates new form ThreeDTab */	public JThreeDTab(java.awt.Frame parent, Boolean modal)	{		super(parent, modal.booleanValue());		initComponents();	}	public JPanel getPanel() { return threeD; }	private boolean initial3DTextChanging = false;	protected JList threeDLayerList;	private DefaultListModel threeDLayerModel;	public Map<Layer,GenMath.MutableDouble> threeDThicknessMap, threeDDistanceMap;    public Map<Layer,J3DAppearance> transparencyMap;	private JThreeDSideView threeDSideView;    /**	 * Method called at the start of the dialog.	 * Caches current values and displays them in the 3D tab.	 */	public void init()	{		threeDTechnology.setText("Layer cross section for technology '" + curTech.getTechName() + "'");		threeDLayerModel = new DefaultListModel();		threeDLayerList = new JList(threeDLayerModel);		threeDLayerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);		threeDLayerPane.setViewportView(threeDLayerList);		threeDLayerList.clearSelection();		threeDLayerList.addMouseListener(new MouseAdapter()		{			public void mouseClicked(MouseEvent evt) { threeDValuesChanged(false); }		});		threeDThicknessMap = new HashMap<Layer,GenMath.MutableDouble>();		threeDDistanceMap = new HashMap<Layer,GenMath.MutableDouble>();        transparencyMap = new HashMap<Layer,J3DAppearance>();        // Sorted by Height to be consistent with LayersTab		for(Layer layer : curTech.getLayersSortedByName())		{			if (layer.isPseudoLayer()) continue;			threeDLayerModel.addElement(layer.getName());            Layer.Function fun = layer.getFunction();            threeDThicknessMap.put(layer, new GenMath.MutableDouble(layer.getThickness()));			threeDDistanceMap.put(layer, new GenMath.MutableDouble(layer.getDistance()));            // Get a copy of JAppearance to set values temporarily            // this function will generate JAppearance if doesn't exist yet            J3DAppearance app = J3DAppearance.getAppearance(layer.getGraphics());            // forcing visibility            J3DAppearance newApp = new J3DAppearance(app);            newApp.getRenderingAttributes().setVisible(true);            transparencyMap.put(layer, newApp);		}                threeDLayerList.setSelectedIndex(0);		threeDHeight.getDocument().addDocumentListener(new ThreeDInfoDocumentListener(this));		threeDThickness.getDocument().addDocumentListener(new ThreeDInfoDocumentListener(this));        // Transparency data        transparancyField.getDocument().addDocumentListener(new ThreeDInfoDocumentListener(this));		threeDSideView = new JThreeDSideView(this);		threeDSideView.setMinimumSize(new java.awt.Dimension(200, 450));		threeDSideView.setPreferredSize(new java.awt.Dimension(200, 450));		GridBagConstraints gbc = new GridBagConstraints();		gbc.gridx = 2;       gbc.gridy = 1;		gbc.gridwidth = 2;   gbc.gridheight = 1;		//gbc.weightx = 0.5;   gbc.weighty = 1.0;		gbc.fill = GridBagConstraints.BOTH;		gbc.insets = new java.awt.Insets(4, 4, 4, 4);		threeD.add(threeDSideView, gbc);        scaleField.setText(TextUtils.formatDouble(J3DUtils.get3DFactor()));        double[] rot = GenMath.transformStringIntoArray(J3DUtils.get3DRotation());        xRotField.setText(TextUtils.formatDouble(rot[0]));        yRotField.setText(TextUtils.formatDouble(rot[1]));        zRotField.setText(TextUtils.formatDouble(rot[2]));		threeDPerspective.setSelected(J3DUtils.is3DPerspective());        // to turn on antialising if available. No by default because of performance.        threeDAntialiasing.setSelected(J3DUtils.is3DAntialiasing());        threeDZoom.setText(TextUtils.formatDouble(J3DUtils.get3DOrigZoom()));        threeDCellBnd.setSelected(J3DUtils.is3DCellBndOn());        threeDAxes.setSelected(J3DUtils.is3DAxesOn());        maxNodeField.setText(String.valueOf(J3DUtils.get3DMaxNumNodes()));        alphaField.setText(String.valueOf(J3DUtils.get3DAlpha()));        for (J3DAppearance.J3DTransparencyOption op : J3DAppearance.J3DTransparencyOption.values())        {            transparencyMode.addItem(op);        }        // Add listener after creating the list        transparencyMode.addActionListener(new ActionListener()        {            public void actionPerformed(ActionEvent evt) { threeDValuesChanged(true); }        });        // Light boxes        String lights = J3DUtils.get3DLightDirs();        Vector3f[] dirs = J3DUtils.transformIntoVectors(lights);        dirOneBox.setSelected(dirs[0] != null);        if (dirOneBox.isSelected())        {            xDirOneField.setText(String.valueOf(dirs[0].x));            yDirOneField.setText(String.valueOf(dirs[0].y));            zDirOneField.setText(String.valueOf(dirs[0].z));        }        dirTwoBox.setSelected(dirs[1] != null);        if (dirTwoBox.isSelected())        {            xDirTwoField.setText(String.valueOf(dirs[1].x));            yDirTwoField.setText(String.valueOf(dirs[1].y));            zDirTwoField.setText(String.valueOf(dirs[1].z));        }        // Setting the initial values		threeDValuesChanged(false);        dirOneBoxStateChanged(null);        dirTwoBoxStateChanged(null);	}    /**	 * Class to handle changes to the thickness or height.	 */	private static class ThreeDInfoDocumentListener implements DocumentListener	{		JThreeDTab dialog;		ThreeDInfoDocumentListener(JThreeDTab dialog) { this.dialog = dialog; }		public void changedUpdate(DocumentEvent e) { dialog.threeDValuesChanged(true); }		public void insertUpdate(DocumentEvent e) { dialog.threeDValuesChanged(true); }		public void removeUpdate(DocumentEvent e) { dialog.threeDValuesChanged(true); }	}	private void threeDValuesChanged(boolean set)	{		String layerName = (String)threeDLayerList.getSelectedValue();		Layer layer = curTech.findLayer(layerName);		if (layer == null) return;        processDataInFields(layer, set);	}    /**     * To process data in fields either from layer list or from     * object picked.     */    void processDataInFields(Layer layer, boolean set)    {        if (!set) initial3DTextChanging = true;        else if (initial3DTextChanging) return;		GenMath.MutableDouble thickness = threeDThicknessMap.get(layer);		GenMath.MutableDouble height = threeDDistanceMap.get(layer);        J3DAppearance app = transparencyMap.get(layer);        TransparencyAttributes ta = app.getTransparencyAttributes();        if (set)        {            thickness.setValue(TextUtils.atof(threeDThickness.getText()));            height.setValue(TextUtils.atof(threeDHeight.getText()));            ta.setTransparency((float)TextUtils.atof(transparancyField.getText()));            J3DAppearance.J3DTransparencyOption op = (J3DAppearance.J3DTransparencyOption)transparencyMode.getSelectedItem();            ta.setTransparencyMode(op.mode);            app.getRenderingAttributes().setDepthBufferEnable(op.mode != TransparencyAttributes.NONE);            threeDSideView.updateZValues(layer, thickness.doubleValue(), height.doubleValue());        }        else        {            threeDHeight.setText(TextUtils.formatDouble(height.doubleValue()));            threeDThickness.setText(TextUtils.formatDouble(thickness.doubleValue()));            transparancyField.setText(TextUtils.formatDouble(ta.getTransparency()));            for (J3DAppearance.J3DTransparencyOption op : J3DAppearance.J3DTransparencyOption.values())            {                if (op.mode == ta.getTransparencyMode())                {                    transparencyMode.setSelectedItem(op);                    break;  // found                }            }        threeDSideView.showLayer(layer);        }        if (!set) initial3DTextChanging = false;    }	/**	 * Method called when the "OK" panel is hit.	 * Updates any changed fields in the 3D tab.	 */	public void term()	{		for(Iterator<Layer> it = curTech.getLayers(); it.hasNext(); )		{			Layer layer = it.next();			if (layer.isPseudoLayer()) continue;			GenMath.MutableDouble thickness = threeDThicknessMap.get(layer);			GenMath.MutableDouble height = threeDDistanceMap.get(layer);            J3DAppearance newApp = transparencyMap.get(layer);            J3DAppearance oldApp = (J3DAppearance)layer.getGraphics().get3DAppearance();            oldApp.setTransparencyAndRenderingAttributes(newApp.getTransparencyAttributes(), newApp.getRenderingAttributes().getDepthBufferEnable());			if (thickness.doubleValue() != layer.getThickness())				layer.setThickness(thickness.doubleValue());			if (height.doubleValue() != layer.getDistance())				layer.setDistance(height.doubleValue());		}		boolean currentBoolean = threeDPerspective.isSelected();		if (currentBoolean != J3DUtils.is3DPerspective())			J3DUtils.set3DPerspective(currentBoolean);        currentBoolean = threeDAntialiasing.isSelected();		if (currentBoolean != J3DUtils.is3DAntialiasing())		{            View3DWindow.setAntialiasing(currentBoolean);			J3DUtils.set3DAntialiasing(currentBoolean);		}        currentBoolean = threeDCellBnd.isSelected();		if (currentBoolean != J3DUtils.is3DCellBndOn())		{            J3DAppearance.setCellVisibility(currentBoolean);			J3DUtils.set3DCellBndOn(currentBoolean);		}        currentBoolean = threeDAxes.isSelected();		if (currentBoolean != J3DUtils.is3DAxesOn())		{            J3DAppearance.setAxesVisibility(currentBoolean);			J3DUtils.set3DAxesOn(currentBoolean);		}        double currentValue = TextUtils.atof(scaleField.getText());        if (currentValue != J3DUtils.get3DFactor())        {            View3DWindow.setScaleFactor(currentValue);            J3DUtils.set3DFactor(currentValue);        }        String rotationValue = "(" +                xRotField.getText() + " " +                yRotField.getText() + " " +                zRotField.getText() + ")";        if (!rotationValue.equals(J3DUtils.get3DRotation()))            J3DUtils.set3DRotation(rotationValue);        currentValue = TextUtils.atof(threeDZoom.getText());        if (GenMath.doublesEqual(currentValue, 0))            System.out.println(currentValue + " is an invalid zoom factor.");        else if (currentValue != J3DUtils.get3DOrigZoom())            J3DUtils.set3DOrigZoom(currentValue);        StringBuffer dir = new StringBuffer();        if (dirOneBox.isSelected())        {            double[] values = new double[] {TextUtils.atof(xDirOneField.getText()),                TextUtils.atof(yDirOneField.getText()),                TextUtils.atof(zDirOneField.getText())};            dir.append(GenMath.transformArrayIntoString(values));        } else            dir.append(GenMath.transformArrayIntoString(new double[] {0,0,0}));

⌨️ 快捷键说明

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