svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / listview / painters / PaintList.java @ 42097
History | View | Annotate | Download (4.66 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.listview.painters; |
25 |
|
26 |
import java.awt.*; |
27 |
import java.util.ArrayList; |
28 |
|
29 |
import org.gvsig.gui.beans.listview.IListViewPainter; |
30 |
import org.gvsig.gui.beans.listview.ListViewItem; |
31 |
import org.gvsig.i18n.Messages; |
32 |
|
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 |
|
39 |
ArrayList items = null; |
40 |
|
41 |
int iconsWidth = 35; |
42 |
|
43 |
int minIconsWidth = 35; |
44 |
|
45 |
Dimension lastDimension = new Dimension(0, 0); |
46 |
|
47 |
public PaintList(ArrayList items) { |
48 |
this.items = items;
|
49 |
} |
50 |
|
51 |
/*
|
52 |
* (non-Javadoc)
|
53 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName()
|
54 |
*/
|
55 |
public String getName() { |
56 |
return Messages.getText("list"); |
57 |
} |
58 |
|
59 |
/*
|
60 |
* (non-Javadoc)
|
61 |
* @see
|
62 |
* org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
|
63 |
*/
|
64 |
public Dimension getPreferredSize() { |
65 |
return lastDimension;
|
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see
|
71 |
* org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D
|
72 |
* , int, int)
|
73 |
*/
|
74 |
public void paint(Graphics2D g, Rectangle visibleRect) { |
75 |
FontMetrics fm = g.getFontMetrics();
|
76 |
|
77 |
int minAux = 0; |
78 |
for (int i = 0; i < items.size(); i++) { |
79 |
int auxWidth = g.getFontMetrics().stringWidth(
|
80 |
((ListViewItem) items.get(i)).getName()) + 8;
|
81 |
if (minAux < auxWidth) minAux = auxWidth;
|
82 |
} |
83 |
minAux = visibleRect.width - minAux; |
84 |
if (minAux < minIconsWidth) minAux = minIconsWidth;
|
85 |
iconsWidth = minAux; |
86 |
|
87 |
int height2 = 0; |
88 |
int width2 = 0; |
89 |
for (int i = 0; i < items.size(); i++) { |
90 |
((ListViewItem) items.get(i)).setNameRectangle(null);
|
91 |
|
92 |
int auxWidth = g.getFontMetrics().stringWidth(
|
93 |
((ListViewItem) items.get(i)).getName()); |
94 |
if ((minIconsWidth + 3 + auxWidth - visibleRect.x) > visibleRect.width) { |
95 |
((ListViewItem) items.get(i)).setShowTooltip(true);
|
96 |
} |
97 |
else {
|
98 |
((ListViewItem) items.get(i)).setShowTooltip(false);
|
99 |
} |
100 |
if (width2 < auxWidth) width2 = auxWidth;
|
101 |
|
102 |
((ListViewItem) items.get(i)).getItemRectangle().setBounds(visibleRect.x, |
103 |
i * 17, visibleRect.width, 17); |
104 |
|
105 |
if (!((ListViewItem) items.get(i)).getItemRectangle().intersects(
|
106 |
visibleRect)) continue;
|
107 |
|
108 |
int upper = fm.getLeading() + fm.getAscent()
|
109 |
+ ((17 - fm.getHeight()) / 2); |
110 |
|
111 |
if (((ListViewItem) items.get(i)).isSelected()) {
|
112 |
Color color1 = new Color(89, 153, 229); |
113 |
Color color2 = new Color(31, 92, 207); |
114 |
g.setPaint(new GradientPaint(0, i * 17 + 1, color1, 0, i * 17 + 16, |
115 |
color2, false));
|
116 |
g.fillRect(visibleRect.x, i * 17 + 1, visibleRect.width, 16); |
117 |
g.setColor(new Color(61, 123, 218)); |
118 |
g.drawLine(visibleRect.x, i * 17, visibleRect.x + visibleRect.width,
|
119 |
i * 17);
|
120 |
g.setColor(Color.white);
|
121 |
} |
122 |
else {
|
123 |
g.setColor(Color.black);
|
124 |
} |
125 |
g.drawString(((ListViewItem) items.get(i)).getName(), iconsWidth + 3,
|
126 |
(i * 17) + upper);
|
127 |
// Guardar el estado de donde se visualiza el nombre y cuanto ocupa
|
128 |
((ListViewItem) items.get(i)) |
129 |
.setNameRectangle(new Rectangle(iconsWidth + 2, i * 17 - 1, |
130 |
visibleRect.width - (iconsWidth + 2), 20)); |
131 |
|
132 |
Shape clip = g.getClip();
|
133 |
g.translate(1, i * 17 + 1); |
134 |
g.setClip(0, 0, iconsWidth, 15); |
135 |
|
136 |
if (((ListViewItem) items.get(i)).getIcon() != null) |
137 |
((ListViewItem) items.get(i)).getIcon().paint(g, |
138 |
((ListViewItem) items.get(i)).isSelected()); |
139 |
|
140 |
g.setClip(clip); |
141 |
g.translate(-1, -(i * 17 + 1)); |
142 |
} |
143 |
height2 = items.size() * 17;
|
144 |
|
145 |
lastDimension = new Dimension(minIconsWidth + 3 + width2, height2); |
146 |
// lastDimension = new Dimension(0, height2);
|
147 |
} |
148 |
} |