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 | 40561 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40561 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40561 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40561 | jjdelcerro | * 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 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.gui.beans.listview.painters; |
||
25 | |||
26 | 42097 | mcompany | import java.awt.*; |
27 | 40435 | jjdelcerro | import java.util.ArrayList; |
28 | |||
29 | import org.gvsig.gui.beans.listview.IListViewPainter; |
||
30 | import org.gvsig.gui.beans.listview.ListViewItem; |
||
31 | 42097 | mcompany | import org.gvsig.i18n.Messages; |
32 | |||
33 | 40435 | jjdelcerro | /**
|
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 | 42097 | mcompany | ArrayList items = null; |
42 | 40435 | jjdelcerro | |
43 | 42097 | mcompany | int iconsWidth = 82; |
44 | 40435 | jjdelcerro | |
45 | 42097 | mcompany | int minIconsWidth = 82; |
46 | 40435 | jjdelcerro | |
47 | 42097 | mcompany | int iconsHeight = 28; |
48 | 40435 | jjdelcerro | |
49 | 42097 | mcompany | Dimension lastDimension = new Dimension(0, 0); |
50 | 40435 | jjdelcerro | |
51 | 42097 | mcompany | int cols = 0; |
52 | 40435 | jjdelcerro | |
53 | 42097 | mcompany | public LargeIcon(ArrayList items) { |
54 | this.items = items;
|
||
55 | } |
||
56 | 40435 | jjdelcerro | |
57 | 42097 | mcompany | /*
|
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 | 40435 | jjdelcerro | |
65 | 42097 | mcompany | /*
|
66 | * (non-Javadoc)
|
||
67 | * @see
|
||
68 | * org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
|
||
69 | */
|
||
70 | public Dimension getPreferredSize() { |
||
71 | return lastDimension;
|
||
72 | } |
||
73 | 40435 | jjdelcerro | |
74 | 42097 | mcompany | /*
|
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 | 40435 | jjdelcerro | |
85 | 42097 | mcompany | int height2 = 0; |
86 | 40435 | jjdelcerro | |
87 | 42097 | mcompany | 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 | 40435 | jjdelcerro | |
94 | 42097 | mcompany | ((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 | 40435 | jjdelcerro | |
102 | 42097 | mcompany | ((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 | 40435 | jjdelcerro | |
113 | 42097 | mcompany | 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 | 40435 | jjdelcerro | } |