Package chunmap.view.render

Source Code of chunmap.view.render.LabelSymbol

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.view.render;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Paint;
import java.awt.font.TextAttribute;
import java.text.AttributedString;

import chunmap.data.feature.Feature;
import chunmap.data.feature.Shape;
import chunmap.model.coord.CPoint;
import chunmap.model.elem.Envelope;
import chunmap.model.geom.Geometry;
import chunmap.view.View;

public class LabelSymbol extends Symbol{

  public Paint stringColor = Color.black;
  public int labelHide = 100;
 
  @Override
  public void draw(Graphics g, Feature f, View view) {
    if(f instanceof Shape){
      Shape shp=(Shape)f;
      drawLabel(g,shp.getGeometry(),shp.getLabel(),view);
    }
  }
 
  private void drawLabel(Graphics g, Geometry geo, String text, View view) {
    if (text == null || text == "") return;
   
    Envelope env=geo.getEnvelop().transform(view.world2Screen());
    if(env.getWidth()+env.getHeight()<labelHide)return;
   
    AttributedString astring = new AttributedString(text);
    astring.addAttribute(TextAttribute.FOREGROUND, stringColor);
    CPoint p = env.getCenter();
    g.drawString(astring.getIterator(), (int) p.getX(), (int) p.getY());
  }
}
TOP

Related Classes of chunmap.view.render.LabelSymbol

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.