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 |
package org.gvsig.fmap.dal.swing.impl.featuretype; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.FlowLayout; |
5 |
import javax.swing.Icon; |
6 |
import javax.swing.ImageIcon; |
7 |
import javax.swing.JLabel; |
8 |
import javax.swing.JPanel; |
9 |
import javax.swing.JTree; |
10 |
import javax.swing.border.EmptyBorder; |
11 |
import javax.swing.tree.DefaultTreeCellRenderer; |
12 |
import javax.swing.tree.TreeCellRenderer; |
13 |
import org.apache.commons.lang3.StringUtils; |
14 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
15 |
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTreeModel.Node; |
16 |
import org.gvsig.tools.swing.api.CompoundIcon; |
17 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
18 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author jjdelcerro
|
23 |
*/
|
24 |
public class FeatureAttributeTreeCellRenderer |
25 |
extends DefaultTreeCellRenderer |
26 |
implements TreeCellRenderer |
27 |
{ |
28 |
|
29 |
private final Icon iconTable; |
30 |
private final Icon iconColumn; |
31 |
private final Icon iconForeingKey; |
32 |
// private final JPanel panel;
|
33 |
// private final JLabel icon;
|
34 |
// private final DefaultTreeCellRenderer label;
|
35 |
private final IconTheme iconTheme; |
36 |
private final ImageIcon iconColumnQueryCalculated; |
37 |
private final ImageIcon iconColumnTableCalculated; |
38 |
|
39 |
public FeatureAttributeTreeCellRenderer() {
|
40 |
this.iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
|
41 |
this.iconTable = iconTheme.get("featurestore-table"); |
42 |
this.iconColumn = iconTheme.get("featurestore-column"); |
43 |
this.iconColumnTableCalculated = iconTheme.get("featurestore-calculated-column"); |
44 |
this.iconColumnQueryCalculated = iconTheme.get("featurestore-query-calculated-column"); |
45 |
this.iconForeingKey = iconTheme.get("featurestore-foreing-key"); |
46 |
|
47 |
// 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 |
|
56 |
} |
57 |
|
58 |
@Override
|
59 |
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
60 |
JLabel theLabel = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); |
61 |
if( !(value instanceof Node) ) { |
62 |
return theLabel;
|
63 |
} |
64 |
Node node = (Node) value; |
65 |
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 |
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 |
} |
88 |
String s = node.getLabel();
|
89 |
if( StringUtils.isBlank(s) ) {
|
90 |
s = "???";
|
91 |
} |
92 |
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 |
} |
99 |
|
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 |
} |
111 |
|
112 |
|
113 |
} |