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 / featuretype / FeatureAttributeTreeCellRenderer.java @ 47426
History | View | Annotate | Download (4.25 KB)
1 | 44713 | jjdelcerro | package org.gvsig.fmap.dal.swing.impl.featuretype; |
---|---|---|---|
2 | 44262 | jjdelcerro | |
3 | import java.awt.Component; |
||
4 | 44263 | jjdelcerro | import java.awt.FlowLayout; |
5 | import javax.swing.Icon; |
||
6 | 47426 | jjdelcerro | import javax.swing.ImageIcon; |
7 | 44262 | jjdelcerro | import javax.swing.JLabel; |
8 | 44263 | jjdelcerro | import javax.swing.JPanel; |
9 | 44262 | jjdelcerro | import javax.swing.JTree; |
10 | 44263 | jjdelcerro | import javax.swing.border.EmptyBorder; |
11 | 44262 | jjdelcerro | import javax.swing.tree.DefaultTreeCellRenderer; |
12 | 44263 | jjdelcerro | import javax.swing.tree.TreeCellRenderer; |
13 | 44684 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
14 | 47426 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
15 | 44713 | jjdelcerro | import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTreeModel.Node; |
16 | 44718 | omartinez | import org.gvsig.tools.swing.api.CompoundIcon; |
17 | 44262 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
18 | import org.gvsig.tools.swing.icontheme.IconTheme; |
||
19 | |||
20 | /**
|
||
21 | *
|
||
22 | * @author jjdelcerro
|
||
23 | */
|
||
24 | 44713 | jjdelcerro | public class FeatureAttributeTreeCellRenderer |
25 | 44718 | omartinez | extends DefaultTreeCellRenderer |
26 | 44263 | jjdelcerro | implements TreeCellRenderer |
27 | { |
||
28 | 44262 | jjdelcerro | |
29 | 44263 | jjdelcerro | private final Icon iconTable; |
30 | private final Icon iconColumn; |
||
31 | private final Icon iconForeingKey; |
||
32 | 44718 | omartinez | // private final JPanel panel;
|
33 | // private final JLabel icon;
|
||
34 | // private final DefaultTreeCellRenderer label;
|
||
35 | 44263 | jjdelcerro | private final IconTheme iconTheme; |
36 | 47426 | jjdelcerro | private final ImageIcon iconColumnQueryCalculated; |
37 | private final ImageIcon iconColumnTableCalculated; |
||
38 | 44262 | jjdelcerro | |
39 | 44713 | jjdelcerro | public FeatureAttributeTreeCellRenderer() {
|
40 | 44263 | jjdelcerro | this.iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
|
41 | this.iconTable = iconTheme.get("featurestore-table"); |
||
42 | this.iconColumn = iconTheme.get("featurestore-column"); |
||
43 | 47426 | jjdelcerro | this.iconColumnTableCalculated = iconTheme.get("featurestore-calculated-column"); |
44 | this.iconColumnQueryCalculated = iconTheme.get("featurestore-query-calculated-column"); |
||
45 | 44263 | jjdelcerro | this.iconForeingKey = iconTheme.get("featurestore-foreing-key"); |
46 | |||
47 | 44718 | omartinez | // this.panel = new JPanel();
|
48 | // this.panel.setLayout(new FlowLayout(FlowLayout.LEADING, 3, 2));
|
||
49 | // this.icon = new JLabel();
|
||
50 | // this.label = new DefaultTreeCellRenderer();
|
||
51 | // this.panel.add(this.icon);
|
||
52 | // this.panel.add(this.label);
|
||
53 | // this.panel.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||
54 | // this.panel.setOpaque(false);
|
||
55 | 44263 | jjdelcerro | |
56 | 44262 | jjdelcerro | } |
57 | |||
58 | @Override
|
||
59 | public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
||
60 | 44718 | omartinez | JLabel theLabel = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); |
61 | 44262 | jjdelcerro | if( !(value instanceof Node) ) { |
62 | 44263 | jjdelcerro | return theLabel;
|
63 | 44262 | jjdelcerro | } |
64 | Node node = (Node) value; |
||
65 | 47426 | jjdelcerro | FeatureAttributeDescriptor attrdesc = node.getValue(); |
66 | Icon iconElement;
|
||
67 | if( node.isRoot() ) {
|
||
68 | iconElement = this.iconTable;
|
||
69 | } else if( attrdesc == null ) { |
||
70 | iconElement = leaf? this.iconColumn: this.iconForeingKey; |
||
71 | } else if( attrdesc.isForeingKey() ) { |
||
72 | iconElement = this.iconForeingKey;
|
||
73 | } else if( attrdesc.isComputed() ) { |
||
74 | iconElement = (attrdesc.getStore()==null)? this.iconColumnQueryCalculated: this.iconColumnTableCalculated; |
||
75 | } else {
|
||
76 | iconElement = iconColumn; |
||
77 | } |
||
78 | // Icon iconElement = node.isRoot()? this.iconTable: leaf? this.iconColumn: this.iconForeingKey;
|
||
79 | 44263 | jjdelcerro | Icon iconDataType = null; |
80 | try {
|
||
81 | if( !node.isRoot() ) {
|
||
82 | String iconName = node.getValue().getDataType().getIconName();
|
||
83 | iconDataType = this.iconTheme.get(iconName);
|
||
84 | } |
||
85 | } catch(Exception ex) { |
||
86 | |||
87 | 44262 | jjdelcerro | } |
88 | 44684 | jjdelcerro | String s = node.getLabel();
|
89 | if( StringUtils.isBlank(s) ) {
|
||
90 | s = "???";
|
||
91 | } |
||
92 | 44718 | omartinez | theLabel.setText(s); |
93 | if (iconDataType != null) { |
||
94 | CompoundIcon compoundIcon = ToolsSwingLocator.getToolsSwingManager().createCompoundIcon(iconElement, iconDataType); |
||
95 | theLabel.setIcon(compoundIcon); |
||
96 | } else {
|
||
97 | theLabel.setIcon(iconElement); |
||
98 | 44684 | jjdelcerro | } |
99 | 44718 | omartinez | |
100 | //
|
||
101 | // this.label.setText(s);
|
||
102 | // try {
|
||
103 | // this.label.setIcon(iconDataType);
|
||
104 | // this.icon.setIcon(iconElement);
|
||
105 | // this.label.invalidate();
|
||
106 | // } catch(Throwable th) {
|
||
107 | // th.getMessage(); // To allow set a break point
|
||
108 | // }
|
||
109 | return theLabel; //return this.label |
||
110 | 44262 | jjdelcerro | } |
111 | |||
112 | |||
113 | } |