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