< prev index next >

src/demo/share/jfc/SwingSet2/BezierAnimationPanel.java

Print this page


   1 /*
   2  *
   3  * Copyright (c) 2007, 2019, 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


  26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 
  34 import javax.swing.*;
  35 import javax.swing.event.*;
  36 import javax.swing.text.*;
  37 import javax.swing.border.*;
  38 import javax.swing.colorchooser.*;
  39 import javax.swing.filechooser.*;
  40 import javax.accessibility.*;
  41 
  42 import java.awt.*;
  43 import java.awt.font.*;
  44 import java.awt.geom.*;
  45 import java.awt.image.*;
  46 import java.lang.reflect.InvocationTargetException;
  47 import java.awt.event.*;
  48 
  49 /**
  50  * BezierAnimationPanel
  51  *
  52  * @author Jim Graham
  53  * @author Jeff Dinkins (removed dynamic setting changes, made swing friendly)
  54  */
  55 class BezierAnimationPanel extends JPanel implements Runnable {
  56 
  57     Color backgroundColor =  new Color(0,     0, 153);
  58     Color outerColor      =  new Color(255, 255, 255);
  59     Color gradientColorA  =  new Color(255,   0, 101);
  60     Color gradientColorB  =  new Color(255, 255,   0);
  61 
  62     boolean bgChanged = false;
  63 
  64     GradientPaint gradient = null;
  65 
  66     public final int NUMPTS = 6;


 293                                  RenderingHints.VALUE_ANTIALIAS_ON);
 294             g2d.setColor(outerColor);
 295             g2d.setComposite(opaque);
 296             g2d.setStroke(solid);
 297             g2d.draw(gp);
 298             g2d.setPaint(gradient);
 299 
 300             if(!bgChanged) {
 301                 bounds = gp.getBounds();
 302             } else {
 303                 bounds = new Rectangle(0, 0, getWidth(), getHeight());
 304                 bgChanged = false;
 305             }
 306             gradient = new GradientPaint(bounds.x, bounds.y, gradientColorA,
 307                                          bounds.x + bounds.width, bounds.y + bounds.height,
 308                                          gradientColorB, true);
 309             g2d.setComposite(blend);
 310             g2d.fill(gp);
 311         }
 312             if (g2d == BufferG2D) {
 313                 try {
 314                     SwingUtilities.invokeAndWait(new Runnable() {
 315 
 316                         @Override
 317                         public void run() {
 318                             repaint();
 319                         }
 320                     });
 321                 } catch (InvocationTargetException | InterruptedException e) {
 322                     e.printStackTrace();
 323                 }
 324             }
 325             ++frame;

 326         }
 327         if (g2d != null) {
 328             g2d.dispose();
 329         }
 330     }
 331 
 332     public void paint(Graphics g) {
 333         synchronized (lock) {
 334            Graphics2D g2d = (Graphics2D) g;
 335            if (img != null) {
 336                g2d.setComposite(AlphaComposite.Src);
 337                g2d.drawImage(img, null, 0, 0);
 338            }
 339         }
 340     }
 341 }
   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


  26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 
  34 import javax.swing.*;
  35 import javax.swing.event.*;
  36 import javax.swing.text.*;
  37 import javax.swing.border.*;
  38 import javax.swing.colorchooser.*;
  39 import javax.swing.filechooser.*;
  40 import javax.accessibility.*;
  41 
  42 import java.awt.*;
  43 import java.awt.font.*;
  44 import java.awt.geom.*;
  45 import java.awt.image.*;

  46 import java.awt.event.*;
  47 
  48 /**
  49  * BezierAnimationPanel
  50  *
  51  * @author Jim Graham
  52  * @author Jeff Dinkins (removed dynamic setting changes, made swing friendly)
  53  */
  54 class BezierAnimationPanel extends JPanel implements Runnable {
  55 
  56     Color backgroundColor =  new Color(0,     0, 153);
  57     Color outerColor      =  new Color(255, 255, 255);
  58     Color gradientColorA  =  new Color(255,   0, 101);
  59     Color gradientColorB  =  new Color(255, 255,   0);
  60 
  61     boolean bgChanged = false;
  62 
  63     GradientPaint gradient = null;
  64 
  65     public final int NUMPTS = 6;


 292                                  RenderingHints.VALUE_ANTIALIAS_ON);
 293             g2d.setColor(outerColor);
 294             g2d.setComposite(opaque);
 295             g2d.setStroke(solid);
 296             g2d.draw(gp);
 297             g2d.setPaint(gradient);
 298 
 299             if(!bgChanged) {
 300                 bounds = gp.getBounds();
 301             } else {
 302                 bounds = new Rectangle(0, 0, getWidth(), getHeight());
 303                 bgChanged = false;
 304             }
 305             gradient = new GradientPaint(bounds.x, bounds.y, gradientColorA,
 306                                          bounds.x + bounds.width, bounds.y + bounds.height,
 307                                          gradientColorB, true);
 308             g2d.setComposite(blend);
 309             g2d.fill(gp);
 310         }
 311             if (g2d == BufferG2D) {
 312                 repaint();










 313             }
 314             ++frame;
 315             Thread.yield();
 316         }
 317         if (g2d != null) {
 318             g2d.dispose();
 319         }
 320     }
 321 
 322     public void paint(Graphics g) {
 323         synchronized (lock) {
 324            Graphics2D g2d = (Graphics2D) g;
 325            if (img != null) {
 326                g2d.setComposite(AlphaComposite.Src);
 327                g2d.drawImage(img, null, 0, 0);
 328            }
 329         }
 330     }
 331 }
< prev index next >