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 | 12821 | bsanchez | /* 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 | 12823 | bsanchez | import java.awt.Component; |
23 | 12821 | bsanchez | 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 | 12942 | bsanchez | import org.gvsig.rastertools.colortable.ui.ColorTablePaint; |
31 | 12821 | bsanchez | /**
|
32 | *
|
||
33 | * @version 17/04/2007
|
||
34 | * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
||
35 | */
|
||
36 | 12823 | bsanchez | public class PaintItem extends Component { |
37 | 12821 | bsanchez | private static final long serialVersionUID = -6448740563809113949L; |
38 | 12823 | bsanchez | // private ListViewItem listViewItem = null;
|
39 | 12821 | bsanchez | private boolean isSelected = false; |
40 | 12823 | bsanchez | private String name = ""; |
41 | private ColorTablePaint colorTablePaint = null; |
||
42 | 12821 | bsanchez | |
43 | 12823 | bsanchez | public PaintItem(String name, ColorTablePaint colorTablePaint, boolean isSelected) { |
44 | this.name = name;
|
||
45 | this.colorTablePaint = colorTablePaint;
|
||
46 | 12821 | bsanchez | this.isSelected = isSelected;
|
47 | |||
48 | setSize(getWidth(), 19);
|
||
49 | setPreferredSize(new Dimension(getWidth(), 19)); |
||
50 | } |
||
51 | |||
52 | 12823 | bsanchez | public void paint(Graphics g) { |
53 | 12821 | bsanchez | 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 | 12823 | bsanchez | g2.drawString(name, bounds.width - 146, upper);
|
75 | 12821 | bsanchez | |
76 | g2.setClip(bounds.x, 0, bounds.width - 150, bounds.height); |
||
77 | |||
78 | 12823 | bsanchez | colorTablePaint.paint((Graphics2D) g2, isSelected);
|
79 | 12821 | bsanchez | } |
80 | } |