Revision 44263 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

View differences:

AdvancedAttributeSelectionTreeCellRenderer.java
1 1
package org.gvsig.fmap.dal.swing.impl.searchpanel;
2 2

  
3 3
import java.awt.Component;
4
import javax.swing.ImageIcon;
4
import java.awt.FlowLayout;
5
import javax.swing.Icon;
5 6
import javax.swing.JLabel;
7
import javax.swing.JPanel;
6 8
import javax.swing.JTree;
9
import javax.swing.border.EmptyBorder;
7 10
import javax.swing.tree.DefaultTreeCellRenderer;
11
import javax.swing.tree.TreeCellRenderer;
8 12
import org.gvsig.fmap.dal.swing.impl.searchpanel.AdvancedAttributeSelectionTreeModel.Node;
9 13
import org.gvsig.tools.swing.api.ToolsSwingLocator;
10 14
import org.gvsig.tools.swing.icontheme.IconTheme;
......
13 17
 *
14 18
 * @author jjdelcerro
15 19
 */
16
public class AdvancedAttributeSelectionTreeCellRenderer extends DefaultTreeCellRenderer {
20
public class AdvancedAttributeSelectionTreeCellRenderer 
21
//        extends DefaultTreeCellRenderer 
22
        implements TreeCellRenderer
23
    {
17 24
    
18
    private final ImageIcon iconTable;
19
    private final ImageIcon iconColumn;
20
    private final ImageIcon iconForeingKey;
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;
21 32
    
22 33
    public AdvancedAttributeSelectionTreeCellRenderer() {
23
        IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
24
        this.iconTable = theme.get("featurestore-table");
25
        this.iconColumn = theme.get("featurestore-column");
26
        this.iconForeingKey = theme.get("featurestore-foreing-key");
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
        
27 48
    }
28 49
    
29 50
    @Override
30 51
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
31
        JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); //To change body of generated methods, choose Tools | Templates.
52
        JLabel theLabel = (JLabel) this.label.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 
32 53
        if( !(value instanceof Node) ) {
33
            return label;
54
            return theLabel;
34 55
        }
35 56
        Node node = (Node) value;
36
        if( node.isRoot() ) {
37
            label.setIcon(this.iconTable);
38
            label.setText(node.getLabel());
39
            return label;
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
            
40 66
        }
41
        if( leaf ) {
42
            label.setIcon(this.iconColumn);
43
            label.setText(node.getLabel());
44
            return label;
45
        }
46
        label.setIcon(this.iconForeingKey);
47
        label.setText(node.getLabel());
48
        return label;
67
        this.label.setIcon(iconDataType);
68
        this.label.setText(node.getLabel());
69
        this.icon.setIcon(iconElement);
70
        return this.panel;
49 71
    }
50 72
    
51 73
    

Also available in: Unified diff