Skip to content

Commit

Permalink
replaced java.awt.Color with our own implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-szu committed Sep 24, 2015
1 parent 766d8b3 commit 70df2f3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
97 changes: 97 additions & 0 deletions zweb/src/org/zkoss/web/fn/Color.java
@@ -0,0 +1,97 @@
/* Color.java
Purpose:
Description:
History:
Tue, Sep 15, 2015 6:39:51 PM, Created by Christopher
Copyright (C) 2015 Potix Corporation. All Rights Reserved.
This program is distributed under LGPL Version 2.1 in the hope that
it will be useful, but WITHOUT ANY WARRANTY.
*/
package org.zkoss.web.fn;

/**
* Simple container for color components, using rgba, all in 0-255 range
* @author Christopher
*
*/
public class Color {

private int red;
private int green;
private int blue;
private int alpha;

/**
* All color channel should be in 0-255 range, alpha will default to 255 if not given
* @param r red
* @param g green
* @param b blue
*/
public Color(int r, int g, int b) {
this(r, g, b, 255);
}

/**
* All color channel should be in 0-255 range
* @param r red
* @param g green
* @param b blue
* @param a alpha
*/
public Color(int r, int g, int b, int a) {
checkColorRange(r, g, b, a);
this.red = r;
this.green = g;
this.blue = b;
this.alpha = a;
}

private void checkColorRange(int r, int g, int b, int a) {
String wrongColors = "";
boolean gotError = false;
if (r < 0 || r > 255) {
gotError = true;
wrongColors += "\"red\"";
}
if (g < 0 || g > 255) {
gotError = true;
wrongColors += " \"green\"";
}
if (b < 0 || b > 255) {
gotError = true;
wrongColors += " \"blue\"";
}
if (a < 0 || a > 255) {
gotError = true;
wrongColors += " \"alpha\"";
}
if(gotError) {
throw new IllegalArgumentException(wrongColors + " color value outside of expected range 0-255");
}
}

public int getRed() {
return red;
}

public int getGreen() {
return green;
}

public int getBlue() {
return blue;
}

public int getAlpha() {
return alpha;
}

public int getRGB() {
return (alpha << 24) + (red << 16) + (green << 8) + blue;
}
}
3 changes: 0 additions & 3 deletions zweb/src/org/zkoss/web/fn/Colors.java
Expand Up @@ -16,8 +16,6 @@
*/
package org.zkoss.web.fn;

import java.awt.Color;

/**
*
* @author simonpai
Expand Down Expand Up @@ -106,5 +104,4 @@ private static String repeat(char c, int i) {
cs[j] = c;
return new String(cs);
}

}
1 change: 0 additions & 1 deletion zweb/src/org/zkoss/web/fn/ThemeFns.java
Expand Up @@ -16,7 +16,6 @@
*/
package org.zkoss.web.fn;

import java.awt.Color;
import java.io.UnsupportedEncodingException;
import java.util.Comparator;
import java.util.HashMap;
Expand Down

0 comments on commit 70df2f3

Please sign in to comment.