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