root / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / utils / SelectedLayersListCellRenderer.java @ 8110
History | View | Annotate | Download (1.9 KB)
1 |
package es.prodevelop.cit.gvsig.arcims.gui.panels.utils; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
|
5 |
import javax.swing.DefaultListCellRenderer; |
6 |
import javax.swing.Icon; |
7 |
import javax.swing.JComponent; |
8 |
import javax.swing.JList; |
9 |
import javax.swing.UIManager; |
10 |
import javax.swing.border.Border; |
11 |
import javax.swing.border.EmptyBorder; |
12 |
|
13 |
/**
|
14 |
* This class sets the tool tips in a JList component.
|
15 |
*
|
16 |
* @author jldominguez
|
17 |
*/
|
18 |
public class SelectedLayersListCellRenderer extends DefaultListCellRenderer { |
19 |
|
20 |
private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, |
21 |
1);
|
22 |
private static final long serialVersionUID = 0; |
23 |
|
24 |
public SelectedLayersListCellRenderer() {
|
25 |
super();
|
26 |
} |
27 |
|
28 |
/**
|
29 |
* Sets special graphic properties (colors, and tool tips) in list elements
|
30 |
* and returns <tt>this</tt>.
|
31 |
*/
|
32 |
public Component getListCellRendererComponent(JList list, Object value, |
33 |
int index, boolean isSelected, boolean cellHasFocus) { |
34 |
|
35 |
JComponent jc;
|
36 |
LayersListElement lle; |
37 |
setComponentOrientation(list.getComponentOrientation()); |
38 |
|
39 |
if (isSelected) {
|
40 |
setBackground(list.getSelectionBackground()); |
41 |
setForeground(list.getSelectionForeground()); |
42 |
} else {
|
43 |
setBackground(list.getBackground()); |
44 |
setForeground(list.getForeground()); |
45 |
} |
46 |
|
47 |
if (value instanceof Icon) { |
48 |
setIcon((Icon) value);
|
49 |
setText("");
|
50 |
} else {
|
51 |
setIcon(null);
|
52 |
setText((value == null) ? "" : value.toString()); |
53 |
} |
54 |
|
55 |
setEnabled(list.isEnabled()); |
56 |
setFont(list.getFont()); |
57 |
setBorder((cellHasFocus) ? UIManager
|
58 |
.getBorder("List.focusCellHighlightBorder")
|
59 |
: getNoFocusBorder()); |
60 |
|
61 |
// Set the specific tool tip:
|
62 |
if (value instanceof LayersListElement) { |
63 |
lle = (LayersListElement) value; |
64 |
jc = (JComponent) this; |
65 |
jc.setToolTipText(lle.toolTipText()); |
66 |
} |
67 |
|
68 |
return this; |
69 |
} |
70 |
|
71 |
private static Border getNoFocusBorder() { |
72 |
if (System.getSecurityManager() != null) { |
73 |
return SAFE_NO_FOCUS_BORDER;
|
74 |
} else {
|
75 |
return noFocusBorder;
|
76 |
} |
77 |
} |
78 |
|
79 |
} |