Revision 42097 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.ui/src/main/java/org/gvsig/gui/beans/listview/painters/SmallIcon.java
SmallIcon.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.gui.beans.listview.painters; |
25 | 25 |
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.Dimension; |
|
28 |
import java.awt.Graphics2D; |
|
29 |
import java.awt.Rectangle; |
|
30 |
import java.awt.Shape; |
|
26 |
import java.awt.*; |
|
31 | 27 |
import java.util.ArrayList; |
32 | 28 |
|
33 | 29 |
import org.gvsig.gui.beans.listview.IListViewPainter; |
34 | 30 |
import org.gvsig.gui.beans.listview.ListViewItem; |
31 |
import org.gvsig.i18n.Messages; |
|
32 |
|
|
35 | 33 |
/** |
36 | 34 |
* Iconos de 82x28 |
37 | 35 |
* |
... | ... | |
39 | 37 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
40 | 38 |
*/ |
41 | 39 |
public class SmallIcon implements IListViewPainter { |
42 |
ArrayList items = null; |
|
43 |
int iconsWidth = 40; |
|
44 |
int minIconsWidth = 40; |
|
45 |
int iconsHeight = 28; |
|
46 |
Dimension lastDimension = new Dimension(0, 0); |
|
47 |
int cols = 0; |
|
48 | 40 |
|
49 |
public SmallIcon(ArrayList items) { |
|
50 |
this.items = items; |
|
51 |
} |
|
41 |
ArrayList items = null; |
|
52 | 42 |
|
53 |
/* |
|
54 |
* (non-Javadoc) |
|
55 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName() |
|
56 |
*/ |
|
57 |
public String getName() { |
|
58 |
return "SmallIcon"; |
|
59 |
} |
|
43 |
int iconsWidth = 40; |
|
60 | 44 |
|
61 |
/* |
|
62 |
* (non-Javadoc) |
|
63 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize() |
|
64 |
*/ |
|
65 |
public Dimension getPreferredSize() { |
|
66 |
return lastDimension; |
|
67 |
} |
|
45 |
int minIconsWidth = 40; |
|
68 | 46 |
|
69 |
/* |
|
70 |
* (non-Javadoc) |
|
71 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D, int, int) |
|
72 |
*/ |
|
73 |
public void paint(Graphics2D g, Rectangle visibleRect) { |
|
74 |
int aux = (int) Math.floor(visibleRect.getWidth() / (minIconsWidth + 2)); |
|
75 |
if (aux > items.size()) |
|
76 |
aux = items.size(); |
|
77 |
iconsWidth = (int) (Math.floor(visibleRect.getWidth() / aux) - 2); |
|
47 |
int iconsHeight = 28; |
|
78 | 48 |
|
79 |
int height2 = 0;
|
|
49 |
Dimension lastDimension = new Dimension(0, 0);
|
|
80 | 50 |
|
81 |
int posX = 0; |
|
82 |
int posY = 0; |
|
83 |
cols = 0; |
|
84 |
for (int i = 0; i < items.size(); i++) { |
|
85 |
// Evito que se pueda editar el nombre |
|
86 |
((ListViewItem) items.get(i)).setNameRectangle(null); |
|
51 |
int cols = 0; |
|
87 | 52 |
|
88 |
((ListViewItem) items.get(i)).setShowTooltip(true); |
|
89 |
if (posX != 0) { |
|
90 |
if (((posX + 1) * (iconsWidth + 2)) > visibleRect.getWidth()) { |
|
91 |
posX = 0; |
|
92 |
posY++; |
|
93 |
} |
|
94 |
} |
|
53 |
public SmallIcon(ArrayList items) { |
|
54 |
this.items = items; |
|
55 |
} |
|
95 | 56 |
|
96 |
((ListViewItem) items.get(i)).getItemRectangle().setBounds(posX * (iconsWidth + 2), (posY * (iconsHeight + 2)), iconsWidth + 2, iconsHeight + 2); |
|
97 |
if (((ListViewItem) items.get(i)).getItemRectangle().intersects(visibleRect)) { |
|
98 |
if (((ListViewItem) items.get(i)).isSelected()) { |
|
99 |
g.setColor(new Color(49, 106, 197)); |
|
100 |
g.fillRect(posX * (iconsWidth + 2), posY * (iconsHeight + 2), iconsWidth + 2, iconsHeight + 2); |
|
101 |
} |
|
57 |
/* |
|
58 |
* (non-Javadoc) |
|
59 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName() |
|
60 |
*/ |
|
61 |
public String getName() { |
|
62 |
return Messages.getText("smallIcon"); |
|
63 |
} |
|
102 | 64 |
|
103 |
Shape clip = g.getClip(); |
|
104 |
g.translate(posX * (iconsWidth + 2) + 1, (posY * (iconsHeight + 2)) + 1); |
|
105 |
g.setClip(0, 0, iconsWidth, iconsHeight); |
|
65 |
/* |
|
66 |
* (non-Javadoc) |
|
67 |
* @see |
|
68 |
* org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize() |
|
69 |
*/ |
|
70 |
public Dimension getPreferredSize() { |
|
71 |
return lastDimension; |
|
72 |
} |
|
106 | 73 |
|
107 |
if (((ListViewItem) items.get(i)).getIcon() != null) |
|
108 |
((ListViewItem) items.get(i)).getIcon().paint(g, ((ListViewItem) items.get(i)).isSelected()); |
|
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); |
|
109 | 84 |
|
110 |
g.setClip(clip); |
|
111 |
g.translate(- (posX * (iconsWidth + 2) + 1), - ((posY * (iconsHeight + 2)) + 1)); |
|
112 |
} |
|
85 |
int height2 = 0; |
|
113 | 86 |
|
114 |
if (height2 < ((posY + 1) * (iconsHeight + 2))) |
|
115 |
height2 = (posY + 1) * (iconsHeight + 2); |
|
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); |
|
116 | 93 |
|
117 |
if (cols < posX) |
|
118 |
cols = posX; |
|
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 |
} |
|
119 | 101 |
|
120 |
posX++; |
|
121 |
} |
|
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 |
} |
|
122 | 112 |
|
123 |
lastDimension = new Dimension(minIconsWidth + 2, height2); |
|
124 |
} |
|
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 |
} |
|
125 | 136 |
} |
Also available in: Unified diff