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