svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / searchpanel / AdvancedAttributeSelectionTreeCellRenderer.java @ 44263
History | View | Annotate | Download (2.61 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.FlowLayout; |
5 |
import javax.swing.Icon; |
6 |
import javax.swing.JLabel; |
7 |
import javax.swing.JPanel; |
8 |
import javax.swing.JTree; |
9 |
import javax.swing.border.EmptyBorder; |
10 |
import javax.swing.tree.DefaultTreeCellRenderer; |
11 |
import javax.swing.tree.TreeCellRenderer; |
12 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.AdvancedAttributeSelectionTreeModel.Node; |
13 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
14 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
15 |
|
16 |
/**
|
17 |
*
|
18 |
* @author jjdelcerro
|
19 |
*/
|
20 |
public class AdvancedAttributeSelectionTreeCellRenderer |
21 |
// extends DefaultTreeCellRenderer
|
22 |
implements TreeCellRenderer |
23 |
{ |
24 |
|
25 |
private final Icon iconTable; |
26 |
private final Icon iconColumn; |
27 |
private final Icon iconForeingKey; |
28 |
private final JPanel panel; |
29 |
private final JLabel icon; |
30 |
private final DefaultTreeCellRenderer label; |
31 |
private final IconTheme iconTheme; |
32 |
|
33 |
public AdvancedAttributeSelectionTreeCellRenderer() {
|
34 |
this.iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
|
35 |
this.iconTable = iconTheme.get("featurestore-table"); |
36 |
this.iconColumn = iconTheme.get("featurestore-column"); |
37 |
this.iconForeingKey = iconTheme.get("featurestore-foreing-key"); |
38 |
|
39 |
this.panel = new JPanel(); |
40 |
this.panel.setLayout(new FlowLayout(FlowLayout.LEADING, 3, 2)); |
41 |
this.icon = new JLabel(); |
42 |
this.label = new DefaultTreeCellRenderer(); |
43 |
this.panel.add(this.icon); |
44 |
this.panel.add(this.label); |
45 |
this.panel.setBorder(new EmptyBorder(0, 0, 0, 0)); |
46 |
this.panel.setOpaque(false); |
47 |
|
48 |
} |
49 |
|
50 |
@Override
|
51 |
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
52 |
JLabel theLabel = (JLabel) this.label.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); |
53 |
if( !(value instanceof Node) ) { |
54 |
return theLabel;
|
55 |
} |
56 |
Node node = (Node) value; |
57 |
Icon iconElement = node.isRoot()? this.iconTable: leaf? this.iconColumn: this.iconForeingKey; |
58 |
Icon iconDataType = null; |
59 |
try {
|
60 |
if( !node.isRoot() ) {
|
61 |
String iconName = node.getValue().getDataType().getIconName();
|
62 |
iconDataType = this.iconTheme.get(iconName);
|
63 |
} |
64 |
} catch(Exception ex) { |
65 |
|
66 |
} |
67 |
this.label.setIcon(iconDataType);
|
68 |
this.label.setText(node.getLabel());
|
69 |
this.icon.setIcon(iconElement);
|
70 |
return this.panel; |
71 |
} |
72 |
|
73 |
|
74 |
} |