root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / listview / painters / PaintList.java @ 12623
History | View | Annotate | Download (4.52 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.gui.beans.listview.painters; |
20 |
|
21 |
import java.awt.Color; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.FontMetrics; |
24 |
import java.awt.GradientPaint; |
25 |
import java.awt.Graphics2D; |
26 |
import java.awt.Rectangle; |
27 |
import java.awt.Shape; |
28 |
import java.util.ArrayList; |
29 |
|
30 |
import org.gvsig.gui.beans.listview.IListViewPainter; |
31 |
import org.gvsig.gui.beans.listview.ListViewComponent; |
32 |
import org.gvsig.gui.beans.listview.ListViewItem; |
33 |
/**
|
34 |
* @version 28/06/2007
|
35 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
36 |
*/
|
37 |
public class PaintList implements IListViewPainter { |
38 |
ListViewComponent parent; |
39 |
ArrayList items = null; |
40 |
int iconsWidth = 35; |
41 |
int minIconsWidth = 35; |
42 |
Dimension lastDimension = new Dimension(0, 0); |
43 |
|
44 |
public PaintList(ArrayList items) { |
45 |
this.items = items;
|
46 |
} |
47 |
|
48 |
/*
|
49 |
* (non-Javadoc)
|
50 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName()
|
51 |
*/
|
52 |
public String getName() { |
53 |
return "List"; |
54 |
} |
55 |
|
56 |
/*
|
57 |
* (non-Javadoc)
|
58 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
|
59 |
*/
|
60 |
public Dimension getPreferredSize() { |
61 |
return lastDimension;
|
62 |
} |
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D, int, int)
|
67 |
*/
|
68 |
public void paint(Graphics2D g, Rectangle visibleRect) { |
69 |
FontMetrics fm = g.getFontMetrics();
|
70 |
|
71 |
int minAux = 0; |
72 |
for (int i = 0; i < items.size(); i++) { |
73 |
int auxWidth = g.getFontMetrics().stringWidth(((ListViewItem) items.get(i)).getName()) + 8; |
74 |
if (minAux < auxWidth)
|
75 |
minAux = auxWidth; |
76 |
} |
77 |
minAux = visibleRect.width - minAux; |
78 |
if (minAux < minIconsWidth)
|
79 |
minAux = minIconsWidth; |
80 |
iconsWidth = minAux; |
81 |
|
82 |
int height2 = 0; |
83 |
int width2 = 0; |
84 |
for (int i = 0; i < items.size(); i++) { |
85 |
((ListViewItem) items.get(i)).setNameRectangle(null);
|
86 |
((ListViewItem) items.get(i)).setItemRectangle(null);
|
87 |
|
88 |
int auxWidth = g.getFontMetrics().stringWidth(((ListViewItem) items.get(i)).getName());
|
89 |
if ((minIconsWidth + 3 + auxWidth - visibleRect.x) > visibleRect.width) { |
90 |
((ListViewItem) items.get(i)).setShowTooltip(true);
|
91 |
} else {
|
92 |
((ListViewItem) items.get(i)).setShowTooltip(false);
|
93 |
} |
94 |
if (width2 < auxWidth)
|
95 |
width2 = auxWidth; |
96 |
|
97 |
if ((((i + 1) * 17) < visibleRect.y) || ((i * 17) > (visibleRect.y + visibleRect.height))) |
98 |
continue;
|
99 |
|
100 |
int upper = fm.getLeading() + fm.getAscent() + ((17 - fm.getHeight()) / 2); |
101 |
|
102 |
if (((ListViewItem) items.get(i)).isSelected()) {
|
103 |
Color color1 = new Color(89, 153, 229); |
104 |
Color color2 = new Color(31, 92, 207); |
105 |
g.setPaint(new GradientPaint(0, i * 17 + 1, color1, 0, i * 17 + 16, color2, false)); |
106 |
g.fillRect(visibleRect.x, i * 17 + 1, visibleRect.width, 16); |
107 |
g.setColor(new Color(61, 123, 218)); |
108 |
g.drawLine(visibleRect.x, i * 17, visibleRect.x + visibleRect.width, i * 17); |
109 |
g.setColor(Color.white);
|
110 |
} else {
|
111 |
g.setColor(Color.black);
|
112 |
} |
113 |
g.drawString(((ListViewItem) items.get(i)).getName(), iconsWidth + 3, (i * 17) + upper); |
114 |
// Guardar el estado de donde se visualiza el nombre y cuanto ocupa
|
115 |
((ListViewItem) items.get(i)).setNameRectangle(new Rectangle(iconsWidth + 2, i * 17 - 1, visibleRect.width - (iconsWidth + 2), 20)); |
116 |
|
117 |
Shape clip = g.getClip();
|
118 |
g.translate(1, i * 17 + 1); |
119 |
g.setClip(0, 0, iconsWidth, 15); |
120 |
|
121 |
((ListViewItem) items.get(i)).setItemRectangle(new Rectangle(visibleRect.x, i * 17, visibleRect.width, 17)); |
122 |
|
123 |
if (((ListViewItem) items.get(i)).getIcon() != null) |
124 |
((ListViewItem) items.get(i)).getIcon().paint(g, ((ListViewItem) items.get(i)).isSelected()); |
125 |
|
126 |
g.setClip(clip); |
127 |
g.translate(-1, -(i * 17 + 1)); |
128 |
} |
129 |
height2 = items.size() * 17;
|
130 |
|
131 |
lastDimension = new Dimension(minIconsWidth + 3 + width2, height2); |
132 |
//lastDimension = new Dimension(0, height2);
|
133 |
} |
134 |
} |