Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / preferences / combocolortable / PreferenceColorTableIconPainter.java @ 17491

History | View | Annotate | Download (3.97 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.gui.preferences.combocolortable;
20

    
21
import java.awt.Color;
22
import java.awt.Graphics2D;
23
import java.awt.Rectangle;
24
import java.util.ArrayList;
25

    
26
import org.gvsig.gui.beans.listview.IIconPaint;
27
import org.gvsig.raster.datastruct.ColorItem;
28
import org.gvsig.raster.datastruct.ColorTable;
29
/**
30
 * Clase para dibujar los iconos del ListViewComponent del panel de color. Se
31
 * puede indicar si la paleta esta seleccionada y si se dibuja con
32
 * interpolaciones.
33
 * 
34
 * @version 29/06/2007
35
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
36
 */
37
public class PreferenceColorTableIconPainter implements IIconPaint {
38
        private ColorTable colorTable;
39

    
40
        /**
41
         * Construye un ColorTablePaint con una tabla de color pasada por parametro
42
         * @param colorTable
43
         */
44
        public PreferenceColorTableIconPainter(ColorTable colorTable) {
45
                this.colorTable = colorTable;
46
        }
47

    
48
        /**
49
         * Define si los valores estan interpolados o no entre si
50
         * @param value
51
         */
52
        public void setInterpolated(boolean value) {
53
                colorTable.setInterpolated(value);
54
        }
55

    
56
        /**
57
         * Obtiene el array de los colores de la paleta de color
58
         * @return
59
         */
60
        public ArrayList getColorItems() {
61
                return colorTable.getColorItems();
62
        }
63

    
64
        /**
65
         * Obtiene el ColorTable
66
         * @return
67
         */
68
        public ColorTable getColorTable() {
69
                return colorTable;
70
        }
71

    
72
        /**
73
         * Especificar los colores de la tabla de color, definiendo si estan los
74
         * valores interpolados y si la paleta se comprimira o no.
75
         * @param value
76
         * @param interpolated
77
         * @param compress
78
         */
79
        public void setColorItems(ArrayList value, boolean interpolated, boolean compress) {
80
                colorTable.createPaletteFromColorItems(value, compress);
81
                setInterpolated(interpolated);
82
        }
83

    
84
        /**
85
         * Metodo de pintado de la tabla de color
86
         * @param g
87
         * @param isSelected
88
         */
89
        public void paint(Graphics2D g, boolean isSelected) {
90
                Rectangle area = g.getClipBounds();
91

    
92
                int x1 = area.x;
93
                int x2 = area.x + area.width - 1;
94

    
95
                Color bgColor = new Color(224, 224, 224);
96
                for (int i = 0; (i * 4) <= area.width; i++) {
97
                        for (int j = 0; (j * 4) <= area.height; j++) {
98
                                if ((i + j) % 2 == 0)
99
                                        g.setColor(Color.white);
100
                                else
101
                                        g.setColor(bgColor);
102
                                g.fillRect(area.x + 1 + i * 4, area.y + 1 + j * 4, 4, 4);
103
                        }
104
                }                
105
                
106
                if (colorTable.getColorItems().size() >= 1) {
107
                        double min = ((ColorItem) colorTable.getColorItems().get(0)).getValue();
108
                        double max = ((ColorItem) colorTable.getColorItems().get(colorTable.getColorItems().size() - 1)).getValue();
109
                        for (int i = area.x; i < (area.x + area.width); i++) {
110
                                double pos = min + (((max - min) * (i - area.x)) / (area.width - 2));
111

    
112
                                byte[] col3 = colorTable.getRGBAByBand(pos);
113
                                g.setColor(new Color(col3[0] & 0xff, col3[1] & 0xff, col3[2] & 0xff, col3[3] & 0xff));
114
                                g.drawLine(i, area.y, i, area.y + area.height);
115
                        }
116
                } else {
117
                        g.setColor(new Color(224, 224, 224));
118
                        g.fillRect(x1, area.y, x2 - x1, area.height - 1);
119
                }
120
                if (isSelected)
121
                        g.setColor(Color.black);
122
                else
123
                        g.setColor(new Color(96, 96, 96));
124
                g.drawRect(x1, area.y, x2 - x1, area.height - 1);
125
        }        
126
}