~ubuntu-branches/ubuntu/intrepid/electric/intrepid

« back to all changes in this revision

Viewing changes to com/sun/electric/tool/user/dialogs/TextAttributesPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2008-07-23 02:09:53 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080723020953-1gmnv7q2wpsdbnop
Tags: 8.07-0ubuntu1
* New Upstream version. Please check changelog for details. (LP: #242720)
* debian/control
  - Add build dependencies *-jdk, cdbs and bsh.
  - Remove build dependency dpatch. We will be using CDBS simple patchsys.
  - Refreshed runtime dependencies to default-jre | java2-runtime and bsh.
  - Added home page field.
  - Standard version 3.8.0.
  - Modify Maintainer value to match the DebianMaintainerField
    specification.
  - Changed email address for original maintainer to indicate who has
    refreshed the packaging.
* debian/rules
  - Revamped to use cdbs.
  - Added get-orig-source target.
* debian/patches
  - 00list, 02_sensible-browser.dpatch, 01_errors-numbers.dpatch,
    03_manpage.dpatch - Deleted, not relevant anymore.
  - 01_fix_build_xml.patch - Patch to fix the build.xml.
* debian/ant.properties
  - File to set various compilation properties.
* debian/electric.1
  - Remove the entry that causes lintian warning.
* debian/electric.desktop
  - Change as suggested by desktop-file-validate.
* debian/electric.docs
  - Updated as per changes in file names.
* debian/electric.svg
  - Name changed from electric_icon.svg.
* debian/install
  - Added appropriate locations for jar file, desktop file and wrapper shell
    script.
* debian/README.source
  - Added to comply with standards version 3.8.0.
* debian/TODO.Debian
  - Name changed form TODO.
* debain/wrapper/electric
  - Wrapper shell script to launch the application.
* debian/manpages
  - Added for installation of manpage.
* debian/watch
  - Updated to match jar files instead of older tar.gz files.
* debian/dirs
  - Removed, not needed anymore.
* debian/{electric.doc-base, electric.examples, substvars}
  - Removed, not relevant anymore.
* debian/*.debhelper
  - Removed auto generated files. Not relevant anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- tab-width: 4 -*-
 
2
 *
 
3
 * Electric(tm) VLSI Design System
 
4
 *
 
5
 * File: TextAttributesPanel.java
 
6
 *
 
7
 * Copyright (c) 2003 Sun Microsystems and Static Free Software
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 */
 
24
 
 
25
package com.sun.electric.tool.user.dialogs;
 
26
 
 
27
import com.sun.electric.database.hierarchy.Cell;
 
28
import com.sun.electric.database.topology.NodeInst;
 
29
import com.sun.electric.database.variable.CodeExpression;
 
30
import com.sun.electric.database.variable.ElectricObject;
 
31
import com.sun.electric.database.variable.TextDescriptor;
 
32
import com.sun.electric.database.variable.Variable;
 
33
import com.sun.electric.tool.Job;
 
34
import com.sun.electric.tool.JobException;
 
35
import com.sun.electric.tool.user.User;
 
36
 
 
37
import java.util.Iterator;
 
38
 
 
39
import javax.swing.JPanel;
 
40
 
 
41
/**
 
42
 * A Panel to display Code, Units, ShowStyle, and isParameter/isInherits
 
43
 * information about a Variable (or TextDescriptor, if passed Variable is null).
 
44
 */
 
45
public class TextAttributesPanel extends JPanel
 
46
{
 
47
    private static final String displaynone = "None";
 
48
 
 
49
        private boolean updateChangesInstantly;
 
50
        private boolean loading = false;
 
51
    private Variable var;
 
52
    private TextDescriptor td;
 
53
    private Variable.Key varKey;
 
54
    private ElectricObject owner;
 
55
    private TextDescriptor.Unit initialUnit;
 
56
    private Object initialDispPos;      // this needs to be an object because one choice, "none" is a string
 
57
                                        // instead of a TextDescriptor.DispPos
 
58
    private CodeExpression.Code initialCode;
 
59
 
 
60
    /**
 
61
     * Create a Panel for editing attribute specific
 
62
     * text options of a Variable
 
63
     */
 
64
    public TextAttributesPanel(boolean updateChangesInstantly)
 
65
    {
 
66
        this.updateChangesInstantly = updateChangesInstantly;
 
67
        initComponents();
 
68
 
 
69
        // add variable code types
 
70
        for (Iterator<CodeExpression.Code> it = CodeExpression.Code.getCodes(); it.hasNext(); ) {
 
71
            code.addItem(it.next());
 
72
        }
 
73
 
 
74
        // populate units dialog box
 
75
        for (Iterator<TextDescriptor.Unit> it = TextDescriptor.Unit.getUnits(); it.hasNext(); ) {
 
76
            units.addItem(it.next());
 
77
        }
 
78
 
 
79
        // populate show style dialog box
 
80
        populateShowComboBox(true);
 
81
 
 
82
        // default settings
 
83
 
 
84
        // set code
 
85
        initialCode = CodeExpression.Code.NONE;
 
86
        code.setSelectedItem(CodeExpression.Code.NONE);
 
87
        // set units
 
88
        initialUnit = TextDescriptor.Unit.NONE;
 
89
        units.setSelectedItem(initialUnit);
 
90
        // set show style
 
91
        initialDispPos = TextDescriptor.DispPos.NAMEVALUE;
 
92
        show.setSelectedItem(initialDispPos);
 
93
 
 
94
        // dialog is disabled by default
 
95
        setVariable(null, null);
 
96
 
 
97
        // listeners
 
98
        code.addActionListener(new java.awt.event.ActionListener()
 
99
        {
 
100
            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }
 
101
        });
 
102
        units.addActionListener(new java.awt.event.ActionListener()
 
103
        {
 
104
            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }
 
105
        });
 
106
        show.addActionListener(new java.awt.event.ActionListener()
 
107
        {
 
108
            public void actionPerformed(java.awt.event.ActionEvent evt) { fieldChanged(); }
 
109
        });
 
110
    }
 
111
 
 
112
        private void fieldChanged()
 
113
        {
 
114
                if (!updateChangesInstantly) return;
 
115
                if (loading) return;
 
116
                applyChanges();
 
117
        }
 
118
 
 
119
    /**
 
120
     * Set the Variable that can be edited through this Panel.
 
121
     * <p>if owner.getTextDescriptor(varKey) returns non-null td, display and allow editing of the td text options
 
122
     * <p>else if varKey is non-null, display and allow editing of default values.
 
123
     * <p>if varKey is null, the entire Panel is disabled.
 
124
     * @param varKey the key of a variable to be changed
 
125
     * @param owner the owner of the variable
 
126
     */
 
127
    public synchronized void setVariable(Variable.Key varKey, ElectricObject owner) {
 
128
 
 
129
        loading = true;
 
130
 
 
131
                // default information
 
132
        if (Job.getDebug())
 
133
        {
 
134
                attrInfo1.setText("YOU ARE RUNNING IN DEBUG MODE, SO:");
 
135
                attrInfo2.setText("To create a parameter on a cell");
 
136
                attrInfo3.setText("its name must start with 'ATTR_'");
 
137
        } else
 
138
        {
 
139
                attrInfo1.setText("");
 
140
                attrInfo2.setText("");
 
141
                attrInfo3.setText("");
 
142
        }
 
143
 
 
144
                // do not allow empty var names
 
145
        if (varKey != null) {
 
146
            if (varKey.getName().trim().equals("")) varKey = null;
 
147
        }
 
148
 
 
149
        this.varKey = varKey;
 
150
        this.owner = owner;
 
151
 
 
152
        boolean enabled = owner != null && varKey != null;
 
153
 
 
154
        // update enabled state of everything
 
155
        // can't just enable all children because objects might be inside JPanel
 
156
        code.setEnabled(enabled);
 
157
        units.setEnabled(enabled);
 
158
        show.setEnabled(enabled);
 
159
 
 
160
        if (!enabled) return;
 
161
 
 
162
        // if td is null (implies var is null)
 
163
        // then use the current panel values to apply to varName.
 
164
        td = owner.getTextDescriptor(varKey);
 
165
        if (td == null) return;
 
166
        var = owner.getParameterOrVariable(varKey);
 
167
 
 
168
        // otherwise, use td
 
169
 
 
170
        // set code
 
171
        initialCode = CodeExpression.Code.NONE;
 
172
        if (var != null) {
 
173
            initialCode = var.getCode();
 
174
            code.setSelectedItem(initialCode);
 
175
        } else {
 
176
            // var null, disable code
 
177
            code.setEnabled(false);
 
178
        }
 
179
        // set units
 
180
        initialUnit = td.getUnit();
 
181
        units.setSelectedItem(td.getUnit());
 
182
        // set show style
 
183
                if (td.isDisplay())
 
184
                        initialDispPos = td.getDispPart();
 
185
                else
 
186
                        initialDispPos = displaynone;
 
187
        // show style is none if var non-null and isDisplay is false
 
188
        if (var != null) {
 
189
            // make sure "none" is a choice
 
190
            populateShowComboBox(true);
 
191
            if (!var.isDisplay()) {
 
192
                show.setSelectedIndex(0);
 
193
            } else {
 
194
                show.setSelectedItem(initialDispPos);
 
195
                if (!td.isParam()) {
 
196
                    show.setEnabled(false);
 
197
                }
 
198
            }
 
199
        } else {
 
200
            populateShowComboBox(false);
 
201
            show.setSelectedItem(initialDispPos);
 
202
        }
 
203
 
 
204
                if (owner instanceof Cell && !td.isInherit())
 
205
                {
 
206
                attrInfo1.setText("NOTE: This cell attribute is NOT");
 
207
                attrInfo2.setText("inherited by instances of the cell");
 
208
                }
 
209
 
 
210
        loading = false;
 
211
    }
 
212
 
 
213
    /**
 
214
     * Method to modify a TextDescriptor to match the settings in this panel.
 
215
     * @param td the input TextDescriptor.
 
216
     * @return the TextDescriptor with code/units/display in this panel.
 
217
     */
 
218
    public TextDescriptor withPanelValues(TextDescriptor td)
 
219
    {
 
220
        // change the units
 
221
        TextDescriptor.Unit newUnit = (TextDescriptor.Unit)units.getSelectedItem();
 
222
        td = td.withUnit(newUnit);
 
223
 
 
224
        // change the show style
 
225
        Object newDispObj = show.getSelectedItem();
 
226
        if (newDispObj == displaynone)
 
227
        {
 
228
            td = td.withDisplay(false);
 
229
        } else
 
230
        {
 
231
            td = td.withDisplay(true);
 
232
                TextDescriptor.DispPos newDisp = (TextDescriptor.DispPos)newDispObj;
 
233
            td = td.withDispPart(newDisp);
 
234
        }
 
235
                return td;
 
236
    }
 
237
 
 
238
    /**
 
239
     * Method to modify a variable value to match the Code settings in this panel.
 
240
     * @param value the input value
 
241
     * @return the value with code in this panel.
 
242
     */
 
243
    public Object withPanelCode(Object value)
 
244
    {
 
245
        // change the code type
 
246
        CodeExpression.Code newCode = (CodeExpression.Code)code.getSelectedItem();
 
247
        return Variable.withCode(value, newCode);
 
248
    }
 
249
 
 
250
    /**
 
251
     * Apply any changes the user has made through the Panel.
 
252
     * @return true if any changes committed to database, false otherwise
 
253
     */
 
254
    public synchronized boolean applyChanges() {
 
255
        if (varKey == null) return false;
 
256
 
 
257
        boolean changed = false;
 
258
 
 
259
        // see if code changed
 
260
        CodeExpression.Code newCode = (CodeExpression.Code)code.getSelectedItem();
 
261
        if (newCode != initialCode) changed = true;
 
262
        // see if units changed
 
263
        TextDescriptor.Unit newUnit = (TextDescriptor.Unit)units.getSelectedItem();
 
264
        if (newUnit != initialUnit) changed = true;
 
265
        // see if show style changed - check if DispPos changed
 
266
        Object newDisp = show.getSelectedItem();
 
267
        if (newDisp != initialDispPos) changed = true;
 
268
        int newDispIndex = -1;
 
269
        if (newDisp != displaynone)
 
270
                newDispIndex = ((TextDescriptor.DispPos)newDisp).getIndex();
 
271
 
 
272
        if (td != null) {
 
273
            // nothing changed on current var/td, return
 
274
            if (!changed) return false;
 
275
        }
 
276
 
 
277
        new ChangeText(
 
278
                owner,
 
279
                varKey,
 
280
                newCode,
 
281
                newUnit.getIndex(),
 
282
                newDispIndex
 
283
        );
 
284
 
 
285
        initialCode = newCode;
 
286
        initialUnit = newUnit;
 
287
        initialDispPos = newDisp;
 
288
        return true;
 
289
    }
 
290
 
 
291
    // populate show combo box. If includeNoneChoice is true, include
 
292
    // the "None" option in the combo box. Note that it is a String, while
 
293
    // all the other objects are TextDescriptor.DispPos objects.
 
294
    private void populateShowComboBox(boolean includeNoneChoice) {
 
295
        show.removeAllItems();
 
296
        // populate show style dialog box
 
297
        if (includeNoneChoice) show.addItem(displaynone);
 
298
        for (Iterator<TextDescriptor.DispPos> it = TextDescriptor.DispPos.getShowStyles(); it.hasNext(); ) {
 
299
            show.addItem(it.next());
 
300
        }
 
301
 
 
302
    }
 
303
 
 
304
    private static class ChangeText extends Job {
 
305
 
 
306
        private ElectricObject owner;
 
307
        private Variable.Key varKey;
 
308
        private CodeExpression.Code code;
 
309
        private int unit;
 
310
        private int dispPos;
 
311
 
 
312
        private ChangeText(
 
313
                ElectricObject owner,
 
314
                Variable.Key varKey,
 
315
                CodeExpression.Code code,
 
316
                int unit,
 
317
                int dispPos)
 
318
        {
 
319
            super("Modify Text Attribute", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);
 
320
            this.owner = owner;
 
321
            this.varKey = varKey;
 
322
            this.code = code;
 
323
            this.unit = unit;
 
324
            this.dispPos = dispPos;
 
325
            startJob();
 
326
        }
 
327
 
 
328
        public boolean doIt() throws JobException {
 
329
            // change the code type
 
330
            if (owner.isParam(varKey)) {
 
331
                if (owner instanceof Cell) {
 
332
                    Cell cell = (Cell)owner;
 
333
                    cell.getCellGroup().updateParam((Variable.AttrKey)varKey, cell.getParameter(varKey).withCode(code).getObject());
 
334
                } else if (owner instanceof NodeInst) {
 
335
                    NodeInst ni = (NodeInst)owner;
 
336
                    ni.addParameter(ni.getParameter(varKey).withCode(code));
 
337
                }
 
338
            } else {
 
339
                owner.updateVarCode(varKey, code);
 
340
            }
 
341
 
 
342
                        TextDescriptor td = owner.getTextDescriptor(varKey);
 
343
                        if (td == null) return false;
 
344
 
 
345
            // change the units
 
346
            td = td.withUnit(TextDescriptor.Unit.getUnitAt(unit));
 
347
            // change the show style
 
348
                        Variable var = owner.getParameterOrVariable(varKey);
 
349
            if (dispPos < 0) {
 
350
                // var should not be null
 
351
                if (var != null) td = td.withDisplay(false);
 
352
            } else {
 
353
                if (var != null) td = td.withDisplay(true);
 
354
                td = td.withDispPart(TextDescriptor.DispPos.getShowStylesAt(dispPos));
 
355
            }
 
356
                        owner.setTextDescriptor(varKey, td);
 
357
                        return true;
 
358
       }
 
359
    }
 
360
 
 
361
    /** This method is called from within the constructor to
 
362
     * initialize the form.
 
363
     * WARNING: Do NOT modify this code. The content of this method is
 
364
     * always regenerated by the Form Editor.
 
365
     */
 
366
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
 
367
    private void initComponents() {
 
368
        java.awt.GridBagConstraints gridBagConstraints;
 
369
 
 
370
        jPanel1 = new javax.swing.JPanel();
 
371
        jLabel1 = new javax.swing.JLabel();
 
372
        code = new javax.swing.JComboBox();
 
373
        jLabel2 = new javax.swing.JLabel();
 
374
        units = new javax.swing.JComboBox();
 
375
        jLabel3 = new javax.swing.JLabel();
 
376
        show = new javax.swing.JComboBox();
 
377
        jPanel2 = new javax.swing.JPanel();
 
378
        attrInfo1 = new javax.swing.JLabel();
 
379
        attrInfo2 = new javax.swing.JLabel();
 
380
        attrInfo3 = new javax.swing.JLabel();
 
381
 
 
382
        setLayout(new java.awt.GridBagLayout());
 
383
 
 
384
        setBorder(javax.swing.BorderFactory.createEtchedBorder());
 
385
        jPanel1.setLayout(new java.awt.GridBagLayout());
 
386
 
 
387
        jLabel1.setText("Code:");
 
388
        gridBagConstraints = new java.awt.GridBagConstraints();
 
389
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
390
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
 
391
        jPanel1.add(jLabel1, gridBagConstraints);
 
392
 
 
393
        gridBagConstraints = new java.awt.GridBagConstraints();
 
394
        gridBagConstraints.gridx = 1;
 
395
        gridBagConstraints.gridy = 0;
 
396
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
397
        gridBagConstraints.weightx = 0.1;
 
398
        jPanel1.add(code, gridBagConstraints);
 
399
 
 
400
        jLabel2.setText("Units:");
 
401
        gridBagConstraints = new java.awt.GridBagConstraints();
 
402
        gridBagConstraints.gridx = 0;
 
403
        gridBagConstraints.gridy = 1;
 
404
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
405
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
 
406
        jPanel1.add(jLabel2, gridBagConstraints);
 
407
 
 
408
        gridBagConstraints = new java.awt.GridBagConstraints();
 
409
        gridBagConstraints.gridx = 1;
 
410
        gridBagConstraints.gridy = 1;
 
411
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
412
        gridBagConstraints.weightx = 0.1;
 
413
        jPanel1.add(units, gridBagConstraints);
 
414
 
 
415
        jLabel3.setText("Show:");
 
416
        gridBagConstraints = new java.awt.GridBagConstraints();
 
417
        gridBagConstraints.gridx = 0;
 
418
        gridBagConstraints.gridy = 2;
 
419
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
420
        gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
 
421
        jPanel1.add(jLabel3, gridBagConstraints);
 
422
 
 
423
        gridBagConstraints = new java.awt.GridBagConstraints();
 
424
        gridBagConstraints.gridx = 1;
 
425
        gridBagConstraints.gridy = 2;
 
426
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
427
        gridBagConstraints.weightx = 0.1;
 
428
        jPanel1.add(show, gridBagConstraints);
 
429
 
 
430
        gridBagConstraints = new java.awt.GridBagConstraints();
 
431
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
432
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
433
        gridBagConstraints.weightx = 1.0;
 
434
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
 
435
        add(jPanel1, gridBagConstraints);
 
436
 
 
437
        jPanel2.setLayout(new java.awt.GridBagLayout());
 
438
 
 
439
        attrInfo1.setText("Attributes created on a cell are");
 
440
        gridBagConstraints = new java.awt.GridBagConstraints();
 
441
        gridBagConstraints.gridx = 0;
 
442
        gridBagConstraints.gridy = 0;
 
443
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
444
        jPanel2.add(attrInfo1, gridBagConstraints);
 
445
 
 
446
        attrInfo2.setText("inherited by instances of that cell");
 
447
        gridBagConstraints = new java.awt.GridBagConstraints();
 
448
        gridBagConstraints.gridx = 0;
 
449
        gridBagConstraints.gridy = 1;
 
450
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
451
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
452
        jPanel2.add(attrInfo2, gridBagConstraints);
 
453
 
 
454
        gridBagConstraints = new java.awt.GridBagConstraints();
 
455
        gridBagConstraints.gridx = 0;
 
456
        gridBagConstraints.gridy = 2;
 
457
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
458
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
459
        jPanel2.add(attrInfo3, gridBagConstraints);
 
460
 
 
461
        gridBagConstraints = new java.awt.GridBagConstraints();
 
462
        gridBagConstraints.gridx = 1;
 
463
        gridBagConstraints.gridy = 0;
 
464
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 
465
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 
466
        gridBagConstraints.insets = new java.awt.Insets(4, 10, 4, 4);
 
467
        add(jPanel2, gridBagConstraints);
 
468
 
 
469
    }// </editor-fold>//GEN-END:initComponents
 
470
 
 
471
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
472
    private javax.swing.JLabel attrInfo1;
 
473
    private javax.swing.JLabel attrInfo2;
 
474
    private javax.swing.JLabel attrInfo3;
 
475
    private javax.swing.JComboBox code;
 
476
    private javax.swing.JLabel jLabel1;
 
477
    private javax.swing.JLabel jLabel2;
 
478
    private javax.swing.JLabel jLabel3;
 
479
    private javax.swing.JPanel jPanel1;
 
480
    private javax.swing.JPanel jPanel2;
 
481
    private javax.swing.JComboBox show;
 
482
    private javax.swing.JComboBox units;
 
483
    // End of variables declaration//GEN-END:variables
 
484
}