Color Util : Color « 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 » ColorScreenshots 
Color Util
     
/*
 * Copyright (C) 2004 NNL Technology AB
 * Visit www.infonode.net for information about InfoNode(R) 
 * products and how to contact NNL Technology AB.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
 * MA 02111-1307, USA.
 */


// $Id: ColorUtil.java,v 1.10 2005/02/16 11:28:14 jesper Exp $


import java.awt.*;

public final class ColorUtil {
  private ColorUtil() {
  }

  public static Color getOpposite(Color c) {
    return isDark(c? Color.WHITE : Color.BLACK;
  }

  public static Color shade(Color c, double amount) {
    return blend(c, getOpposite(c), amount);
  }

  public static final Color mult(Color c, double amount) {
    return c == null null new Color(Math.min(255(int) (c.getRed() * amount)),
                                        Math.min(255(int) (c.getGreen() * amount)),
                                        Math.min(255(int) (c.getBlue() * amount)),
                                        c.getAlpha());
  }

  public static Color setAlpha(Color c, int alpha) {
    return c == null null new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
  }

  public static final Color add(Color c1, Color c2) {
    return c1 == null ? c2 :
           c2 == null ? c1 :
           new Color(Math.min(255, c1.getRed() + c2.getRed()),
                     Math.min(255, c1.getGreen() + c2.getGreen()),
                     Math.min(255, c1.getBlue() + c2.getBlue()),
                     c1.getAlpha());
  }

  public static Color blend(Color c1, Color c2, double v) {
    double v2 = - v;
    return c1 == null (c2 == null null : c2:
           c2 == null ? c1 :
           new Color(Math.min(255(int) (c1.getRed() * v2 + c2.getRed() * v)),
                     Math.min(255(int) (c1.getGreen() * v2 + c2.getGreen() * v)),
                     Math.min(255(int) (c1.getBlue() * v2 + c2.getBlue() * v)),
                     Math.min(255(int) (c1.getAlpha() * v2 + c2.getAlpha() * v)));
  }

  public static boolean isDark(Color c) {
    return c.getRed() + c.getGreen() + c.getBlue() 180;
  }

  public static Color highlight(Color c) {
    return mult(c, isDark(c1.5F 0.67F);
  }

  public static Color copy(Color c) {
    return c == null null new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
  }

}

   
    
    
    
    
  
Related examples in the same category
1.Color class is used to work with colors in Java 2D
2.Color Utilities: common color operations
3.Color Difference
4.Rainbow ColorRainbow Color
5.XOR colorXOR color
6.Color Gradient
7.Common color utilities
8.Drawing with Color
9.Color fading animation
10.140 colors - defined for X Window System listed in O'Reilly html pocket reference 87pp
11.Color Factory
12.An efficient color quantization algorithm
13.Utility for checking colors given either hexa or natural language string descriptions.
14.Derives a color by adding the specified offsets to the base color's hue, saturation, and brightness values
15.Map colors into names and vice versa.
16.Converts a given string into a color.
17.If the color is equal to one of the defined constant colors, that name is returned instead.
18.Converts the String representation of a color to an actual Color object.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.