svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / DefaultColorTablePainter.java @ 40561
History | View | Annotate | Download (2.83 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.Rectangle; |
29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
31 |
|
32 |
public class DefaultColorTablePainter implements ColorTablePainter { |
33 |
private class ColorItem { |
34 |
Color color = null; |
35 |
double value =0; |
36 |
|
37 |
ColorItem(double value, Color color) { |
38 |
this.color = color;
|
39 |
this.value = value;
|
40 |
} |
41 |
|
42 |
Color getColor() {
|
43 |
return color;
|
44 |
} |
45 |
|
46 |
double getValue() {
|
47 |
return value;
|
48 |
} |
49 |
} |
50 |
|
51 |
List<ColorItem> colorItems = null; |
52 |
|
53 |
DefaultColorTablePainter() { |
54 |
this.colorItems = new ArrayList<ColorItem>(); |
55 |
int n = 256; |
56 |
for( int i=0; i<n; i++) { |
57 |
Color color = Color.getHSBColor((float) i / (float) n, 0.85f, 1.0f); |
58 |
this.colorItems.add( new ColorItem(i,color)); |
59 |
} |
60 |
|
61 |
} |
62 |
|
63 |
public Color[] getColors() { |
64 |
Color[] colors = new Color[colorItems.size()]; |
65 |
for (int i = 0; i < colors.length; i++) { |
66 |
colors[i] = ((ColorItem) colorItems.get(i)).getColor(); |
67 |
} |
68 |
return colors;
|
69 |
} |
70 |
|
71 |
public String getTableName() { |
72 |
return "Default colot table"; |
73 |
} |
74 |
|
75 |
public void paint(Graphics2D g, boolean isSelected) { |
76 |
Rectangle area = g.getClipBounds();
|
77 |
area.y=0;
|
78 |
area.x=0;
|
79 |
int x1 = area.x;
|
80 |
int x2 = area.x + area.width - 1; |
81 |
|
82 |
if( this.colorItems.size() > 0 ) { |
83 |
double min = colorItems.get(0).getValue(); |
84 |
double max = colorItems.get(colorItems.size() - 1).getValue(); |
85 |
for (int i = area.x; i < (area.x + area.width - 1); i++) { |
86 |
double pos = min + (((max - min) * (i - area.x)) / (area.width - 2)); |
87 |
g.setColor(this.colorItems.get((int) pos).getColor()); |
88 |
g.drawLine(i, area.y, i, area.y + area.height); |
89 |
} |
90 |
} else {
|
91 |
g.setColor(new Color(224, 224, 224)); |
92 |
g.fillRect(x1, area.y, x2 - x1, area.height - 1);
|
93 |
} |
94 |
if (isSelected) {
|
95 |
g.setColor(Color.black);
|
96 |
} else {
|
97 |
g.setColor(new Color(96, 96, 96)); |
98 |
} |
99 |
g.drawRect(x1, area.y, x2 - x1, area.height - 1);
|
100 |
} |
101 |
|
102 |
} |