Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / listview / painters / SmallIcon.java @ 12623

History | View | Annotate | Download (3.81 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.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 SmallIcon implements IListViewPainter {
38

    
39
        ListViewComponent parent;
40
        ArrayList items = null;
41
        int iconsWidth = 40;
42
        int minIconsWidth = 40;
43
        int iconsHeight = 28;
44
        Dimension lastDimension = new Dimension(0, 0);
45
        int cols = 0;
46

    
47
        public SmallIcon(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 "SmallIcon";
57
        }
58

    
59
        /*
60
         * (non-Javadoc)
61
         * @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
62
         */
63
        public Dimension getPreferredSize() {
64
                return lastDimension;
65
        }
66

    
67
        /*
68
         * (non-Javadoc)
69
         * @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D, int, int)
70
         */
71
        public void paint(Graphics2D g, Rectangle visibleRect) {
72
                int aux = (int) Math.floor(visibleRect.getWidth() / (minIconsWidth + 2));
73
                if (aux > items.size())
74
                        aux = items.size();
75
                iconsWidth = (int) (Math.floor(visibleRect.getWidth() / aux) - 2);
76

    
77
                int height2 = 0;
78

    
79
                int posX = 0;
80
                int posY = 0;
81
                cols = 0;
82
                for (int i = 0; i < items.size(); i++) {
83
                        // Evito que se pueda editar el nombre
84
                        ((ListViewItem) items.get(i)).setNameRectangle(null);
85
                        ((ListViewItem) items.get(i)).setItemRectangle(null);
86

    
87
                        ((ListViewItem) items.get(i)).setShowTooltip(true);
88
                        if (posX != 0) {
89
                                if (((posX + 1) * (iconsWidth + 2)) > visibleRect.getWidth()) {
90
                                        posX = 0;
91
                                        posY++;
92
                                }
93
                        }
94

    
95
                        Rectangle rectangleItem = new Rectangle(posX * (iconsWidth + 2) + 1, (posY * (iconsHeight + 2)) + 1, iconsWidth - 1, iconsHeight - 1);
96
                        if (rectangleItem.intersects(visibleRect)) {
97
                                if (((ListViewItem) items.get(i)).isSelected()) {
98
                                        g.setColor(new Color(49, 106, 197));
99
                                        g.fillRect(posX * (iconsWidth + 2), posY * (iconsHeight + 2), iconsWidth + 2, iconsHeight + 2);
100
                                }
101

    
102
                                Shape clip = g.getClip();
103
                                g.translate(posX * (iconsWidth + 2) + 1, (posY * (iconsHeight + 2)) + 1);
104
                                g.setClip(0, 0, iconsWidth, iconsHeight);
105

    
106
                                if (((ListViewItem) items.get(i)).getIcon() != null)
107
                                        ((ListViewItem) items.get(i)).getIcon().paint(g, ((ListViewItem) items.get(i)).isSelected());
108

    
109
                                g.setClip(clip);
110
                                g.translate(- (posX * (iconsWidth + 2) + 1), - ((posY * (iconsHeight + 2)) + 1));
111

    
112
                                ((ListViewItem) items.get(i)).setItemRectangle(rectangleItem);
113
                        }
114

    
115
                        if (height2 < ((posY + 1) * (iconsHeight + 2)))
116
                                height2 = (posY + 1) * (iconsHeight + 2);
117

    
118
                        if (cols < posX)
119
                                cols = posX;
120

    
121
                        posX++;
122
                }
123

    
124
                lastDimension = new Dimension(minIconsWidth + 2, height2);
125
        }
126
}