Revision 25637

View differences:

trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/symbols/SmartTextSymbol.java
1 1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2 2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
3
 * Copyright (C) 2005-8 IVER T.I. and Generalitat Valenciana.
4 4
 *
5 5
 * This program is free software; you can redistribute it and/or
6 6
 * modify it under the terms of the GNU General Public License
......
109 109
import javax.swing.JPanel;
110 110
import javax.swing.JTextField;
111 111

  
112
import org.apache.batik.ext.awt.geom.PathLength;
113 112
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
114 113
import org.gvsig.gui.beans.swing.JComboBoxFonts;
115 114
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
......
195 194
			this.setTextColor(mySym.getTextColor());
196 195
			this.setUnit(mySym.getUnit());
197 196
			super.setText(this.getText());
198

  
199 197
			this.constraints = constraints;
200 198

  
201
			setCharacterSpacing(5);
202
			setWordSpacing(2);
203
			setAlignment(FConstant.SYMBOL_STYLE_TEXTALIGNMENT_CENTERED);
199
			setCharacterSpacing(2);
200
			setWordSpacing(TextPath.DEFAULT_WORD_SPACING);
201
			boolean rtl = false; // right to left text
202
			if (constraints.isAtTheBeginingOfLine()) {
203
				if (rtl) {
204
					setAlignment(FConstant.SYMBOL_STYLE_TEXTALIGNMENT_RIGHT);
205
				}
206
				else {
207
					setAlignment(FConstant.SYMBOL_STYLE_TEXTALIGNMENT_LEFT);
208
				}
209
			}
210
			else if (constraints.isAtTheEndOfLine()) {
211
				if (rtl) {
212
					setAlignment(FConstant.SYMBOL_STYLE_TEXTALIGNMENT_LEFT);
213
				}
214
				else {
215
					setAlignment(FConstant.SYMBOL_STYLE_TEXTALIGNMENT_RIGHT);
216
				}
217
			}
218
			else { //constraints.isInTheMiddleOfLine() or constraints.isAtBestOfLine()
219
				setAlignment(FConstant.SYMBOL_STYLE_TEXTALIGNMENT_CENTERED);
220
			}
204 221
			setKerning(false);
205
			setRightToLeft(false);
222
			setRightToLeft(rtl);
206 223
		}
207 224
	}
208 225
	public SmartTextSymbol() {
......
218 235
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
219 236
		if (!isShapeVisible()) return;
220 237

  
221
		PathLength pathLen = new PathLength(shp);
238
		setMargin(0);
222 239

  
223
		if(this.constraints != null){
224
			if(this.constraints.isAtTheBeginingOfLine())
225
				setMargin(0);
226
			else if (this.constraints.isAtTheEndOfLine()){
227
				double dist = (charText.length+1) * (characterSpacing+characterWidth);
228
				setMargin(2*(pathLen.lengthOfPath()-dist));
229
			}
230
			else if (this.constraints.isInTheMiddleOfLine()){
231
				setMargin(pathLen.lengthOfPath());
232
			}
233
		}
234 240

  
235

  
236 241
		tp = new TextPath(g, shp, charText, getFont(),
237 242
				(float) characterSpacing, (float) characterWidth, kerning,
238 243
				(float) leading, alignment, (float) wordSpacing, (float) margin, rightToLeft);
......
251 256
			else if(this.constraints.isOnTheLine())
252 257
				cons = 0;
253 258

  
259
			// move the label 'cons" units above/below the line
254 260
			double xOffset = cons * Math.sin(coords[2]);
255 261
			double yOffset = cons * Math.cos(coords[2]);
256 262

  
257 263
			g.translate(coords[0]+xOffset, coords[1]-yOffset);
258 264
			g.rotate(coords[2]);
259
			g.setColor(Color.BLACK);
260
			g.drawString(new String(new char[] {charText[i]}), 0, 0);
265
			g.setColor(this.getTextColor());
266
			g.drawString(String.valueOf(charText[i]), 0, 0);
261 267
			g.rotate(-coords[2]);
262 268
			g.translate(-coords[0]-xOffset, -coords[1]+yOffset);
263 269
		}
......
412 418
		controlPanel.addComponent(chkKerning);
413 419
		controlPanel.addComponent(chkRightToLeft);
414 420

  
415
//		final SmartTextSymbol sms = new SmartTextSymbol();
416

  
417 421
		content.add(controlPanel, BorderLayout.NORTH);
418 422

  
419 423
		final JPanel canvas = new JPanel() {
......
425 429
				double width = getBounds().getWidth();
426 430
				double height= getBounds().getHeight();
427 431
				GeneralPathX gpx = new GeneralPathX();
428
//				gpx.moveTo(0.033*width, 0.033*height);
429
//				gpx.lineTo(0.066*width, 0.5*height);
430
//				gpx.lineTo(0.5*width, 0.266*height);
431
//				gpx.lineTo(0.66*width, 0.4*height);
432
//				gpx.lineTo(0.933*width, 0.733*height);
433
//				gpx.lineTo(0.933*width, 0.866*height);
434
//				gpx.lineTo(0.833*width, 0.933*height);
435
//				gpx.lineTo(0.666*width, 0.933*height);
436 432

  
437 433
				gpx.moveTo(50, 100);
438 434
				gpx.lineTo(100, 50);
......
480 476
	}
481 477

  
482 478
}
483

  
484
/*
485
private double factor = 0.4;
486
private int starPointCount = 5;
487

  
488
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp,
489
		Cancellable cancel) {
490
	FPoint2D p = (FPoint2D) shp;
491
	g.rotate(getRotation(), p.getX(), p.getY());
492
	double bigRadius = getSize()*0.5 ;
493
	Shape star = createStar((float) p.getX(), (float) p.getY(), (float) bigRadius, (float) (bigRadius*factor), starPointCount);
494
	g.setColor(getColor());
495
	g.fill(star);
496
	g.rotate(-getRotation(), p.getX(), p.getY());
497

  
498
}
499

  
500
private Shape createStar(float centerX, float centerY, float bigRadius, float smallRadius, int starPointCount) {
501
	GeneralPath gp = new GeneralPath();
502
	gp.moveTo(centerX, centerY-bigRadius);
503
	double TWO_PI = Math.PI*2;
504
	double subdivisionTheta =  TWO_PI / (2*starPointCount);
505
	for (int i = 1; i <= starPointCount*2; i++) {
506
		double theta = i * subdivisionTheta;
507
		double radius = i % 2 == 0 ? bigRadius : smallRadius;
508
		gp.lineTo(centerX - (float) ( radius*Math.sin(theta)),
509
				  centerY - (float) ( radius*Math.cos(theta)));
510

  
511
	}
512
	return gp;
513
}
514

  
515
public ISymbol getSymbolForSelection() {
516
	return this;
517
}
518

  
519

  
520

  
521

  
522

  
523
public void setXMLEntity(XMLEntity xml) {
524
	factor = xml.getDoubleProperty("factor");
525
	starPointCount = xml.getIntProperty("starPointCount");
526
	setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
527
	setRotation(xml.getDoubleProperty("rotation"));
528
	setDescription(xml.getStringProperty("desc"));
529
	setSize(xml.getDoubleProperty("size"));
530
	setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
531
	setUnit(xml.getIntProperty("unit"));
532
	setReferenceSystem(xml.getIntProperty("referenceSystem"));
533
}
534

  
535

  
536
*/

Also available in: Unified diff