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