Revision 42439 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.labeling.app/org.gvsig.labeling.app.mainplugin/src/main/java/org/gvsig/labeling/symbol/CharacterMarkerSymbol.java

View differences:

CharacterMarkerSymbol.java
232 232
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
233 233
 */
234 234
public class CharacterMarkerSymbol implements IMarkerSymbol {
235
	
235

  
236 236
	private static Logger logger =
237 237
			LoggerFactory.getLogger(CharacterMarkerSymbol.class);
238
	
238

  
239 239
	public static final String CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME =
240 240
			"CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME";
241
	
241

  
242 242
	private Font font = new Font("Arial", Font.PLAIN, 20);
243 243
	private int unicode;
244 244
	private ISymbol selectionSymbol;
245 245
	private VisualCorrection visualCorrection;
246 246
	private double size;
247
	
247

  
248 248
	private boolean isShapeVisible = true;
249 249
	private String desc = "";
250
	
250

  
251 251
	private IMask mask;
252 252
	private int unit = -1;
253 253
	private int referenceSystem = CartographicSupport.WORLD;
254
	
254

  
255 255
	private int alpha = 255;
256 256
	private Point2D offset = new Point2D.Double();
257
	
257

  
258 258
	/*
259
	 * 
259
	 *
260 260
	 */
261 261
	private double rotation_radians = 0;
262 262
	private Color color = Color.BLACK;
263
	
263

  
264 264
	private static GeometryManager geoman = GeometryLocator.getGeometryManager();
265 265

  
266 266
	/**
......
308 308
		if (selectionSymbol == null) {
309 309
			selectionSymbol = (ISymbol) LabelClassUtils.clone(this);
310 310
			selectionSymbol.setColor(MapContext.getSelectionColor());
311
		}else{
312
		    selectionSymbol.setColor(MapContext.getSelectionColor());
311 313
		}
312 314
		return selectionSymbol;
313 315
	}
314
	
315
	
316

  
317

  
316 318
	public void draw(Graphics2D g,
317 319
			AffineTransform affineTransform, Geometry geom,
318 320
			Feature feat, Cancellable cancel) {
319
		
321

  
320 322
		g.setColor(getColor());
321 323
		double theta = getRotation();
322 324

  
......
327 329
		if (size < 0.0001) {
328 330
			return;
329 331
		}
330
		
332

  
331 333
		org.gvsig.fmap.geom.primitive.Point cen = null;
332 334
		try {
333 335
			cen = geom.centroid();
334 336
		} catch (Exception e) {
335 337
			logger.error("While getting centroid", e);
336 338
		}
337
		
339

  
338 340
		Point2D p = new Point2D.Double(cen.getX(), cen.getY());
339 341

  
340 342
		if (isVisuallyCorrected()) {
......
369 371

  
370 372

  
371 373

  
372
	
373 374

  
375

  
374 376
	/**
375 377
	 * Sets the unicode for a symbol represented by a character
376 378
	 * @param symbol, int
......
504 506
					}
505 507
				}
506 508
			}
507
			
509

  
508 510
			int realWidth = bi.getWidth() - realRight-realLeft;
509 511
			int realHeight = bi.getHeight() - realBottom - realTop;
510 512

  
511 513
			visualCorrection = new VisualCorrection();
512
			
514

  
513 515
			if (realBottom!=-1 && realTop!=-1 && realLeft!=-1 && realRight != -1) {
514 516
				double correctingSize = Math.max(realHeight, realWidth);
515 517
				visualCorrection.sizeScale = clone.getSize() / correctingSize;
......
525 527
			visualCorrection = null;
526 528
		}
527 529
	}
528
	
529
	
530

  
531

  
530 532
	public Object clone() throws CloneNotSupportedException {
531 533
		return LabelClassUtils.clone(this);
532 534
	}
533
	
534
	
535

  
536

  
535 537
	public void getPixExtentPlus(
536 538
			Geometry geom, float[] distances,
537 539
			ViewPort viewPort, int dpi) {
538
		
540

  
539 541
		float cs = (float) getCartographicSize(viewPort, dpi, geom);
540 542
		distances[0] = cs;
541 543
		distances[1] = cs;
......
572 574
			return onePoint;
573 575
		}
574 576
	}
575
	
577

  
576 578
	public int getOnePointRgb() {
577 579
		return this.getColor().getRGB();
578 580
	}
......
601 603
	public void drawInsideRectangle(Graphics2D g,
602 604
			AffineTransform scaleInstance, Rectangle r,
603 605
			PrintAttributes properties) throws SymbolDrawingException {
604
		
605
		
606

  
607

  
606 608
		org.gvsig.fmap.geom.primitive.Point center = null;
607 609
		try {
608 610
			center = geoman.createPoint(
......
630 632
			print(g, scaleInstance, center, properties);
631 633
			setSize(originalSize);
632 634
		}
633
		
635

  
634 636
	}
635 637

  
636 638

  
......
649 651
		}
650 652
		*/
651 653

  
652
		draw(g,at,geom,null,null);	
654
		draw(g,at,geom,null,null);
653 655
	}
654 656

  
655 657
	public void setUnit(int unitIndex) {
......
670 672

  
671 673
	public double toCartographicSize(ViewPort viewPort, double dpi,
672 674
			Geometry geom) {
673
		
675

  
674 676
		double oldSize = getSize();
675 677
		setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom);
676 678
		return oldSize;	}
......
681 683

  
682 684
	public double getCartographicSize(ViewPort viewPort, double dpi,
683 685
			Geometry geom) {
684
		
686

  
685 687
		return SymbolUtils.getCartographicLength(this,
686 688
									  getSize(),
687 689
									  viewPort,
......
723 725
	public void setMask(IMask m) {
724 726
		mask = m;
725 727
	}
726
	
728

  
727 729
	// =========================================
728
	
730

  
729 731
	public void loadFromState(PersistentState state) throws PersistenceException {
730
		
732

  
731 733
		if (state.hasValue("vc_xOffsetScale")) {
732 734
			this.visualCorrection = new VisualCorrection();
733 735
			this.visualCorrection.xOffsetScale = state.getDouble("vc_xOffsetScale");
......
744 746
		// ==============================================
745 747
		this.color = (Color) state.get("color");
746 748
		this.font = (Font) state.get("font");
747
		
749

  
748 750
		double aux = state.getDouble("size");
749 751
		this.setSize(aux);
750
		
752

  
751 753
		this.unicode = state.getInt("unicode");
752 754
		this.desc = state.getString("desc");
753 755
		this.isShapeVisible = state.getBoolean("isShapeVisible");
754
		
756

  
755 757
		double x = state.getDouble("xOffset");
756 758
		double y = state.getDouble("yOffset");
757 759
		this.offset = new Point2D.Double(x, y);
758
		
760

  
759 761
		this.rotation_radians = state.getDouble("rotation");
760 762
		this.unit = state.getInt("unit");
761
		this.referenceSystem = state.getInt("referenceSystem");		
763
		this.referenceSystem = state.getInt("referenceSystem");
762 764
	}
763 765

  
764 766
	public void saveToState(PersistentState state) throws PersistenceException {
765
		
767

  
766 768
		if (this.visualCorrection != null) {
767 769
			state.set("vc_xOffsetScale", this.visualCorrection.xOffsetScale);
768 770
			state.set("vc_yOffsetScale", this.visualCorrection.yOffsetScale);
......
782 784
		state.set("yOffset", this.offset.getY());
783 785
		state.set("rotation", this.rotation_radians);
784 786
		state.set("unit", this.unit);
785
		state.set("referenceSystem", this.referenceSystem);		
787
		state.set("referenceSystem", this.referenceSystem);
786 788
	}
787
	
789

  
788 790
	public static void registerPersistent() {
789
		
791

  
790 792
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
791 793
		if( manager.getDefinition(CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME)==null ) {
792 794
			DynStruct definition = manager.addDefinition(
793 795
					CharacterMarkerSymbol.class,
794 796
					CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME,
795 797
					CHARACTER_MARKER_SYMBOL_PERSISTENCE_NAME+" Persistence definition",
796
					null, 
798
					null,
797 799
					null
798 800
			);
799
			
801

  
800 802
			definition.addDynFieldObject("color").setClassOfValue(Color.class).setMandatory(true);
801 803
			definition.addDynFieldObject("font").setClassOfValue(Font.class).setMandatory(true);
802 804
			definition.addDynFieldDouble("size").setMandatory(true);
......
813 815
			definition.addDynFieldDouble("vc_xOffsetScale").setMandatory(false);
814 816
			definition.addDynFieldDouble("vc_yOffsetScale").setMandatory(false);
815 817
			definition.addDynFieldDouble("vc_sizeScale").setMandatory(false);
816
		}		
818
		}
817 819
	}
818 820

  
819 821

  
......
829 831
		double yOffsetScale = 1;
830 832
		double sizeScale = 1;
831 833
	}
832
		
834

  
833 835
}

Also available in: Unified diff