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 | 40561 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40561 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40561 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40561 | jjdelcerro | * 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 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.gui.beans.listview.painters; |
||
25 | |||
26 | 42097 | mcompany | import java.awt.*; |
27 | 40435 | jjdelcerro | import java.util.ArrayList; |
28 | |||
29 | import org.gvsig.gui.beans.listview.IListViewPainter; |
||
30 | import org.gvsig.gui.beans.listview.ListViewItem; |
||
31 | 42097 | mcompany | import org.gvsig.i18n.Messages; |
32 | |||
33 | 40435 | jjdelcerro | /**
|
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 | 42097 | mcompany | ArrayList items = null; |
40 | 40435 | jjdelcerro | |
41 | 42097 | mcompany | int iconsWidth = 35; |
42 | 40435 | jjdelcerro | |
43 | 42097 | mcompany | int minIconsWidth = 35; |
44 | 40435 | jjdelcerro | |
45 | 42097 | mcompany | Dimension lastDimension = new Dimension(0, 0); |
46 | 40435 | jjdelcerro | |
47 | 42097 | mcompany | public PaintList(ArrayList items) { |
48 | this.items = items;
|
||
49 | } |
||
50 | 40435 | jjdelcerro | |
51 | 42097 | mcompany | /*
|
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 | 40435 | jjdelcerro | |
59 | 42097 | mcompany | /*
|
60 | * (non-Javadoc)
|
||
61 | * @see
|
||
62 | * org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
|
||
63 | */
|
||
64 | public Dimension getPreferredSize() { |
||
65 | return lastDimension;
|
||
66 | } |
||
67 | 40435 | jjdelcerro | |
68 | 42097 | mcompany | /*
|
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 | 40435 | jjdelcerro | |
77 | 42097 | mcompany | 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 | 40435 | jjdelcerro | |
87 | 42097 | mcompany | int height2 = 0; |
88 | int width2 = 0; |
||
89 | for (int i = 0; i < items.size(); i++) { |
||
90 | ((ListViewItem) items.get(i)).setNameRectangle(null);
|
||
91 | 40435 | jjdelcerro | |
92 | 42097 | mcompany | 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 | 40435 | jjdelcerro | |
102 | 42097 | mcompany | ((ListViewItem) items.get(i)).getItemRectangle().setBounds(visibleRect.x, |
103 | i * 17, visibleRect.width, 17); |
||
104 | 40435 | jjdelcerro | |
105 | 42097 | mcompany | if (!((ListViewItem) items.get(i)).getItemRectangle().intersects(
|
106 | visibleRect)) continue;
|
||
107 | 40435 | jjdelcerro | |
108 | 42097 | mcompany | int upper = fm.getLeading() + fm.getAscent()
|
109 | + ((17 - fm.getHeight()) / 2); |
||
110 | 40435 | jjdelcerro | |
111 | 42097 | mcompany | 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 | 40435 | jjdelcerro | } |