Revision 20857

View differences:

branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrDefault.java
69 69

  
70 70
/**
71 71
 * <p>Implementation of the common characteristics of all layers: visibility, activation, name, ...</p>
72
 * 
73
 * <p>Represents the definition of a basic layer, implementing {@link FLayer FLayer}, and new functionality: 
72
 *
73
 * <p>Represents the definition of a basic layer, implementing {@link FLayer FLayer}, and new functionality:
74 74
 * <ul>
75 75
 *  <li>Supports transparency.
76 76
 *  <li>Notification of evens produced using this layer.
......
96 96

  
97 97
	/**
98 98
	 * Path to the upper layer which this layer belongs.
99
	 * 
99
	 *
100 100
	 * @see #getParentLayer()
101 101
	 * @see #setParentLayer(FLayers)
102 102
	 */
......
104 104

  
105 105
	/**
106 106
	 * A node in the tree of layers. Isn't used.
107
	 * 
107
	 *
108 108
	 * @see #getVirtualLayers()
109 109
	 * @see #setVirtualLayers(FLayers)
110 110
	 */
......
401 401
	 * Returns the transparency level of this layer, in the range 0-255 .
402 402
	 *
403 403
	 * @return the transparency level
404
	 * 
404
	 *
405 405
	 * @see #setTransparency(int)
406 406
	 */
407 407
	public int getTransparency() {
......
412 412
	 * Inserts the transparency level for this layer, the range allowed is 0-255 .
413 413
	 *
414 414
	 * @param trans the transparency level
415
	 * 
415
	 *
416 416
	 * @see #getTransparency()
417 417
	 */
418 418
	public void setTransparency(int trans) {
......
461 461
	 *   </ul>
462 462
	 *  <ul>
463 463
	 * </p>
464
	 * 
464
	 *
465 465
	 * @return an XML entity with information to the current layer
466 466
	 * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
467
	 * 
467
	 *
468 468
	 * @see #setXMLEntity(XMLEntity)
469 469
	 * @see #setXMLEntity03(XMLEntity)
470 470
	 */
......
492 492
		xml.putProperty("isInTOC", status.inTOC);
493 493

  
494 494
		// persist Properties hashTable
495

  
496 495
		Set keyset = properties.keySet();
496
		Iterator keyitr = keyset.iterator();
497
		XMLEntity xmlProperties = new XMLEntity();
498
		xmlProperties.putProperty("childName","properties");
499
		while (keyitr.hasNext()) {
500
			String propName = (String)keyitr.next();
501
			Object obj = properties.get(propName);
502
			if (obj instanceof IPersistance)
503
			{
504
				IPersistance persistObj = (IPersistance)obj;
505
				XMLEntity xmlPropObj = persistObj.getXMLEntity();
506
				// make sure the node contains the class name
507
				if (!xmlPropObj.contains("className")) {
508
					try {
509
						String propClassName = persistObj.getClassName();
510
						System.out.println("PROP CLASS NAME "+propClassName);
511
						xmlPropObj.putProperty("className", propClassName);
512
					} catch (Exception e) {
513
						e.printStackTrace();
514
					}
515
				}
516
				xmlPropObj.putProperty("layerPropertyName", propName);
517
				xmlProperties.addChild(xmlPropObj);
518
			} else if (obj instanceof String) {
519
				XMLEntity xmlPropObj = new XMLEntity();
520
				xmlPropObj.putProperty("className", String.class.getName());
521
				xmlPropObj.putProperty("value",(String)obj);
522
				xmlPropObj.putProperty("layerPropertyName", propName);
523
				xmlProperties.addChild(xmlPropObj);
497 524

  
525
			}
526
		}
527
		if (xmlProperties.getChildrenCount() > 0) {
528
			xml.addChild(xmlProperties);
529
		}
498 530

  
499
		int numProperties = 0;
500
		Iterator keyitr = keyset.iterator();
501
	    while (keyitr.hasNext()) {
502
	      String propName = (String)keyitr.next();
503
	      Object obj = properties.get(propName);
504
	      if (obj instanceof IPersistance)
505
	      {
506
	    	  IPersistance persistObj = (IPersistance)obj;
507
	          XMLEntity xmlPropObj = persistObj.getXMLEntity();
508
              // make sure the node contains the class name
509
	          if (!xmlPropObj.contains("className")) {
510
	        	  try {
511
	        		  String propClassName = persistObj.getClassName();
512
		        	  System.out.println("PROP CLASS NAME "+propClassName);
513
		        	  xmlPropObj.putProperty("className", propClassName);
514
	        	  } catch (Exception e) {
515
	        		  e.printStackTrace();
516
	        	  }
517
	          }
518
	          xmlPropObj.putProperty("layerPropertyName", propName);
519
	          xml.addChild(xmlPropObj);
520
	          numProperties++;
521
	      } else if (obj instanceof String) {
522
	          XMLEntity xmlPropObj = new XMLEntity();
523
        	  xmlPropObj.putProperty("className", String.class.getName());
524
        	  xmlPropObj.putProperty("value",(String)obj);
525
	          xmlPropObj.putProperty("layerPropertyName", propName);
526
	          xml.addChild(xmlPropObj);
527
	          numProperties++;
528
	      }
529
	    }
530
	    xml.putProperty("numProperties", numProperties);
531

  
532 531
		return xml;
533 532
	}
534 533

  
......
545 544
	 * @param xml an <code>XMLEntity</code> with the information
546 545
	 *
547 546
	 * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error setting the object.
548
	 * 
547
	 *
549 548
	 * @see #getXMLEntity()
550 549
	 */
551 550
	public void setXMLEntity(XMLEntity xml) throws XMLException {
......
565 564
//			isInTOC = xml.getBooleanProperty("isInTOC");
566 565
			status.inTOC = xml.getBooleanProperty("isInTOC");
567 566

  
568
        // recreate Properties hashTable
569

  
570
		if (xml.contains("numProperties")) {
567
		// recreate Properties hashTable
568
		if (xml.contains("numProperties")) { // for older projects
571 569
			int numProps = xml.getIntProperty("numProperties");
572 570
			Object obj= null;
573 571
			IPersistance objPersist;
574
            for (int iProp=0; iProp<numProps; iProp++) {
575
        	    XMLEntity xmlProp = xml.getChild(0);
576
        	    try {
577
        	    	String className = xmlProp.getStringProperty("className");
578
        	    	if (className.equals(String.class.getName())) {
579
        	    		obj = xmlProp.getStringProperty("value");
580
        	    	} else {
581
	        	        Class classProp = Class.forName(className);
582
		                obj = classProp.newInstance();
583
	    	            objPersist = (IPersistance)obj;
584
	        	        objPersist.setXMLEntity(xmlProp);
585
	                }
586
	                String propName = xmlProp.getStringProperty("layerPropertyName");
587
	                properties.put(propName, obj);
588
        		} catch (Exception e) {
589
        			continue;
590
        		}
591
        		// remove Properties children to avoid breaking layers' XML reading logic
592
        		xml.removeChild(0);
593
            }
572
			for (int iProp=0; iProp<numProps; iProp++) {
573
				XMLEntity xmlProp = xml.getChild(0);
574
				try {
575
					String className = xmlProp.getStringProperty("className");
576
					if (className.equals(String.class.getName())) {
577
						obj = xmlProp.getStringProperty("value");
578
					} else {
579
						Class classProp = Class.forName(className);
580
						obj = classProp.newInstance();
581
						objPersist = (IPersistance)obj;
582
						objPersist.setXMLEntity(xmlProp);
583
					}
584
					String propName = xmlProp.getStringProperty("layerPropertyName");
585
					properties.put(propName, obj);
586
				} catch (Exception e) {
587
					continue;
588
				}
589
				// remove Properties children to avoid breaking layers' XML reading logic
590
				xml.removeChild(0);
591
			}
594 592
		}
593
		else { // newer projects store properties under a node
594
			int chidNumb = xml.getChildrenCount();
595
			int xmlPropertiesPos = -1;
596
			for (int i=0; i<chidNumb; i++) {
597
				if (xml.getChild(i).contains("childName") &&
598
						xml.getChild(i).getStringProperty("childName").equals("properties")) {
599
					xmlPropertiesPos = i;
600
					break;
601
				}
602
			}
603
			XMLEntity xmlProperties =null;
604
			if (xmlPropertiesPos > -1)
605
				xmlProperties = xml.getChild(xmlPropertiesPos);
606

  
607
			if (xmlProperties != null) {
608

  
609
				int numProps = xmlProperties.getChildrenCount();
610
				Object obj;
611
				String className;
612
				Class classProp;
613
				IPersistance objPersist;
614
				for (int iProp=0; iProp<numProps; iProp++) {
615
					XMLEntity xmlProp = xmlProperties.getChild(iProp);
616
					try {
617
						className = xmlProp.getStringProperty("className");
618
						if (className.equals(String.class.getName())) {
619
							obj = xmlProp.getStringProperty("value");
620
						} else {
621
							classProp = Class.forName(className);
622
							obj = classProp.newInstance();
623
							objPersist = (IPersistance)obj;
624
							objPersist.setXMLEntity(xmlProp);
625

  
626
						}
627
						String propName = xmlProp.getStringProperty("layerPropertyName");
628
						properties.put(propName, obj);
629
					} catch (Exception e) {
630
						//FIXME: OJO !!!!!
631
						continue;
632
					}
633
				}
634
				// remove Properties children to avoid breaking layers' XML reading logic
635
				xml.removeChild(xmlPropertiesPos);
636
			}
637
		}
638

  
595 639
	}
596 640

  
597 641
	/**
......
614 658
	 * @param xml an <code>XMLEntity</code> with the information
615 659
	 *
616 660
	 * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
617
	 * 
661
	 *
618 662
	 * @see #getXMLEntity()
619 663
	 * @see #setXMLEntity(XMLEntity)
620 664
	 */
......
676 720
	 *  that its name has changed.
677 721
	 *
678 722
	 * @param e a layer event with the name of the property that has changed
679
	 * 
723
	 *
680 724
	 * @see #setName(String)
681 725
	 */
682 726
	private void callNameChanged(LayerEvent e) {
......
692 736
	 *  that its visibility has changed.
693 737
	 *
694 738
	 * @param e a layer event with the name of the property that has changed
695
	 * 
739
	 *
696 740
	 * @see #setVisible(boolean)
697 741
	 */
698 742
	private void callVisibilityChanged(LayerEvent e) {
......
708 752
	 *  that its active state has changed.
709 753
	 *
710 754
	 * @param e a layer event with the name of the property that has changed
711
	 * 
755
	 *
712 756
	 * @see #setActive(boolean)
713 757
	 */
714 758
	private void callActivationChanged(LayerEvent e) {
......
723 767
	 * Returns the virtual layers associated to this layer.
724 768
	 *
725 769
	 * @return a node with the layers
726
	 * 
770
	 *
727 771
	 * @see #setVirtualLayers(FLayers)
728 772
	 */
729 773
	public FLayers getVirtualLayers() {
......
734 778
	 * Inserts a virtual layer node to this layer.
735 779
	 *
736 780
	 * @param virtualLayers a node with the layers
737
	 * 
781
	 *
738 782
	 * @see #getVirtualLayers()
739 783
	 */
740 784
	public void setVirtualLayers(FLayers virtualLayers) {
......
745 789
	 * Returns the text layer associated to this layer.
746 790
	 *
747 791
	 * @return a text layer
748
	 * 
792
	 *
749 793
	 * @see #setLayerText(FLyrText)
750 794
	 */
751 795
	public FLyrText getLayerText() {
......
756 800
	 * Sets the text layer associated to this layer.
757 801
	 *
758 802
	 * @param layerText a text layer
759
	 * 
803
	 *
760 804
	 * @see #getLayerText()
761 805
	 */
762 806
	public void setLayerText(FLyrText layerText) {
......
767 811
	 * Sets the transformation coordinates for this layer.
768 812
	 *
769 813
	 * @param ct the new transformation coordinates
770
	 * 
814
	 *
771 815
	 * @see #getCoordTrans()
772 816
	 */
773 817
	public void setCoordTrans(ICoordTrans ct) {
......
778 822
	 * Returns the transformation coordinates of this layer.
779 823
	 *
780 824
	 * @return ct current transformation coordinates
781
	 * 
825
	 *
782 826
	 * @see #setCoordTrans(ICoordTrans)
783 827
	 */
784 828
	public ICoordTrans getCoordTrans() {
......
848 892
	 * Returns the strategy of drawing and processing this layer.
849 893
	 *
850 894
	 * @return an object that implements the <code>Strategy</code> interface.
851
	 * 
895
	 *
852 896
	 * @see #setStrategy(Strategy)
853 897
	 */
854 898
	public Strategy getStrategy() {
......
859 903
	 * Inserts the strategy of drawing and processing this layer.
860 904
	 *
861 905
	 * @param s an object that implements the <code>Strategy</code> interface.
862
	 * 
906
	 *
863 907
	 * @see #getStrategy()
864 908
	 */
865 909
	public void setStrategy(Strategy s) {
......
878 922
	}
879 923

  
880 924
	/**
881
	 * Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies 
925
	 * Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies
882 926
	 *  all listeners associated to this layer, that its edition state has changed.
883 927
	 *
884 928
	 * @param e a layer event with the name of the property that has changed
885
	 * 
929
	 *
886 930
	 * @see #setEditing(boolean)
887 931
	 */
888 932
	protected void callEditionChanged(LayerEvent e) {
......
1111 1155
	}
1112 1156

  
1113 1157
	/**
1114
	 * Inserts the image icon that will be shown in the TOC next to this layer, according its status. 
1115
	 * 
1158
	 * Inserts the image icon that will be shown in the TOC next to this layer, according its status.
1159
	 *
1116 1160
	 * @param tocStatusImage the image
1117
	 * 
1161
	 *
1118 1162
	 * @see #getTocStatusImage()
1119 1163
	 */
1120 1164
	public void setTocStatusImage(Image tocStatusImage) {

Also available in: Unified diff