Revision 3855 branches/v05/extensions/extWMS/src/com/iver/cit/gvsig/gui/panels/StyleTree.java

View differences:

StyleTree.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.2.2.2  2006-01-26 17:12:16  jaume
46
* Revision 1.2.2.3  2006-01-31 16:25:24  jaume
47
* correcciones de bugs
48
*
49
* Revision 1.4  2006/01/31 10:40:31  jaume
47 50
* *** empty log message ***
48 51
*
49 52
* Revision 1.3  2006/01/26 16:07:14  jaume
......
146 149
                if (leaf) {
147 150
                    JPanel leafComponent = new JPanel();
148 151
                    leafComponent.setBackground(Color.WHITE);
149
                    JRadioButton leafRadioButton = new JRadioButton("", ((StylesTreeModel) getModel()).isSelected((FMapWMSStyle) value));//selected);
152
                    JRadioButton leafRadioButton = new JRadioButton("", ((StyleTreeModel) getModel()).isSelected((FMapWMSStyle) value));//selected);
150 153
                    leafRadioButton.setBackground(Color.WHITE);
151 154
                    leafComponent.add(leafRadioButton);
152 155
                    leafComponent.add(new JLabel(((FMapWMSStyle) value).title));
......
159 162
            }});
160 163
        addMouseListener(new java.awt.event.MouseAdapter() { 
161 164
            public void mouseClicked(java.awt.event.MouseEvent e) {
162
                ((StylesTreeModel)getModel()).setSelectedLeaf(getSelectionPath());
165
                ((StyleTreeModel)getModel()).setSelectedLeaf(getSelectionPath());
163 166
                clearSelection();
164 167
                repaint();
165 168
            }
......
179 182
    }
180 183
    
181 184
    public Vector getStylesSelection(){
182
    	return ((StylesTreeModel)getModel()).getStylesSelection();
185
    	return ((StyleTreeModel)getModel()).getStylesSelection();
183 186
    }
184 187
    
185 188
    public Vector getStyleSelectionTitles(){
186
        if (getModel() instanceof StylesTreeModel)
187
            return ((StylesTreeModel)getModel()).getStyleSelectionTitles();
189
        if (getModel() instanceof StyleTreeModel)
190
            return ((StyleTreeModel)getModel()).getStyleSelectionTitles();
188 191
        else
189 192
            return null;
190 193
    }
......
199 202
     * @param styleNames, Vector containing the style names. 
200 203
     * The styles order <b>must match</b> with the layer order. 
201 204
     */
202
    public void setSelections(Vector styleNames){
205

  
206
    public void setSelections(WMSLayerNode[] selectedLayers, Vector styleNames){
203 207
    	if (styleNames!=null) {
204
    		StylesTreeModel model = (StylesTreeModel) getModel();
205
    		if (model.getChildCount(model.getRoot())!=styleNames.size()){
208
    		StyleTreeModel model = (StyleTreeModel) getModel();
209
    		//if (model.getChildCount(model.getRoot())!=styleNames.size()){
210
    		if (model.getCount()!=styleNames.size()){
206 211
    			throw new RuntimeException("Bad arguments: styleNames length is "
207 212
    					+styleNames.size()+", should be "
208
    					+model.getChildCount(model.getRoot())+".");
213
    					+model.getCount()+".");
209 214
    		}
210
    		
211
    		for (int i = 0; i < styleNames.size(); i++) {
212
    			if (styleNames.get(i)==null || ((String)styleNames.get(i)).equals(""))
213
    				continue;
214
    			Object node = model.getChild(model.getRoot(), i);
215
    			for (int j = 0; j < model.getChildCount(node); j++) {
216
    				if (((String)styleNames.get(i)).equals(((FMapWMSStyle)model.getChild(node, j)).name))
217
    					model.selectStyle(model.getChild(node, j));
218
    				
219
    			}
220
    		}
215
    		model.clear();
216
    		for (int i = 0; i < selectedLayers.length; i++) {
217
				model.addLayerBranch(selectedLayers[i]);
218
				if (styleNames.get(i)!=null && styleNames.get(i)!="")
219
					model.setStyleSelected(i, (String) styleNames.get(i));
220
			}	
221 221
    	}
222 222
    }
223

  
224
//    public void _setSelections(WMSLayerNode[] selectedLayers, Vector styleNames){
225
//    	if (styleNames!=null) {
226
//    		StyleTreeModel model = (StyleTreeModel) getModel();
227
//    		if (model.getChildCount(model.getRoot())!=styleNames.size()){
228
//    			throw new RuntimeException("Bad arguments: styleNames length is "
229
//    					+styleNames.size()+", should be "
230
//    					+model.getCount()+".");
231
//    		}
232
//    		
233
//    		for (int i = 0; i < styleNames.size(); i++) {
234
//    			if (styleNames.get(i)==null || ((String)styleNames.get(i)).equals(""))
235
//    				continue;
236
//    			Object node = model.getChild(model.getRoot(), i);
237
//    			for (int j = 0; j < model.getChildCount(node); j++) {
238
//    				if (((String)styleNames.get(i)).equals(((FMapWMSStyle)model.getChild(node, j)).name))
239
//    					model.selectStyle(model.getChild(node, j));
240
//    				
241
//    			}
242
//    		}
243
//    	}
244
//    }
223 245
    
224 246
}
225 247

  
226 248

  
227
class StylesTreeModel implements TreeModel {
228
    WMSLayerNode root;
249
class StyleTreeModel implements TreeModel {
250
    private WMSLayerNode root;
229 251
    /**
230
     * key: LayerNode.
252
     * key: WMSLayerNode.
231 253
     * value: FMapWMSStyle
232 254
     */
233
    Hashtable selections = new Hashtable();
255
    private Hashtable selections = new Hashtable();
234 256
    /**
235 257
     * this will hold the layers order even if the layer does not appear in
236 258
     * the tree because it has no styles.
237 259
     */
238
    ArrayList layers = new ArrayList();
239
    
240
    public StylesTreeModel(WMSLayerNode root){
260
    private ArrayList layers = new ArrayList();
261
	
262
    public StyleTreeModel(WMSLayerNode root){
241 263
        this.root = root;
242 264
        
243 265
    }
244 266
    
245
    /**
267
    protected void clear() {
268
		layers.clear();
269
		selections.clear();
270
	}
271

  
272
	protected void setStyleSelected(int index, String styleName) {
273
    	WMSLayerNode layer = (WMSLayerNode) layers.get(index);
274
    	if (layer.getStyles()==null)
275
    		return;
276
    	for (int i = 0; i < layer.getStyles().size(); i++) {
277
			FMapWMSStyle sty = (FMapWMSStyle) layer.getStyles().get(i);
278
			if (sty.name.equals(styleName))
279
				selections.put(sty.parent, sty);
280
		}
281
	}
282

  
283
	/**
284
     * Returns the amount of layers currently selected.
285
     * @return
286
     */
287
    public int getCount() {
288
    	if (layers==null)
289
    		return 0;
290
    	else return layers.size();
291
	}
292

  
293
	/**
246 294
     * Marks this style as selected in the StylesTreeModel.
247 295
     * @param style
248 296
     */
......
270 318
        	else 
271 319
        		values.set(i, sty.name);
272 320
		}
273
//      TODO em pareix que a?? no est? b? (que no reestablix l'ordre), comprovar.
274
        
275
//        Iterator it = layers.iterator();
276
//        int i = 0;
277
//        while (it.hasNext()){
278
//            Object key = it.next();
279
//            values.set(, ((FMapWMSStyle)selections.get(key)).name);
280
//            i++;
281
//        }
282 321
        return values;
283 322
    }
284 323
    
......
302 341
        	else 
303 342
        		values.set(i, sty.title);
304 343
		}
305
//        for (int i = 0; i < ((WMSLayerNode)getRoot()).getChildren().size(); i++) {
306
//            values.add(i, "");
307
//        }
308
//        
309
//        Iterator it = selections.keySet().iterator();
310
//        int i = 0;
311
//        while (it.hasNext()){
312
//            Object key = it.next();
313
//            values.set(i, ((FMapWMSStyle)selections.get(key)).title);
314
//            i++;
315
//        }
316 344
        return values;
317 345
    }
318 346

  
......
336 364
     * @return
337 365
     */
338 366
    protected boolean isSelected(FMapWMSStyle style){
339
        return selections.get(style.parent) == style;
367
    	String layerName = style.parent.getName();
368
    	boolean b = false;
369
    	for (int i = 0; i < layers.size(); i++) {
370
			WMSLayerNode lyr = (WMSLayerNode) layers.get(i);
371
			if (lyr.getName().equals(layerName))
372
				//if (selections.get(lyr) == style)
373
				if (((FMapWMSStyle)selections.get(lyr)).name.equals(style.name))
374
					return true;
375
		}
376
        return false;
377
    	//return selections.get(style.parent) == style;
340 378
    }
341 379
    
342 380
    /*

Also available in: Unified diff