1
/* -*- tab-width: 4 -*-
3
* Electric(tm) VLSI Design System
7
* Copyright (c) 2004 Sun Microsystems and Static Free Software
9
* Electric(tm) is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* Electric(tm) is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with Electric(tm); see the file COPYING. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
* Boston, Mass 02111-1307, USA.
24
package com.sun.electric.tool.user.dialogs.options;
26
import com.sun.electric.database.geometry.EGraphics;
27
import com.sun.electric.database.text.TextUtils;
28
import com.sun.electric.technology.Layer;
29
import com.sun.electric.technology.Technology;
30
import com.sun.electric.tool.user.Resources;
31
import com.sun.electric.tool.user.User;
32
import com.sun.electric.tool.user.dialogs.ColorPatternPanel;
33
import com.sun.electric.tool.user.ui.WindowFrame;
35
import java.awt.Color;
36
import java.awt.Frame;
37
import java.awt.GridBagConstraints;
38
import java.awt.event.ActionEvent;
39
import java.awt.event.ActionListener;
40
import java.lang.reflect.Method;
41
import java.util.ArrayList;
42
import java.util.Collections;
43
import java.util.HashMap;
44
import java.util.Iterator;
45
import java.util.List;
47
import javax.swing.JPanel;
50
* Class to handle the "Colors and Layers" tab of the Preferences dialog.
52
public class LayersTab extends PreferencePanel
54
private HashMap<Layer,ColorPatternPanel.Info> layerMap;
55
private HashMap<String,ColorPatternPanel.Info> transAndSpecialMap;
56
private HashMap<User.ColorPrefType, String> nameTypeSpecialMap;
57
private HashMap<Technology,Color []> colorMapMap;
58
private MyColorPatternPanel colorAndPatternPanel;
60
private static class MyColorPatternPanel extends ColorPatternPanel
64
public MyColorPatternPanel(LayersTab lt, boolean showPrinter, boolean showFactoryReset)
66
super(showPrinter, showFactoryReset);
70
public void factoryResetActionPerformed()
76
private void resetColorPanelInfo(ColorPatternPanel.Info cpi)
78
int factoryColor = -1;
79
if (cpi.graphics != null)
81
cpi.useStippleDisplay = cpi.graphics.isFactoryPatternedOnDisplay();
82
cpi.useStipplePrinter = cpi.graphics.isFactoryPatternedOnPrinter();
83
cpi.outlinePatternDisplay = cpi.graphics.getFactoryOutlined();
84
cpi.transparentLayer = cpi.graphics.getFactoryTransparentLayer();
85
cpi.pattern = cpi.graphics.getFactoryPattern();
86
cpi.opacity = cpi.graphics.getFactoryOpacity();
87
factoryColor = cpi.graphics.getFactoryColor(); // color given by graphics for the rest of layers
90
factoryColor = cpi.theColor.getIntFactoryValue(); // factory color for special layers
91
cpi.red = (factoryColor>>16) & 0xFF;
92
cpi.green = (factoryColor>>8) & 0xFF;
93
cpi.blue = factoryColor & 0xFF;
96
private void factoryResetAll()
98
for(Layer layer : layerMap.keySet())
100
ColorPatternPanel.Info cpi = layerMap.get(layer);
101
resetColorPanelInfo(cpi);
104
for(ColorPatternPanel.Info cpi: transAndSpecialMap.values())
106
resetColorPanelInfo(cpi);
109
for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); )
111
Technology tech = it.next();
112
Color [] map = new Color[tech.getNumTransparentLayers()];
113
Color [] fullMap = tech.getFactoryColorMap();
114
for(int i=0; i<map.length; i++)
115
map[i] = fullMap[1<<i];
116
colorMapMap.put(tech, map);
121
/** Creates new form LayerTab */
122
public LayersTab(Frame parent, boolean modal)
124
super(parent, modal);
127
// make the color/pattern panel
128
colorAndPatternPanel = new MyColorPatternPanel(this, true, true);
129
GridBagConstraints gbc = new GridBagConstraints();
130
gbc.gridx = 0; gbc.gridy = 1;
131
gbc.weightx = 1; gbc.weighty = 1;
132
gbc.gridwidth = 4; gbc.gridheight = 1;
133
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
134
layers.add(colorAndPatternPanel, gbc);
136
layerMap = new HashMap<Layer,ColorPatternPanel.Info>();
137
transAndSpecialMap = new HashMap<String,ColorPatternPanel.Info>();
138
nameTypeSpecialMap = new HashMap<User.ColorPrefType, String>();
139
colorMapMap = new HashMap<Technology,Color []>();
140
layerName.addActionListener(new ActionListener()
142
public void actionPerformed(ActionEvent evt) { layerSelected(); }
144
for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); )
146
Technology tech = it.next();
147
technology.addItem(tech.getTechName());
149
technology.addActionListener(new ActionListener()
151
public void actionPerformed(ActionEvent evt) { setTechnology(); }
155
/** return the panel to use for this preferences tab. */
156
public JPanel getPanel() { return layers; }
158
/** return the name of this preferences tab. */
159
public String getName() { return "Layers"; }
162
* Method called at the start of the dialog.
163
* Caches current values and displays them in the tab.
167
// make a map of all layers
168
for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); )
170
Technology tech = it.next();
171
for(Iterator<Layer> lIt = tech.getLayers(); lIt.hasNext(); )
173
Layer layer = lIt.next();
174
if (layer.isPseudoLayer() && layer.getNonPseudoLayer() != layer) continue;
175
layerName.addItem(layer.getName());
176
ColorPatternPanel.Info li = new ColorPatternPanel.Info(layer.getGraphics());
177
layerMap.put(layer, li);
180
// make an entry for the technology's color map
181
Color [] map = new Color[tech.getNumTransparentLayers()];
182
Color [] fullMap = tech.getColorMap();
183
for(int i=0; i<map.length; i++)
184
map[i] = fullMap[1<<i];
185
colorMapMap.put(tech, map);
188
// add the special layers
189
nameTypeSpecialMap.put(User.ColorPrefType.BACKGROUND, "Special: BACKGROUND");
190
nameTypeSpecialMap.put(User.ColorPrefType.GRID, "Special: GRID");
191
nameTypeSpecialMap.put(User.ColorPrefType.HIGHLIGHT, "Special: HIGHLIGHT");
192
nameTypeSpecialMap.put(User.ColorPrefType.MOUSEOVER_HIGHLIGHT, "Special: MOUSE-OVER HIGHLIGHT");
193
nameTypeSpecialMap.put(User.ColorPrefType.PORT_HIGHLIGHT, "Special: PORT HIGHLIGHT");
194
nameTypeSpecialMap.put(User.ColorPrefType.TEXT, "Special: TEXT");
195
nameTypeSpecialMap.put(User.ColorPrefType.INSTANCE, "Special: INSTANCE OUTLINES");
196
nameTypeSpecialMap.put(User.ColorPrefType.DOWNINPLACEBORDER, "Special: DOWN-IN-PLACE BORDER");
197
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_BACKGROUND, "Special: WAVEFORM BACKGROUND");
198
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_FOREGROUND, "Special: WAVEFORM FOREGROUND");
199
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_STIMULI, "Special: WAVEFORM STIMULI");
200
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_OFF_STRENGTH, "Special: WAVEFORM OFF STRENGTH");
201
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_NODE_STRENGTH, "Special: WAVEFORM NODE (WEAK) STRENGTH");
202
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_GATE_STRENGTH, "Special: WAVEFORM GATE STRENGTH");
203
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_POWER_STRENGTH, "Special: WAVEFORM POWER STRENGTH");
204
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_CROSS_LOW, "Special: WAVEFORM CROSSPROBE LOW");
205
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_CROSS_HIGH, "Special: WAVEFORM CROSSPROBE HIGH");
206
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_CROSS_UNDEF, "Special: WAVEFORM CROSSPROBE UNDEFINED");
207
nameTypeSpecialMap.put(User.ColorPrefType.WAVE_CROSS_FLOAT, "Special: WAVEFORM CROSSPROBE FLOATING");
209
for (User.ColorPrefType type : User.ColorPrefType.values())
211
transAndSpecialMap.put(nameTypeSpecialMap.get(type), new ColorPatternPanel.Info(User.getColorPref(type)));
217
Class<?> j3DUtilsClass = Resources.get3DClass("utils.J3DUtils");
218
if (j3DUtilsClass != null)
220
Method setMethod = j3DUtilsClass.getDeclaredMethod("get3DColorsInTab", new Class[] {HashMap.class});
221
setMethod.invoke(j3DUtilsClass, new Object[]{transAndSpecialMap});
224
System.out.println("Cannot call 3D plugin method get3DColorsInTab");
225
} catch (Exception e) {
226
System.out.println("Cannot call 3D plugin method get3DColorsInTab");
230
technology.setSelectedItem(Technology.getCurrent().getTechName());
234
* Method called when the Technology popup changes.
236
private void setTechnology()
238
String techName = (String)technology.getSelectedItem();
239
Technology tech = Technology.findTechnology(techName);
240
if (tech == null) return;
242
// report the map for the technology
243
Color [] map = colorMapMap.get(tech);
244
colorAndPatternPanel.setColorMap(map);
246
layerName.removeAllItems();
248
// add all layers in the technology
249
for(Iterator<Layer> lIt = tech.getLayers(); lIt.hasNext(); )
251
Layer layer = lIt.next();
252
if (layer.isPseudoLayer() && layer.getNonPseudoLayer() != layer) continue;
253
layerName.addItem(layer.getName());
256
// add special layer names
257
List<String> specialList = new ArrayList<String>();
258
for(String name : transAndSpecialMap.keySet())
259
specialList.add(name);
260
Collections.sort(specialList, TextUtils.STRING_NUMBER_ORDER);
261
for(String name : specialList)
263
layerName.addItem(name);
270
* Method called when the Layer popup changes.
272
private void layerSelected()
274
String techName = (String)technology.getSelectedItem();
275
Technology tech = Technology.findTechnology(techName);
276
if (tech == null) return;
278
String name = (String)layerName.getSelectedItem();
279
ColorPatternPanel.Info li = transAndSpecialMap.get(name);
283
layer = tech.findLayer(name);
284
li = layerMap.get(layer);
286
if (li == null) return;
287
colorAndPatternPanel.setColorPattern(li);
289
// see if this layer is transparent and shares with another layer
290
String otherLayers = null;
291
if (li.transparentLayer > 0 && layer != null)
293
for(Iterator<Layer> it = tech.getLayers(); it.hasNext(); )
295
Layer oLayer = it.next();
296
if (oLayer == layer) continue;
297
ColorPatternPanel.Info oLi = layerMap.get(oLayer);
298
if (oLi != null && oLi.transparentLayer == li.transparentLayer)
300
if (otherLayers == null) otherLayers = oLayer.getName(); else
301
otherLayers += ", " + oLayer.getName();
305
colorAndPatternPanel.setOtherTransparentLayerNames(otherLayers);
309
* Method called when the "OK" panel is hit.
310
* Updates any changed fields in the Layers tab.
314
boolean changed = false;
315
for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); )
317
Technology tech = it.next();
318
for(Iterator<Layer> lIt = tech.getLayers(); lIt.hasNext(); )
320
Layer layer = lIt.next();
321
ColorPatternPanel.Info li = layerMap.get(layer);
322
EGraphics graphics = layer.getGraphics();
323
if (layer.isPseudoLayer())
325
ColorPatternPanel.Info altLI = layerMap.get(layer.getNonPseudoLayer());
326
if (altLI != null) li = altLI;
328
if (li.updateGraphics(graphics))
332
// determine the original colors for this technology
333
Color [] fullOrigMap = tech.getColorMap();
334
Color [] origMap = new Color[tech.getNumTransparentLayers()];
335
for(int i=0; i<origMap.length; i++)
336
origMap[i] = fullOrigMap[1<<i];
338
// see if any colors changed
339
boolean mapChanged = false;
340
Color [] map = colorMapMap.get(tech);
341
for(int i=0; i<map.length; i++)
342
if (map[i].getRGB() != origMap[i].getRGB()) mapChanged = true;
344
tech.setColorMapFromLayers(map);
347
// also get any changes to special layers
348
for (User.ColorPrefType type : User.ColorPrefType.values())
350
int c = specialMapColor(nameTypeSpecialMap.get(type), User.getColor(type));
353
User.setColor(type, c);
361
Class<?> j3DUtilsClass = Resources.get3DClass("utils.J3DUtils");
362
Method setMethod = j3DUtilsClass.getDeclaredMethod("set3DColorsInTab", new Class[] {LayersTab.class});
363
Object color3DChanged = setMethod.invoke(j3DUtilsClass, new Object[]{this});
364
if (!changed && color3DChanged != null)
366
changed = ((Boolean)color3DChanged).booleanValue();
368
} catch (Exception e) {
369
System.out.println("Cannot call 3D plugin method set3DColorsInTab: " + e.getMessage());
373
// redisplay if changes were made
376
WindowFrame.redrawNewColors();
380
public int specialMapColor(String title, int curColor)
382
ColorPatternPanel.Info li = transAndSpecialMap.get(title);
383
if (li == null) return -1;
384
int newColor = (li.red << 16) | (li.green << 8) | li.blue;
385
if (newColor != curColor) return newColor;
389
/** This method is called from within the constructor to
390
* initialize the form.
391
* WARNING: Do NOT modify this code. The content of this method is
392
* always regenerated by the Form Editor.
394
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
395
private void initComponents()
397
java.awt.GridBagConstraints gridBagConstraints;
399
layers = new javax.swing.JPanel();
400
layerName = new javax.swing.JComboBox();
401
layerTechName = new javax.swing.JLabel();
402
technology = new javax.swing.JComboBox();
403
layerTechName1 = new javax.swing.JLabel();
405
getContentPane().setLayout(new java.awt.GridBagLayout());
407
setTitle("Edit Options");
409
addWindowListener(new java.awt.event.WindowAdapter()
411
public void windowClosing(java.awt.event.WindowEvent evt)
417
layers.setLayout(new java.awt.GridBagLayout());
419
gridBagConstraints = new java.awt.GridBagConstraints();
420
gridBagConstraints.gridx = 3;
421
gridBagConstraints.gridy = 0;
422
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
423
gridBagConstraints.weightx = 0.5;
424
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
425
layers.add(layerName, gridBagConstraints);
427
layerTechName.setText("Layer:");
428
gridBagConstraints = new java.awt.GridBagConstraints();
429
gridBagConstraints.gridx = 2;
430
gridBagConstraints.gridy = 0;
431
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
432
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
433
layers.add(layerTechName, gridBagConstraints);
435
gridBagConstraints = new java.awt.GridBagConstraints();
436
gridBagConstraints.gridx = 1;
437
gridBagConstraints.gridy = 0;
438
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
439
gridBagConstraints.weightx = 0.5;
440
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
441
layers.add(technology, gridBagConstraints);
443
layerTechName1.setText("Technology:");
444
gridBagConstraints = new java.awt.GridBagConstraints();
445
gridBagConstraints.gridx = 0;
446
gridBagConstraints.gridy = 0;
447
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
448
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
449
layers.add(layerTechName1, gridBagConstraints);
451
getContentPane().add(layers, new java.awt.GridBagConstraints());
454
}// </editor-fold>//GEN-END:initComponents
456
/** Closes the dialog */
457
private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
461
}//GEN-LAST:event_closeDialog
463
// Variables declaration - do not modify//GEN-BEGIN:variables
464
private javax.swing.JComboBox layerName;
465
private javax.swing.JLabel layerTechName;
466
private javax.swing.JLabel layerTechName1;
467
private javax.swing.JPanel layers;
468
private javax.swing.JComboBox technology;
469
// End of variables declaration//GEN-END:variables