Statistics
| Revision:

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 / DefaultFeatureAttributeSelectionPanel.java @ 44713

History | View | Annotate | Download (3.46 KB)

1
package org.gvsig.fmap.dal.swing.impl.featuretype;
2

    
3
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeSelectionPanel;
4
import java.awt.Dimension;
5
import java.net.URL;
6
import javax.swing.ImageIcon;
7
import javax.swing.JComponent;
8
import org.apache.commons.io.FilenameUtils;
9
import org.gvsig.fmap.dal.complements.Search;
10
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
11
import org.gvsig.fmap.dal.feature.FeatureStore;
12
import org.gvsig.fmap.dal.swing.impl.featuretype.FeatureAttributeTreeModel.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 DefaultFeatureAttributeSelectionPanel
21
        extends DefaultFeatureAttributeSelectionPanelView
22
        implements FeatureAttributeSelectionPanel {
23

    
24
  private final FeatureStore store;
25

    
26
  public DefaultFeatureAttributeSelectionPanel(FeatureStore store) {
27
    this.store = store;
28
    this.initComponents();
29
  }
30

    
31
  private void initComponents() {
32
    FeatureAttributeTreeModel treeModel = new FeatureAttributeTreeModel(
33
            this.store,
34
            true,
35
            Search.BASIC_TYPES_FILTER
36
    );
37
    this.treeFields.setCellRenderer(new FeatureAttributeTreeCellRenderer());
38
    this.treeFields.setModel(treeModel);
39
    try {
40
      this.treeFields.setSelectionRow(1);
41
    } catch (Throwable th) {
42
    }
43

    
44
    Dimension sz = this.getPreferredSize();
45
    if (sz.width < DEFAULT_WIDTH) {
46
      sz.width = DEFAULT_WIDTH;
47
    }
48
    if (sz.height < DEFAULT_HEIGHT) {
49
      sz.height = DEFAULT_HEIGHT;
50
    }
51
    this.setPreferredSize(sz);
52
  }
53

    
54
  /**
55
   * Return a TreePath<FeatureAttributeTreeModel.Node> for the selected
56
   * attribute.
57
   *
58
   * @return
59
   */
60
  @Override
61
  public FeatureAttributeDescriptor[] getSelectedPath() {
62
    Node[] nodes = (Node[]) this.treeFields.getSelectionPath().getPath();
63
    FeatureAttributeDescriptor[] attrs = new FeatureAttributeDescriptor[nodes.length];
64
    for (int i = 0; i < attrs.length; i++) {
65
      attrs[i] = nodes[i].getValue();
66
    }
67
    return attrs;
68
  }
69

    
70
  @Override
71
  public FeatureAttributeDescriptor getSelectedAttributeDescriptor() {
72
    Node node = (Node) this.treeFields.getSelectionPath().getLastPathComponent();
73
    FeatureAttributeDescriptor attrdesc = node.getValue();
74
    return attrdesc;
75
  }
76

    
77
  @Override
78
  public FeatureStore getSelectedStore() {
79
    Node node = (Node) this.treeFields.getSelectionPath().getLastPathComponent();
80
    FeatureStore theStore = node.getFeatureStore();
81
    return theStore;
82
  }
83

    
84
  @Override
85
  public String getSelectedName() {
86
    return this.getSelectedAttributeDescriptor().getName();
87
  }
88
  
89
  @Override
90
  public JComponent asJComponent() {
91
    return this;
92
  }
93

    
94
  @Override
95
  public ImageIcon loadImage(String imageName) {
96
    String name = FilenameUtils.getBaseName(imageName);
97
    IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault();
98
    if (theme.exists(name)) {
99
      return theme.get(name);
100
    }
101
    URL url = this.getClass().getResource(name + ".png");
102
    if (url == null) {
103
      return null;
104
    }
105
    return new ImageIcon(url);
106
  }
107

    
108
  public static void selfRegister() {
109
    String[][] iconNames = new String[][]{
110
      new String[]{"dalswing", "common-filter"},};
111
    IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
112
    for (String[] icon : iconNames) {
113
      URL url = DefaultFeatureAttributeSelectionPanel.class.getResource(icon[1] + ".png");
114
      theme.registerDefault("DALSwing", icon[0], icon[1], null, url);
115
    }
116
  }
117
}