Revision 44910

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/legend/gui/LegendManager.java
663 663
         * try to apply the legend to all the active layers that
664 664
         * can accept it
665 665
         */
666
        FLayer[] activeLyrs = layer.getMapContext().getLayers().getActives();
667
        for (int i = 0; i < activeLyrs.length; i++) {
668
            FLayer laux = activeLyrs[i];
666
//        FLayer[] activeLyrs = layer.getMapContext().getLayers().getActives();
667
//        for (int i = 0; i < activeLyrs.length; i++) {
668
            FLayer laux = this.getLayer(); //activeLyrs[i];
669 669

  
670
            if (activeLyrs[i] instanceof FLayers) {
671
                laux = getFirstActiveLayerVect((FLayers) activeLyrs[i]);
672
            }
670
//            if (activeLyrs[i] instanceof FLayers) {
671
//                laux = getFirstActiveLayerVect((FLayers) activeLyrs[i]);
672
//            }
673 673

  
674 674
            if (laux instanceof ClassifiableVectorial) {
675 675
                ClassifiableVectorial aux2 = (ClassifiableVectorial) laux;
......
702 702
                        "legend_exception"), e);
703 703
                }
704 704
            }
705
        }
705
        
706 706
    }
707 707

  
708 708
    private void applyRestOfLegends(Hashtable<FLayer, ILegend> table2,
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/legend/gui/VectorialUniqueValue.java
67 67
import org.gvsig.gui.beans.swing.JButton;
68 68
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
69 69
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
70
import org.gvsig.tools.ToolsLocator;
70 71
import org.gvsig.tools.dispose.DisposableIterator;
71 72
import org.slf4j.Logger;
72 73
import org.slf4j.LoggerFactory;
......
185 186

  
186 187
        try {
187 188
            elRs = ((FLyrVect) layer).getFeatureStore();
188
//            logger.debug("elRs.start()");
189
//            elRs.start();
190

  
191
//            int idField = -1;
192 189
            String fieldName = (String) cmbFields.getSelectedItem();
193 190
            if (fieldName == null) {
194 191
                JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "no_hay_campo_seleccionado"));
195 192
                return;
196 193
            }
197 194

  
198
//            idField = elRs.getFieldIndexByName(fieldName);
199
            auxLegend.setClassifyingFieldNames(new String[]{fieldName});
200

  
201
            //long numReg = elRs.getRowCount();
202
//            if (idField == -1) {
203
//                NotificationManager.addWarning(
204
//                		PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
205
//
206
//                return;
207
//            }
208 195
            symbolTable.removeAllItems();
209 196

  
210 197
            int numSymbols = 0;
......
216 203
                    .getMapContextManager().createLegend(
217 204
                            IVectorialUniqueValueLegend.LEGEND_NAME);
218 205
            auxLegend.setShapeType(layer.getShapeType());
219

  
206
            auxLegend.setClassifyingFieldNames(new String[]{fieldName});
207
            FeatureAttributeDescriptor attr = elRs.getDefaultFeatureTypeQuietly().getAttributeDescriptor(fieldName);
208
            int fieldType = attr.getDataType().getType();
209
            auxLegend.setClassifyingFieldTypes(new int[]{fieldType});
220 210
            Object clave = null;
221 211

  
222 212
            //Object resul;
......
492 482
            Iterator iterator = rs.getDefaultFeatureType().iterator();
493 483
            while (iterator.hasNext()) {
494 484
                FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
495
                names.add(descriptor.getName());
485
                Class fieldClass = ToolsLocator.getDataTypesManager().getDefaultClass(descriptor.getDataType().getType());
486
                if (Comparable.class.isAssignableFrom(fieldClass)) {
487
                    names.add(descriptor.getName());
488
                }
496 489
            }
497 490
//            String[] nomFields = new String[rs.getFieldCount()];
498 491
//
......
511 504
        }
512 505
    }
513 506

  
507
    @Override
514 508
    public void setData(FLayer layer, ILegend legend) {
515 509
        this.layer = (ClassifiableVectorial) layer;
516 510
        int shapeType = 0;
......
583 577
    /* (non-Javadoc)
584 578
     * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
585 579
     */
580
    @Override
586 581
    public ILegend getLegend() {
587 582
        fillSymbolListFromTable();
588 583

  
......
647 642
        symbolTable.removeRow(null);
648 643
        symbolTable.repaint();
649 644
    }
650

  
645
   
646
    @Override
651 647
    public void actionPerformed(ActionEvent e) {
652 648

  
653 649
        //modificar el combobox de valor
......
728 724
        }
729 725
    }
730 726

  
727
    @Override
731 728
    public String getDescription() {
732 729
        return PluginServices.getText(this, "Dado_un_campo_de_atributos") + "," + PluginServices.getText(this, "muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico") + ".";
733 730
    }
734 731

  
732
    @Override
735 733
    public ImageIcon getIcon() {
736 734
        return IconThemeHelper.getImageIcon(
737 735
                "legend-overview-vectorial-unique-value");
738 736
    }
739 737

  
738
    @Override
740 739
    public Class getParentClass() {
741 740
        return Categories.class;
742 741
    }
743 742

  
743
    @Override
744 744
    public String getTitle() {
745 745
        return PluginServices.getText(this, "Valores_unicos");
746 746
    }
747 747

  
748
    @Override
748 749
    public JPanel getPanel() {
749 750
        return this;
750 751
    }
751 752

  
753
    @Override
752 754
    public Class getLegendClass() {
753 755
        return VectorialUniqueValueLegend.class;
754 756
    }
755 757

  
758
    @Override
756 759
    public boolean isSuitableFor(FLayer layer) {
757 760
        return (layer instanceof FLyrVect);
758 761
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/impl/VectorialUniqueValueLegend.java
31 31
import java.util.Map;
32 32
import java.util.Map.Entry;
33 33
import java.util.TreeMap;
34
import java.util.logging.Level;
35
import org.apache.commons.lang3.ObjectUtils;
36
import org.apache.commons.lang3.mutable.MutableObject;
37
import org.gvsig.fmap.dal.DataTypeUtils;
34 38

  
35 39
import org.slf4j.Logger;
36 40
import org.slf4j.LoggerFactory;
......
45 49
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
46 50
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
47 51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.dataTypes.Coercion;
53
import org.gvsig.tools.dataTypes.CoercionException;
48 54
import org.gvsig.tools.dynobject.DynStruct;
49 55
import org.gvsig.tools.persistence.PersistenceManager;
50 56
import org.gvsig.tools.persistence.PersistentState;
......
94 100
    	setShapeType(shapeType);
95 101
    }
96 102

  
103
        @Override
97 104
    public void setShapeType(int shapeType) {
98 105
    	if (this.shapeType != shapeType) {
99 106
    		if(defaultSymbol==null || defaultSymbol.getSymbolType()!=shapeType){
......
105 112
    	}
106 113
    }
107 114

  
115
        @Override
108 116
    public void setValueSymbolByID(int id, ISymbol symbol) {
109 117
        ISymbol old = (ISymbol)symbols.put(keys.get(id), symbol);
110 118
        fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
111 119
    }
112 120

  
121
        @Override
113 122
    public Object[] getValues() {
114 123
        return symbols.keySet().toArray(new Object[0]);
115 124
    }
116 125

  
126
        @Override
117 127
    public void addSymbol(Object key, ISymbol symbol) {
118 128
    	ISymbol resul;
119 129
    	if (key == null) {
......
143 153
        fireLegendClearEvent(new LegendClearEvent(olds));
144 154
    }
145 155
    
156
        @Override
146 157
    public void clear() {
147 158
        keys.clear();
148 159
        ISymbol[] olds = (ISymbol[])symbols.values().toArray(new ISymbol[0]);
......
153 164
        fireLegendClearEvent(new LegendClearEvent(olds));
154 165
    }
155 166

  
167
        @Override
156 168
    public String[] getDescriptions() {
157 169
        String[] descriptions = new String[symbols.size()];
158 170
        ISymbol[] auxSym = getSymbols();
......
164 176
        return descriptions;
165 177
    }
166 178

  
179
        @Override
167 180
     public ISymbol[] getSymbols() {
168 181
 		ISymbol[] symbolList;
169 182
		if (nullValueSymbol == null) {
......
183 196
		}
184 197
    }
185 198

  
199
        @Override
186 200
    public void setClassifyingFieldNames(String[] fNames) {
187 201
        // TODO: Check if need more process
188 202
        super.setClassifyingFieldNames(fNames);
......
199 213
	 * @return S?mbolo.
200 214
     * @throws MapContextException
201 215
	 */
216
        @Override
202 217
    public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
203 218

  
204 219
        Object val = null;
......
223 238
    }
224 239

  
225 240

  
241
        @Override
226 242
    public ISymbol getDefaultSymbol() {
227 243

  
228 244
    	if(defaultSymbol==null) {
......
232 248
    	return defaultSymbol;
233 249
    }
234 250

  
251
        @Override
235 252
	public void setDefaultSymbol(ISymbol s) {
236 253
    	ISymbol mySymbol = defaultSymbol;
237 254

  
......
250 267
     *
251 268
     * @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
252 269
     */
270
        @Override
253 271
    public ISymbol getSymbolByValue(Object key) {
254 272
    	ISymbol symbol = null;
255 273
    	if (key == null) {
......
265 283

  
266 284
    }
267 285

  
286
        @Override
268 287
	public Object getSymbolKey(ISymbol symbol) {
269 288
		if (symbol != null) {
270 289
			for (Iterator<Entry<Object, ISymbol>> iterator = symbols.entrySet()
......
278 297
		return null;
279 298
	}
280 299

  
300
        @Override
281 301
    public int getShapeType() {
282 302
        return shapeType;
283 303
    }
284 304

  
305
        @Override
285 306
    public void useDefaultSymbol(boolean b) {
286 307
        useDefaultSymbol = b;
287 308
    }
......
290 311
	 * Devuelve si se utiliza o no el resto de valores para representarse.
291 312
	 * @return  True si se utiliza el resto de valores.
292 313
	 */
314
        @Override
293 315
    public boolean isUseDefaultSymbol() {
294 316
        return useDefaultSymbol;
295 317
    }
296 318

  
319
        @Override
297 320
    public void delSymbol(Object key) {
298 321
        keys.remove(key);
299 322

  
......
307 330
		return getClass().getName();
308 331
	}
309 332

  
333
        @Override
310 334
	public void replace(ISymbol oldSymbol, ISymbol newSymbol) {
311 335
		if (symbols.containsValue(oldSymbol)) {
312 336
			Iterator<Object> it = symbols.keySet().iterator();
......
320 344
			}
321 345
		}
322 346
	}
347
        @Override
323 348
	public Color[] getColorScheme() {
324 349
		return selectedColors;
325 350
	}
326 351

  
352
        @Override
327 353
	public void setColorScheme(Color[] cc) {
328 354
		 this.selectedColors = cc;
329 355
	}
330 356

  
357
        @Override
331 358
	public Object clone() throws CloneNotSupportedException {
332 359
		VectorialUniqueValueLegend clone =
333 360
				(VectorialUniqueValueLegend) super.clone();
......
381 408
            removeLegendListener(list[i]);
382 409
        }
383 410
    }
384

  
411
    
412
    public void setClassifyingFieldTypes(int[] fieldTypes) {
413
        
414
        Class fieldClass = ToolsLocator.getDataTypesManager().getDefaultClass(fieldTypes[0]);
415
        if (!Comparable.class.isAssignableFrom(fieldClass)) {
416
             throw new IllegalArgumentException("Should be comparable");   
417
        }
418
        super.setClassifyingFieldTypes(fieldTypes);
419
    }
420
        
385 421
    private Map<Object, ISymbol> createSymbolMap() {
386
		return new TreeMap<Object, ISymbol>(
387
				new Comparator<Object>() {
388
					public int compare(Object o1, Object o2) {
389
						if ((o1 != null) && (o2 != null)) {
390
							Object v2 = o2;
391
							Object v1 = o1;
392
							if (v1 instanceof Number && v2 instanceof Number) {
393
								return ((Number) v1).intValue()
394
										- ((Number) v2).intValue();
395
							}
396
							if (v1 instanceof String && v2 instanceof String) {
397
								return ((String) v1).compareTo(((String) v2));
398
							}
399
						}
422
        final MutableObject<Coercion> convert = new MutableObject<>();
400 423

  
401
						return 0;
402
					}
403
				});
424
        return new TreeMap<Object, ISymbol>(
425
                new Comparator<Object>() {
426
            public int compare(Object o1, Object o2) {
427
                if (convert.getValue() == null) {
428
                    convert.setValue(ToolsLocator.getDataTypesManager().getCoercion(getClassifyingFieldTypes()[0]));
429
                }
430
                try {
431
                    return ObjectUtils.compare((Comparable) (convert.getValue().coerce(o1)), (Comparable) (convert.getValue().coerce(o2)));
432
                } catch (CoercionException ex) {
433
                    throw new RuntimeException("Not able to coerce values in symbol map");
434
                }
435
            }
436
        });
437
    }
404 438

  
405
	}
406

  
407 439
	@SuppressWarnings({ "unchecked", "rawtypes" })
408 440
	public void loadFromState(PersistentState state)
409 441
			throws PersistenceException {

Also available in: Unified diff