< prev index next >

src/demo/share/jfc/J2Ddemo/java2d/demos/Composite/ACrules.java

Print this page


   1 /*
   2  *
   3  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  47 import java.awt.AlphaComposite;
  48 import java.awt.Color;
  49 import java.awt.Font;
  50 import java.awt.GradientPaint;
  51 import java.awt.Graphics2D;
  52 import java.awt.RenderingHints;
  53 import java.awt.font.FontRenderContext;
  54 import java.awt.font.LineMetrics;
  55 import java.awt.font.TextLayout;
  56 import java.awt.geom.GeneralPath;
  57 import java.awt.image.BufferedImage;
  58 import java2d.AnimatingSurface;
  59 
  60 
  61 /**
  62  * All the AlphaCompositing Rules demonstrated.
  63  */
  64 @SuppressWarnings("serial")
  65 public class ACrules extends AnimatingSurface {
  66 
  67     private static String compNames[] = {
  68         "Src",
  69         "SrcOver",
  70         "SrcIn",
  71         "SrcOut",
  72         "SrcAtop",
  73         "Clear",
  74         "Dst",
  75         "DstOver",
  76         "DstIn",
  77         "DstOut",
  78         "DstAtop",
  79         "Xor", };
  80     private static final AlphaComposite compObjs[] = {
  81         Src, SrcOver, SrcIn, SrcOut, SrcAtop, Clear,
  82         Dst, DstOver, DstIn, DstOut, DstAtop, Xor, };
  83     private static final int NUM_RULES = compObjs.length;
  84     private static final int HALF_NUM_RULES = NUM_RULES / 2;
  85     private int fadeIndex;
  86     private static float fadeValues[][] = {
  87         { 1.0f, -0.1f, 0.0f, 1.0f, 0.0f, 1.0f },
  88         { 0.0f, 0.1f, 1.0f, 1.0f, -0.1f, 0.0f },
  89         { 1.0f, 0.0f, 1.0f, 0.0f, 0.1f, 1.0f }, };
  90     private static String fadeNames[] = {
  91         "Src => transparent, Dest opaque",
  92         "Src => opaque, Dest => transparent",
  93         "Src opaque, Dest => opaque", };
  94     private static Font f = new Font("serif", Font.PLAIN, 10);
  95     private float srca = fadeValues[fadeIndex][0];
  96     private float dsta = fadeValues[fadeIndex][3];
  97     private String fadeLabel = fadeNames[0];
  98     private BufferedImage statBI, animBI;
  99     private int PADLEFT, PADRIGHT, HPAD;
 100     private int PADABOVE, PADBELOW, VPAD;
 101     private int RECTWIDTH, RECTHEIGHT;
 102     private int PADDEDHEIGHT;
 103     private GeneralPath srcpath = new GeneralPath();
 104     private GeneralPath dstpath = new GeneralPath();
 105     private LineMetrics lm;
 106     private BufferedImage dBI, sBI;
 107     private GradientPaint gradientDst, gradientSrc;
 108 
 109     public ACrules() {
 110         setBackground(Color.white);


 240                 gS.fill(srcpath);
 241             }
 242 
 243             gD.setComposite(compObjs[i]);
 244             gD.drawImage(sBI, 0, 0, null);
 245 
 246             big.drawImage(dBI, 0, 0, null);
 247             big.setColor(Color.black);
 248             big.drawString(compNames[i], 0, -lm.getDescent());
 249             big.drawRect(0, 0, RECTWIDTH, RECTHEIGHT);
 250             big.translate(-x, -y);
 251         }
 252 
 253         gD.dispose();
 254         gS.dispose();
 255         big.dispose();
 256 
 257         return bi;
 258     }
 259 
 260     public static void main(String argv[]) {
 261         createDemoFrame(new ACrules());
 262     }
 263 }
   1 /*
   2  *
   3  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  47 import java.awt.AlphaComposite;
  48 import java.awt.Color;
  49 import java.awt.Font;
  50 import java.awt.GradientPaint;
  51 import java.awt.Graphics2D;
  52 import java.awt.RenderingHints;
  53 import java.awt.font.FontRenderContext;
  54 import java.awt.font.LineMetrics;
  55 import java.awt.font.TextLayout;
  56 import java.awt.geom.GeneralPath;
  57 import java.awt.image.BufferedImage;
  58 import java2d.AnimatingSurface;
  59 
  60 
  61 /**
  62  * All the AlphaCompositing Rules demonstrated.
  63  */
  64 @SuppressWarnings("serial")
  65 public class ACrules extends AnimatingSurface {
  66 
  67     private static String[] compNames = {
  68         "Src",
  69         "SrcOver",
  70         "SrcIn",
  71         "SrcOut",
  72         "SrcAtop",
  73         "Clear",
  74         "Dst",
  75         "DstOver",
  76         "DstIn",
  77         "DstOut",
  78         "DstAtop",
  79         "Xor", };
  80     private static final AlphaComposite[] compObjs = {
  81         Src, SrcOver, SrcIn, SrcOut, SrcAtop, Clear,
  82         Dst, DstOver, DstIn, DstOut, DstAtop, Xor, };
  83     private static final int NUM_RULES = compObjs.length;
  84     private static final int HALF_NUM_RULES = NUM_RULES / 2;
  85     private int fadeIndex;
  86     private static float[][] fadeValues = {
  87         { 1.0f, -0.1f, 0.0f, 1.0f, 0.0f, 1.0f },
  88         { 0.0f, 0.1f, 1.0f, 1.0f, -0.1f, 0.0f },
  89         { 1.0f, 0.0f, 1.0f, 0.0f, 0.1f, 1.0f }, };
  90     private static String[] fadeNames = {
  91         "Src => transparent, Dest opaque",
  92         "Src => opaque, Dest => transparent",
  93         "Src opaque, Dest => opaque", };
  94     private static Font f = new Font("serif", Font.PLAIN, 10);
  95     private float srca = fadeValues[fadeIndex][0];
  96     private float dsta = fadeValues[fadeIndex][3];
  97     private String fadeLabel = fadeNames[0];
  98     private BufferedImage statBI, animBI;
  99     private int PADLEFT, PADRIGHT, HPAD;
 100     private int PADABOVE, PADBELOW, VPAD;
 101     private int RECTWIDTH, RECTHEIGHT;
 102     private int PADDEDHEIGHT;
 103     private GeneralPath srcpath = new GeneralPath();
 104     private GeneralPath dstpath = new GeneralPath();
 105     private LineMetrics lm;
 106     private BufferedImage dBI, sBI;
 107     private GradientPaint gradientDst, gradientSrc;
 108 
 109     public ACrules() {
 110         setBackground(Color.white);


 240                 gS.fill(srcpath);
 241             }
 242 
 243             gD.setComposite(compObjs[i]);
 244             gD.drawImage(sBI, 0, 0, null);
 245 
 246             big.drawImage(dBI, 0, 0, null);
 247             big.setColor(Color.black);
 248             big.drawString(compNames[i], 0, -lm.getDescent());
 249             big.drawRect(0, 0, RECTWIDTH, RECTHEIGHT);
 250             big.translate(-x, -y);
 251         }
 252 
 253         gD.dispose();
 254         gS.dispose();
 255         big.dispose();
 256 
 257         return bi;
 258     }
 259 
 260     public static void main(String[] argv) {
 261         createDemoFrame(new ACrules());
 262     }
 263 }
< prev index next >