~ubuntu-branches/ubuntu/jaunty/electric/jaunty

« back to all changes in this revision

Viewing changes to com/sun/electric/database/geometry/EGraphics.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-01-08 02:05:08 UTC
  • mfrom: (1.1.2 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090108020508-0h3li7zt9mu5gf0i
Tags: 8.08-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
241
241
                this.red = red;
242
242
                this.green = green;
243
243
                this.blue = blue;
244
 
                this.opacity = opacity;
 
244
                this.opacity = validateOpacity(opacity);
245
245
                this.foreground = foreground;
246
246
                setPatternLow(pattern);
247
247
                if (transparentLayer < 0 || transparentLayer > TRANSPARENT_12)
304
304
                String layerTechMsg = layer.getName() + "In" + tech.getTechName();
305
305
 
306
306
                Pref usePatternDisplayPref = Pref.makeBooleanPref("UsePatternDisplayFor" + layerTechMsg,
307
 
                        Technology.getTechnologyPreferences(), displayPatterned);
 
307
                        tech.getTechnologyPreferences(), displayPatterned);
308
308
                displayPatterned = usePatternDisplayPref.getBoolean();
309
309
                usePatternDisplayMap.put(layer, usePatternDisplayPref);
310
310
 
311
311
                Pref usePatternPrinterPref = Pref.makeBooleanPref("UsePatternPrinterFor" + layerTechMsg,
312
 
                        Technology.getTechnologyPreferences(), printPatterned);
 
312
                        tech.getTechnologyPreferences(), printPatterned);
313
313
                printPatterned = usePatternPrinterPref.getBoolean();
314
314
                usePatternPrinterMap.put(layer, usePatternPrinterPref);
315
315
 
316
316
                // read any previous outline information and apply it
317
317
                Pref oldOutlinePatternDisplayPref = Pref.makeBooleanPref("OutlinePatternDisplayFor" + layerTechMsg,
318
 
                        Technology.getTechnologyPreferences(), false);
 
318
                        tech.getTechnologyPreferences(), false);
319
319
                if (oldOutlinePatternDisplayPref.getBoolean()) patternOutline = Outline.PAT_S;
320
320
 
321
321
                Pref outlinePatternPref = Pref.makeIntPref("OutlinePatternFor" + layerTechMsg,
322
 
                                Technology.getTechnologyPreferences(), patternOutline.getIndex());
 
322
                                tech.getTechnologyPreferences(), patternOutline.getIndex());
323
323
                patternOutline = Outline.findOutline(outlinePatternPref.getInt());
324
324
                outlinePatternMap.put(layer, outlinePatternPref);
325
325
 
326
326
                Pref transparentLayerPref = Pref.makeIntPref("TransparentLayerFor" + layerTechMsg,
327
 
                        Technology.getTechnologyPreferences(), transparentLayer);
 
327
                        tech.getTechnologyPreferences(), transparentLayer);
328
328
                transparentLayer = transparentLayerPref.getInt();
329
329
                transparentLayerMap.put(layer, transparentLayerPref);
330
330
 
331
331
                Pref opacityPref = Pref.makeDoublePref("OpacityFor" + layerTechMsg,
332
 
                        Technology.getTechnologyPreferences(), opacity);
333
 
                opacity = opacityPref.getDouble();
 
332
                        tech.getTechnologyPreferences(), opacity);
 
333
                opacity = validateOpacity(opacityPref.getDouble());
334
334
                opacityMap.put(layer, opacityPref);
335
 
                
 
335
 
336
336
                Pref colorPref = Pref.makeIntPref("ColorFor" + layerTechMsg,
337
 
                        Technology.getTechnologyPreferences(), (red<<16) | (green << 8) | blue);
 
337
                        tech.getTechnologyPreferences(), (red<<16) | (green << 8) | blue);
338
338
                int color = colorPref.getInt();
339
339
                red = (color >> 16) & 0xFF;
340
340
                green = (color >> 8) & 0xFF;
343
343
 
344
344
                String pat = makePatString(pattern);
345
345
                Pref patternPref = Pref.makeStringPref("PatternFor" + layerTechMsg,
346
 
                        Technology.getTechnologyPreferences(), pat);
 
346
                        tech.getTechnologyPreferences(), pat);
347
347
                pat = patternPref.getString();
348
348
                parsePatString(pat, pattern);
349
349
                setPatternLow(pattern);
372
372
                transparentLayer = transparentLayerPref.getInt();
373
373
 
374
374
                Pref opacityPref = opacityMap.get(layer);
375
 
                opacity = opacityPref.getDouble();
376
 
                
 
375
                opacity = validateOpacity(opacityPref.getDouble());
 
376
 
377
377
                Pref colorPref = colorMap.get(layer);
378
378
                int color = colorPref.getInt();
379
379
                red = (color >> 16) & 0xFF;
386
386
                setPatternLow(pattern);
387
387
        }
388
388
 
 
389
        /**
 
390
         * Method to reset this Graphics to its factory state.
 
391
         */
 
392
        public void factoryReset()
 
393
        {
 
394
                if (getFactoryColor() != getRGB()) setColor(new Color(getFactoryColor()));
 
395
                if (getFactoryTransparentLayer() != getTransparentLayer()) setTransparentLayer(getFactoryTransparentLayer());
 
396
                if (getFactoryOpacity() != getOpacity()) setOpacity(getFactoryOpacity());
 
397
                if (getForeground() != getForeground()) setForeground(getForeground());
 
398
                if (!getFactoryPattern().equals(getPattern())) setPattern(getFactoryPattern());
 
399
                if (!getFactoryOutlined().equals(getOutlined())) setOutlined(getFactoryOutlined());
 
400
                if (isFactoryPatternedOnDisplay() != isPatternedOnDisplay()) setPatternedOnDisplay(isFactoryPatternedOnDisplay());
 
401
                if (isFactoryPatternedOnPrinter() != isPatternedOnPrinter()) setPatternedOnPrinter(isFactoryPatternedOnPrinter());
 
402
        }
 
403
 
389
404
        private String makePatString(int [] pattern)
390
405
        {
391
406
                StringBuffer sb = new StringBuffer();
669
684
                return pref.getDoubleFactoryValue();
670
685
        }
671
686
 
672
 
        /**
 
687
    /**
 
688
     * Method to check range of opacity provided.
 
689
     * If < 0, reset it to zero.
 
690
     * If > 1, reset it to one.
 
691
     * @param opacity
 
692
     * @return
 
693
     */
 
694
    private static double validateOpacity(double opacity)
 
695
    {
 
696
        if (opacity < 0)
 
697
        {
 
698
            System.out.println("Opacity " + opacity + " smaller than 0. Resetting to 0");
 
699
            return 0;
 
700
        }
 
701
        else if (opacity > 1)
 
702
        {
 
703
 
 
704
            System.out.println("Opacity " + opacity + " bigger than 1. Resetting to 1");
 
705
            return 1;
 
706
        }
 
707
        return opacity;
 
708
    }
 
709
 
 
710
    /**
673
711
         * Method to set the opacity of this EGraphics.
674
712
         * Opacity runs from 0 (transparent) to 1 (opaque).
675
713
         * @param opacity the opacity of this EGraphics.
676
714
         */
677
715
        public void setOpacity(double opacity)
678
716
        {
679
 
                this.opacity = opacity;
 
717
        this.opacity = validateOpacity(opacity);
680
718
 
681
719
                if (layer != null)
682
720
                {
683
721
                        Pref pref = opacityMap.get(layer);
684
 
                        if (pref != null) pref.setDouble(opacity);
 
722
                        if (pref != null) pref.setDouble(this.opacity);
685
723
                }
686
724
        }
687
725
 
725
763
        /**
726
764
         * Method to get the RGB value representing the color by factory default.
727
765
         * (Bits 16-23 are red, 8-15 are green, 0-7 are blue).
728
 
         * Alpha/opacity component is not returned 
 
766
         * Alpha/opacity component is not returned.
729
767
         * @return the RGB value representing the color by factory default.
730
768
         */
731
769
        public int getFactoryColor()
738
776
        /**
739
777
         * Returns the RGB value representing the color associated with this EGraphics.
740
778
         * (Bits 16-23 are red, 8-15 are green, 0-7 are blue).
741
 
         * Alpha/opacity component is not returned 
 
779
         * Alpha/opacity component is not returned
742
780
         * @return the RGB value of the color
743
781
         */
744
782
        public int getRGB() {