Revision 11536

View differences:

trunk/extensions/extAnnotations/build.xml
1
<project name="Generar extension Anotaciones en Andami" default="generate-without-source" basedir=".">
2
    <description>
3
        Instala el plugin en Andami
4
    </description>
5
  <!-- set global properties for this build -->
6
  <property name="src" location="src"/>
7
  <property name="build" location="bin"/>
8
  <property name="dist"  location="dist"/>
9
  <property name="mainplugin" value="com.iver.cit.gvsig"/>
10
  <property name="plugin" value="com.iver.cit.gvsig.annotation"/>
11
  <property name="gvsiglibjar" value="gvsig-annotation"/>
12
  <property name="driverjar" value="annotation"/>
13
  <property name="extensionDir" location="../_fwAndami/gvSIG/extensiones"/>
14
  <property name="drivers-dir" location="${extensionDir}/${mainplugin}/drivers" />
15

  
16
  <target name="init">
17
    <!-- Create the time stamp -->
18
    <tstamp/>
19
    <!-- Create the build directory structure used by compile -->
20
    <mkdir dir="${build}"/>
21
    <mkdir dir="${dist}"/>
22

  
23
  </target>
24

  
25
  <target name="generate-without-source" depends="init"
26
  		description="generate the distribution without the source file">
27
    <!-- Create the distribution directory -->
28
    <mkdir dir="${dist}"/>
29
    <mkdir dir="${dist}/lib"/>
30
  	<mkdir dir="${dist}/images"/>
31
	<mkdir dir="${drivers-dir}/annotation" />
32

  
33
    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
34
    <jar jarfile="${dist}/lib/${plugin}.jar" basedir="${build}" excludes="**/*Driver*" includes="com/iver/cit/gvsig/**"/>
35
    <!-- <jar jarfile="${drivers-dir}/sde/sde.jar" basedir="${build}" includes="com/iver/cit/gvsig/fmap/drivers/sde/**"/> -->
36
  	<copy file="config/config.xml" todir="${dist}"/>
37
    <copy todir="${dist}">
38
    	<fileset dir="." includes="text*.properties"/>
39
    </copy>
40
    <copy todir="${dist}/lib">
41
    	<fileset dir="./lib" includes="*.jar,*.zip"/>
42
    	<!-- <fileset dir="." includes=".keystore"/> -->
43
    </copy>
44
  	<copy todir="${dist}/images">
45
  	    	<fileset dir="images" includes="*"/>
46
  	</copy>
47
  	<move todir="${extensionDir}/${plugin}/images">
48
  	  	<fileset dir="${dist}/images" includes="*"/>
49
  	</move>
50
  	<move todir="${extensionDir}/${plugin}">
51
  	  	<fileset dir="${dist}" includes="*"/>
52
  	</move>
53
  	<move todir="${extensionDir}/${plugin}/lib">
54
  	  	<fileset dir="${dist}/lib" includes="**"/>
55
  	</move>
56
  	<jar jarfile="${drivers-dir}/annotation/annotation.jar" basedir="./bin"	includes="com/iver/cit/gvsig/fmap/drivers/annotation/*.*"
57
  	  	/>
58
  	<!--jar jarfile="${extensionDir}/${mainplugin}/lib/gvsig-annotation.jar" basedir="./bin" includes="**/VectorialSDE*.*"/-->
59

  
60
  </target>
61

  
62

  
63
  <!--target name="generate-with-source" description="generate the distribution with the source file" >
64
    <mkdir dir="${dist}"/>
65
  	<mkdir dir="${dist}/images"/>
66

  
67
    <jar jarfile="${dist}/${plugin}.jar" basedir="${build}"/>
68
    <copy file="config/config.xml" todir="${dist}"/>
69
    <copy todir="${dist}">
70
    	<fileset dir="." includes="text*.properties"/>
71
    </copy>
72
    <copy todir="${dist}">
73
    	<fileset dir="." includes="${src}"/>
74

  
75
    </copy>
76
  	<copy todir="${dist}/images">
77
    	<fileset dir="images/" includes="*"/>
78
    </copy>
79
  	<move todir="${extensionDir}/${plugin}/images">
80
  		<fileset dir="images/" includes="*"/>
81
  	</move>
82
    <move todir="${extensionDir}/${plugin}/">
83
    	<fileset dir="${dist}" includes="**/**" excludes="com/iver/cit/gvsig/fmap/drivers/sde/**"/>
84
    </move>
85
  	<jar jarfile="${drivers-dir}/sde/sde.jar" basedir="./bin" excludes="**/*VectorialSDEDriver*"
86
  	includes="com/iver/cit/gvsig/fmap/drivers/sde/*.*"
87
  	/>
88
  	<jar jarfile="${extensionDir}/${mainplugin}/lib/gvsig-sde.jar" basedir="./bin" includes="com/iver/cit/gvsig/fmap/drivers/sde/VectorialSDEDriver.*"/>
89
  </target-->
90

  
91
  <target name="clean"
92
        description="clean up" >
93
    <delete dir="${dist}"/>
94
  </target>
95
</project>
96

  
0 97

  
trunk/extensions/extAnnotations/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/>
6
	<classpathentry sourcepath="/libGDBMS" kind="lib" path="/libFMap/lib/gdbms-0.8-SNAPSHOT.jar"/>
7
	<classpathentry sourcepath="/libDriverManager" kind="lib" path="/libFMap/lib/driver-manager-1.1.jar"/>
8
	<classpathentry sourcepath="/libCq CMS for java" kind="lib" path="/libFMap/lib/cms.jar"/>
9
	<classpathentry sourcepath="/Utiles/src" kind="lib" path="/_fwAndami/lib/iver-utiles.jar"/>
10
	<classpathentry sourcepath="D:/eclipse_3_1/workspace_pruebas/jts/src" kind="lib" path="/libFMap/lib/jts-1.7.jar"/>
11
	<classpathentry combineaccessrules="false" kind="src" path="/_fwAndami"/>
12
	<classpathentry combineaccessrules="false" kind="src" path="/appgvSIG"/>
13
	<classpathentry sourcepath="D:/Download/geotools2/geotools-src-2.1.M4/geotools/module/main/src" kind="lib" path="/libFMap/lib/gt2-main.jar"/>
14
	<classpathentry kind="output" path="bin"/>
15
</classpath>
0 16

  
trunk/extensions/extAnnotations/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>extAnnotations</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>de.loskutov.FileSync.FSBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
	</buildSpec>
19
	<natures>
20
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
21
		<nature>org.eclipse.jdt.core.javanature</nature>
22
		<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
23
	</natures>
24
</projectDescription>
0 25

  
trunk/extensions/extAnnotations/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="com.iver.cit.gvsig" />
4
	<libraries library-dir="lib"/>
5
	<extensions>
6
		<extension class-name="com.iver.cit.gvsig.Annotation_Extension"
7
			description="Annotation extension"
8
			active="true"
9
			priority="1">
10

  
11
			<menu text="Capa/export_to/annotation" action-command="ANNOTATIONLAYER" key="d"
12
				tooltip="Create annotation layer"
13
				position="7"/>
14
		</extension>
15
		<extension class-name="com.iver.cit.gvsig.Annotation_PropertiesExtension"
16
			description="Annotation properties extension"
17
			active="true"
18
			priority="1">
19

  
20
			<menu text="Capa/annotation_properties" action-command="ANNOTATIONPROPERTIES"
21
				tooltip="Annotation properties layer"
22
				position="6"/>
23
		</extension>
24
	</extensions>
25
</plugin-config>
0 26

  
trunk/extensions/extAnnotations/src/com/iver/cit/gvsig/Annotation_PropertiesExtension.java
1
package com.iver.cit.gvsig;
2

  
3
import javax.swing.ImageIcon;
4

  
5
import com.hardcode.gdbms.engine.data.driver.DriverException;
6
import com.iver.andami.PluginServices;
7
import com.iver.andami.plugins.Extension;
8
import com.iver.andami.ui.mdiManager.IWindow;
9
import com.iver.cit.gvsig.fmap.MapContext;
10
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
11
import com.iver.cit.gvsig.fmap.layers.FLayer;
12
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
13
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
14
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard;
15
import com.iver.cit.gvsig.project.documents.gui.Annotation_ConfigureLabel;
16
import com.iver.cit.gvsig.project.documents.gui.Annotation_Create;
17
import com.iver.cit.gvsig.project.documents.gui.Annotation_FieldSelect;
18
import com.iver.cit.gvsig.project.documents.gui.Annotation_Modify;
19
import com.iver.cit.gvsig.project.documents.view.IProjectView;
20

  
21
public class Annotation_PropertiesExtension extends Extension {
22
	private MapContext map = null;
23
	public void initialize() {
24
		// TODO Auto-generated method stub
25

  
26
	}
27

  
28
	public void execute(String actionCommand) {
29
		if ("ANNOTATIONPROPERTIES".equals(actionCommand)) {
30
			ImageIcon Logo = new javax.swing.ImageIcon(this.getClass()
31
					.getClassLoader()
32
					.getResource("images/package_graphics.png"));
33

  
34
			SimpleWizard wizard = new SimpleWizard(Logo);
35

  
36
			Annotation_Layer la = (Annotation_Layer) map.getLayers().getActives()[0];
37
			Annotation_FieldSelect panel1 = new Annotation_FieldSelect(wizard
38
					.getWizardComponents(), la);
39
			Annotation_ConfigureLabel panel2 = new Annotation_ConfigureLabel(
40
					wizard.getWizardComponents(), la);
41

  
42
			wizard.getWizardComponents().addWizardPanel(panel1);
43
			wizard.getWizardComponents().addWizardPanel(panel2);
44

  
45
			wizard.getWizardComponents()
46
					.setFinishAction(
47
							new Annotation_Modify(wizard.getWizardComponents(),
48
									map, la));
49

  
50
			wizard.getWindowInfo().setWidth(540);
51
			wizard.getWindowInfo().setHeight(380);
52
			wizard.getWindowInfo().setTitle(
53
					PluginServices.getText(this, "to_annotation"));
54

  
55
			PluginServices.getMDIManager().addWindow(wizard);
56

  
57
			/*
58
			 * FLyrVect lv=(FLyrVect)map.getLayers().getActives()[0];
59
			 * FLyrAnnotation la=new FLyrAnnotation();
60
			 * la.setSource(lv.getSource());
61
			 *
62
			 * MappingFieldsToAnotation mfta=new MappingFieldsToAnotation(la);
63
			 * PluginServices.getMDIManager().addView(mfta);
64
			 *
65
			 * if (mfta.isOk()){ map.getLayers().addLayer(la);
66
			 * map.getLayers().removeLayer(lv); }
67
			 */
68
		}
69

  
70
	}
71

  
72
	public boolean isEnabled() {
73
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
74

  
75
		if ((v != null)
76
				&& v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
77
			com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) v;
78
			IProjectView model = vista.getModel();
79
			map = model.getMapContext();
80

  
81
			FLayer[] layers = map.getLayers().getActives();
82

  
83
			if (layers.length == 1) {
84
				if (layers[0].isAvailable()
85
						&& layers[0] instanceof Annotation_Layer) {
86
					return true;
87
				}
88
			}
89
		}
90

  
91
		return false;
92
	}
93

  
94
	public boolean isVisible() {
95
		IWindow v = PluginServices.getMDIManager().getActiveWindow();
96

  
97
		if (v == null) {
98
			return false;
99
		} else if (v instanceof com.iver.cit.gvsig.project.documents.view.gui.View) {
100
			return true;
101
		} else {
102
			return false;
103
		}
104
	}
105

  
106
}
0 107

  
trunk/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/operation/strategies/Annotation_Strategy.java
1
package com.iver.cit.gvsig.fmap.operation.strategies;
2

  
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.FontMetrics;
6
import java.awt.Graphics2D;
7
import java.awt.Shape;
8
import java.awt.font.FontRenderContext;
9
import java.awt.font.GlyphVector;
10
import java.awt.geom.AffineTransform;
11
import java.awt.geom.Point2D;
12
import java.awt.geom.Rectangle2D;
13
import java.awt.image.BufferedImage;
14
import java.util.List;
15
import java.util.logging.Level;
16
import java.util.logging.Logger;
17

  
18
import org.cresques.cts.ICoordTrans;
19

  
20
import com.hardcode.driverManager.DriverLoadException;
21
import com.hardcode.gdbms.engine.values.NullValue;
22
import com.hardcode.gdbms.engine.values.NumericValue;
23
import com.hardcode.gdbms.engine.values.StringValue;
24
import com.hardcode.gdbms.engine.values.Value;
25
import com.iver.cit.gvsig.fmap.DriverException;
26
import com.iver.cit.gvsig.fmap.ViewPort;
27
import com.iver.cit.gvsig.fmap.core.FPoint2D;
28
import com.iver.cit.gvsig.fmap.core.FShape;
29
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
30
import com.iver.cit.gvsig.fmap.core.IGeometry;
31
import com.iver.cit.gvsig.fmap.core.ISymbol;
32
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
33
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
34
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
35
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
36
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
37
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
38
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
39
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
40
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
41
import com.iver.cit.gvsig.fmap.layers.FBitSet;
42
import com.iver.cit.gvsig.fmap.layers.FLayer;
43
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
44
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
45
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
46
import com.iver.cit.gvsig.fmap.layers.SpatialCache;
47
import com.iver.cit.gvsig.fmap.operations.strategies.DefaultStrategy;
48
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
49
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
50
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
51
import com.iver.utiles.swing.threads.Cancellable;
52
import com.vividsolutions.jts.geom.Geometry;
53
import com.vividsolutions.jts.geom.IntersectionMatrix;
54

  
55

  
56
/**
57
 * Esta clase se encargar? de dibujar de la forma m?s eficiente los temas de
58
 * anotaciones.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class Annotation_Strategy extends DefaultStrategy {
63
	private FSymbol symbolPoint=new FSymbol(FShape.POINT,Color.black);
64
	private Graphics2D graphics=null;
65
	private ViewPort viewPort=null;
66
	private double heightDefault=-1;
67
	private Annotation_Layer capa;
68
	/**
69
     * Crea un nuevo AnotationStrategy.
70
     *
71
     * @param layer
72
     */
73
    public Annotation_Strategy(FLayer layer) {
74
        super(layer);
75
        capa = (Annotation_Layer)getCapa();
76
        symbolPoint.setSize(5);
77
    }
78
//    /**
79
//	 * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
80
//	 * 		java.awt.Graphics2D, ISymbol)
81
//	 */
82
//	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
83
//		Cancellable cancel) throws DriverException {
84
//		Rectangle2D elExtent = viewPort.getAdjustedExtent();
85
//		graphics=g;
86
//		Annotation_Layer lyrAnnotation=(Annotation_Layer)capa;
87
//		List lstIndexes=null;
88
//
89
//		Annotation_Legend l=(Annotation_Legend)lyrAnnotation.getLegend();
90
//		FBitSet bitSet=lyrAnnotation.getRecordset().getSelection();
91
//
92
//		boolean inPixels=lyrAnnotation.isInPixels();
93
//		FSymbol theSymbol = (FSymbol) l.getDefaultSymbol();
94
//		theSymbol.setFontSizeInPixels(inPixels);
95
//		System.out.println("Dibujando Anotaciones...");
96
//		this.viewPort=viewPort;//capa.getFMap().getViewPort();
97
//		AffineTransform at=viewPort.getAffineTransform();
98
//		try {
99
//			int sc;
100
//			sc=lyrAnnotation.getSource().getShapeCount();
101
//            // If area of needed extent is less than fullExtent / 4,
102
//            // it will be worthy to use SpatialIndex.
103
//            // Otherwhise, we will not use it.
104
//			boolean bUseSpatialIndex = false;
105
//            if(lyrAnnotation.getISpatialIndex() != null)
106
//            {
107
//            	if(isSpatialIndexNecessary(elExtent)){
108
//            		lstIndexes = lyrAnnotation.getISpatialIndex().query(elExtent);
109
//                    sc = lstIndexes.size();
110
//                    System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc);
111
//                    bUseSpatialIndex = true;
112
//            	}//if
113
//            }//if
114
//
115
//			FontMetrics metrics = g.getFontMetrics();
116
//			SpatialCache cache = lyrAnnotation.getSpatialCache();
117
//			cache.clearAll();
118
//			int numOriginal;
119
//			ReadableVectorial adapter = capa.getSource();
120
//			adapter.start();
121
//			for (int numReg = 0; numReg < sc; numReg++) {
122
//				if (cancel.isCanceled()){
123
//					break;
124
//				}
125
//                if (bUseSpatialIndex){
126
//                    Integer idRec = (Integer) lstIndexes.get(numReg);
127
//                    numOriginal = idRec.intValue();
128
//                }else{
129
//                    numOriginal = numReg;
130
//                }
131
//				/* if (lyrAnnotation.getSource() instanceof EditableAdapter)
132
//					numOriginal=((EditableAdapter)lyrAnnotation.getSource()).getCalculatedIndex(numOriginal);*/
133
//                theSymbol = (FSymbol) l.getSymbol(numReg);
134
//				IGeometry geom = l.getTextWrappingGeometry(theSymbol,numOriginal);
135
////				if ((theLabel == null) || (theLabel.getOrig() == null))
136
////					continue;
137
//
138
//
139
//				Rectangle2D r=null;
140
//				if (inPixels || lyrAnnotation.getMapping().getColumnHeight()==-1) {
141
//					r=geom.getBounds2D();//getDefaultBoundBoxinPixels(metrics,theLabel.getOrig(),theLabel.getString());
142
//				}else {
143
//					r=geom.getBounds2D();//getBoundBox(theLabel.getOrig(),(float)theLabel.getHeight(), theLabel.getJustification(),theLabel.getString());
144
//				}
145
////				theLabel.setBoundBox(r);
146
//
147
//				if (XRectangle2D.intersectInclusive(r,elExtent))
148
//				{
149
//					FPoint2D p=new FPoint2D(viewPort.fromMapPoint(new Point2D.Double(r.getX(),r.getY())));
150
//					symbolPoint.draw(g, at, p);
151
//					// FGraphicUtilities.DrawShape(g,at,p,symbolPoint);
152
//					FLabel label=new FLabel();
153
//					label.setHeight(theSymbol.getFontSize());
154
//					label.setRotation(theSymbol.getRotation());
155
//					label.setString(theSymbol.getDescription());
156
//					label.setOrig(new Point2D.Double(r.getMinX(),r.getMaxY()));
157
//					if (bitSet.get(numOriginal)) {
158
//						FGraphicUtilities.DrawAnnotation(g, at, theSymbol, label,metrics,true);
159
//					}else{
160
//
161
//
162
//						FGraphicUtilities.DrawAnnotation(g, at, theSymbol, label,metrics,false);
163
//					}
164
//
165
//
166
//					if (lyrAnnotation.isSpatialCacheEnabled())
167
//					{
168
//						if (cache.getMaxFeatures() >= cache.size())
169
//						{
170
//							// 	Ya reproyectado todo
171
//							IGeometry geo=ShapeFactory.createPoint2D(r.getX(),r.getY());
172
//							Rectangle2D re= new Rectangle2D.Double(r.getX(),r.getY(),1,1);
173
//							cache.insert(re, geo);
174
//						}
175
//					}
176
//				} // XIntersects
177
//
178
//
179
//			}
180
//			adapter.stop();
181
//
182
//		//	 System.out.println("..................Fin del dibujado ..............");
183
//		} catch (DriverIOException e) {
184
//			e.printStackTrace();
185
//		} catch (DriverException e) {
186
//			// TODO Auto-generated catch block
187
//			e.printStackTrace();
188
//		}
189
//		heightDefault=-1;
190
//	}
191

  
192

  
193
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
194
			Cancellable cancel) {
195
		// Copia draw AttrInTableLabeling
196
		Annotation_Legend l = (Annotation_Legend) capa.getLegend();
197
		FSymbol sym = (FSymbol) l.getDefaultSymbol();
198

  
199
		Rectangle2D elExtent = viewPort.getAdjustedExtent();
200
		List lstIndexes=null;
201

  
202
		try {
203
			int sc;
204
			ReadableVectorial source = capa.getSource();
205
			sc=source.getShapeCount();
206

  
207
			SelectableDataSource recordSet = source.getRecordset();
208
			FBitSet bitSet=recordSet.getSelection();
209
			// If area of needed extent is less than fullExtent / 4,
210
            // it will be worthy to use SpatialIndex.
211
            // Otherwhise, we will not use it.
212
			boolean bUseSpatialIndex = false;
213
            if(capa.getISpatialIndex() != null)
214
            {
215
            	if(isSpatialIndexNecessary(elExtent)){
216
            		lstIndexes = capa.getISpatialIndex().query(elExtent);
217
                    sc = lstIndexes.size();
218
                    System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc);
219
                    bUseSpatialIndex = true;
220
            	}//if
221
            }//if
222
            FontMetrics metrics = g.getFontMetrics();
223
			Annotation_Mapping mapping = ((Annotation_Layer) capa)
224
				.getMapping();
225
			int idHeightField = mapping.getColumnHeight();
226
			int idFontName = mapping.getColumnTypeFont();
227
			int idFontStyle = mapping.getColumnStyleFont();
228
			int idRotationField = mapping.getColumnRotate();
229
			int idFontColor = mapping.getColumnColor();
230
			int idTextField = mapping.getColumnText();
231

  
232
			double rotation = 0D;
233
			double size = sym.getFont().getSize();
234
			sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels());
235
			String fontName = "Dialog";
236
			int fontStyle = sym.getFont().getStyle();
237
			int fontColor = sym.getFontColor().getRGB();
238
			SpatialCache cache = capa.getSpatialCache();
239
			cache.clearAll();
240
			int numOriginal;
241
			for (int numReg = 0; numReg < sc; numReg++) {
242
            	if (cancel.isCanceled()){
243
					break;
244
				}
245
                if (bUseSpatialIndex){
246
                    Integer idRec = (Integer) lstIndexes.get(numReg);
247
                    numOriginal = idRec.intValue();
248
                }else{
249
                    numOriginal = numReg;
250
                }
251
                Value[] vv = recordSet.getRow(numOriginal);
252
				if (idHeightField != -1) {
253
					// text size is defined in the table
254
					try {
255
						size = ((NumericValue) vv[idHeightField]).doubleValue()
256
								* FConstant.FONT_HEIGHT_SCALE_FACTOR;
257
					} catch (ClassCastException ccEx) {
258
						if (!NullValue.class.equals(vv[idHeightField]
259
								.getClass())) {
260
							// throw new ReadDriverException("Unknown", ccEx);
261
						}
262
						// a null value
263
						// Logger.getAnonymousLogger().
264
						// warning("Null text height value for text
265
						// '"+vv[idTextField].toString()+"'");
266
						continue;
267
					}
268
				} else {
269
					// otherwise will use the size in the symbol
270

  
271
				}
272

  
273
				// size = CartographicSupportToolkit.
274
				// toScreenUnitYAxis(size,
275
				// unit,
276
				// viewPort
277
				// );
278

  
279
//				if (size <= 3) {
280
//					// label is too small to be readable, will be skipped
281
//					// this speeds up the rendering in wider zooms
282
//					continue;
283
//				}
284

  
285

  
286
				if (idFontName != -1) {
287
					fontName = ((StringValue) vv[idFontName]).toString();
288
				}
289

  
290

  
291
				if (idFontStyle != -1) {
292
					fontStyle = ((NumericValue) vv[idFontStyle]).intValue();
293
				}
294

  
295

  
296

  
297
				if (idRotationField != -1) {
298
					// text rotation is defined in the table
299
					rotation = ((NumericValue) vv[idRotationField])
300
							.doubleValue();
301
				}
302

  
303

  
304
				if (idFontColor != -1) {
305
					// text rotation is defined in the table
306
					fontColor = ((NumericValue) vv[idFontColor]).intValue();
307
					sym.setFontColor(new Color(fontColor));
308
				}
309

  
310
				if (bitSet.get(numOriginal)){
311
					sym = (FSymbol)sym.getSymbolForSelection();
312
				}
313
				IGeometry geom = source.getShape(numOriginal);
314

  
315
				sym.setFont(new Font(fontName, fontStyle, (int) size));
316

  
317

  
318
//				sym.setDescription(vv[idTextField].toString());
319
//				sym.setRotation((int) rotation);
320
				FLabel[] aux = geom.createLabels(0, true);
321
				aux[0].setHeight(size);
322
				aux[0].setRotation((int) rotation);
323
				aux[0].setString(vv[idTextField].toString());
324
				symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig())));
325
				FGraphicUtilities.DrawAnnotation(g, viewPort
326
						.getAffineTransform(), sym, aux[0], metrics, false);
327
			}
328

  
329

  
330

  
331

  
332

  
333

  
334

  
335
//			// limit the labeling to the visible extent
336
//			FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent());
337
//
338
//
339
//			SelectableDataSource recordSet = source.getRecordset();
340
//			FBitSet bitSet=recordSet.getSelection();
341
//			FontMetrics metrics = g.getFontMetrics();
342
//			Annotation_Mapping mapping = ((Annotation_Layer) capa)
343
//				.getMapping();
344
//			int idHeightField = mapping.getColumnHeight();
345
//			int idFontName = mapping.getColumnTypeFont();
346
//			int idFontStyle = mapping.getColumnStyleFont();
347
//			int idRotationField = mapping.getColumnRotate();
348
//			int idFontColor = mapping.getColumnColor();
349
//			int idTextField = mapping.getColumnText();
350
//
351
//			double rotation = 0D;
352
//			double size = sym.getFont().getSize();
353
//			sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels());
354
//			String fontName = "Dialog";
355
//			int fontStyle = sym.getFont().getStyle();
356
//			int fontColor = sym.getFontColor().getRGB();
357
//			for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
358
//				if (cancel.isCanceled()){
359
//					break;
360
//				}
361
//				Value[] vv = recordSet.getRow(i);
362
//				if (idHeightField != -1) {
363
//					// text size is defined in the table
364
//					try {
365
//						size = ((NumericValue) vv[idHeightField]).doubleValue()
366
//								* FConstant.FONT_HEIGHT_SCALE_FACTOR;
367
//					} catch (ClassCastException ccEx) {
368
//						if (!NullValue.class.equals(vv[idHeightField]
369
//								.getClass())) {
370
//							// throw new ReadDriverException("Unknown", ccEx);
371
//						}
372
//						// a null value
373
//						// Logger.getAnonymousLogger().
374
//						// warning("Null text height value for text
375
//						// '"+vv[idTextField].toString()+"'");
376
//						continue;
377
//					}
378
//				} else {
379
//					// otherwise will use the size in the symbol
380
//
381
//				}
382
//
383
//				// size = CartographicSupportToolkit.
384
//				// toScreenUnitYAxis(size,
385
//				// unit,
386
//				// viewPort
387
//				// );
388
//
389
////				if (size <= 3) {
390
////					// label is too small to be readable, will be skipped
391
////					// this speeds up the rendering in wider zooms
392
////					continue;
393
////				}
394
//
395
//
396
////				if (idFontName != -1) {
397
////					fontName = ((StringValue) vv[idFontName]).toString();
398
////				}
399
//
400
//
401
////				if (idFontStyle != -1) {
402
////					fontStyle = ((NumericValue) vv[idFontStyle]).intValue();
403
////				}
404
//
405
//
406
//
407
//				if (idRotationField != -1) {
408
//					// text rotation is defined in the table
409
//					rotation = ((NumericValue) vv[idRotationField])
410
//							.doubleValue();
411
//				}
412
//
413
//
414
//				if (idFontColor != -1) {
415
//					// text rotation is defined in the table
416
//					fontColor = ((NumericValue) vv[idFontColor]).intValue();
417
//					sym.setFontColor(new Color(fontColor));
418
//				}
419
//
420
//				if (bitSet.get(i)){
421
//					sym = (FSymbol)sym.getSymbolForSelection();
422
//				}
423
//				IGeometry geom = source.getShape(i);
424
//
425
//				sym.setFont(new Font(fontName, fontStyle, (int) size));
426
//
427
//
428
////				sym.setDescription(vv[idTextField].toString());
429
////				sym.setRotation((int) rotation);
430
//				FLabel[] aux = geom.createLabels(0, true);
431
//				aux[0].setHeight(size);
432
//				aux[0].setRotation((int) rotation);
433
//				aux[0].setString(vv[idTextField].toString());
434
//				symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig())));
435
//				FGraphicUtilities.DrawAnnotation(g, viewPort
436
//						.getAffineTransform(), sym, aux[0], metrics, false);
437
//			}
438
		} catch (Exception e) {
439
			// Logger.getAnonymousLogger().log(Level.SEVERE, "Could not get the
440
			// layer extent.\n" +
441
			// e.getMessage());
442
			e.printStackTrace();
443
		}
444

  
445
		// }
446
	}
447

  
448

  
449

  
450

  
451

  
452

  
453

  
454

  
455
	  /**
456
		 * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
457
		 *      java.awt.Graphics2D, ISymbol)
458
		 */
459
	public void print(BufferedImage image, Graphics2D g, ViewPort viewPort,
460
		Cancellable cancel) throws DriverException {
461
//		Rectangle2D elExtent = viewPort.getAdjustedExtent();
462
//		graphics=g;
463
//		Annotation_Layer lyrAnnotation=(Annotation_Layer)capa;
464
//		List lstIndexes=null;
465
//
466
//		VectorialLegend l=(VectorialLegend)lyrAnnotation.getLegend();
467
//		FBitSet bitSet=lyrAnnotation.getRecordset().getSelection();
468
//
469
//		boolean inPixels=lyrAnnotation.isInPixels();
470
//		FSymbol theSymbol = (FSymbol) l.getDefaultSymbol();
471
//		theSymbol.setFontSizeInPixels(inPixels);
472
//		this.viewPort=viewPort;//capa.getFMap().getViewPort();
473
//		AffineTransform at=viewPort.getAffineTransform();
474
//		try {
475
//			int sc;
476
//			sc=lyrAnnotation.getSource().getShapeCount();
477
//            // If area of needed extent is less than fullExtent / 4,
478
//            // it will be worthy to use SpatialIndex.
479
//            // Otherwhise, we will not use it.
480
//			boolean bUseSpatialIndex = false;
481
//            if(lyrAnnotation.getISpatialIndex() != null)
482
//            {
483
//            	if(isSpatialIndexNecessary(elExtent)){
484
//            		lstIndexes = lyrAnnotation.getISpatialIndex().query(elExtent);
485
//                    sc = lstIndexes.size();
486
//                    bUseSpatialIndex = true;
487
//            	}//if
488
//            }//if
489
//
490
//			FontMetrics metrics = g.getFontMetrics();
491
//			//SpatialCache cache = lyrAnnotation.createSpatialCache();
492
//			int numOriginal;
493
//			for (int numReg = 0; numReg < sc; numReg++) {
494
//				if (cancel.isCanceled()){
495
//					break;
496
//				}
497
//                if (bUseSpatialIndex){
498
//                    Integer idRec = (Integer) lstIndexes.get(numReg);
499
//                    numOriginal = idRec.intValue();
500
//                }else{
501
//                    numOriginal = numReg;
502
//                }
503
//				/* if (lyrAnnotation.getSource() instanceof EditableAdapter)
504
//					numOriginal=((EditableAdapter)lyrAnnotation.getSource()).getCalculatedIndex(numOriginal);*/
505
//
506
//				FLabel theLabel = lyrAnnotation.getLabel(numOriginal);
507
//				if ((theLabel == null) || (theLabel.getOrig() == null))
508
//					continue;
509
//
510
//
511
//				Rectangle2D r=null;
512
//				if (inPixels && lyrAnnotation.getMapping().getColumnHeight()==-1) {
513
//					r=getDefaultBoundBoxinPixels(metrics,theLabel.getOrig(),theLabel.getString());
514
//				}else {
515
//					r=getBoundBox(theLabel.getOrig(),(float)theLabel.getHeight(), theLabel.getJustification(),theLabel.getString());
516
//				}
517
//				theLabel.setBoundBox(r);
518
//
519
//				if (elExtent.intersects(r))
520
//				{
521
//					FPoint2D p=new FPoint2D(viewPort.fromMapPoint(new Point2D.Double(r.getX(),r.getY())));
522
//					FGraphicUtilities.DrawShape(g,at,p,symbolPoint);
523
//					if (bitSet.get(numOriginal)) {
524
//						FGraphicUtilities.DrawAnnotation(g, at, theSymbol, theLabel,metrics,true);
525
//					}else{
526
//						FGraphicUtilities.DrawAnnotation(g, at, theSymbol, theLabel,metrics,false);
527
//					}
528
//
529
//
530
//				} // XIntersects
531
//
532
//
533
//			}
534
//
535
//		} catch (DriverIOException e) {
536
//			e.printStackTrace();
537
//		}
538
//		heightDefault=-1;
539
	}
540

  
541
	 public Rectangle2D getDefaultBoundBoxinPixels(FontMetrics metrics,
542
			Point2D p, String s) {
543
		int w = metrics.stringWidth(s);
544
		double width = viewPort.toMapDistance(w);
545
		if (heightDefault == -1) {
546
			int h = metrics.getMaxAscent();
547
			heightDefault = viewPort.toMapDistance(h);
548
		}
549
		return new Rectangle2D.Double(p.getX(), p.getY(), width, heightDefault);
550

  
551
	}
552

  
553
	 /**
554
		 * Construcci?n del rect?ngulo
555
		 *
556
		 * @param p
557
		 * @param g
558
		 *            DOCUMENT ME!
559
		 * @param justification
560
		 *            DOCUMENT ME!
561
		 * @param vp
562
		 *            DOCUMENT ME!
563
		 *
564
		 * @return
565
		 */
566
    public Rectangle2D getBoundBox(Point2D p, float hp,
567
        int justification,String s) {
568
        //Rectangle2D bounding=null;
569
        if (((Annotation_Layer)capa).isInPixels()){
570
        	graphics.setFont(graphics.getFont().deriveFont(hp));
571
        }else{
572
        	float alturaPixels = (float) ((hp * viewPort.getAffineTransform().getScaleX())*FConstant.FONT_HEIGHT_SCALE_FACTOR);
573
        	graphics.setFont(graphics.getFont().deriveFont(alturaPixels));
574
        }
575
        FontMetrics metrics = graphics.getFontMetrics();
576
        int w = metrics.stringWidth(s);
577
        double width = viewPort.toMapDistance(w);
578
        int h = metrics.getMaxAscent();
579
        double height = viewPort.toMapDistance(h);
580
        //double dist = viewPort.toMapDistance(3);
581
        return new Rectangle2D.Double(p.getX(), p.getY(), width, height);
582
       /* switch (justification) {
583
            case FLabel.LEFT_BOTTOM:
584
                bounding=justification(p, width,height, 0, 0);
585

  
586
                break;
587

  
588
            case FLabel.LEFT_CENTER:
589
            	 bounding=justification(p, width,height, 0, -(height / 2));
590

  
591
                break;
592

  
593
            case FLabel.LEFT_TOP:
594
            	 bounding=justification(p,width,height, 0, -height);
595

  
596
                break;
597

  
598
            case FLabel.CENTER_BOTTOM:
599
            	 bounding=justification(p, width,height, -(width / 2), -dist);
600

  
601
                break;
602

  
603
            case FLabel.CENTER_CENTER:
604
            	 bounding=justification(p, width,height, -(width / 2), -(height / 2));
605

  
606
                break;
607

  
608
            case FLabel.CENTER_TOP:
609
            	 bounding=justification(p, width,height, -(width / 2), -height);
610

  
611
                break;
612

  
613
            case FLabel.RIGHT_BOTTOM:
614
            	 bounding=justification(p, width,height, -width, -dist);
615

  
616
                break;
617

  
618
            case FLabel.RIGHT_CENTER:
619
            	 bounding=justification(p, width,height, -width, -(height / 2));
620

  
621
                break;
622

  
623
            case FLabel.RIGHT_TOP:
624
            	 bounding=justification(p, width,height, -width, -height);
625

  
626
                break;
627
        }
628

  
629
        return bounding;
630
        */
631
    }
632
  /*  private Rectangle2D justification(Point2D p, double w,double h, double x, double y) {
633
        Rectangle2D r=new Rectangle2D.Double(p.getX() + x, p.getY() - y, w, h);
634
        return r;
635
    }
636
    */
637

  
638
    /* (non-Javadoc)
639
     * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int)
640
     */
641
    public FBitSet queryByShape(IGeometry g, int relationship)
642
    throws DriverException, VisitException {
643
        // Si hay un ?ndice espacial, lo usamos para hacer el query.
644
        FLyrVect lyr = (FLyrVect) capa;
645
//        if (lyr.getSpatialIndex() == null)
646
        if(lyr.getISpatialIndex() == null)
647
            return super.queryByShape(g, relationship);
648

  
649
        long t1 = System.currentTimeMillis();
650
        ReadableVectorial va = lyr.getSource();
651
        ICoordTrans ct = lyr.getCoordTrans();
652
        Rectangle2D bounds = g.getBounds2D();
653
//        Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY());
654
//        Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY());
655
//        Envelope env = new Envelope(c1, c2);
656
//        List lstRecs = lyr.getSpatialIndex().query(env);
657
        List lstRecs = lyr.getISpatialIndex().query(bounds);
658
        Integer idRec;
659
        FBitSet bitset = new FBitSet();
660
        Geometry jtsShape = g.toJTSGeometry();
661
        IntersectionMatrix m;
662
        int index;
663
        try {
664
            va.start();
665
//            Annotation_Legend aLegend=(Annotation_Legend)capa.getLegend();
666
            for (int i=0; i < lstRecs.size(); i++)
667
            {
668
                idRec = (Integer) lstRecs.get(i);
669
                index = idRec.intValue();
670
                IGeometry geom=va.getShape(index);
671
//                FSymbol symbol=(FSymbol)aLegend.getSymbol(index);
672
//                IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index);
673
//                IGeometry geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox());
674
                if (ct != null) {
675
                    geom.reProject(ct);
676
                }
677
                Geometry jtsGeom = geom.toJTSGeometry();
678
                switch (relationship) {
679
                case CONTAINS:
680
                    m = jtsShape.relate(jtsGeom);
681
                    if (m.isContains()) {
682
                        bitset.set(index, true);
683
                    }
684
                    break;
685

  
686
                case CROSSES:
687
                    m = jtsShape.relate(jtsGeom);
688
                    if (m.isCrosses(jtsGeom.getDimension(), jtsShape.getDimension())) {
689
                        bitset.set(index, true);
690
                    }
691
                    break;
692

  
693
                case DISJOINT:
694
                    // TODO: CREO QUE EL DISJOINT NO SE PUEDE METER AQUI
695
                    m = jtsShape.relate(jtsGeom);
696
                    if (m.isDisjoint()) {
697
                        bitset.set(index, true);
698
                    }
699
                    break;
700

  
701
                case EQUALS:
702
                    m = jtsShape.relate(jtsGeom);
703
                    if (m.isEquals(jtsGeom.getDimension(), jtsShape.getDimension())) {
704
                        bitset.set(index, true);
705
                    }
706
                    break;
707

  
708
                case INTERSECTS:
709
                    m = jtsShape.relate(jtsGeom);
710
                    if (m.isIntersects()) {
711
                        bitset.set(index, true);
712
                    }
713
                    break;
714

  
715
                case OVERLAPS:
716
                    m = jtsShape.relate(jtsGeom);
717
                    if (m.isOverlaps(jtsGeom.getDimension(), jtsShape.getDimension()))
718
                    {
719
                        bitset.set(index, true);
720
                    }
721

  
722
                    break;
723

  
724
                case TOUCHES:
725
                    m = jtsShape.relate(jtsGeom);
726
                    if (m.isTouches(jtsGeom.getDimension(), jtsShape.getDimension()))
727
                    {
728
                        bitset.set(index, true);
729
                    }
730

  
731
                    break;
732

  
733
                case WITHIN:
734
                    m = jtsShape.relate(jtsGeom);
735
                    if (m.isWithin()) {
736
                        bitset.set(index, true);
737
                    }
738

  
739
                    break;
740
                }
741
            }
742
            va.stop();
743
        } catch (DriverIOException e) {
744
            // TODO Auto-generated catch block
745
            e.printStackTrace();
746
        }
747
        long t2 = System.currentTimeMillis();
748
//        logger.debug("queryByShape optimizado sobre la capa " + lyr.getName() + ". " + (t2-t1) + " mseg.");
749
        return bitset;
750
    }
751
    public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
752
        // Si hay un ?ndice espacial, lo usamos para hacer el query.
753
        Annotation_Layer lyr = (Annotation_Layer) capa;
754
//        if (lyr.getSpatialIndex() == null)
755
          if(lyr.getISpatialIndex() == null)
756
            return super.queryByRect(rect);
757

  
758
        ReadableVectorial va = lyr.getSource();
759
        ICoordTrans ct = lyr.getCoordTrans();
760
        Rectangle2D bounds = rect;
761
//        Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY());
762
//        Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY());
763
//        Envelope env = new Envelope(c1, c2);
764
//
765
//        List lstRecs = lyr.getSpatialIndex().query(env);
766
        //azabala
767
        List lstRecs = lyr.getISpatialIndex().query(bounds);
768
        Integer idRec;
769
        FBitSet bitset = new FBitSet();
770
        int index;
771
        try {
772
            va.start();
773
            DriverAttributes attr = va.getDriverAttributes();
774
            boolean bMustClone = false;
775
            if (attr != null)
776
            {
777
                if (attr.isLoadedInMemory())
778
                {
779
                    bMustClone = attr.isLoadedInMemory();
780
                }
781
            }
782
//            Annotation_Legend aLegend=(Annotation_Legend)capa.getLegend();
783
            for (int i=0; i < lstRecs.size(); i++)
784
            {
785
                idRec = (Integer) lstRecs.get(i);
786
                index = idRec.intValue();
787
//                FSymbol symbol=(FSymbol)aLegend.getSymbol(index);
788
//                IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index);
789
                Annotation_Mapping mapping=((Annotation_Layer)capa).getMapping();
790
				NumericValue vRotation = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnRotate());
791
				NumericValue vHeight = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnHeight());
792
				Value vText = va.getRecordset().getFieldValue(index,mapping.getColumnText());
793
				IGeometry geom=((Annotation_Legend)capa.getLegend()).getTextWrappingGeometry(vHeight.floatValue(),
794
						vText.toString(),vRotation.doubleValue(),index);
795
//                  IGeometry geom=va.getShape(index);
796
//                IGeometry geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox());
797
                if (ct != null) {
798
                    if (bMustClone)
799
                        geom = geom.cloneGeometry();
800
                    geom.reProject(ct);
801
                }
802
                //System.out.println("Rect?ngulo de selecci?n = "+ rect);
803
                //System.out.println("Rect?ngulo de la geometr?a = "+ geom.getBounds2D());
804
                if (geom.intersects(rect)){
805
                    bitset.set(index, true);
806
                }
807

  
808
            }
809
            va.stop();
810
        } catch (DriverIOException e) {
811
            // TODO Auto-generated catch block
812
            e.printStackTrace();
813
        } catch (DriverLoadException e) {
814
			// TODO Auto-generated catch block
815
			e.printStackTrace();
816
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
817
			// TODO Auto-generated catch block
818
			e.printStackTrace();
819
		}
820
        return bitset;
821

  
822
    }
823

  
824
    /* (non-Javadoc)
825
     * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D, double)
826
     */
827
    public FBitSet queryByPoint(Point2D p, double tolerance)
828
    throws DriverException {
829
        // TODO: OJO!!!!. Est? implementado como un rectangulo.
830
        // Lo correcto deber?a ser calculando las distancias reales
831
        // es decir, con un c?rculo.
832
        Rectangle2D recPoint = new Rectangle2D.Double(p.getX() - (tolerance / 2),
833
                p.getY() - (tolerance / 2), tolerance, tolerance);
834
        return queryByRect(recPoint);
835
    }
836
    private IGeometry getGeometry(Rectangle2D r){
837
    	GeneralPathX resul = new GeneralPathX();
838
		Point2D[] vs=new Point2D[4];
839
		vs[0]=new Point2D.Double(r.getX(),r.getY());
840
    	vs[1]=new Point2D.Double(r.getMaxX(),r.getY());
841
    	vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY());
842
    	vs[3]=new Point2D.Double(r.getX(),r.getMaxY());
843
    	//vs[4]=new Point2D.Double(r.getX(),r.getY());
844
		for (int i = 0; i < vs.length; i++) {
845
			if (i == 0) {
846
				resul.moveTo(vs[i].getX(),vs[i].getY());
847
			} else {
848
				resul.lineTo(vs[i].getX(),vs[i].getY());
849
			}
850
		}
851
		resul.closePath();
852
		return ShapeFactory.createPolygon2D(resul);
853
    }
854
//    public IGeometry getTextWrappingGeometry(FSymbol symbol,String description,double rotation,int numReg) throws DriverIOException {
855
//		ReadableVectorial adapter = capa.getSource();
856
////		adapter.start();
857
//		ICoordTrans ct = capa.getCoordTrans();
858
//		IGeometry geom = adapter.getShape(numReg);
859
//		boolean bMustClone = false;
860
//		if (geom == null) {
861
//			return null;
862
//		}
863
//		if (ct != null) {
864
//			if (bMustClone)
865
//				geom = geom.cloneGeometry();
866
//			geom.reProject(ct);
867
//		}
868
//		FLabel[] lbls = geom.createLabels(0, true);
869
//		Point2D p=lbls[0].getOrig();
870
//		// assuming FShape is a point with the starting position of the text
871
//		  Font font = symbol.getFont();
872
//
873
//		  FontRenderContext frc = new FontRenderContext(new AffineTransform(),false,false);//g.getFontRenderContext();
874
//
875
//		  GlyphVector gv = font.createGlyphVector(frc, description);
876
//
877
//		  /*p.transform(affineTransform);*/
878
//		  Shape shape = gv.getOutline((float) p.getX(), (float) p.getY());
879
//		  IGeometry myFShape = ShapeFactory.createPolygon2D(new GeneralPathX(shape.getBounds2D()));
880
//		  if (rotation != 0) {
881
//			  myFShape.transform(AffineTransform.getRotateInstance(rotation, p.getX(), p.getY()));
882
//		  }
883
////		  adapter.stop();
884
//		  return myFShape;
885
//		 }
886

  
887
}
0 888

  
trunk/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/edition/Annotation_EditableAdapter.java
1
package com.iver.cit.gvsig.fmap.edition;
2

  
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.FontMetrics;
6
import java.awt.geom.Point2D;
7
import java.awt.geom.Rectangle2D;
8
import java.io.IOException;
9
import java.util.ArrayList;
10
import java.util.Collection;
11
import java.util.Iterator;
12
import java.util.List;
13
import java.util.TreeMap;
14

  
15
import com.hardcode.driverManager.DriverLoadException;
16
import com.hardcode.gdbms.engine.values.DoubleValue;
17
import com.hardcode.gdbms.engine.values.IntValue;
18
import com.hardcode.gdbms.engine.values.NullValue;
19
import com.hardcode.gdbms.engine.values.NumericValue;
20
import com.hardcode.gdbms.engine.values.StringValue;
21
import com.hardcode.gdbms.engine.values.Value;
22
import com.hardcode.gdbms.engine.values.ValueFactory;
23
import com.iver.cit.gvsig.fmap.DriverException;
24
import com.iver.cit.gvsig.fmap.DriverIOExceptionType;
25
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType;
26
import com.iver.cit.gvsig.fmap.ViewPort;
27
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
28
import com.iver.cit.gvsig.fmap.core.DefaultRow;
29
import com.iver.cit.gvsig.fmap.core.FShape;
30
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
31
import com.iver.cit.gvsig.fmap.core.IFeature;
32
import com.iver.cit.gvsig.fmap.core.IGeometry;
33
import com.iver.cit.gvsig.fmap.core.IRow;
34
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
35
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
36
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
37
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
38
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
39
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
40
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
41
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
42
import com.iver.cit.gvsig.fmap.layers.FBitSet;
43
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
44
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
45
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy;
46
import com.iver.cit.gvsig.fmap.rendering.Legend;
47
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
48
import com.vividsolutions.jts.geom.Envelope;
49
import com.vividsolutions.jts.index.quadtree.Quadtree;
50

  
51
public class Annotation_EditableAdapter extends VectorialEditableAdapter{
52
	private ArrayList labels;
53
	private Annotation_Mapping mapping;
54
	private Legend legend;
55
	private boolean isInPixels=true;
56
	private Annotation_Layer lyrAnnotation;
57
	private LabelExpansion labelExpansion=new LabelExpansion();
58
	private boolean isToSave=false;
59

  
60
	public FLabel createLabel(IRow row){
61
//		FSymbol symbol;
62
//		// El mapping[0] es el text
63
//		int fieldId = mapping.getColumnText();
64
//		// El mapping[1] es el ?ngulo
65
//		int idFieldRotationText = mapping.getColumnRotate();
66
//		// El mapping[2] es el color
67
//		int idFieldColorText = mapping.getColumnColor();
68
//		// El mapping[3] es el alto
69
//		int idFieldHeightText = mapping.getColumnHeight();
70
//		// El mapping[4] es el tipo de fuente
71
//		int idFieldTypeFontText = mapping.getColumnTypeFont();
72
//		// El mapping[5] es el estilo de fuente
73
//		int idFieldStyleFontText = mapping.getColumnStyleFont();
74
//
75
//		IGeometry geom = ((IFeature) row).getGeometry();
76
//		String t = new String();
77
//		Value val = row.getAttribute(fieldId);
78
//		t = val.toString();
79
//		if (idFieldColorText != -1) {
80
//			Value value=row.getAttribute(idFieldColorText);
81
//			if (!(value instanceof NullValue)){
82
//				DoubleValue valColor = (DoubleValue) value;
83
//				t = t.concat(valColor.toString());
84
//			}
85
//		}
86
//		if (idFieldTypeFontText != -1) {
87
//			Value value=row.getAttribute(idFieldTypeFontText);
88
//			if (!(value instanceof NullValue)){
89
//				StringValue valTypeFont = (StringValue) value;
90
//				t = t.concat(valTypeFont.toString());
91
//			}
92
//		}
93
//		if (idFieldStyleFontText != -1) {
94
//			Value value=row.getAttribute(idFieldStyleFontText);
95
//			if (!(value instanceof NullValue)){
96
//				IntValue valStyleFont = (IntValue) value;
97
//				t = t.concat(valStyleFont.toString());
98
//			}
99
//		}
100
//
101
//		Value total = ValueFactory.createValue(t);
102
//
103
//		FLabel[] lbls = geom.createLabels(0, true);
104
//		double rotat = 0;
105
//		FSymbol sym = (FSymbol) legend.getDefaultSymbol();
106
//		for (int j = 0; j < lbls.length; j++) {
107
//			if (lbls[j] != null) {
108
//				lbls[j].setString(val.toString());
109
//				if (idFieldRotationText != -1) {
110
//					Value value=row.getAttribute(idFieldRotationText);
111
//					if (value instanceof NullValue){
112
//						rotat = sym.getRotation();
113
//					}else{
114
//						NumericValue rotation = (NumericValue) value;
115
//						rotat = rotation.doubleValue();
116
//					}
117
//				} else {
118
//					rotat = sym.getRotation();
119
//				}
120
//				lbls[j].setRotation(rotat);
121
//
122
//				float height;
123
//				if (idFieldHeightText != -1) {
124
//					Value value=row.getAttribute(idFieldHeightText);
125
//					if (value instanceof NullValue){
126
//						height = sym.getFontSize();
127
//						lbls[j].setHeight(height);
128
//					}else{
129
//						NumericValue h = (NumericValue) value;
130
//						height = h.floatValue();
131
//						lbls[j].setHeight(height);
132
//					}
133
//
134
//				} else {
135
//					height = sym.getFontSize();
136
//					lbls[j].setHeight(height);
137
//				}
138
//				Annotation_Legend vuvl = (Annotation_Legend) legend;
139
//				if (vuvl.getSymbolByValue(total) == null) {
140
//					Color color;
141
//					if (idFieldColorText != -1) {
142
//						DoubleValue c = (DoubleValue) row
143
//								.getAttribute(idFieldColorText);
144
//						color = new Color((int) c.getValue());
145
//					} else {
146
//						color = sym.getFontColor();
147
//					}
148
//					String typeFont;
149
//					if (idFieldTypeFontText != -1) {
150
//						StringValue tf = (StringValue) row
151
//								.getAttribute(idFieldTypeFontText);
152
//						typeFont = tf.getValue();
153
//					} else {
154
//						typeFont = sym.getFont()
155
//								.getFontName();
156
//					}
157
//					int style;
158
//					if (idFieldStyleFontText != -1) {
159
//						IntValue sf = (IntValue) row
160
//								.getAttribute(idFieldStyleFontText);
161
//						style = sf.getValue();
162
//					} else {
163
//						style = sym.getFont().getStyle();
164
//					}
165
//					symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
166
//					symbol.setFontSizeInPixels(isInPixels);
167
//					symbol.setFont(new Font(typeFont, style, (int) height));
168
//					symbol.setDescription(lbls[j].getString());
169
//					symbol.setFontColor(color);
170
//					vuvl.addSymbol(total, symbol);
171
//				}
172
//
173
//			}
174
//			return lbls[0];
175
//		}
176
		return null;
177
	}
178

  
179

  
180

  
181

  
182
//	public int doAddRow(IRow feat, int sourceType) throws DriverIOException, IOException {
183
//		boolean cancel = fireBeforeRowAdded(sourceType);
184
//		if (cancel)
185
//			return -1;
186
//		Value[] values=feat.getAttributes();
187
//		values[mapping.getColumnText()]=ValueFactory.createValue("New");
188
//		FLabel label=createLabel(feat);
189
//		//Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
190
//		//r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
191
//		//label.setBoundBox(r);
192
//		Annotation_Strategy strategy = (Annotation_Strategy)lyrAnnotation.getStrategy();
193
//		Rectangle2D r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString());
194
//        label.setBoundBox(r);
195
//		IGeometry geom=getGeometry(label.getBoundBox());
196
//		feat=new DefaultFeature(geom,values,feat.getID());
197
//
198
//		///lyrAnnotation.deleteSpatialIndex();
199
//
200
//		int calculatedIndex = -1;
201
//		calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
202
//
203
//		int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
204
//		labelExpansion.addLabel(label);
205
//		relations.put(new Integer(calculatedIndex), new Integer(pos));
206
//		numAdd++;
207
//
208
//		index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
209
//                r.getY() + r.getHeight()), new Integer(calculatedIndex));
210
//        //lyrAnnotation.getFMap().invalidate();
211
//        fireAfterRowAdded(feat,calculatedIndex, sourceType);
212
//        return calculatedIndex;
213
//	}
214

  
215
//	public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws IOException, DriverIOException {
216
//		boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
217
//		if (cancel)
218
//			return -1;
219
//		int posAnteriorInExpansionFile = -1;
220
//		Integer integer = new Integer(calculatedIndex);
221
//
222
////		System.err.println("Modifica una Row en la posici?n: "
223
////				+ calculatedIndex);
224
//		// Si la geometr?a no ha sido modificada
225
//		if (!relations.containsKey(integer)) {
226
//			FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
227
//			Value value=feat.getAttribute(mapping.getColumnText());
228
//			Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
229
//			label.setString(value.toString());
230
//
231
//			if (mapping.getColumnRotate()==mapping.getColumnText()){
232
//				label.setRotation(((NumericValue)value).doubleValue());
233
//			} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
234
//
235
//
236
//			int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
237
//			relations.put(integer, new Integer(newPosition));
238
//
239
//			// Se actualiza el ?ndice espacial
240
//			IGeometry g=((IFeature) feat).getGeometry();
241
//			double[] d=new double[4];
242
//			//Rectangle2D r = g.getBounds2D();
243
//			g.getPathIterator(null).currentSegment(d);
244
//			Point2D p=new Point2D.Double(d[0],d[1]);
245
//			label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
246
//			Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
247
//			label.setOrig(p);
248
//			index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
249
//					+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
250
//					+ rLabelAnt.getHeight()), new Integer(calculatedIndex));
251
//			index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
252
//					.getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
253
//					calculatedIndex));
254
//			labelExpansion.addLabel(label);
255
//		} else {
256
//			FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone();
257
//			Value value=feat.getAttribute(mapping.getColumnText());
258
//			Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
259
//			label.setString(value.toString());
260
//
261
//			if (mapping.getColumnRotate()==mapping.getColumnText()){
262
//				label.setRotation(((NumericValue)value).doubleValue());
263
//			} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
264
//
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff