Statistics
| Revision:

root / branches / gvSIG_1.11.0_Mejoras_gvSIG-EIEL / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / order / RasterPolLinePointOrderManager.java @ 35647

History | View | Annotate | Download (2.81 KB)

1
package com.iver.cit.gvsig.fmap.layers.order;
2

    
3
import java.util.Map;
4

    
5
import org.apache.log4j.Logger;
6

    
7
import sun.print.PSPrinterJob.PluginPrinter;
8

    
9
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
10
import com.iver.cit.gvsig.fmap.Messages;
11
import com.iver.cit.gvsig.fmap.core.FShape;
12
import com.iver.cit.gvsig.fmap.layers.FLayer;
13
import com.iver.cit.gvsig.fmap.layers.FLayers;
14
import com.iver.cit.gvsig.fmap.layers.FLyrRasterMenuEntry;
15
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
16
import com.iver.utiles.XMLEntity;
17
import com.iver.utiles.extensionPoints.ExtensionPoint;
18

    
19
public class RasterPolLinePointOrderManager extends DefaultOrderManager {
20

    
21
        private static Logger logger =
22
                Logger.getLogger(RasterPolLinePointOrderManager.class.getName());
23
        
24
        private final String name = "Raster-Polygon-Line-Point order manager";
25
        private final String description =
26
                "Raster_to_bottom_then_polygons_lines_points";
27
        public static final String CODE =
28
                RasterPolLinePointOrderManager.class.getName();
29

    
30
        public int getPosition(FLayers target, FLayer newLayer) {
31
                
32
                int new_weight = 3;
33
                new_weight = getLayerWeight(newLayer);
34
                
35
                int len = target.getLayersCount();
36
                int item_w = 0;
37
                // from top to bottom,
38
                // look for a layer at
39
                // least as "heavy" as this one
40
                for (int i=(len-1); i>=0; i--) {
41
                        item_w = getLayerWeight(target.getLayer(i));
42
                        if (item_w >= new_weight) {
43
                                return (i+1);
44
                        }
45
                }
46
                // layer "falls" to bottom
47
                return 0;
48
        }
49

    
50
        public String getDescription() {
51
                return Messages.getString(description);
52
        }
53

    
54
        public String getName() {
55
                return name;
56
        }
57

    
58
        public String getClassName() {
59
                return CODE;
60
        }
61
        
62
        public String getCode() {
63
                return CODE;
64
        }
65

    
66
        /**
67
         * 
68
         * @param lyr
69
         * @return weight: point=0, line=1, polygon=2, other=3, raster=4
70
         */
71
        private int getLayerWeight(FLayer lyr) {
72
                
73
                if (lyr.getClass().getName().indexOf("FLyrRasterSE") != -1) {
74
                        return 4;
75
                } else {
76
                        if (lyr instanceof FLyrVect) {
77
                                FLyrVect lyrv = (FLyrVect) lyr;
78
                                int type2d = FShape.POLYGON;
79
                                try {
80
                                        type2d = simplifyType(lyrv.getShapeType());
81
                                } catch (ReadDriverException e) {
82
                                        logger.error("While getting shape type from layer: " + lyrv.getName() + " (assumed polygon)");
83
                                }
84
                                switch (type2d) {
85
                                case FShape.POLYGON:
86
                                        return 2;
87
                                case FShape.LINE:
88
                                        return 1;
89
                                case FShape.POINT:
90
                                        return 0;
91
                                default:
92
                                        // should not reach this
93
                                        return 3;
94
                                }
95
                        } else {
96
                                // other:
97
                                return 3;
98
                        }
99
                }
100
                
101
        }
102

    
103
        /**
104
         * 
105
         * @param t
106
         * @return FShape.POLYGON, LINE or POINT
107
         */
108
        private int simplifyType(int t) {
109

    
110
                int ty = t % FShape.Z;
111
                switch (ty) {
112
                case FShape.POLYGON:
113
                case FShape.MULTI:
114
                case FShape.NULL:
115
                        return FShape.POLYGON;
116
                case FShape.LINE:
117
                        return FShape.LINE;
118
                case FShape.POINT:
119
                case FShape.MULTIPOINT:
120
                        return FShape.POINT;
121
                default:
122
                        return FShape.POLYGON;
123
                }
124
                
125
        }
126
        
127

    
128

    
129
}