gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / colortable / ui / library / ColorTableIconPainter.java @ 2818
History | View | Annotate | Download (3.89 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool.colortable.ui.library; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Graphics2D; |
26 |
import java.awt.Rectangle; |
27 |
import java.util.List; |
28 |
|
29 |
import org.gvsig.fmap.dal.coverage.datastruct.ColorItem; |
30 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
31 |
import org.gvsig.gui.ColorTablePainter; |
32 |
import org.gvsig.gui.beans.listview.IIconPaint; |
33 |
/**
|
34 |
* Clase para dibujar los iconos del ListViewComponent del panel de color. Se
|
35 |
* puede indicar si la paleta esta seleccionada y si se dibuja con
|
36 |
* interpolaciones.
|
37 |
*
|
38 |
* @version 29/06/2007
|
39 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
40 |
*/
|
41 |
public class ColorTableIconPainter implements IIconPaint, ColorTablePainter { |
42 |
private ColorTable colorTable;
|
43 |
|
44 |
/**
|
45 |
* Construye un ColorTablePaint con una tabla de color pasada por parametro
|
46 |
* @param colorTable
|
47 |
*/
|
48 |
public ColorTableIconPainter(ColorTable colorTable) {
|
49 |
this.colorTable = colorTable;
|
50 |
} |
51 |
|
52 |
/**
|
53 |
* Define si los valores estan interpolados o no entre si
|
54 |
* @param value
|
55 |
*/
|
56 |
public void setInterpolated(boolean value) { |
57 |
colorTable.setInterpolated(value); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Obtiene el ColorTable
|
62 |
* @return
|
63 |
*/
|
64 |
public ColorTable getColorTable() {
|
65 |
return colorTable;
|
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see org.gvsig.gui.ColorTablePainter#getColors()
|
71 |
*/
|
72 |
public Color[] getColors() { |
73 |
List<ColorItem> cItem = colorTable.getColorItems();
|
74 |
Color[] colorList = new Color[cItem.size()]; |
75 |
for (int i = 0; i < colorList.length; i++) { |
76 |
colorList[i] = cItem.get(i).getColor(); |
77 |
} |
78 |
return colorList;
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Metodo de pintado de la tabla de color
|
83 |
* @param g
|
84 |
* @param isSelected
|
85 |
*/
|
86 |
public void paint(Graphics2D g, boolean isSelected) { |
87 |
Rectangle area = g.getClipBounds();
|
88 |
|
89 |
int x1 = area.x;
|
90 |
int x2 = area.x + area.width - 1; |
91 |
|
92 |
Color bgColor = new Color(224, 224, 224); |
93 |
for (int i = 0; (i * 4) <= area.width; i++) { |
94 |
for (int j = 0; (j * 4) <= area.height; j++) { |
95 |
if ((i + j) % 2 == 0) |
96 |
g.setColor(Color.white);
|
97 |
else
|
98 |
g.setColor(bgColor); |
99 |
g.fillRect(area.x + 1 + i * 4, area.y + 1 + j * 4, 4, 4); |
100 |
} |
101 |
} |
102 |
|
103 |
if (colorTable.getColorItems().size() >= 1) { |
104 |
double min = ((ColorItem) colorTable.getColorItems().get(0)).getValue(); |
105 |
double max = ((ColorItem) colorTable.getColorItems().get(colorTable.getColorItems().size() - 1)).getValue(); |
106 |
for (int i = area.x; i < (area.x + area.width); i++) { |
107 |
double pos = min + (((max - min) * (i - area.x)) / (area.width - 2)); |
108 |
|
109 |
byte[] col3 = colorTable.getRGBAByBand(pos); |
110 |
g.setColor(new Color(col3[0] & 0xff, col3[1] & 0xff, col3[2] & 0xff, col3[3] & 0xff)); |
111 |
g.drawLine(i, area.y, i, area.y + area.height); |
112 |
} |
113 |
} else {
|
114 |
g.setColor(new Color(224, 224, 224)); |
115 |
g.fillRect(x1, area.y, x2 - x1, area.height - 1);
|
116 |
} |
117 |
if (isSelected)
|
118 |
g.setColor(Color.black);
|
119 |
else
|
120 |
g.setColor(new Color(96, 96, 96)); |
121 |
g.drawRect(x1, area.y, x2 - x1, area.height - 1);
|
122 |
} |
123 |
|
124 |
/*
|
125 |
* (non-Javadoc)
|
126 |
* @see org.gvsig.gui.ColorTablePainter#getTableName()
|
127 |
*/
|
128 |
public String getTableName() { |
129 |
return colorTable.getName();
|
130 |
} |
131 |
} |