Revision 11243

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/SimpleLabelStyle.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.11  2007-04-12 14:28:43  jaume
46
* Revision 1.12  2007-04-18 15:35:11  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.11  2007/04/12 14:28:43  jaume
47 50
* basic labeling support for lines
48 51
*
49 52
* Revision 1.10  2007/04/11 16:01:34  jaume
......
94 97
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
95 98
import com.iver.cit.gvsig.fmap.core.FShape;
96 99
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
100
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
97 101
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
98 102
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
99 103
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
......
103 107
/**
104 108
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
105 109
 */
106
public class SimpleLabelStyle extends SVGStyle implements ILabelStyle {
110
public class SimpleLabelStyle extends AbstractStyle implements ILabelStyle {
107 111
	private String text;
108 112
	private Point2D markerPoint = new Point2D.Double();
109 113
	// conertir a?? a Rectangle2D[] ja que pot arribar a gastar-se massivament
110 114
	// en el pintat
111 115
	private ArrayList textFieldAreas = new ArrayList();
116
	private BackgroundFileStyle background;
112 117

  
113 118
	public int getFieldCount() {
114 119
		return 1;
......
137 142
	}
138 143

  
139 144
	public XMLEntity getXMLEntity() {
140
		XMLEntity xml = super.getXMLEntity();
145
		XMLEntity xml = new XMLEntity();
141 146
		xml.putProperty("className", getClassName());
142 147
		xml.putProperty("desc", getDescription());
143 148
		xml.putProperty("text", text);
......
166 171
	}
167 172

  
168 173
	public void setXMLEntity(XMLEntity xml) {
169
		super.setXMLEntity(xml);
170 174
		setDescription(xml.getStringProperty("desc"));
171 175
		text = xml.getStringProperty("text");
176
		System.err.println(getDescription());
172 177
		double x = xml.getDoubleProperty("markerPointX");
173 178
		double y = xml.getDoubleProperty("markerPointY");
174 179

  
......
180 185
			addTextFieldArea(new Rectangle2D.Double(minx[i], miny[i], widths[i], heights[i]));
181 186
		}
182 187
		markerPoint.setLocation(x, y);
188
		background = (BackgroundFileStyle) SymbologyFactory.createStyleFromXML(xml.getChild(0), null);
183 189
	}
184 190

  
185 191
	public Rectangle2D[] getTextBounds() {
......
188 194

  
189 195
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
190 196
		g.translate(r.getX(), r.getY());
191
		super.drawInsideRectangle(g, r);
197
		background.drawInsideRectangle(g, r);
192 198
		g.translate(-r.getX(), -r.getY());
193 199
	}
194 200

  
195 201
	public Rectangle getBounds() {
196
		return super.getBounds();
202
		return background.getBounds();
197 203
	}
198 204

  
199 205
	public Point2D getMarkerPoint() {
......
210 216
	}
211 217

  
212 218
	public void drawOutline(Graphics2D g, Rectangle r) {
213
		super.drawOutline(g, r);
219
		background.drawOutline(g, r);
214 220
		Rectangle labelSz = getBounds();
215 221

  
216 222
		final double ratioLabel = labelSz.getWidth()/labelSz.getHeight();
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/BackgroundFileStyle.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.core.styles;
42

  
43
import java.awt.Rectangle;
44
import java.awt.image.BufferedImage;
45
import java.io.File;
46
import java.io.IOException;
47

  
48
import com.iver.utiles.XMLEntity;
49

  
50
/**
51
 * @author jaume dominguez faus - jaume.dominguez@iver.es
52
 */
53
public abstract class BackgroundFileStyle extends AbstractStyle {
54
	protected String sourceFile;
55

  
56
	public abstract void setSource(File f) throws IOException;
57
	public XMLEntity getXMLEntity() {
58
		XMLEntity xml = new XMLEntity();
59
		xml.putProperty("className", getClassName());
60
		xml.putProperty("source", sourceFile);
61
		xml.putProperty("desc", getDescription());
62
		return xml;
63
	}
64

  
65
	public void setXMLEntity(XMLEntity xml) {
66
		try {
67
			setSource(new File(xml.getStringProperty("source")));
68
			setDescription(xml.getStringProperty("desc"));
69
		} catch (IOException e) {
70
			// TODO Auto-generated catch block
71
			e.printStackTrace();
72
		}
73
	}
74
	public abstract Rectangle getBounds();
75
	public final String getSource() {
76
		return sourceFile;
77
	}
78

  
79
}
0 80

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/SVGStyle.java
65 65
 * @author jaume dominguez faus - jaume.dominguez@iver.es
66 66
 *
67 67
 */
68
public class SVGStyle extends AbstractStyle {
68
public class SVGStyle extends BackgroundFileStyle {
69 69

  
70 70
	private GVTBuilder gvtBuilder = new GVTBuilder();
71 71
    private UserAgentAdapter userAgent;
......
74 74
	private GraphicsNode gvtRoot;
75 75
	private BridgeContext ctx;
76 76
	private Element elt;
77
	private String sourceFile;
77
	
78 78
	protected static RenderingHints defaultRenderingHints;
79 79
    static {
80 80
        defaultRenderingHints = new RenderingHints(null);
......
114 114
		return getClass().getName();
115 115
	}
116 116

  
117
	public XMLEntity getXMLEntity() {
118
		XMLEntity xml = new XMLEntity();
119
		xml.putProperty("className", getClassName());
120
		xml.putProperty("source", sourceFile);
121
		xml.putProperty("desc", getDescription());
122
		return xml;
123
	}
124 117

  
125
	public void setXMLEntity(XMLEntity xml) {
126
		try {
127
			setSource(new File(xml.getStringProperty("source")));
128
			setDescription(xml.getStringProperty("desc"));
129
		} catch (IOException e) {
130
			// TODO Auto-generated catch block
131
			e.printStackTrace();
132
		}
133
	}
134 118

  
135 119
	public void setSource(File f) throws IOException {
136 120
		sourceFile = f.getAbsolutePath();
......
140 124
        elt = ((SVGDocument)svgDoc).getRootElement();
141 125
	}
142 126

  
143
	protected Rectangle getBounds() {
127
	public Rectangle getBounds() {
144 128
		Rectangle2D r = gvtRoot.getBounds();
145 129
		return new Rectangle((int) r.getX(),
146 130
				 (int) r.getY(),
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/ImageStyle.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.core.styles;
42

  
43
import java.awt.Dimension;
44
import java.awt.Graphics2D;
45
import java.awt.Rectangle;
46
import java.awt.image.BufferedImage;
47
import java.io.File;
48
import java.io.IOException;
49

  
50
import javax.imageio.ImageIO;
51
import javax.swing.ImageIcon;
52

  
53
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
54
import com.iver.utiles.XMLEntity;
55

  
56
/**
57
 * @author jaume dominguez faus - jaume.dominguez@iver.es
58
 */
59
public class ImageStyle extends BackgroundFileStyle {
60
	private BufferedImage img;
61
	public Rectangle getBounds() {
62
		return new Rectangle(new Dimension(img.getWidth(), img.getHeight()));
63
	}
64
	public void setSource(File f) throws IOException {
65
		sourceFile = f.getAbsolutePath();
66
		img = ImageIO.read(f);
67
	}
68

  
69
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
70
		g.setClip(r);
71
		g.drawRenderedImage(img, null);
72
	}
73

  
74
	public boolean isSuitableFor(ISymbol symbol) {
75
		// TODO Implement it
76
		throw new Error("Not yet implemented!");
77

  
78
	}
79

  
80
	public void drawOutline(Graphics2D g, Rectangle r) {
81
		drawInsideRectangle(g, r);
82
	}
83

  
84
	public String getClassName() {
85
		return getClass().getName();
86
	}
87

  
88
	public XMLEntity getXMLEntity() {
89
		XMLEntity xml = new XMLEntity();
90
		xml.putProperty("className", getClassName());
91
		xml.putProperty("source", getSource());
92
		xml.putProperty("desc", getDescription());
93
		return xml;
94
	}
95

  
96
	public void setXMLEntity(XMLEntity xml) {
97
		try {
98
			setSource(new File(xml.getStringProperty("source")));
99
			setDescription(xml.getStringProperty("desc"));
100
		} catch (IOException e) {
101
			// TODO Auto-generated catch block
102
			e.printStackTrace();
103
		}
104
	}
105
}
0 106

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLayers.java
417 417
			Cancellable cancel,double scale) throws ReadDriverException {
418 418
		draw(image,g,viewPort,cancel, scale, null);
419 419
	}
420
	
421
	
420

  
421

  
422 422
	public ComposedLayer draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
423 423
			Cancellable cancel,double scale, ComposedLayer group) throws ReadDriverException {
424 424
	    //double scale = getFMap().getScaleView();
......
431 431
		    long tg1 = System.currentTimeMillis();
432 432
   			///// CHEMA ComposedLayer
433 433

  
434
        	
435
        	
434

  
435

  
436 436
//    		while (iter.hasNext())
437 437
//    		{
438 438
    		 for (int i=0; i < layers.size(); i++) {
......
442 442
    			FLayer lyr = (FLayer) layers.get(i);
443 443

  
444 444

  
445
    			
446
    			
445

  
446

  
447 447
    		/*	if (lyr instanceof FLyrVect && ((FLyrVect)lyr).isBroken()){
448 448
    				continue;
449 449
    			}
......
452 452
    			fmap.fireLayerDrawingEvent(beforeEvent);
453 453
    			if ((lyr.isDirty()) || (lyr.isCachingDrawnLayers() == false))
454 454
    				bNeedRecalculateCache = true;
455
    			
455

  
456 456
    			if (lyr.isVisible()) {
457
    				
457

  
458 458
    				long t1 = System.currentTimeMillis();
459 459
    				System.err.println("Layer " + lyr.getName() + " dirty=" + lyr.isDirty());
460 460
    				// synchronized (this) {
......
469 469
    					    lyr.draw(image, g, viewPort, cancel,scale);
470 470
    					    // Si hay que acumlar:
471 471
    					     lyr.acumulateDrawing(antLayer);
472
    					     
472

  
473 473
    					     }
474 474
    					     else */
475
    					
475

  
476 476
    					if (lyr.isCachingDrawnLayers())
477 477
    					{
478 478
    						if ((bNeedRecalculateCache) || (lyr.getCacheImageDrawnLayers()==null))
479 479
    						{
480 480
    							//if (bNeedRecalculateCache)
481 481
    							// {
482
    							
482

  
483 483
    							///// CHEMA ComposedLayer
484 484
    							if (group != null) {
485 485
    								//si tenemos un grupo pendiente de pintar, pintamos
......
488 488
    								group = null;
489 489
    							}
490 490
    							///// CHEMA ComposedLayer
491
    							
492
    							
491

  
492

  
493 493
    							// Copiamos la imagen actual
494 494
    							BufferedImage buff = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
495 495
    							WritableRaster w = buff.getRaster();
......
507 507
    							// prepareDrawing de FMap.
508 508
    							if (lyr.isDirty())
509 509
    							{
510
    								
511
    								
510

  
511

  
512 512
    								///// CHEMA ComposedLayer
513 513
    								// Checks for draw group (ComposedLayer)
514 514
    								if (group != null) {
......
517 517
    									group = null;
518 518
    								}
519 519
    								///// CHEMA ComposedLayer
520
    								
521
    								
520

  
521

  
522 522
    								g.drawImage(lyr.getCacheImageDrawnLayers(), 0, 0, null);
523 523
    								System.err.println("Pinto con acelerado lo que hab?a antes de " + lyr.getName());
524 524
    							}
......
532 532
    						///// CHEMA ComposedLayer
533 533
    						//lyr.draw(image, g, viewPort, cancel,scale);
534 534
    						///// CHEMA ComposedLayer
535
    						
535

  
536 536
    						// Checks for draw group (ComposedLayer)
537 537
    						if (group != null) {
538 538
    							if (lyr instanceof FLayers){
......
546 546
    								} else {
547 547
    									// draw the 'pending to draw' layer group
548 548
    									group.draw(image, g, viewPort, cancel,scale);
549
    									
549

  
550 550
    									// gets a new group instance
551 551
    									group = lyr.newComposedLayer();
552
    									// if layer hasn't group, draws it inmediately 
552
    									// if layer hasn't group, draws it inmediately
553 553
    									if (group == null) {
554 554
    										if (lyr instanceof FLayers){
555 555
    											group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group);
......
557 557
    											lyr.draw(image, g, viewPort, cancel,scale);
558 558
    										}
559 559
    										LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
560
    										fmap.fireLayerDrawingEvent(afterEvent);   		   			        					
560
    										fmap.fireLayerDrawingEvent(afterEvent);
561 561
    									} else {
562 562
    										// add the layer to the group
563 563
    										group.setMapContext(fmap);
564 564
    										group.add(lyr);
565
    										
565

  
566 566
    									}
567 567
    								}
568 568
    							}
569 569
    						} else {
570 570
    							// gets a new group instance
571 571
    							group = lyr.newComposedLayer();
572
    							// if layer hasn't group, draws it inmediately 
572
    							// if layer hasn't group, draws it inmediately
573 573
    							if (group == null) {
574 574
    								if (lyr instanceof FLayers){
575 575
    									group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group);
......
577 577
    									lyr.draw(image, g, viewPort, cancel,scale);
578 578
    								}
579 579
    								LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
580
    								fmap.fireLayerDrawingEvent(afterEvent);	   			        				
580
    								fmap.fireLayerDrawingEvent(afterEvent);
581 581
    							} else {
582 582
    								// adds the layer to the group
583 583
    								group.setMapContext(fmap);
......
585 585
    							}
586 586
    						}
587 587
    						///// CHEMA ComposedLayer
588
    						
589
    						/* 
588

  
589
    						/*
590 590
    						 * (Jaume)
591 591
    						 * If the layer is instance of ILabelable then it may have labels.
592 592
    						 */
593 593
    						if (lyr instanceof ILabelable && ((ILabelable) lyr).isLabeled()) {
594
    							
595
    							///// CHEMA ComposedLayer   			        				
594

  
595
    							///// CHEMA ComposedLayer
596 596
    							if (group != null) {
597 597
    								//si tenemos un grupo pendiente de pintar, pintamos
598 598
    								// para que se pinten correctamente las etiquetas
......
600 600
    								group = null;
601 601
    							}
602 602
    							///// CHEMA ComposedLayer
603
    							
604
    							
603

  
604

  
605 605
    							((ILabelable) lyr).drawLabels(image, g, viewPort, cancel, scale);
606 606
    						}
607 607
    						bNeedRecalculateCache = true;
......
627 627
    		 }
628 628
    		 ///// CHEMA ComposedLayer
629 629
    		if (group != null && this.getParentLayer() == null) {
630
 				//si tenemos un grupo pendiente de pintar, pintamos    			 
630
 				//si tenemos un grupo pendiente de pintar, pintamos
631 631
 				group.draw(image, g, viewPort, cancel,scale);
632 632
 				group = null;
633 633

  
......
636 636
    		if (getVirtualLayers() != null) {
637 637
    			getVirtualLayers().draw(image, g, viewPort, cancel,scale);
638 638
    		}
639
    		
640
    		
639

  
640

  
641 641
//        }
642 642
//        catch (ConcurrentModificationException e)
643 643
//        {
644 644
//            System.err.println(e.getMessage());
645 645
//        }
646 646
			long tg2 = System.currentTimeMillis();
647
			
647

  
648 648
			System.out.println("Draw all layer " +this.getName() + " " +
649 649
			        + (tg2-tg1) + " milisecs.");
650 650
    		///// CHEMA ComposedLayer
651 651
    		return group;
652 652
    		///// CHEMA ComposedLayer
653
			
653

  
654 654
	}
655
	
655

  
656 656
	/**
657 657
	 * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
658 658
	 * 		com.iver.cit.gvsig.fmap.ViewPort,
......
667 667
		for (int i=0; i < layers.size(); i++) {
668 668
			FLayer lyr = (FLayer) layers.get(i);
669 669
			lyr.print(g, viewPort, cancel, scale, properties);
670
			if (lyr instanceof ILabelable) {
670
			if (lyr instanceof ILabelable && ((ILabelable) lyr).isLabeled()) {
671 671
				ILabelable lLayer = (ILabelable) lyr;
672 672

  
673 673
				lLayer.drawLabels(null, g, viewPort, cancel, scale);
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LabelClass.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.7  2007-04-12 14:28:43  jaume
46
 * Revision 1.8  2007-04-18 15:35:11  jaume
47
 * *** empty log message ***
48
 *
49
 * Revision 1.7  2007/04/12 14:28:43  jaume
47 50
 * basic labeling support for lines
48 51
 *
49 52
 * Revision 1.6  2007/04/11 16:01:08  jaume
......
83 86
 */
84 87
package com.iver.cit.gvsig.fmap.rendering.styling;
85 88

  
86
import java.awt.Color;
87 89
import java.awt.Graphics2D;
88
import java.awt.Point;
89 90
import java.awt.Rectangle;
90 91
import java.awt.geom.AffineTransform;
91 92
import java.awt.geom.PathIterator;
92
import java.awt.geom.Point2D;
93 93
import java.awt.geom.Rectangle2D;
94 94

  
95
import org.opengis.layer.Attribution;
96

  
97 95
import com.iver.cit.gvsig.fmap.core.FPoint2D;
98 96
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
99
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
100 97
import com.iver.cit.gvsig.fmap.core.FShape;
101 98
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
102 99
import com.iver.cit.gvsig.fmap.core.IGeometry;
......
173 170
		this.texts = texts;
174 171
	}
175 172

  
176
	public void drawTransformed(Graphics2D graphics, Rectangle bounds) {
177

  
178
	}
179 173
	public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds) {
180 174
		if (labelStyle != null) {
181 175
			// apply the offset to the markerPoint
182 176

  
183
			graphics.setColor(Color.RED);
184
			graphics.draw(bounds);
185 177
			labelStyle.drawInsideRectangle(graphics, bounds);
186 178

  
187 179
			for (int i = 0; i < texts.length; i++) {
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/PolygonPlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.6  2007-04-13 11:59:30  jaume
46
* Revision 1.7  2007-04-18 15:35:11  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.6  2007/04/13 11:59:30  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.5  2007/04/12 14:28:43  jaume
50 53
* basic labeling support for lines
51 54
*
......
65 68
*/
66 69
package com.iver.cit.gvsig.fmap.rendering.styling;
67 70

  
71
import java.awt.Color;
68 72
import java.awt.Graphics2D;
73
import java.awt.Rectangle;
69 74
import java.awt.geom.AffineTransform;
75
import java.awt.geom.PathIterator;
76
import java.awt.geom.Point2D;
77
import java.util.Vector;
78
import java.util.logging.Level;
79
import java.util.logging.Logger;
70 80

  
71 81
import org.cresques.px.gml.MultiPolygon;
72 82

  
83
import com.iver.cit.gvsig.fmap.core.FPoint2D;
73 84
import com.iver.cit.gvsig.fmap.core.FShape;
74 85
import com.iver.cit.gvsig.fmap.core.IGeometry;
75
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
86
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
76 87
import com.iver.utiles.XMLEntity;
88
import com.vividsolutions.jts.geom.Geometry;
89
import com.vividsolutions.jts.geom.Point;
77 90
/**
78 91
 *
79 92
 * @author jaume dominguez faus - jaume.dominguez@iver.es
80 93
 *
81 94
 */
82 95
public class PolygonPlacementConstraints extends AbstractPlacementConstraints {
96
	private static final double HALF_PI = Math.PI * 0.5;
97
	public PolygonPlacementConstraints() {
98
		setPlacementMode(HORIZONTAL);
99
	}
83 100

  
84 101
	public FShape[] getLocationsFor(IGeometry geom, FShape labelShape, MultiPolygon exclusionZone) {
85 102
		// TODO Implement it
......
88 105
	}
89 106

  
90 107
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform) {
91
		// TODO Implement it
92
		throw new Error("Not yet implemented!");
108
		Rectangle labelBounds = lc.getShape(g, transform, geom).getBounds();
109
		double theta = 0;
110
		Geometry geo = FConverter.java2d_to_jts((FShape) geom.getInternalShape());
93 111

  
112
		if (geo == null) {
113
			return;
114
		}
115

  
116
		Point pJTS = geo.getCentroid();
117

  
118
		if (pJTS == null) {
119
			Logger.getAnonymousLogger().log(Level.SEVERE, "no centroid could be found");
120
			return;
121
		}
122

  
123
		FPoint2D startingPoint = new FPoint2D(pJTS.getX(), pJTS.getY());
124
		if (isHorizontal()) {
125

  
126
		} else if (isParallel()) {
127
			// calculated with the Linear Regression technique
128
			PathIterator pi = geom.getPathIterator(transform);
129
			geom.transform(transform);
130
			Rectangle geomBounds =geom.getBounds();
131
			double sumx = 0, sumy = 0, sumxx = 0, sumyy = 0, sumxy = 0;
132
			double Sxx, Sxy, b, a;
133
			double[] coords = new double[6];
134
			int count = 0;
135

  
136
			// add points to the regression process
137
			Vector v = new Vector();
138
			while (!pi.isDone()) {
139
				pi.currentSegment(coords);
140
				Point2D p;
141
				if (geomBounds.width > geomBounds.height)
142
					p = new Point2D.Double(coords[0], coords[1]);
143
				else
144
					p = new Point2D.Double(coords[1], coords[0]);
145
				v.addElement(p);
146
				count++;
147
				sumx += p.getX();
148
				sumy += p.getY();
149
				sumxx += p.getX()*p.getX();
150
				sumyy += p.getY()*p.getY();
151
				sumxy += p.getX()*p.getY();
152
				pi.next();
153
			}
154

  
155
			// start regression
156
			double n = (double) count;
157
			Sxx = sumxx-sumx*sumx/n;
158
			Sxy = sumxy-sumx*sumy/n;
159
			b = Sxy/Sxx;
160
			a = (sumy-b*sumx)/n;
161

  
162
			boolean isVertical = false;
163
			if (geomBounds.width < geomBounds.height) {
164
				if (b == 0) {
165
					// force vertical (to avoid divide by zero)
166
					isVertical = true;
167

  
168
				} else {
169
					double bAux = 1/b;
170
					a = - a / b;
171
					b = bAux;
172
				}
173
			}
174

  
175
			if (isVertical){
176
				theta = HALF_PI;
177
			} else {
178
				double p1x = 0;
179
				double  p1y =geomBounds.height-a;
180
				double  p2x = geomBounds.width;
181
				double  p2y = geomBounds.height-
182
				(a+geomBounds.width*b);
183

  
184
				theta = -Math.atan(((p2y - p1y) / (p2x - p1x)) );
185
			}
186

  
187

  
188
//			} else {
189
//			int minx = 0, miny = 0, maxx = 0, maxy = 0;
190
//			while (!pi.isDone()) {
191
//			pi.currentSegment(coords);
192
//			FPoint2D p = new FPoint2D(coords[0], coords[1]);
193
//			if (coords[0] < geomBounds.width /2) {
194
//			minx += coords[0] % geomBounds.width;
195
//			} else {
196
//			maxx += coords[0] %geomBounds.width;
197
//			}
198
//
199
//			if (coords[1] < geomBounds.height/2) {
200
//			miny += coords[1] %geomBounds.height;
201
//			} else {
202
//			maxy += coords[1] %geomBounds.height;
203
//			}
204
//
205
//			g.drawRect((int) coords[0], (int) coords[1], 1, 1);
206
//			pi.next();
207
//			count++;
208
//			}
209
//
210
//			if (count >0) {
211
//			minx /= count;
212
//			miny /= count;
213
//			maxx /= count;
214
//			maxy /= count;
215
//
216
//			theta = -Math.atan(((maxy - miny) / (maxx - minx)) );
217
//			System.err.println("("+minx+","+miny+","+maxx+","+maxy+")");
218
//			g.setColor(Color.RED);
219
//			g.drawRect((int) (maxx + geomBounds.x), (int) (maxy + geomBounds.y), 1,1);
220
//			g.setColor(Color.BLUE);
221
//			g.drawRect((int) minx + geomBounds.x, (int) miny + geomBounds.y, 1,1);
222
//			}
223
//			}
224
		}
225
		startingPoint.transform(transform);
226
		labelBounds.setLocation(0-(int) (labelBounds.width*.5), 0 - (int) (labelBounds.height*.5));
227
		g.translate((int) startingPoint.getX(), (int) startingPoint.getY());
228
		if (theta != 0) {
229
			g.rotate(theta);
230
		}
231
		lc.drawInsideRectangle(g, labelBounds);
232
		if (theta != 0) {
233
			g.rotate(-theta);
234
		}
235
		g.translate(-(int) startingPoint.getX(), -(int) startingPoint.getY());
236

  
94 237
	}
95 238

  
96 239

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/LinePlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.7  2007-04-13 11:59:30  jaume
46
* Revision 1.8  2007-04-18 15:35:11  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.7  2007/04/13 11:59:30  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.6  2007/04/12 16:01:11  jaume
50 53
* *** empty log message ***
51 54
*
......
71 74
import java.awt.Graphics2D;
72 75
import java.awt.Rectangle;
73 76
import java.awt.geom.AffineTransform;
77
import java.util.logging.Logger;
74 78

  
75 79
import org.apache.batik.ext.awt.geom.PathLength;
76 80
import org.cresques.px.gml.MultiPolygon;
......
87 91
public class LinePlacementConstraints extends AbstractPlacementConstraints {
88 92
	private static final double HALF_PI = Math.PI * 0.5;
89 93

  
94
	public LinePlacementConstraints() {
95
		super();
96
		setPlacementMode(PARALLEL);
97
	}
98

  
90 99
	public FShape[] getLocationsFor(IGeometry geom, FShape labelShape, MultiPolygon exclusionZone) {
91 100
		return new FShape[] { (FShape) geom.getInternalShape() };
92 101
	}
93
	
102

  
94 103
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform at) {
95 104
		Rectangle labelBounds = lc.getShape(g, at, geom).getBounds();
96 105

  
......
137 146

  
138 147
			if (isBellowTheLine()) {
139 148
				// Offset to be on bellow of the line.
149
				// TODO
150
				Logger.getAnonymousLogger().warning("Bellow the line label place, not yet implemented");
140 151
			} else if (isAboveTheLine()) {
141 152
				// Offset to be above the line (inverse offset to under the line)
153
				// TODO
154
				Logger.getAnonymousLogger().warning("Above the line label place, not yet implemented");
155

  
142 156
			} else {
143 157
				// No offset.
158
				// TODO
144 159
			}
145 160

  
146 161
			/*
......
148 163
			 * either the line or the page.
149 164
			 */
150 165
			if (isPageOriented()) {
166
				// TODO
167
				Logger.getAnonymousLogger().warning("page oriented label place, not yet implemented");
151 168

  
152 169
			} else {
153 170
				// The line defines the orientation.
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/IPlacementConstraints.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.8  2007-04-13 12:42:32  jaume
46
 * Revision 1.9  2007-04-18 15:35:11  jaume
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.8  2007/04/13 12:42:32  jaume
50
 * *** empty log message ***
51
 *
49 52
 * Revision 1.7  2007/04/13 11:59:30  jaume
50 53
 * *** empty log message ***
51 54
 *
......
157 160
	public abstract boolean isPerpendicular();
158 161

  
159 162
	public abstract boolean isHorizontal();
163

  
164
	public abstract boolean isAtTheBeginingOfLine();
165

  
166
	public abstract boolean isInTheMiddleOfLine();
167

  
168
	public abstract boolean isAtTheEndOfLine();
169

  
170
	public abstract boolean isOnTopOfThePoint();
171

  
172
	public abstract boolean isAroundThePoint();
173

  
174
	public boolean isFitInsidePolygon();
175

  
176
	public void setFitInsidePolygon(boolean b);
177

  
160 178
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/PointPlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.7  2007-04-13 11:59:30  jaume
46
* Revision 1.8  2007-04-18 15:35:11  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.7  2007/04/13 11:59:30  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.6  2007/04/12 14:28:43  jaume
50 53
* basic labeling support for lines
51 54
*
......
69 72
package com.iver.cit.gvsig.fmap.rendering.styling;
70 73

  
71 74
import java.awt.Graphics2D;
75
import java.awt.Rectangle;
72 76
import java.awt.geom.AffineTransform;
77
import java.util.logging.Logger;
73 78

  
74 79
import org.cresques.px.gml.MultiPolygon;
75 80

  
......
101 106
	}
102 107

  
103 108
	public void placeLabel(Graphics2D g, IGeometry geom, LabelClass lc, MultiPolygon exclusionZone, AffineTransform transform) {
104
		// TODO Implement it
105
		throw new Error("Not yet implemented!");
109
		Rectangle labelBounds = lc.getShape(g, transform, geom).getBounds();
110
		FPoint2D startingPoint = (FPoint2D) geom.getInternalShape();
111
		if (isOnTopOfThePoint()) {
112
			// tal cual
113
		} else {
114
			Logger.getAnonymousLogger().warning("point label style not yet implemented");
115
		}
106 116

  
117
		startingPoint.transform(transform);
118
		labelBounds.setLocation(0-(int) (labelBounds.width*.5), 0 - (int) (labelBounds.height*.5));
119
		g.translate((int) startingPoint.getX(), (int) startingPoint.getY());
120
//		if (theta != 0) {
121
//			g.rotate(theta);
122
//		}
123
		lc.drawInsideRectangle(g, labelBounds);
124
//		if (theta != 0) {
125
//			g.rotate(-theta);
126
//		}
127
		g.translate(-(int) startingPoint.getX(), -(int) startingPoint.getY());
128

  
107 129
	}
108 130

  
109 131
	public String getClassName() {
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/AbstractPlacementConstraints.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.6  2007-04-13 12:42:45  jaume
46
* Revision 1.7  2007-04-18 15:35:11  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.6  2007/04/13 12:42:45  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.5  2007/04/13 11:59:30  jaume
50 53
* *** empty log message ***
51 54
*
......
88 91
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
89 92
 */
90 93
public abstract class AbstractPlacementConstraints implements Cloneable, IPlacementConstraints {
91
	private int shapeType;
92

  
93 94
	private int duplicateLabelsMode = ONE_LABEL_PER_FEATURE_PART; // default duplicate treatment
94 95
	private int placementMode;
95 96
	private boolean bellowTheLine;
......
97 98
	private boolean onTheLine;
98 99
	private boolean pageOriented;
99 100
	private int locationAlongLine;
101
	private boolean fitInsidePolygon;
100 102

  
101 103
	public void setDuplicateLabelsMode(int mode) {
102 104
		if (mode != REMOVE_DUPLICATE_LABELS &&
......
206 208
		return locationAlongLine == AT_THE_END_OF_THE_LINE;
207 209
	}
208 210

  
209

  
210 211
	public boolean isAtTheBeginingOfLine() {
211 212
		return locationAlongLine == AT_THE_BEGINING_OF_THE_LINE;
212 213
	}
213 214

  
215
	public boolean isInTheMiddleOfLine() {
216
		return locationAlongLine == AT_THE_MIDDLE_OF_THE_LINE;
217
	}
218

  
219
	public boolean isAroundThePoint() {
220
		return placementMode == OFFSET_HORIZONTALY_AROUND_THE_POINT;
221
	}
222

  
223
	public boolean isFitInsidePolygon() {
224
		return fitInsidePolygon;
225
	}
226

  
227
	public void setFitInsidePolygon(boolean b) {
228
		fitInsidePolygon = b;
229
	}
230

  
214 231
	public void setLocationAlongTheLine(int location) {
215 232
		if (location != IPlacementConstraints.AT_THE_MIDDLE_OF_THE_LINE
216 233
			&& location != IPlacementConstraints.AT_THE_BEGINING_OF_THE_LINE
......
224 241

  
225 242
	public XMLEntity getXMLEntity() {
226 243
		XMLEntity xml = new XMLEntity();
244
		xml.putProperty("duplicateLabelsMode", duplicateLabelsMode);
245
		xml.putProperty("placementMode", placementMode);
246
		xml.putProperty("bellowTheLine", bellowTheLine);
247
		xml.putProperty("aboveTheLine", aboveTheLine);
248
		xml.putProperty("onTheLine", onTheLine);
249
		xml.putProperty("pageOriented", pageOriented);
250
		xml.putProperty("locationAlongLine", locationAlongLine);
251
		xml.putProperty("fitInsidePolygon", fitInsidePolygon);
227 252
		return xml;
228 253
	}
229 254

  
230 255
	public void setXMLEntity(XMLEntity xml) {
231

  
256
		duplicateLabelsMode = xml.getIntProperty("duplicateLabelsMode");
257
		placementMode = xml.getIntProperty("placementMode");
258
		bellowTheLine = xml.getBooleanProperty("bellowTheLine");
259
		aboveTheLine = xml.getBooleanProperty("aboveTheLine");
260
		onTheLine = xml.getBooleanProperty("onTheLine");
261
		pageOriented = xml.getBooleanProperty("pageOriented");
262
		locationAlongLine = xml.getIntProperty("locationAlongLine");
263
		fitInsidePolygon = xml.getBooleanProperty("fitInsidePolygon");
232 264
	}
233 265
}

Also available in: Unified diff