001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005 006package armyc2.c5isr.renderer.utilities; 007import armyc2.c5isr.graphics2d.BasicStroke; 008import armyc2.c5isr.graphics2d.GeneralPath; 009import armyc2.c5isr.graphics2d.Point; 010import armyc2.c5isr.graphics2d.Point2D; 011import armyc2.c5isr.graphics2d.Rectangle; 012import armyc2.c5isr.graphics2d.Shape; 013import armyc2.c5isr.graphics2d.TextLayout; 014import armyc2.c5isr.graphics2d.TexturePaint; 015 016import java.util.ArrayList; 017import java.util.Map; 018 019import android.graphics.Bitmap; 020import android.graphics.BitmapShader; //for pattern fill. this is the only native android graphics to import 021 022/** 023 * Holds information on how to draw the pieces of a multipoint symbol. 024 * Can be retrieved from {@link MilStdSymbol#getSymbolShapes()} and 025 * {@link MilStdSymbol#getModifierShapes()} after {@link armyc2.c5isr.web.render.WebRenderer#RenderMultiPointAsMilStdSymbol(String, String, String, String, String, String, double, String, Map, Map)} is called. 026 */ 027public class ShapeInfo { 028 029 030 public static final int SHAPE_TYPE_POLYLINE=0; 031 //public static final int SHAPE_TYPE_POLYGON=1; 032 public static final int SHAPE_TYPE_FILL=1; 033 public static final int SHAPE_TYPE_MODIFIER=2; 034 public static final int SHAPE_TYPE_MODIFIER_FILL=3; 035 public static final int SHAPE_TYPE_UNIT_FRAME=4; 036 public static final int SHAPE_TYPE_UNIT_FILL=5; 037 public static final int SHAPE_TYPE_UNIT_SYMBOL1=6; 038 public static final int SHAPE_TYPE_UNIT_SYMBOL2=7; 039 public static final int SHAPE_TYPE_UNIT_DISPLAY_MODIFIER=8; 040 public static final int SHAPE_TYPE_UNIT_ECHELON=9; 041 public static final int SHAPE_TYPE_UNIT_AFFILIATION_MODIFIER=10; 042 public static final int SHAPE_TYPE_UNIT_HQ_STAFF=11; 043 public static final int SHAPE_TYPE_TG_SP_FILL=12; 044 public static final int SHAPE_TYPE_TG_SP_FRAME=13; 045 public static final int SHAPE_TYPE_TG_Q_MODIFIER=14; 046 public static final int SHAPE_TYPE_TG_SP_OUTLINE=15; 047 public static final int SHAPE_TYPE_SINGLE_POINT_OUTLINE=16; 048 public static final int SHAPE_TYPE_UNIT_OUTLINE=17; 049 public static final int justify_left=0; 050 public static final int justify_center=1; 051 public static final int justify_right=2; 052 053 protected Shape _Shape; 054 private BasicStroke stroke; 055 private GeneralPath gp; 056 private int fillStyle; 057 private TexturePaint texturePaint; 058 private int shapeType=-1; 059 private Color lineColor = null; 060 private Color fillColor = null; 061 private int _justify=justify_left; 062// private AffineTransform affineTransform = null; 063 064 //private GlyphVector _GlyphVector = null; 065 private TextLayout _TextLayout = null; 066 private Point2D _Position = null; 067 private String _ModifierString = null; 068 069 private Bitmap _ModifierImage = null; 070 private Point2D _ModifierPosition = null; 071 private double _ModifierAngle = 0; 072 private Object _Tag = null; 073 private BitmapShader _shader=null; 074 private Bitmap _patternFill = null; 075 //for google earth 076 private ArrayList<ArrayList<Point2D>> _Polylines = null; 077 078 //for google earth 079 //private ArrayList<ArrayList<Point2D>> _Polylines = null; 080 081 //enum DrawMethod{Draw,Fill;} 082 083 //private Polygon poly=new Polygon(); 084 protected ShapeInfo() 085 { 086 087 } 088 089 public ShapeInfo(Shape shape) 090 { 091 _Shape = shape; 092 } 093 094// public ShapeInfo(GlyphVector glyphVector, Point2D position) 095// { 096// _GlyphVector = glyphVector; 097// _Position = position; 098// } 099 100 public ShapeInfo(TextLayout textLayout, Point2D position) 101 { 102 _TextLayout = textLayout; 103 _Position = position; 104 } 105 106 /** 107 * 108 * @param shape 109 * @param shapeType 110 * ShapeInfo.SHAPE_TYPE_ 111 */ 112 public ShapeInfo(Shape shape, int shapeType) 113 { 114 _Shape = shape; 115 } 116 117 public Shape getShape() 118 { 119 return _Shape; 120 } 121 122 public void setShape(Shape value) 123 { 124 _Shape = value; 125 //_GlyphVector = null; 126 _TextLayout = null; 127 } 128 129// public GlyphVector getGlyphVector() 130// { 131// return _GlyphVector; 132// } 133// 134// public void setGlyphVector(GlyphVector value, Point2D position) 135// { 136// _GlyphVector = value; 137// _Position = position; 138// _Shape = null; 139// _TextLayout = null; 140// } 141 142 public TextLayout getTextLayout() 143 { 144 return _TextLayout; 145 } 146 147 public void setTextLayout(TextLayout value) 148 { 149 _TextLayout = value; 150 //_GlyphVector = null; 151 _Shape = null; 152 } 153 154 //set this when returning text string. 155 public void setModifierString(String value) 156 { 157 _ModifierString = value; 158 } 159 160 public String getModifierString() 161 { 162 return _ModifierString; 163 } 164 165 public void setModifierImage(Bitmap value) 166 { 167 _ModifierImage = value; 168 } 169 170 public Bitmap getModifierImage() 171 { 172 return _ModifierImage; 173 } 174 175 //location to draw ModifierString. 176 public void setModifierPosition(Point2D value) 177 { 178 _ModifierPosition = value; 179 } 180 181 public Point2D getModifierPosition() 182 { 183 return _ModifierPosition; 184 } 185 186 //angle to draw ModifierString. 187 public void setModifierAngle(double value) 188 { 189 _ModifierAngle = value; 190 } 191 192 public double getModifierAngle() 193 { 194 return _ModifierAngle; 195 } 196 197 /** 198 * Object that can be used to store anything. 199 * Will not be looked at when rendering. 200 * Null by default 201 * @param value 202 */ 203 public void setTag(Object value) 204 { 205 _Tag = value; 206 } 207 208 /** 209 * Object that can be used to store anything. 210 * Will not be looked at when rendering. 211 * Null by default 212 * @return 213 */ 214 public Object getTag() 215 { 216 return _Tag; 217 } 218 219 220 /* 221 * OLD 222 * @return 223 *//* 224 public Rectangle getBounds() 225 { 226 Rectangle temp = null; 227 228 if(_Shape != null) 229 return _Shape.getBounds(); 230 else if(_GlyphVector != null) 231 return _GlyphVector.getPixelBounds(null, (float)_Position.getX(), (float)_Position.getY()); 232 else if(_TextLayout != null && _Position != null) 233 { 234 temp = _TextLayout.getPixelBounds(null, (float)_Position.getX(), (float)_Position.getY()); 235 return temp; 236 } 237 else if(_TextLayout != null)//for deutch multipoint labels 238 { 239 //in this case, user set position using affine tranformation. 240 temp = new Rectangle(); 241 temp.setRect(_TextLayout.getBounds()); 242 return temp; 243 } 244 else 245 return null; 246 }//*/ 247 248 /** 249 * Gets bounds for the shapes. Incorporates AffineTransform if not null 250 * in the ShapeInfo object. 251 * @return 252 */ 253 public Rectangle getBounds() 254 { 255 Rectangle temp = null; 256 if(_Shape != null) 257 { 258 temp = _Shape.getBounds(); 259 if(_Shape instanceof GeneralPath) 260 { 261 if(shapeType == SHAPE_TYPE_UNIT_OUTLINE) 262 { 263 if(lineColor != null && stroke != null) 264 { 265 if(stroke != null && stroke.getLineWidth() > 2) 266 temp.grow((int)stroke.getLineWidth()/2, (int)stroke.getLineWidth()/2); 267 } 268 } 269 else 270 { 271 //mobility and other drawn symbol decorations. 272 if(lineColor != null && stroke != null) 273 { 274 if(stroke != null && stroke.getLineWidth() > 2) 275 temp.grow((int)stroke.getLineWidth()-1, (int)stroke.getLineWidth()-1); 276 } 277 } 278 } 279 } 280// else if(_GlyphVector != null) 281// { 282// temp = _GlyphVector.getPixelBounds(null, (float)_Position.getX(), (float)_Position.getY()); 283// } 284 if(_TextLayout != null && _Position != null) 285 { 286 temp = _TextLayout.getPixelBounds(null, (float)_Position.getX(), (float)_Position.getY()); 287 288 } 289 else if(_TextLayout != null)//for deutch multipoint labels 290 { 291 temp = new Rectangle(0,0,0,0); 292 temp.setRect(_TextLayout.getBounds()); 293 //return temp; 294 } 295 else 296 return null; 297 298 299// if(this.affineTransform != null) 300// { 301// //position set by affinetransform 302// 303// Shape sTemp = temp; 304// sTemp = affineTransform.createTransformedShape(temp); 305// temp = sTemp.getBounds(); 306// 307// } 308 309 return temp; 310 } 311 312 /** 313 * needed to draw Glyphs and TextLayouts 314 * @param position 315 */ 316 public void setGlyphPosition(Point position) 317 { 318 _Position = new Point2D.Double(position.x,position.y); 319 //this._ModifierStringPosition=new Point2D.Double(position.x,position.y); 320 } 321 322 /** 323 * needed to draw Glyphs and TextLayouts 324 * @param position 325 */ 326 public void setGlyphPosition(Point2D position) 327 { 328 _Position = position; 329 //this._ModifierStringPosition=new Point2D.Double(position.getX(),position.getY()); 330 } 331 332 /** 333 * needed to draw Glyphs and TextLayouts 334 * @return 335 */ 336 public Point2D getGlyphPosition() 337 { 338 return _Position; 339 } 340 341 public void setLineColor(Color value) 342 { 343 lineColor=value; 344 } 345 public Color getLineColor() 346 { 347 return lineColor; 348 } 349 350// /** 351// * 352// * @param value 353// * @deprecated Use setStroke 354// */ 355// public void setLineWidth(int value) 356// { 357// lineWidth=value; 358// } 359// /** 360// * @deprecated Use getStroke 361// * @return 362// */ 363// public int getLineWidth() 364// { 365// return lineWidth; 366// } 367 368 public void setFillColor(Color value) 369 { 370 fillColor=value; 371 } 372 public Color getFillColor() 373 { 374 return fillColor; 375 } 376 377// public void setAffineTransform(AffineTransform value) 378// { 379// affineTransform=value; 380// } 381// public AffineTransform getAffineTransform() 382// { 383// return affineTransform; 384// } 385 386 387 public BasicStroke getStroke() 388 { 389 return stroke; 390 } 391 //client will use this to do fills (if it is not null) 392 393 /** 394 * @deprecated use getShader() 395 */ 396 public TexturePaint getTexturePaint() 397 { 398 return texturePaint; 399 } 400 401 /** 402 * @deprecated use setShader() 403 */ 404 public void setTexturePaint(TexturePaint value) 405 { 406 texturePaint=value; 407 } 408 409 public int getFillStyle() 410 { 411 return fillStyle; 412 } 413 public void setFillStyle(int value) 414 { 415 fillStyle=value; 416 } 417 418 public void setStroke(BasicStroke s) 419 { 420 stroke=s; 421 } 422 423 /** 424 * For Internal Renderer use 425 * @param value 426 * ShapeInfo.SHAPE_TYPE_ 427 * 428 */ 429 public void setShapeType(int value) 430 { 431 shapeType=value; 432 } 433 /** 434 * For Internal Renderer use 435 * @return ShapeInfo.SHAPE_TYPE_ 436 * 437 */ 438 public int getShapeType() 439 { 440 return shapeType; 441 } 442 443 public ArrayList<ArrayList<Point2D>> getPolylines() 444 { 445 return _Polylines; 446 } 447 448 public void setPolylines(ArrayList<ArrayList<Point2D>> value) 449 { 450 _Polylines = value; 451 } 452 public void setShader(BitmapShader value) 453 { 454 _shader=value; 455 } 456 public BitmapShader getShader() 457 { 458 return _shader; 459 } 460 461 public void setPatternFillImage(Bitmap bmp){_patternFill = bmp;} 462 public Bitmap getPatternFillImage(){return _patternFill;} 463 public int getTextJustify() 464 { 465 return _justify; 466 } 467 468 public void setTextJustify(int value) 469 { 470 _justify = value; 471 } 472}