svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / listview / painters / SmallIcon.java @ 40561
History | View | Annotate | Download (3.75 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.Color; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Graphics2D; |
29 |
import java.awt.Rectangle; |
30 |
import java.awt.Shape; |
31 |
import java.util.ArrayList; |
32 |
|
33 |
import org.gvsig.gui.beans.listview.IListViewPainter; |
34 |
import org.gvsig.gui.beans.listview.ListViewItem; |
35 |
/**
|
36 |
* Iconos de 82x28
|
37 |
*
|
38 |
* @version 28/06/2007
|
39 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
40 |
*/
|
41 |
public class SmallIcon implements IListViewPainter { |
42 |
ArrayList items = null; |
43 |
int iconsWidth = 40; |
44 |
int minIconsWidth = 40; |
45 |
int iconsHeight = 28; |
46 |
Dimension lastDimension = new Dimension(0, 0); |
47 |
int cols = 0; |
48 |
|
49 |
public SmallIcon(ArrayList items) { |
50 |
this.items = items;
|
51 |
} |
52 |
|
53 |
/*
|
54 |
* (non-Javadoc)
|
55 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName()
|
56 |
*/
|
57 |
public String getName() { |
58 |
return "SmallIcon"; |
59 |
} |
60 |
|
61 |
/*
|
62 |
* (non-Javadoc)
|
63 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
|
64 |
*/
|
65 |
public Dimension getPreferredSize() { |
66 |
return lastDimension;
|
67 |
} |
68 |
|
69 |
/*
|
70 |
* (non-Javadoc)
|
71 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D, int, int)
|
72 |
*/
|
73 |
public void paint(Graphics2D g, Rectangle visibleRect) { |
74 |
int aux = (int) Math.floor(visibleRect.getWidth() / (minIconsWidth + 2)); |
75 |
if (aux > items.size())
|
76 |
aux = items.size(); |
77 |
iconsWidth = (int) (Math.floor(visibleRect.getWidth() / aux) - 2); |
78 |
|
79 |
int height2 = 0; |
80 |
|
81 |
int posX = 0; |
82 |
int posY = 0; |
83 |
cols = 0;
|
84 |
for (int i = 0; i < items.size(); i++) { |
85 |
// Evito que se pueda editar el nombre
|
86 |
((ListViewItem) items.get(i)).setNameRectangle(null);
|
87 |
|
88 |
((ListViewItem) items.get(i)).setShowTooltip(true);
|
89 |
if (posX != 0) { |
90 |
if (((posX + 1) * (iconsWidth + 2)) > visibleRect.getWidth()) { |
91 |
posX = 0;
|
92 |
posY++; |
93 |
} |
94 |
} |
95 |
|
96 |
((ListViewItem) items.get(i)).getItemRectangle().setBounds(posX * (iconsWidth + 2), (posY * (iconsHeight + 2)), iconsWidth + 2, iconsHeight + 2); |
97 |
if (((ListViewItem) items.get(i)).getItemRectangle().intersects(visibleRect)) {
|
98 |
if (((ListViewItem) items.get(i)).isSelected()) {
|
99 |
g.setColor(new Color(49, 106, 197)); |
100 |
g.fillRect(posX * (iconsWidth + 2), posY * (iconsHeight + 2), iconsWidth + 2, iconsHeight + 2); |
101 |
} |
102 |
|
103 |
Shape clip = g.getClip();
|
104 |
g.translate(posX * (iconsWidth + 2) + 1, (posY * (iconsHeight + 2)) + 1); |
105 |
g.setClip(0, 0, iconsWidth, iconsHeight); |
106 |
|
107 |
if (((ListViewItem) items.get(i)).getIcon() != null) |
108 |
((ListViewItem) items.get(i)).getIcon().paint(g, ((ListViewItem) items.get(i)).isSelected()); |
109 |
|
110 |
g.setClip(clip); |
111 |
g.translate(- (posX * (iconsWidth + 2) + 1), - ((posY * (iconsHeight + 2)) + 1)); |
112 |
} |
113 |
|
114 |
if (height2 < ((posY + 1) * (iconsHeight + 2))) |
115 |
height2 = (posY + 1) * (iconsHeight + 2); |
116 |
|
117 |
if (cols < posX)
|
118 |
cols = posX; |
119 |
|
120 |
posX++; |
121 |
} |
122 |
|
123 |
lastDimension = new Dimension(minIconsWidth + 2, height2); |
124 |
} |
125 |
} |