View Javadoc

1   // Copyright 2000, CERN, Geneva, Switzerland and University of Santa Cruz, California, U.S.A.
2   package org.freehep.graphicsio.ps;
3   
4   import java.awt.Color;
5   
6   /**
7    * 
8    * @author Charles Loomis
9    * @version $Id: MappedColor.java 8584 2006-08-10 23:06:37Z duns $
10   */
11  public class MappedColor extends java.awt.Color {
12  
13      /**
14       * Index of the color in the color map.
15       */
16      protected int colorIndex;
17  
18      /**
19       * Value of the brightness/darkness of this color. Larger values indicate
20       * darker colors and vice versa.
21       */
22      protected int brightness;
23  
24      /**
25       * Constructor takes the RGB color components and the color index.
26       */
27      public MappedColor(int r, int g, int b, int colorIndex) {
28  
29          // Call the Color constructor.
30          super(r, g, b);
31  
32          // Set the color index and brightness.
33          this.colorIndex = colorIndex;
34          brightness = 0;
35      }
36  
37      /**
38       * Constructor takes the RGB color components, the color index, and the
39       * brightness.
40       */
41      public MappedColor(int r, int g, int b, int colorIndex, int brightness) {
42  
43          // Call the Color constructor.
44          super(r, g, b);
45  
46          // Set the color index and brightness.
47          this.colorIndex = colorIndex;
48          this.brightness = brightness;
49      }
50  
51      /**
52       * Make a brightened color based on this color.
53       */
54      public Color brighter() {
55  
56          int r = getRed() * 10 / 7;
57          int g = getGreen() * 10 / 7;
58          int b = getBlue() * 10 / 7;
59  
60          r = (int) Math.max(0, Math.min(255, r));
61          g = (int) Math.max(0, Math.min(255, g));
62          b = (int) Math.max(0, Math.min(255, b));
63  
64          return (Color) new MappedColor(r, g, b, colorIndex, brightness - 1);
65      }
66  
67      /**
68       * Make a darkened color based on this color.
69       */
70      public Color darker() {
71  
72          int r = getRed() * 7 / 10;
73          int g = getGreen() * 7 / 10;
74          int b = getBlue() * 7 / 10;
75  
76          r = (int) Math.max(0, Math.min(255, r));
77          g = (int) Math.max(0, Math.min(255, g));
78          b = (int) Math.max(0, Math.min(255, b));
79  
80          return (Color) new MappedColor(r, g, b, colorIndex, brightness - 1);
81      }
82  
83      /**
84       * Get the brightness of this color.
85       */
86      public int getBrightness() {
87          return brightness;
88      }
89  
90      /**
91       * Get the tag associated with this color.
92       */
93      public String getColorTag() {
94          return ColorMap.getTag(colorIndex);
95      }
96  
97  }