Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / awt / Color.java
1 package javajs.awt;
2
3 import javajs.api.GenericColor;
4
5 public class Color implements GenericColor {
6
7         public int argb;
8
9
10   @Override
11   public int getRGB() {
12                 return argb & 0x00FFFFFF;
13         }
14
15
16   @Override
17   public int getOpacity255() {
18                 return ((argb >> 24) & 0xFF);
19         }
20
21         
22   @Override
23   public void setOpacity255(int a) {
24                 argb = argb & 0xFFFFFF | ((a & 0xFF) << 24);
25         }
26
27         public static GenericColor get1(int rgb) {
28                 Color c = new Color();
29                 c.argb = rgb | 0xFF000000;
30                 return c;
31         }
32
33         public static GenericColor get3(int r, int g, int b) {
34                 return new Color().set4(r, g, b, 0xFF);
35         }
36
37         public static GenericColor get4(int r, int g, int b, int a) {
38                 return new Color().set4(r, g, b, a);
39         }
40
41         private GenericColor set4(int r, int g, int b, int a) {
42                 argb = ((a << 24) | (r << 16) | (g << 8) | b) & 0xFFFFFFFF;
43                 return this;
44         }
45
46   @Override
47   public String toString() {
48     String s = ("00000000" + Integer.toHexString(argb));
49     return "[0x" + s.substring(s.length() - 8, s.length()) + "]";
50   }
51
52         
53 }