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