HTML color and Java Color : HTML Output « Servlets « Java

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 Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Servlets » HTML OutputScreenshots 
HTML color and Java Color
 

/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 
 *   http://www.sun.com/cddl/
 *   
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

//Revised from ajax4jsf

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;


/**
 @author shura (latest modification by $Author: slava_kabanovich $)
 @version $Revision: 1.2 $ $Date: 2006/07/12 14:59:33 $
 *
 */
public class HtmlColor {
  private static Map colorNames;
  
  static {
    // color names.
    colorNames = new HashMap();
      colorNames.put("black"new Color(0x000000));
    colorNames.put("green"new Color(0x008000));
    colorNames.put("silver"new Color(0xC0C0C0));
    colorNames.put("lime"new Color(0x00FF00));
    colorNames.put("gray"new Color(0x808080));
    colorNames.put("olive"new Color(0x808000));
    colorNames.put("white"new Color(0xFFFFFF));
    colorNames.put("yellow"new Color(0xFFFF00));
    colorNames.put("maroon"new Color(0x800000));
    colorNames.put("navy"new Color(0x000080));
    colorNames.put("red"new Color(0xFF0000));
    colorNames.put("blue"new Color(0x0000FF));
    colorNames.put("purple"new Color(0x800080));
    colorNames.put("teal"new Color(0x008080));
    colorNames.put("fuchsia"new Color(0xFF00FF));
    colorNames.put("aqua"new Color(0x00FFFF));
  }

  /**
   * Decode HTML-attribute style of color to {@link Color}
   @param color - color name or #RRGGBB string
   @return - color for this value.
   */
  public static Color decode(String color){
    if(null == color) {
      throw new IllegalArgumentException("NULL_COLOR_PARAMETER_ERROR");
    }
    Color c = (ColorcolorNames.get(color.trim().toLowerCase());
    if (null == c) {
      try {
        c = Color.decode(color.trim());
      catch (NumberFormatException e) {
        throw new IllegalArgumentException("DECODE_COLOR_PARAMETER_ERROR");
      }
    }
    return c;
  }
  
  public static Integer integerValue(String color){
    return new Integer(decode(color).getRGB());
  }
  
  public static String encodeRGB(Color color){
    if(null == color) {
      throw new IllegalArgumentException("NULL_COLOR_PARAMETER_ERROR_2");
    }
    return "#" + Integer.toHexString(color.getRGB()).substring(2).toUpperCase();
  }
  
}

   
  
Related examples in the same category
1. Servlet Output HTML Demo
2. Servlet Display Static HTML
3. Prints a conversion table of miles per gallon to kilometers per liter
4. Servlet: Print Table
5. Html utilities
6. Html Parse Servlet
7. Escape and unescape string
8. Escapes newlines, tabs, backslashes, and quotes in the specified string
9. Web Calendar
10. HTML Helper
11. Escape HTML
12. Convert HTML to text
13. Text To HTML
14. Unescape HTML
15. Java object representations of the HTML table structure
16. Entity Decoder
17. Format a color to HTML RGB color format (e.g. #FF0000 for Color.red)
18. Definitions of HTML character entities and conversions between unicode characters and HTML character entities
19. Encode special characters and do formatting for HTML output
20. HTML color names
21. Utility methods for dealing with HTML
22. Filter the specified message string for characters that are sensitive in HTML
23. A collection of all character entites defined in the HTML4 standard.
24. Decode an HTML color string like '#F567BA;' into a Color
25. Normalize Post Data
26. Get HTML Color String from Java Color object
27. HTML Decoder
28. HTML Parser
29. HTML form Utilites
30. Html Dimensions
31. break Lines with HTML
32. insert HTML block dynamically
33. Convert an integer to an HTML RGB value
34. Convert to HTML string
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.