Last change
on this file since 192 was
192,
checked in by vmipsl, 13 years ago
|
Servlet _ Contour en cours _ package gov2
|
File size:
1.3 KB
|
Line | |
---|
1 | package gov.noaa.pmel.util; |
---|
2 | |
---|
3 | import java.util.*; |
---|
4 | import java.awt.*; |
---|
5 | |
---|
6 | |
---|
7 | public class IndexedColorMap { |
---|
8 | String mParamName; |
---|
9 | double mMinVal; |
---|
10 | double mMaxVal; |
---|
11 | double[] mVals = null; |
---|
12 | Color[] mColors = null; |
---|
13 | int mNumColors; |
---|
14 | ColorMap mColorMap; |
---|
15 | |
---|
16 | public IndexedColorMap(ColorMap inCM, int numColors) { |
---|
17 | mNumColors = numColors; |
---|
18 | mColorMap = inCM; |
---|
19 | mVals = new double[mNumColors]; |
---|
20 | mColors = new Color[mNumColors]; |
---|
21 | |
---|
22 | // initialize the indexed colormap |
---|
23 | mMinVal = mColorMap.getMinValue(); |
---|
24 | mMaxVal = mColorMap.getMaxValue(); |
---|
25 | mParamName = new String(mColorMap.getParamName()); |
---|
26 | |
---|
27 | double delta = (mMaxVal - mMinVal)/(double)mNumColors; |
---|
28 | |
---|
29 | for (int i=0; i<mNumColors; i++) { |
---|
30 | mVals[i] = mMinVal + (double)i * delta; |
---|
31 | } |
---|
32 | |
---|
33 | mVals[mNumColors-1] = mMaxVal; |
---|
34 | |
---|
35 | for (int i=0; i<mNumColors; i++) { |
---|
36 | mColors[i] = mColorMap.getColor(mVals[i]); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | public IndexedColorMap(IndexedColorMap inMap) { |
---|
41 | // copy constructor |
---|
42 | } |
---|
43 | |
---|
44 | // public methods |
---|
45 | public Color getColor(double inVal) { |
---|
46 | return new Color(1.0f, 1.0f, 1.0f); |
---|
47 | } |
---|
48 | |
---|
49 | public Color getColor(int index) { |
---|
50 | if (index < 0) |
---|
51 | return mColors[0]; |
---|
52 | else if (index >= mNumColors) |
---|
53 | return mColors[mNumColors-1]; |
---|
54 | else |
---|
55 | return mColors[index]; |
---|
56 | } |
---|
57 | |
---|
58 | public Color[] getColors() { |
---|
59 | return mColors; |
---|
60 | } |
---|
61 | |
---|
62 | public String getParamName() { |
---|
63 | return mParamName; |
---|
64 | } |
---|
65 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.