Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src-test-ui / org / gvsig / rastertools / colortableJaume / PaintItem.java @ 12942

History | View | Annotate | Download (2.67 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.rastertools.colortableJaume;
20

    
21
import java.awt.Color;
22
import java.awt.Component;
23
import java.awt.Dimension;
24
import java.awt.FontMetrics;
25
import java.awt.GradientPaint;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.Rectangle;
29

    
30
import org.gvsig.rastertools.colortable.ui.ColorTablePaint;
31
/**
32
 *
33
 * @version 17/04/2007
34
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
35
 */
36
public class PaintItem extends Component {
37
        private static final long serialVersionUID = -6448740563809113949L;
38
//        private ListViewItem listViewItem = null;
39
        private boolean isSelected = false;
40
        private String name = "";
41
        private ColorTablePaint colorTablePaint = null;
42

    
43
        public PaintItem(String name, ColorTablePaint colorTablePaint, boolean isSelected) {
44
                this.name = name;
45
                this.colorTablePaint = colorTablePaint;
46
                this.isSelected = isSelected;
47

    
48
                setSize(getWidth(), 19);
49
                setPreferredSize(new Dimension(getWidth(), 19));
50
        }
51

    
52
        public void paint(Graphics g) {
53
                Graphics2D g2 = (Graphics2D) g;
54
                if (isSelected) {
55
                        Color color1 = new Color(89, 153, 229);
56
                        Color color2 = new Color(31, 92, 207);
57
                        g2.setPaint(new GradientPaint(0, 1, color1, 0, getHeight() - 1, color2, false));
58
                        g2.fillRect(0, 1, getWidth(), getHeight() - 1);
59
                        g2.setColor(new Color(61, 123, 218));
60
                        g2.drawLine(0, 0, getWidth(), 0);
61
                        g2.setColor(Color.white);
62
                } else {
63
                        g2.setColor(Color.white);
64
                        g2.fillRect(0, 0, getWidth(), getHeight());
65
                        g2.setColor(Color.black);
66
                }
67

    
68
                Rectangle bounds = getBounds();
69

    
70
                FontMetrics fm = g2.getFontMetrics();
71
                int upper = (bounds.height + fm.getHeight()) / 2 - fm.getDescent();
72

    
73
                g2.setClip(bounds.x, 0, bounds.width, bounds.height);
74
                g2.drawString(name, bounds.width - 146, upper);
75

    
76
                g2.setClip(bounds.x, 0, bounds.width - 150, bounds.height);
77

    
78
                colorTablePaint.paint((Graphics2D) g2, isSelected);
79
        }
80
}