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.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Book
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
20.Gradient effects
ww___w_.__ja__va___2___s__.c__o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.