Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / listview / painters / LargeIcon.java @ 42097

History | View | Annotate | Download (3.93 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.*;
27
import java.util.ArrayList;
28

    
29
import org.gvsig.gui.beans.listview.IListViewPainter;
30
import org.gvsig.gui.beans.listview.ListViewItem;
31
import org.gvsig.i18n.Messages;
32

    
33
/**
34
 * Iconos de 82x28
35
 *
36
 * @version 28/06/2007
37
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
38
 */
39
public class LargeIcon implements IListViewPainter {
40

    
41
  ArrayList items = null;
42

    
43
  int iconsWidth = 82;
44

    
45
  int minIconsWidth = 82;
46

    
47
  int iconsHeight = 28;
48

    
49
  Dimension lastDimension = new Dimension(0, 0);
50

    
51
  int cols = 0;
52

    
53
  public LargeIcon(ArrayList items) {
54
    this.items = items;
55
  }
56

    
57
  /*
58
   * (non-Javadoc)
59
   * @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName()
60
   */
61
  public String getName() {
62
    return Messages.getText("largeIcon");
63
  }
64

    
65
  /*
66
   * (non-Javadoc)
67
   * @see
68
   * org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
69
   */
70
  public Dimension getPreferredSize() {
71
    return lastDimension;
72
  }
73

    
74
  /*
75
   * (non-Javadoc)
76
   * @see
77
   * org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D
78
   * , int, int)
79
   */
80
  public void paint(Graphics2D g, Rectangle visibleRect) {
81
    int aux = (int) Math.floor(visibleRect.getWidth() / (minIconsWidth + 2));
82
    if (aux > items.size()) aux = items.size();
83
    iconsWidth = (int) (Math.floor(visibleRect.getWidth() / aux) - 2);
84

    
85
    int height2 = 0;
86

    
87
    int posX = 0;
88
    int posY = 0;
89
    cols = 0;
90
    for (int i = 0; i < items.size(); i++) {
91
      // Evito que se pueda editar el nombre
92
      ((ListViewItem) items.get(i)).setNameRectangle(null);
93

    
94
      ((ListViewItem) items.get(i)).setShowTooltip(true);
95
      if (posX != 0) {
96
        if (((posX + 1) * (iconsWidth + 2)) > visibleRect.getWidth()) {
97
          posX = 0;
98
          posY++;
99
        }
100
      }
101

    
102
      ((ListViewItem) items.get(i)).getItemRectangle().setBounds(
103
          posX * (iconsWidth + 2), (posY * (iconsHeight + 2)), iconsWidth + 2,
104
          iconsHeight + 2);
105
      if (((ListViewItem) items.get(i)).getItemRectangle().intersects(
106
          visibleRect)) {
107
        if (((ListViewItem) items.get(i)).isSelected()) {
108
          g.setColor(new Color(49, 106, 197));
109
          g.fillRect(posX * (iconsWidth + 2), posY * (iconsHeight + 2),
110
              iconsWidth + 2, iconsHeight + 2);
111
        }
112

    
113
        Shape clip = g.getClip();
114
        g.translate(posX * (iconsWidth + 2) + 1, (posY * (iconsHeight + 2)) + 1);
115
        g.setClip(0, 0, iconsWidth, iconsHeight);
116

    
117
        if (((ListViewItem) items.get(i)).getIcon() != null)
118
          ((ListViewItem) items.get(i)).getIcon().paint(g,
119
              ((ListViewItem) items.get(i)).isSelected());
120

    
121
        g.setClip(clip);
122
        g.translate(-(posX * (iconsWidth + 2) + 1),
123
            -((posY * (iconsHeight + 2)) + 1));
124
      }
125

    
126
      if (height2 < ((posY + 1) * (iconsHeight + 2)))
127
        height2 = (posY + 1) * (iconsHeight + 2);
128

    
129
      if (cols < posX) cols = posX;
130

    
131
      posX++;
132
    }
133

    
134
    lastDimension = new Dimension(minIconsWidth + 2, height2);
135
  }
136
}