Statistics
| Revision:

svn-gvsig-desktop / trunk / prototypes / mobile / desktop / extensions / extExportMobile / src / es / prodevelop / gvsig / exportMobile / ui / order / FLayerWithNewName.java @ 19124

History | View | Annotate | Download (2.46 KB)

1
package es.prodevelop.gvsig.exportMobile.ui.order;
2

    
3
import java.util.ArrayList;
4
import java.util.Arrays;
5

    
6
import com.iver.cit.gvsig.fmap.layers.FLayer;
7
import com.iver.cit.gvsig.fmap.layers.FLayers;
8

    
9
public class FLayerWithNewName {
10
        
11
        private FLayer lyr = null;
12
        private String suffix = "";
13
        private String differencer = "";
14

    
15
        public FLayerWithNewName(FLayer l) {
16
                lyr = l;
17
                suffix = getSuffix(lyr);
18
        }
19
        
20
        public static String getSuffix(FLayer l) {
21

    
22
                String suff = "";
23
                FLayer item = l.getParentLayer();
24
                while ((item != null) && (item.getParentLayer() != null)) {
25
                        suff = suff + "." + item.getName();
26
                        item = item.getParentLayer();
27
                }
28
                return removePointShp(suff);
29
        }
30
        
31
        public static String removePointShp(String str) {
32
                String aux = str.toLowerCase();
33
                aux = aux.replaceAll("\\.shp", "");
34
                return aux;
35
        }
36

    
37
        public String getNewName() {
38

    
39
                return removePointShp(lyr.getName()) + differencer + suffix;
40
        }
41
        
42
        public String getNewName(String op) {
43
                return removePointShp(lyr.getName()) + differencer + "." + op + suffix;
44
        }
45
        
46
        public String getNewNameNoDiff() {
47
                return removePointShp(lyr.getName()) + suffix;
48
        }
49
        
50
        
51
        public void setDiff(String d) {
52
                differencer = d;
53
        }
54

    
55
        public FLayer getLayer() {
56
                return lyr;
57
        }
58
        
59
        public static ArrayList getAll(FLayers root) {
60
                
61
                ArrayList resp = new ArrayList();
62
                addThisOrChildren(resp, root);
63
                setDiffs(resp);
64
                return resp;
65
                
66
        }
67
        
68

    
69
        private static void setDiffs(ArrayList l) {
70
                
71
                int sz = l.size();
72
                FLayerWithNewName[] non_sorted = new FLayerWithNewName[sz];
73
                for (int i=0; i<sz; i++)  non_sorted[i] = (FLayerWithNewName) l.get(i);
74
                Arrays.sort(non_sorted, new LayerNamesComparator());
75
                
76
                int ind = 1;
77
                for (int i=1; i<sz; i++) {
78
                        
79
                        FLayerWithNewName item_0 = non_sorted[i-1];
80
                        FLayerWithNewName item_1 = non_sorted[i];
81
                        if (item_0.getNewNameNoDiff().compareToIgnoreCase(item_1.getNewNameNoDiff()) == 0) {
82
                                item_1.setDiff("_" + ind);
83
                                ind++;
84
                        } else {
85
                                ind = 1;
86
                        }
87
                }
88
        }
89

    
90
        public static void addThisOrChildren(ArrayList list, FLayer l) {
91
                
92
                if ((! l.isOk()) || (! l.isAvailable())) {
93
                        // excluded layers
94
                        return;
95
                }
96
                
97
                if (l instanceof FLayers) {
98
                        FLayers col = (FLayers) l;
99
                        for (int i=0; i<col.getLayersCount(); i++) {
100
                                addThisOrChildren(list, col.getLayer(i));
101
                        }
102
                } else {
103
                        list.add(new FLayerWithNewName(l));
104
                }
105
                
106
        }
107

    
108
        public String getOriginalName() {
109
                return lyr.getName();
110
        }
111

    
112
}