Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / graphic / listview / painters / LargeIcon.java @ 12592

History | View | Annotate | Download (3.93 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.graphic.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.graphic.listview.IListViewPainter;
29
import org.gvsig.gui.beans.graphic.listview.ListViewComponent;
30
import org.gvsig.gui.beans.graphic.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

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

    
93
                        if (((ListViewItem) items.get(i)).isSelected()) {
94
                                g.setColor(new Color(49, 106, 197));
95
                                g.fillRect(posX * (iconsWidth + 2), posY * (iconsHeight + 2), iconsWidth + 2, iconsHeight + 2);
96
                        }
97

    
98
                        Shape clip = g.getClip();
99
                        g.translate(posX * (iconsWidth + 2) + 1, (posY * (iconsHeight + 2)) + 1);
100
                        g.setClip(0, 0, iconsWidth, iconsHeight);
101

    
102
                        if (((ListViewItem) items.get(i)).getIcon() != null)
103
                                ((ListViewItem) items.get(i)).getIcon().paint(g, ((ListViewItem) items.get(i)).isSelected());
104

    
105
                        g.setClip(clip);
106
                        g.translate(-(posX * (iconsWidth + 2) + 1), -((posY * (iconsHeight + 2)) + 1));
107

    
108
                        if (height2 < ((posY + 1) * (iconsHeight + 2)))
109
                                height2 = (posY + 1) * (iconsHeight + 2);
110

    
111
                        if (cols < posX)
112
                                cols = posX;
113

    
114
                        posX++;
115
                }
116

    
117
                lastDimension = new Dimension(minIconsWidth + 2, height2);
118
        }
119

    
120
        /*
121
         * (non-Javadoc)
122
         * @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getItem(int, int)
123
         */
124
        public int getItem(int x, int y) {
125
                if (((cols + 1) * (iconsWidth + 2)) < x)
126
                        return -1;
127

    
128
                int col = (int) Math.floor(x / (iconsWidth + 2));
129
                int row = (int) Math.floor(y / (iconsHeight + 2));
130

    
131
                int pos = ((row * (cols + 1)) + col);
132
                if ((pos >= 0) && (pos < items.size()))
133
                        return pos;
134

    
135
                return -1;
136
        }
137
}