Statistics
| Revision:

root / trunk / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / gui / panels / utils / LayersListElement.java @ 8110

History | View | Annotate | Download (6.23 KB)

1
package es.prodevelop.cit.gvsig.arcims.gui.panels.utils;
2

    
3
import java.util.Vector;
4

    
5
import javax.swing.JComponent;
6

    
7
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayer;
8
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerFeatures;
9
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayerImage;
10
import org.gvsig.remoteClient.utils.BoundaryBox;
11

    
12
import com.iver.andami.PluginServices;
13

    
14
import es.prodevelop.cit.gvsig.arcims.fmap.layers.LayerScaleData;
15

    
16
/**
17
 * Implements the class used as a list element in most lists
18
 * in this plugin. 
19
 * 
20
 * @author jldominguez
21
 *
22
 */
23
public class LayersListElement extends JComponent {
24
        
25
        private String name, type, id, theFclasstype, visible, mapUnits;
26
        private double maxscale, minscale;
27
        private BoundaryBox envelope;
28
        private boolean showIds = false;
29
        private boolean isAdded = false;
30
        private int theDPI;
31
        private static final long serialVersionUID = 0;
32
        
33
        public boolean isAdded() {
34
                return isAdded;
35
        }
36
        public void setAdded(boolean isAdded) {
37
                this.isAdded = isAdded;
38
        }
39
        public void setShowIds(boolean show) {
40
                this.showIds = show;
41
        }
42
        public String getID() { return id; }
43
        public String getName() { return name; }
44
        
45
        public LayersListElement(ServiceInformationLayer sil, String mapunits, int dpi) {
46
                if (sil instanceof ServiceInformationLayerImage) {
47
                        ServiceInformationLayerImage sili = (ServiceInformationLayerImage) sil;
48
                        id = sili.getId(); if (id == null) id = "";
49
                        name = sili.getName(); if (name == null) name = "";
50
                        type = sili.getType(); if (type == null) type = "";
51
                        theFclasstype = "";
52
                        maxscale = sili.getMaxscale(); minscale = sili.getMinscale();
53
                        visible = sili.getVisible(); if (visible == null) visible = "";
54
                        envelope = sili.getEnvelope();
55
                }
56
                
57
                if (sil instanceof ServiceInformationLayerFeatures) {
58
                        ServiceInformationLayerFeatures silf = (ServiceInformationLayerFeatures) sil;
59
                        id = silf.getId(); if (id == null) id = "";
60
                        name = silf.getName(); if (name == null) name = "";
61
                        type = silf.getType(); if (type == null) type = "";
62
                        theFclasstype = silf.getFclasstype(); if (theFclasstype == null) theFclasstype = "";
63
                        maxscale = silf.getMaxscale(); minscale = silf.getMinscale();
64
                        visible = silf.getVisible(); if (visible == null) visible = "";
65
                        envelope = silf.getEnvelope();
66
                }
67
                mapUnits = mapunits; theDPI = dpi;
68
        }
69
        private String boundaryBoxXRangeToString(BoundaryBox bb) {
70
                String r = "[ " + ServicesTableModel.leaveNDigits(bb.getXmin(), 10) + " , ";
71
                r = r + ServicesTableModel.leaveNDigits(bb.getXmax(), 10) + " ]";
72
                return r;
73
        }
74
        
75
        private String boundaryBoxYRangeToString(BoundaryBox bb) {
76
                String r = "[ " + ServicesTableModel.leaveNDigits(bb.getYmin(), 10) + " , ";
77
                r = r + ServicesTableModel.leaveNDigits(bb.getYmax(), 10) + " ]";
78
                return r;
79
        }
80
        
81

    
82
        /**
83
         * Gets a description of the layer to be shown on one of the
84
         * wizard's panes.
85
         * 
86
         * @return a description of the layer
87
         */
88
        public Vector getDataVector() {
89
                long true_scale;
90
                Vector data = new Vector();
91
                Vector item = new Vector();
92
                
93
                item.add("ID"); item.add(id);
94
                data.add(item.clone()); item.removeAllElements();
95
                
96
                item.add(PluginServices.getText(this, "name"));
97
                item.add(name); data.add(item.clone()); item.removeAllElements();
98
                
99
                item.add(PluginServices.getText(this, "type"));
100
                item.add(PluginServices.getText(this, type)); data.add(item.clone()); item.removeAllElements();
101
                
102
                item.add(PluginServices.getText(this, "vector_type"));
103
                if (theFclasstype.length() != 0) { item.add(PluginServices.getText(this, theFclasstype)); } else {
104
                        item.add(PluginServices.getText(this, "not_available"));
105
                }
106
                data.add(item.clone()); item.removeAllElements();
107
                
108
                item.add(PluginServices.getText(this, "max_scale"));
109
                true_scale = LayerScaleData.getTrueScaleFromRelativeScaleAndMapUnits(maxscale, mapUnits, theDPI);
110
                if (maxscale != -1.0) { item.add("1 : " + String.valueOf(true_scale)); } else {
111
                        item.add(PluginServices.getText(this, "not_available"));
112
                }
113
                data.add(item.clone()); item.removeAllElements();
114
                
115
                item.add(PluginServices.getText(this, "min_scale"));
116
                true_scale = LayerScaleData.getTrueScaleFromRelativeScaleAndMapUnits(minscale, mapUnits, theDPI);
117
                if (minscale != -1.0) { item.add("1 : " + String.valueOf(true_scale)); } else {
118
                        item.add(PluginServices.getText(this, "not_available"));
119
                }
120
                data.add(item.clone()); item.removeAllElements();
121
                
122
                item.add(PluginServices.getText(this, "visible"));
123
                if (visible.length() != 0) { item.add(visible); } else {
124
                        item.add(PluginServices.getText(this, "not_available"));
125
                }
126
                data.add(item.clone()); item.removeAllElements();
127
                
128
                if (envelope == null) {
129
                        item.add(PluginServices.getText(this, "envelope"));
130
                        item.add(PluginServices.getText(this, "not_available"));
131
                        data.add(item.clone()); item.removeAllElements();
132
                } else {
133
                        item.add(PluginServices.getText(this, "envelope") + " (" + PluginServices.getText(this, "xrange") + ")");
134
                        item.add(boundaryBoxXRangeToString(envelope));
135
                        data.add(item.clone()); item.removeAllElements();
136
                        item.add(PluginServices.getText(this, "envelope") + " (" + PluginServices.getText(this, "yrange") + ")");
137
                        item.add(boundaryBoxYRangeToString(envelope));
138
                        data.add(item.clone()); item.removeAllElements();
139
                }
140
                return data;
141
        }
142
        
143
        /**
144
         * Implements the toString() method automatically invoqued by the system
145
         * to paint a list.
146
         * 
147
         * @return a String that identifies the layer on the list
148
         */
149
        public String toString() {
150
                if (showIds) {
151
                        return  "[" + id + "] " + name;
152
                } else {
153
                        // String tail = repeatString(" ", id.length() + 5);
154
                        // return  name + tail;
155
                        return name;
156
                }
157
         }
158
        
159
        public String toolTipText() {
160
                Vector v = getDataVector();
161
                Vector vv = null;
162
                String r = "";
163
                for (int i=0; i<v.size(); i++) {
164
                        vv = (Vector) v.get(i);
165
                        r = r + "\n " + ((String) vv.get(0)) + ": ";
166
                        r = r + ((String) vv.get(1)) + " ";
167
                }
168
                r = r.substring(1);
169
                return r;
170
        }
171
        
172
        /**
173
         * Utility method. 
174
         * @param array
175
         * @param s
176
         * @return index of the first occurrence of <tt>s</tt> in <tt>array</tt>.
177
         */
178
        public static int getFirstIndexInIntArray(int[] array, int s) {
179
                for (int i = 0; i < array.length; i++) {
180
                        if (array[i] == s) return i; 
181
                }
182
                return -1;
183
        }
184
        
185
        public static String repeatString(String s, int n) {
186
                String r = "";
187
                for (int i = 0; i < n; i++) r = r + s;
188
                return r;
189
        }
190
        
191
}