Returns true if the two Paint objects are equal OR both null. : Gradient Paint « 2D Graphics GUI « Java

Home
Java
1.2D Graphics GUI
2.2D Graphics GUI1
3.3D
4.Advanced Graphics
5.Ant
6.Apache Common
7.Chart
8.Class
9.Collections Data Structure
10.Data Type
11.Database SQL JDBC
12.Design Pattern
13.Development Class
14.EJB3
15.Email
16.Event
17.File Input Output
18.Game
19.Generics
20.GWT
21.Hibernate
22.I18N
23.J2EE
24.J2ME
25.JDK 6
26.JNDI LDAP
27.JPA
28.JSP
29.JSTL
30.Language Basics
31.Network Protocol
32.PDF RTF
33.Reflection
34.Regular Expressions
35.Scripting
36.Security
37.Servlets
38.Spring
39.Swing Components
40.Swing JFC
41.SWT JFace Eclipse
42.Threads
43.Tiny Application
44.Velocity
45.Web Services SOA
46.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
SCJP
Java » 2D Graphics GUI » Gradient PaintScreenshots 
Returns true if the two Paint objects are equal OR both null.
  
import java.awt.GradientPaint;
import java.awt.Paint;

/* 
 * JCommon : a free general purpose class library for the Java(tm) platform
 
 *
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 
 * Project Info:  http://www.jfree.org/jcommon/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 
 * -------------------
 * PaintUtilities.java
 * -------------------
 * (C) Copyright 2003-2005, by Object Refinery Limited.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: PaintUtilities.java,v 1.10 2007/11/02 17:50:37 taqua Exp $
 *
 * Changes
 * -------
 * 13-Nov-2003 : Version 1 (DG);
 * 04-Oct-2004 : Renamed PaintUtils --> PaintUtilities (DG);
 * 23-Feb-2005 : Rewrote equal() method with less indenting required (DG);
 *
 */

public class Main {
  /**
   * Returns <code>true</code> if the two <code>Paint</code> objects are equal 
   * OR both <code>null</code>.  This method handles
   * <code>GradientPaint</code> as a special case.
   *
   @param p1  paint 1 (<code>null</code> permitted).
   @param p2  paint 2 (<code>null</code> permitted).
   *
   @return A boolean.
   */
  public static boolean equal(final Paint p1, final Paint p2) {

      // handle cases where either or both arguments are null
      if (p1 == null) {
          return (p2 == null);   
      }
      if (p2 == null) {
          return false;   
      }
      
      boolean result = false;
      // handle GradientPaint as a special case...
      if (p1 instanceof GradientPaint && p2 instanceof GradientPaint) {
          final GradientPaint gp1 = (GradientPaintp1;
          final GradientPaint gp2 = (GradientPaintp2;
          result = gp1.getColor1().equals(gp2.getColor1()) 
              && gp1.getColor2().equals(gp2.getColor2())
              && gp1.getPoint1().equals(gp2.getPoint1())    
              && gp1.getPoint2().equals(gp2.getPoint2())
              && gp1.isCyclic() == gp2.isCyclic()
              && gp1.getTransparency() == gp1.getTransparency()
      }
      else {
          result = p1.equals(p2);
      }
      return result;

  }

}

   
    
  
Related examples in the same category
1.Gradients: a smooth blending of shades from light to dark or from one color to another
2.Gradient Shapes
3.GradientPaint demoGradientPaint demo
4.GradientPaint EllipseGradientPaint Ellipse
5.Another GradientPaint DemoAnother GradientPaint Demo
6.Text effect: rotation and transparentText effect: rotation and transparent
7.Text effect: image texture
8.Texture paint Texture paint
9.Round GradientPaint Fill demoRound GradientPaint Fill demo
10.GradientPaint: ironGradientPaint: iron
11.Color gradientColor gradient
12.Drawing with a Gradient Color
13.A non-cyclic gradient
14.A cyclic gradient
15.PaintsPaints
16.Horizontal Gradients
17.Vertical Gradient Paint
18.Gradients in the middle
19.Control the direction of Gradients
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.