Revision 42097 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.ui/src/main/java/org/gvsig/gui/beans/listview/painters/PaintList.java
PaintList.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.FontMetrics; |
|
29 |
import java.awt.GradientPaint; |
|
30 |
import java.awt.Graphics2D; |
|
31 |
import java.awt.Rectangle; |
|
32 |
import java.awt.Shape; |
|
26 |
import java.awt.*; |
|
33 | 27 |
import java.util.ArrayList; |
34 | 28 |
|
35 | 29 |
import org.gvsig.gui.beans.listview.IListViewPainter; |
36 | 30 |
import org.gvsig.gui.beans.listview.ListViewItem; |
31 |
import org.gvsig.i18n.Messages; |
|
32 |
|
|
37 | 33 |
/** |
38 | 34 |
* @version 28/06/2007 |
39 | 35 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
40 | 36 |
*/ |
41 | 37 |
public class PaintList implements IListViewPainter { |
42 |
ArrayList items = null; |
|
43 |
int iconsWidth = 35; |
|
44 |
int minIconsWidth = 35; |
|
45 |
Dimension lastDimension = new Dimension(0, 0); |
|
46 | 38 |
|
47 |
public PaintList(ArrayList items) { |
|
48 |
this.items = items; |
|
49 |
} |
|
39 |
ArrayList items = null; |
|
50 | 40 |
|
51 |
/* |
|
52 |
* (non-Javadoc) |
|
53 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName() |
|
54 |
*/ |
|
55 |
public String getName() { |
|
56 |
return "List"; |
|
57 |
} |
|
41 |
int iconsWidth = 35; |
|
58 | 42 |
|
59 |
/* |
|
60 |
* (non-Javadoc) |
|
61 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize() |
|
62 |
*/ |
|
63 |
public Dimension getPreferredSize() { |
|
64 |
return lastDimension; |
|
65 |
} |
|
43 |
int minIconsWidth = 35; |
|
66 | 44 |
|
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 |
FontMetrics fm = g.getFontMetrics(); |
|
45 |
Dimension lastDimension = new Dimension(0, 0); |
|
73 | 46 |
|
74 |
int minAux = 0; |
|
75 |
for (int i = 0; i < items.size(); i++) { |
|
76 |
int auxWidth = g.getFontMetrics().stringWidth(((ListViewItem) items.get(i)).getName()) + 8; |
|
77 |
if (minAux < auxWidth) |
|
78 |
minAux = auxWidth; |
|
79 |
} |
|
80 |
minAux = visibleRect.width - minAux; |
|
81 |
if (minAux < minIconsWidth) |
|
82 |
minAux = minIconsWidth; |
|
83 |
iconsWidth = minAux; |
|
47 |
public PaintList(ArrayList items) { |
|
48 |
this.items = items; |
|
49 |
} |
|
84 | 50 |
|
85 |
int height2 = 0; |
|
86 |
int width2 = 0; |
|
87 |
for (int i = 0; i < items.size(); i++) { |
|
88 |
((ListViewItem) items.get(i)).setNameRectangle(null); |
|
51 |
/* |
|
52 |
* (non-Javadoc) |
|
53 |
* @see org.gvsig.gui.beans.graphic.listview.IListViewPainter#getName() |
|
54 |
*/ |
|
55 |
public String getName() { |
|
56 |
return Messages.getText("list"); |
|
57 |
} |
|
89 | 58 |
|
90 |
int auxWidth = g.getFontMetrics().stringWidth(((ListViewItem) items.get(i)).getName());
|
|
91 |
if ((minIconsWidth + 3 + auxWidth - visibleRect.x) > visibleRect.width) {
|
|
92 |
((ListViewItem) items.get(i)).setShowTooltip(true);
|
|
93 |
} else {
|
|
94 |
((ListViewItem) items.get(i)).setShowTooltip(false);
|
|
95 |
}
|
|
96 |
if (width2 < auxWidth)
|
|
97 |
width2 = auxWidth;
|
|
59 |
/*
|
|
60 |
* (non-Javadoc)
|
|
61 |
* @see
|
|
62 |
* org.gvsig.gui.beans.graphic.listview.IListViewPainter#getPreferredSize()
|
|
63 |
*/
|
|
64 |
public Dimension getPreferredSize() {
|
|
65 |
return lastDimension;
|
|
66 |
}
|
|
98 | 67 |
|
99 |
((ListViewItem) items.get(i)).getItemRectangle().setBounds(visibleRect.x, i * 17, visibleRect.width, 17); |
|
68 |
/* |
|
69 |
* (non-Javadoc) |
|
70 |
* @see |
|
71 |
* org.gvsig.gui.beans.graphic.listview.IListViewPainter#paint(java.awt.Graphics2D |
|
72 |
* , int, int) |
|
73 |
*/ |
|
74 |
public void paint(Graphics2D g, Rectangle visibleRect) { |
|
75 |
FontMetrics fm = g.getFontMetrics(); |
|
100 | 76 |
|
101 |
if (!((ListViewItem) items.get(i)).getItemRectangle().intersects(visibleRect)) |
|
102 |
continue; |
|
77 |
int minAux = 0; |
|
78 |
for (int i = 0; i < items.size(); i++) { |
|
79 |
int auxWidth = g.getFontMetrics().stringWidth( |
|
80 |
((ListViewItem) items.get(i)).getName()) + 8; |
|
81 |
if (minAux < auxWidth) minAux = auxWidth; |
|
82 |
} |
|
83 |
minAux = visibleRect.width - minAux; |
|
84 |
if (minAux < minIconsWidth) minAux = minIconsWidth; |
|
85 |
iconsWidth = minAux; |
|
103 | 86 |
|
104 |
int upper = fm.getLeading() + fm.getAscent() + ((17 - fm.getHeight()) / 2); |
|
87 |
int height2 = 0; |
|
88 |
int width2 = 0; |
|
89 |
for (int i = 0; i < items.size(); i++) { |
|
90 |
((ListViewItem) items.get(i)).setNameRectangle(null); |
|
105 | 91 |
|
106 |
if (((ListViewItem) items.get(i)).isSelected()) { |
|
107 |
Color color1 = new Color(89, 153, 229); |
|
108 |
Color color2 = new Color(31, 92, 207); |
|
109 |
g.setPaint(new GradientPaint(0, i * 17 + 1, color1, 0, i * 17 + 16, color2, false)); |
|
110 |
g.fillRect(visibleRect.x, i * 17 + 1, visibleRect.width, 16); |
|
111 |
g.setColor(new Color(61, 123, 218)); |
|
112 |
g.drawLine(visibleRect.x, i * 17, visibleRect.x + visibleRect.width, i * 17); |
|
113 |
g.setColor(Color.white); |
|
114 |
} else { |
|
115 |
g.setColor(Color.black); |
|
116 |
} |
|
117 |
g.drawString(((ListViewItem) items.get(i)).getName(), iconsWidth + 3, (i * 17) + upper); |
|
118 |
// Guardar el estado de donde se visualiza el nombre y cuanto ocupa |
|
119 |
((ListViewItem) items.get(i)).setNameRectangle(new Rectangle(iconsWidth + 2, i * 17 - 1, visibleRect.width - (iconsWidth + 2), 20)); |
|
92 |
int auxWidth = g.getFontMetrics().stringWidth( |
|
93 |
((ListViewItem) items.get(i)).getName()); |
|
94 |
if ((minIconsWidth + 3 + auxWidth - visibleRect.x) > visibleRect.width) { |
|
95 |
((ListViewItem) items.get(i)).setShowTooltip(true); |
|
96 |
} |
|
97 |
else { |
|
98 |
((ListViewItem) items.get(i)).setShowTooltip(false); |
|
99 |
} |
|
100 |
if (width2 < auxWidth) width2 = auxWidth; |
|
120 | 101 |
|
121 |
Shape clip = g.getClip(); |
|
122 |
g.translate(1, i * 17 + 1); |
|
123 |
g.setClip(0, 0, iconsWidth, 15); |
|
102 |
((ListViewItem) items.get(i)).getItemRectangle().setBounds(visibleRect.x, |
|
103 |
i * 17, visibleRect.width, 17); |
|
124 | 104 |
|
125 |
if (((ListViewItem) items.get(i)).getIcon() != null)
|
|
126 |
((ListViewItem) items.get(i)).getIcon().paint(g, ((ListViewItem) items.get(i)).isSelected());
|
|
105 |
if (!((ListViewItem) items.get(i)).getItemRectangle().intersects(
|
|
106 |
visibleRect)) continue;
|
|
127 | 107 |
|
128 |
g.setClip(clip); |
|
129 |
g.translate(-1, -(i * 17 + 1)); |
|
130 |
} |
|
131 |
height2 = items.size() * 17; |
|
108 |
int upper = fm.getLeading() + fm.getAscent() |
|
109 |
+ ((17 - fm.getHeight()) / 2); |
|
132 | 110 |
|
133 |
lastDimension = new Dimension(minIconsWidth + 3 + width2, height2); |
|
134 |
//lastDimension = new Dimension(0, height2); |
|
135 |
} |
|
111 |
if (((ListViewItem) items.get(i)).isSelected()) { |
|
112 |
Color color1 = new Color(89, 153, 229); |
|
113 |
Color color2 = new Color(31, 92, 207); |
|
114 |
g.setPaint(new GradientPaint(0, i * 17 + 1, color1, 0, i * 17 + 16, |
|
115 |
color2, false)); |
|
116 |
g.fillRect(visibleRect.x, i * 17 + 1, visibleRect.width, 16); |
|
117 |
g.setColor(new Color(61, 123, 218)); |
|
118 |
g.drawLine(visibleRect.x, i * 17, visibleRect.x + visibleRect.width, |
|
119 |
i * 17); |
|
120 |
g.setColor(Color.white); |
|
121 |
} |
|
122 |
else { |
|
123 |
g.setColor(Color.black); |
|
124 |
} |
|
125 |
g.drawString(((ListViewItem) items.get(i)).getName(), iconsWidth + 3, |
|
126 |
(i * 17) + upper); |
|
127 |
// Guardar el estado de donde se visualiza el nombre y cuanto ocupa |
|
128 |
((ListViewItem) items.get(i)) |
|
129 |
.setNameRectangle(new Rectangle(iconsWidth + 2, i * 17 - 1, |
|
130 |
visibleRect.width - (iconsWidth + 2), 20)); |
|
131 |
|
|
132 |
Shape clip = g.getClip(); |
|
133 |
g.translate(1, i * 17 + 1); |
|
134 |
g.setClip(0, 0, iconsWidth, 15); |
|
135 |
|
|
136 |
if (((ListViewItem) items.get(i)).getIcon() != null) |
|
137 |
((ListViewItem) items.get(i)).getIcon().paint(g, |
|
138 |
((ListViewItem) items.get(i)).isSelected()); |
|
139 |
|
|
140 |
g.setClip(clip); |
|
141 |
g.translate(-1, -(i * 17 + 1)); |
|
142 |
} |
|
143 |
height2 = items.size() * 17; |
|
144 |
|
|
145 |
lastDimension = new Dimension(minIconsWidth + 3 + width2, height2); |
|
146 |
// lastDimension = new Dimension(0, height2); |
|
147 |
} |
|
136 | 148 |
} |
Also available in: Unified diff