Revision 10436 branches/simbologia/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/DefaultLabelingStrategy.java

View differences:

DefaultLabelingStrategy.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.1.2.4  2007-02-15 16:23:44  jaume
46
* Revision 1.1.2.5  2007-02-21 07:34:08  jaume
47
* labeling starts working
48
*
49
* Revision 1.1.2.4  2007/02/15 16:23:44  jaume
47 50
* *** empty log message ***
48 51
*
49 52
* Revision 1.1.2.3  2007/02/09 07:47:05  jaume
......
63 66
import java.awt.geom.AffineTransform;
64 67
import java.awt.geom.Rectangle2D;
65 68
import java.awt.image.BufferedImage;
69
import java.util.Hashtable;
66 70
import java.util.logging.Level;
67 71
import java.util.logging.Logger;
68 72

  
69 73
import com.iver.cit.gvsig.fmap.DriverException;
70 74
import com.iver.cit.gvsig.fmap.ViewPort;
75
import com.iver.cit.gvsig.fmap.core.FPoint2D;
71 76
import com.iver.cit.gvsig.fmap.core.FShape;
72 77
import com.iver.cit.gvsig.fmap.core.IGeometry;
78
import com.iver.cit.gvsig.fmap.core.TextPath;
73 79
import com.iver.cit.gvsig.fmap.core.symbols.TextSymbol;
74 80
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
75 81
import com.iver.cit.gvsig.fmap.layers.FBitSet;
76 82
import com.iver.cit.gvsig.fmap.layers.FLayer;
77 83
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
84
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
85
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
78 86
import com.iver.utiles.XMLEntity;
79 87
import com.iver.utiles.swing.threads.Cancellable;
80 88

  
......
88 96
	private IPlacementConstraints placementConstraints;
89 97
	private FLyrVect layer;
90 98
	private IZoomConstraints zoomConstraints;
91

  
99
	private Hashtable textPaths = new Hashtable(), texts = new Hashtable();
92 100
	protected DefaultLabelingStrategy(FLayer layer) throws DriverException {
93 101
		FLyrVect l = (FLyrVect) layer;
94 102
		this.layer = l;
......
120 128
		 FBitSet bs = layer.queryByRect(theExtent);
121 129
		 LabelClass lc = method.getDefaultLabelClass();
122 130

  
131
		 ReadableVectorial rv = layer.getSource();
132
		 SelectableDataSource sds = rv.getRecordset();
123 133

  
124

  
125 134
		 TextSymbol sym = lc.getLabelSymbol();
126 135
		 for(int i=bs.nextSetBit(0); i>=0 && !cancel.isCanceled(); i=bs.nextSetBit(i+1)) {
127 136
			 IGeometry geom;
128 137
			 try {
129
				 geom = layer.getSource().getShape(i);
138
				 Integer index = new Integer(i);
139
				 
140
				 String text = getText(index, sds);
141
				 sym.setText(text);
142
//				 System.err.println(index+","+text);
143
				 geom = rv.getShape(i);
130 144
				 FShape shp = placementConstraints.getLocationFor(geom, sym, null);
131 145
				 AffineTransform at = viewPort.getAffineTransform();
132

  
133
				 // to screen coordinates
134
				 shp.transform(at);
146
				
135 147
				 sym.draw(g, at, shp);
136 148
			 } catch (DriverIOException e) {
137
				 // TODO Auto-generated catch block
138 149
				 logger.log(Level.SEVERE, "Draw label for "+i+"th shape of "+layer.getName());
139 150

  
140
			 }
151
			 } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
152
				 logger.log(Level.SEVERE, "Getting label text for "+i+"th shape of "+layer.getName());
153
				
154
			}
141 155

  
142 156
		 }
143 157
	}
144 158

  
159
	private String getText(Integer index, SelectableDataSource sds) throws com.hardcode.gdbms.engine.data.driver.DriverException {
160
		String text = (String) texts.get(index);
161
		if (text == null) {
162
			String expr = method.getDefaultLabelClass().getLabelExpression();
163
			
164
			// TODO el analizador sint?ctico de momento s?lo pilla un valor del combo por 
165
			// defecto
166
			String fieldName = expr.replaceAll("\\[", "").replaceAll("\\]", "").trim();
167
			
168
			text = sds.getFieldValue(index.longValue(), sds.getFieldIndexByName(fieldName)).toString();
169
			texts.put(index, text);
170
		}
171
		return text;
172
	}
173

  
174
	private TextPath getTreePath(Integer index, Graphics2D g, FShape shp, char[] text) {
175
		TextPath tp = (TextPath) textPaths.get(index);
176
		if (tp == null) {
177
			tp = new TextPath(g, shp, text); 
178
			textPaths.put(index, tp);
179
		}
180
		return tp;
181
	}
182
	
183
	
184

  
145 185
	public String getClassName() {
146 186
		return getClass().getName();
147 187
	}

Also available in: Unified diff