001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005
006package armyc2.c2sd.renderer.utilities;
007
008//import android.graphics.Color;
009import android.annotation.SuppressLint;
010import android.graphics.Paint;
011import android.graphics.Paint.Cap;
012import android.graphics.Paint.Join;
013import android.graphics.Typeface;
014
015import java.util.ArrayList;
016import java.util.List;
017import java.util.logging.Level;
018
019
020/**
021 *Static class that holds the setting for the JavaRenderer.
022 * Allows different parts of the renderer to know what
023 * values are being used.
024 * @author michael.spinelli
025 */
026public class RendererSettings{
027
028    private static RendererSettings _instance = null;
029    
030    private static List<SettingsChangedEventListener> _listeners = new ArrayList<SettingsChangedEventListener>();  
031
032    //outline approach.  none, filled rectangle, outline (default),
033    //outline quick (outline will not exceed 1 pixels).
034    private static int _TextBackgroundMethod = 2;
035    /**
036     * There will be no background for text
037     */
038    public static final int TextBackgroundMethod_NONE = 0;
039
040    /**
041     * There will be a colored box behind the text
042     */
043    public static final int TextBackgroundMethod_COLORFILL = 1;
044
045    /**
046     * There will be an adjustable outline around the text
047     * Outline width of 4 is recommended.
048     */
049    public static final int TextBackgroundMethod_OUTLINE = 2;
050
051    /**
052     * A different approach for outline which is quicker and seems to use
053     * less memory.  Also, you may do well with a lower outline thickness setting
054     * compared to the regular outlining approach.  Outline Width of 2 is
055     * recommended.  Only works with RenderMethod_NATIVE.
056     * @deprecated
057     */
058    public static final int TextBackgroundMethod_OUTLINE_QUICK = 3;
059
060    /**
061     * Value from 0 to 255. The closer to 0 the lighter the text color has to be
062     * to have the outline be black. Default value is 160.
063     */
064    private static int _TextBackgroundAutoColorThreshold = 160;
065
066    //if TextBackgroundMethod_OUTLINE is set, This value determnies the width of that outline.
067    private static int _TextOutlineWidth = 4;
068
069    //label foreground color, uses line color of symbol if null.
070    private static int _ColorLabelForeground =  android.graphics.Color.BLACK;
071    //label background color, used if TextBackGroundMethod = TextBackgroundMethod_COLORFILL && not null
072    private static int _ColorLabelBackground =  android.graphics.Color.WHITE;
073
074    private static int _SymbolRenderMethod = 1;
075    private static int _UnitRenderMethod = 1;
076    private static int _TextRenderMethod = 1;
077    
078    private static int _SymbolOutlineWidth = 3;
079
080    /**
081     * Collapse labels for fire support areas when the symbol isn't large enough to show all
082     * the labels.
083     */
084    private static boolean _AutoCollapseModifiers = true;
085
086    /**
087     * If true (default), when HQ Staff is present, location will be indicated by the free
088     * end of the staff
089     */
090    private static Boolean _CenterOnHQStaff = true;
091
092    /**
093     * Everything that comes back from the Renderer is a Java Shape.  Simpler,
094     * but can be slower when rendering modifiers or a large number of single
095     * point symbols. Not recommended
096     */
097    public static final int RenderMethod_SHAPES = 0;
098    /**
099     * Adds a level of complexity to the rendering but is much faster for 
100     * certain objects.  Modifiers and single point graphics will render faster.
101     * MultiPoints will still be shapes.  Recommended
102     */
103    public static final int RenderMethod_NATIVE = 1;
104
105    /**
106     * 2525Bch2 and USAS 11-12 symbology
107     */
108    public static final int Symbology_2525B = 0;
109    /**
110     * 2525Bch2 and USAS 13/14 symbology
111     * @deprecated use 2525B
112     */
113    public static final int Symbology_2525Bch2_USAS_13_14 = 0;
114    /**
115     * 2525C, which includes 2525C & USAS COEv3
116     */
117    public static final int Symbology_2525C = 1;
118    
119    private static int _SymbologyStandard = 1;
120
121    public static int OperationalConditionModifierType_SLASH = 0;
122    public static int OperationalConditionModifierType_BAR = 1;
123    private static int _OCMType = 1;
124
125
126    private static boolean _UseLineInterpolation = true;
127
128        //single points
129    //private static Font _ModifierFont = new Font("arial", Font.TRUETYPE_FONT, 12);
130    private static String _ModifierFontName = "arial";
131    //private static int _ModifierFontType = Font.TRUETYPE_FONT;
132    private static int _ModifierFontType = Typeface.BOLD;
133    private static int _ModifierFontSize = 18;
134    private static int _ModifierFontKerning = 0;//0=off, 1=on (TextAttribute.KERNING_ON)
135    //private static float _ModifierFontTracking = TextAttribute.TRACKING_LOOSE;//loose=0.4f;
136    
137        //multi points
138    private static String _MPModifierFontName = "arial";
139    //private static int _ModifierFontType = Font.TRUETYPE_FONT;
140    private static int _MPModifierFontType = Typeface.BOLD;
141    private static int _MPModifierFontSize = 18;
142    private static int _MPModifierFontKerning = 0;//0=off, 1=on (TextAttribute.KERNING_ON)
143    //private static float _ModifierFontTracking = TextAttribute.TRACKING_LOOSE;//loose=0.4f;
144    private static float _KMLLabelScale = 1.0f;
145    
146    private boolean _scaleEchelon = false;
147    private boolean _DrawAffiliationModifierAsLabel = true;
148    
149    private float _SPFontSize = 60f;
150    private float _UnitFontSize = 50f;
151    private int _PixelSize = 35;
152    private int _DPI = 90;
153    
154    private static int _CacheSize = 1024;
155    private static int _VMSize = 10240;
156    private static boolean _CacheEnabled = true;
157    
158    //acevedo - 11/29/2017 - adding option to render only 2 labels.
159    private boolean _TwoLabelOnly = true;
160
161    private double _overscanScale = 1.0;
162
163    private boolean _autoAdjustScale = true;
164
165    //acevedo - 12/8/17 - allow the setting of affiliation colors.
166    private   Color _friendlyUnitFillColor = AffiliationColors.FriendlyUnitFillColor;
167    /// <summary>
168    /// Hostile Unit Fill Color.
169    /// </summary>
170    private   Color _hostileUnitFillColor = AffiliationColors.HostileUnitFillColor;//new Color(255,130,132);//Color.RED;
171    /// <summary>
172    /// Neutral Unit Fill Color.
173    /// </summary>
174    private   Color _neutralUnitFillColor = AffiliationColors.NeutralUnitFillColor;//new Color(144,238,144);//Color.GREEN;//new Color(0,255,0);//new Color(144,238,144);//light green//Color.GREEN;new Color(0,226,0);
175    /// <summary>
176    /// Unknown Unit Fill Color.
177    /// </summary>
178    private Color _unknownUnitFillColor = AffiliationColors.UnknownUnitFillColor;// new Color(255,255,128);//Color.YELLOW;
179
180    /// <summary>
181    /// Friendly Graphic Fill Color.
182    /// </summary>
183    private   Color _friendlyGraphicFillColor = AffiliationColors.FriendlyGraphicFillColor;//Crystal Blue //Color.CYAN;
184    /// <summary>
185    /// Hostile Graphic Fill Color.
186    /// </summary>
187    private Color _hostileGraphicFillColor = AffiliationColors.HostileGraphicFillColor;//salmon
188    /// <summary>
189    /// Neutral Graphic Fill Color.
190    /// </summary>
191    private   Color _neutralGraphicFillColor = AffiliationColors.NeutralGraphicFillColor;//Bamboo Green //new Color(144,238,144);//light green
192    /// <summary>
193    /// Unknown Graphic Fill Color.
194    /// </summary>
195    private   Color _unknownGraphicFillColor = AffiliationColors.UnknownGraphicFillColor;//light yellow  new Color(255,255,224);//light yellow
196
197    /// <summary>
198    /// Friendly Unit Line Color.
199    /// </summary>
200    private   Color _friendlyUnitLineColor = AffiliationColors.FriendlyUnitLineColor;
201    /// <summary>
202    /// Hostile Unit Line Color.
203    /// </summary>
204    private   Color _hostileUnitLineColor = AffiliationColors.HostileUnitLineColor;
205    /// <summary>
206    /// Neutral Unit Line Color.
207    /// </summary>
208    private   Color _neutralUnitLineColor = AffiliationColors.NeutralUnitLineColor;
209    /// <summary>
210    /// Unknown Unit Line Color.
211    /// </summary>
212    private   Color _unknownUnitLineColor = AffiliationColors.UnknownUnitLineColor;
213
214    /// <summary>
215    /// Friendly Graphic Line Color.
216    /// </summary>
217    private   Color _friendlyGraphicLineColor = AffiliationColors.FriendlyGraphicLineColor;
218    /// <summary>
219    /// Hostile Graphic Line Color.
220    /// </summary>
221    private   Color _hostileGraphicLineColor = AffiliationColors.HostileGraphicLineColor;
222    /// <summary>
223    /// Neutral Graphic Line Color.
224    /// </summary>
225    private   Color _neutralGraphicLineColor = AffiliationColors.NeutralGraphicLineColor;
226    /// <summary>
227    /// Unknown Graphic Line Color.
228    /// </summary>
229    private   Color _unknownGraphicLineColor = AffiliationColors.UnknownGraphicLineColor;
230
231    /*private   Color WeatherRed = new Color(198,16,33);//0xC61021;// 198,16,33
232    private   Color WeatherBlue = new Color(0,0,255);//0x0000FF;// 0,0,255
233
234    private   Color WeatherPurpleDark = new Color(128,0,128);//0x800080;// 128,0,128 Plum Red
235    private   Color WeatherPurpleLight = new Color(226,159,255);//0xE29FFF;// 226,159,255 Light Orchid
236
237    private   Color WeatherBrownDark = new Color(128,98,16);//0x806210;// 128,98,16 Safari
238    private   Color WeatherBrownLight = new Color(210,176,106);//0xD2B06A;// 210,176,106 Khaki
239    */
240
241    private RendererSettings()
242    {
243        Init();
244    }
245
246
247    public static synchronized RendererSettings getInstance()
248    {
249        if(_instance == null)
250        {
251            _instance = new RendererSettings();
252        }
253
254        return _instance;
255    }
256
257    private void Init()
258    {
259        try
260        {
261            _VMSize = (int)Runtime.getRuntime().maxMemory();
262            _CacheSize = Math.round(_VMSize * 0.05f);
263        }
264        catch(Exception exc)
265        {
266            ErrorLogger.LogException("RendererSettings", "Init", exc, Level.WARNING);
267        }
268    }
269
270    private void throwEvent(SettingsChangedEvent sce)
271    {
272        for (SettingsChangedEventListener listener : _listeners) {
273                listener.onSettingsChanged(sce);
274                }
275    }
276    
277    public void addEventListener(SettingsChangedEventListener scel)
278    {
279        _listeners.add(scel);
280    }
281
282
283
284
285    /**
286     * None, outline (default), or filled background.
287     * If set to OUTLINE, TextOutlineWidth changed to default of 4.
288     * If set to OUTLINE_QUICK, TextOutlineWidth changed to default of 2.
289     * Use setTextOutlineWidth if you'd like a different value.
290     * @param textBackgroundMethod
291     */
292    synchronized public void setTextBackgroundMethod(int textBackgroundMethod)
293    {
294        _TextBackgroundMethod = textBackgroundMethod;
295        if(_TextBackgroundMethod == TextBackgroundMethod_OUTLINE)
296            _TextOutlineWidth = 4;
297        else if(_TextBackgroundMethod == TextBackgroundMethod_OUTLINE_QUICK)
298            _TextOutlineWidth = 2;
299    }
300
301    /**
302     * None, outline (default), or filled background.
303     * @return method like RenderSettings.TextBackgroundMethod_NONE
304     */
305    synchronized public int getTextBackgroundMethod()
306    {
307        return _TextBackgroundMethod;
308    }
309    
310
311    /*public void setUnitFontSize(float size)
312    {
313        _UnitFontSize = size;
314    }//*/
315    
316    public float getUnitFontSize()
317    {
318        return _UnitFontSize;
319    }
320    
321    /*public void setSPFontSize(float size)
322    {
323        _SPFontSize = size;
324    }//*/
325    
326    public float getSPFontSize()
327    {
328        return _SPFontSize;
329    }
330    
331    public void setDefaultPixelSize(int size)
332    {
333        _PixelSize = size;
334    }
335    
336    public int getDefaultPixelSize()
337    {
338        return _PixelSize;
339    }
340    
341    public int getDeviceDPI()
342    {
343        return _DPI;
344    }
345    
346    public void setDeviceDPI(int size)
347    {
348        _DPI = size;
349    }
350    
351    /**
352     * Controls what symbols are supported.
353     * Set this before loading the renderer.
354     * @param standard
355     * Like RendererSettings.Symbology_2525Bch2_USAS_13_14
356     */
357    public void setSymbologyStandard(int standard)
358    {
359        _SymbologyStandard = standard;
360    }
361
362    /**
363     * Current symbology standard
364     * @return symbologyStandard
365     * Like RendererSettings.Symbology_2525Bch2_USAS_13_14
366     */
367    public int getSymbologyStandard()
368    {
369        return _SymbologyStandard;
370    }
371
372    /**
373     * Set the operational condition modifier to be slashes or bars
374     * @param value like RendererSettings.OperationalConditionModifierType_SLASH
375     */
376    public void setOperationalConditionModifierType(int value)
377    {
378        _OCMType = value;
379    }
380
381    public int getOperationalConditionModifierType()
382    {
383        return _OCMType;
384    }
385
386    /**
387     * For lines symbols with "decorations" like FLOT or LOC, when points are 
388     * too close together, we will start dropping points until we get enough 
389     * space between 2 points to draw the decoration.  Without this, when points
390     * are too close together, you run the chance that the decorated line will
391     * look like a plain line because there was no room between points to
392     * draw the decoration.
393     * @param value 
394     */
395    public void setUseLineInterpolation(boolean value)
396    {
397        _UseLineInterpolation = value;
398    }
399    
400    /**
401     * Returns the current setting for Line Interpolation.
402     * @return 
403     */
404    public boolean getUseLineInterpolation()
405    {
406        return _UseLineInterpolation;
407    }
408
409    /**
410     * Collapse Modifiers for fire support areas when the symbol isn't large enough to show all
411     * the labels.  Identifying label will always be visible.  Zooming in, to make the symbol larger,
412     * will make more modifiers visible.  Resizing the symbol can also make more modifiers visible.
413     * @param value
414     */
415    public void setAutoCollapseModifiers(boolean value) {_AutoCollapseModifiers = value;}
416
417    public boolean getAutoCollapseModifiers() {return _AutoCollapseModifiers;}
418
419    /**
420     * determines what kind of java objects will be generated when processing
421     * a symbol. RenderMethod_SHAPES is simpler as everything is treated
422     * the same. RenderMethod_NATIVE is faster but, in addition to shapes,
423     * uses GlyphVectors and TextLayouts.
424     * @param symbolRenderMethod
425     */
426    public void setUnitRenderMethod(int symbolRenderMethod)
427    {
428        _UnitRenderMethod = symbolRenderMethod;
429    }
430
431    /**
432     * Maps to RendererSetting.RenderMethod_SHAPES or
433     * RendererSetting.RenderMethod_NATIVE
434     * @return method like RendererSetting.RenderMethod_NATIVE
435     */
436    public int getUnitRenderMethod()
437    {
438        return _UnitRenderMethod;
439    }
440
441    /**
442     * if true (default), when HQ Staff is present, location will be indicated by the free
443     * end of the staff
444     * @param value
445     */
446    public void setCenterOnHQStaff(Boolean value)
447    {
448        _CenterOnHQStaff = value;
449    }
450
451    /**
452     * if true (default), when HQ Staff is present, location will be indicated by the free
453     * end of the staff
454     * @param
455     */
456    public Boolean getCenterOnHQStaff()
457    {
458        return _CenterOnHQStaff;
459    }
460
461     /**
462     * determines what kind of java objects will be generated when processing
463     * a symbol. RenderMethod_SHAPES is simpler as everything is treated
464     * the same. RenderMethod_NATIVE is faster but, in addition to shapes,
465     * uses GlyphVectors and TextLayouts.  In the case of text, NATIVE tends to
466     * render sharper and clearer text.
467     * @param symbolRenderMethod
468     */
469    public void setTextRenderMethod(int symbolRenderMethod)
470    {
471        _TextRenderMethod = symbolRenderMethod;
472    }
473
474    /**
475     * Maps to RendererSetting.RenderMethod_SHAPES or
476     * RendererSetting.RenderMethod_NATIVE
477     * @return
478     */
479    public int getTextRenderMethod()
480    {
481        return _TextRenderMethod;
482    }
483
484    /**
485     * if RenderSettings.TextBackgroundMethod_OUTLINE is used,
486     * the outline will be this many pixels wide.
487     * @param width
488     */
489    synchronized public void setTextOutlineWidth(int width)
490    {
491        _TextOutlineWidth = width;
492    }
493
494    /**
495     * if RenderSettings.TextBackgroundMethod_OUTLINE is used,
496     * the outline will be this many pixels wide.
497     * @param
498     * @return
499     */
500    synchronized public int getTextOutlineWidth()
501    {
502        return _TextOutlineWidth;
503    }
504
505     /**
506     * Refers to text color of modifier labels
507     * @return
508      *  
509     */
510    public int getLabelForegroundColor()
511    {
512        return _ColorLabelForeground;
513    }
514
515    /**
516     * Refers to text color of modifier labels
517     * Default Color is Black.  If NULL, uses line color of symbol
518     * @param value
519     * 
520     */
521    synchronized public void setLabelForegroundColor(int value)
522    {
523       _ColorLabelForeground = value;
524    }
525
526    /**
527     * Refers to background color of modifier labels
528     * @return
529     * 
530     */
531    public int getLabelBackgroundColor()
532    {
533        return _ColorLabelBackground;
534    }
535
536    /**
537     * Refers to text color of modifier labels
538     * Default Color is White.
539     * Null value means the optimal background color (black or white)
540     * will be chose based on the color of the text.
541     * @param value
542     * 
543     */
544    synchronized public void setLabelBackgroundColor(int value)
545    {
546        _ColorLabelBackground = value;
547    }
548
549    /**
550     * Value from 0 to 255. The closer to 0 the lighter the text color has to be
551     * to have the outline be black. Default value is 160.
552     * @param value
553     */
554    public void setTextBackgroundAutoColorThreshold(int value)
555    {
556        _TextBackgroundAutoColorThreshold = value;
557    }
558
559    /**
560     * Value from 0 to 255. The closer to 0 the lighter the text color has to be
561     * to have the outline be black. Default value is 160.
562     * @return
563     */
564    public int getTextBackgroundAutoColorThreshold()
565    {
566        return _TextBackgroundAutoColorThreshold;
567    }
568    
569    /**
570     * This applies to Single Point Tactical Graphics.
571     * Setting this will determine the default value for milStdSymbols when created.
572     * 0 for no outline,
573     * 1 for outline thickness of 1 pixel, 
574     * 2 for outline thickness of 2 pixels,
575     * greater than 2 is not currently recommended.
576     * @param width
577     */
578    synchronized public void setSinglePointSymbolOutlineWidth(int width)
579    {
580        _SymbolOutlineWidth = width;
581    }
582
583    /**
584     * This applies to Single Point Tactical Graphics.
585     * @return
586     */
587    synchronized public int getSinglePointSymbolOutlineWidth()
588    {
589        return _SymbolOutlineWidth;
590    }
591    
592    /**
593     * false to use label font size
594     * true to scale it using symbolPixelBounds / 3.5
595     * @param value 
596     */
597    public void setScaleEchelon(boolean value)
598    {
599        _scaleEchelon = value;
600    }
601    /**
602     * Returns the value determining if we scale the echelon font size or
603     * just match the font size specified by the label font.
604     * @return true or false
605     */
606    public boolean getScaleEchelon()
607    {
608        return _scaleEchelon;
609    }
610    
611     /**
612     * Determines how to draw the Affiliation modifier.
613     * True to draw as modifier label in the "E/F" location.
614     * False to draw at the top right corner of the symbol
615     */
616    public void setDrawAffiliationModifierAsLabel(boolean value)
617    {
618        _DrawAffiliationModifierAsLabel = value;
619    }
620    /**
621     * True to draw as modifier label in the "E/F" location.
622     * False to draw at the top right corner of the symbol
623     */
624    public boolean getDrawAffiliationModifierAsLabel()
625    {
626        return _DrawAffiliationModifierAsLabel;
627    }    
628    /**
629     * 
630     * @param name Like "arial"
631     * @param type Like Font.BOLD
632     * @param size Like 12
633     * @param kerning - default false. The default advances of single characters are not
634     * appropriate for some character sequences, for example "To" or
635     * "AWAY".  Without kerning the adjacent characters appear to be
636     * separated by too much space.  Kerning causes selected sequences
637     * of characters to be spaced differently for a more pleasing
638     * visual appearance. 
639     * @param tracking - default 0.04 (TextAttribute.TRACKING_LOOSE).
640     * The tracking value is multiplied by the font point size and
641     * passed through the font transform to determine an additional
642     * amount to add to the advance of each glyph cluster.  Positive
643     * tracking values will inhibit formation of optional ligatures.
644     * Tracking values are typically between <code>-0.1</code> and
645     * <code>0.3</code>; values outside this range are generally not
646     * desireable.
647     * @deprecated
648     */
649    public void setModifierFont(String name, int type, int size, Boolean kerning, float tracking)
650    {
651        if(!(_ModifierFontName.equals(name) &&
652                _ModifierFontType == type &&
653                _ModifierFontSize == size))
654        {
655            _ModifierFontName = name;
656            _ModifierFontType = type;
657            _ModifierFontSize = size;
658            throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_FontChanged));
659        }
660        /*if(kerning==false)
661                _ModifierFontKerning = 0;
662            else
663                _ModifierFontKerning = TextAttribute.KERNING_ON;
664            _ModifierFontTracking = tracking;//*/
665    }
666    
667    /**
668     * 
669     * @param name
670     * @param type Typeface
671     * @param size
672     */
673    public void setModifierFont(String name, int type, int size)
674    {
675        if(!(_ModifierFontName.equals(name) &&
676        _ModifierFontType == type &&
677        _ModifierFontSize == size))
678        {
679            _ModifierFontName = name;
680            _ModifierFontType = type;
681            _ModifierFontSize = size;
682            throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_FontChanged));
683        }
684    }
685    
686    
687    /**
688     * Sets the font to be used for multipoint modifier labels
689     * @param name Like "arial"
690     * @param type Like Font.TRUETYPE_FONT
691     * @param size Like 12
692     */
693    public void setMPModifierFont(String name, int type, int size)
694    {
695        if(!(_MPModifierFontName.equals(name) &&
696                _MPModifierFontType == type &&
697                _MPModifierFontSize == size))
698        {
699            _MPModifierFontName = name;
700            _MPModifierFontType = type;
701            _MPModifierFontSize = size;
702            _KMLLabelScale = 1.0f;
703            throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_MPFontChanged));
704        }
705    }
706    
707    /**
708     * Sets the font to be used for multipoint modifier labels
709     * @param name Like "arial"
710     * @param type Like Font.TRUETYPE_FONT
711     * @param size Like 12
712     * @param kmlScale only set if you're rendering in KML (default 1.0)
713     */
714    public void setMPModifierFont(String name, int type, int size, float kmlScale)
715    {
716        if(!(_MPModifierFontName.equals(name) &&
717                _MPModifierFontType == type &&
718                _MPModifierFontSize == size))
719        {
720            _MPModifierFontName = name;
721            _MPModifierFontType = type;
722            _MPModifierFontSize = Math.round(size * kmlScale);
723            _KMLLabelScale = kmlScale;
724            throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_MPFontChanged));
725        }
726    }
727
728    
729
730
731    /**
732     * get font object used for labels
733     * @return Font object
734     */
735    public Paint getModiferFont()
736    {
737        Paint p = null;
738        try
739        {
740                //need to create a paint and set it's typeface along with it's properties
741                Typeface tf = Typeface.create(_ModifierFontName, _ModifierFontType);
742                p = new Paint();
743                p.setTextSize(_ModifierFontSize);
744                p.setAntiAlias(true);
745                p.setColor(_ColorLabelForeground);
746                        //p.setTextAlign(Align.CENTER);
747                p.setTypeface(tf);
748                
749                        p.setStrokeCap(Cap.BUTT);
750                        p.setStrokeJoin(Join.MITER);
751                        p.setStrokeMiter(3f);
752                
753        }
754        catch(Exception exc)
755        {
756            String message = "font creation error, returning \"" + _ModifierFontName + "\" font, " + _ModifierFontSize + "pt. Check font name and type.";
757            ErrorLogger.LogMessage("RendererSettings", "getLabelFont", message);
758            ErrorLogger.LogMessage("RendererSettings", "getLabelFont", exc.getMessage());
759            try
760            {
761                Typeface tf = Typeface.create("arial", Typeface.BOLD);
762                        p = new Paint();
763                        p.setTextSize(12);
764                        p.setAntiAlias(true);
765                        p.setColor(android.graphics.Color.BLACK);
766                        p.setTypeface(tf);
767                        
768                        p.setStrokeCap(Cap.BUTT);
769                                p.setStrokeJoin(Join.MITER);
770                                p.setStrokeMiter(3f);
771            }
772            catch(Exception exc2)
773            {
774                //failed to make a default font, return null
775                p=null;
776            }
777        }
778        return p;
779    }
780    
781    /**
782     * get font object used for labels
783     * @return Font object
784     */
785    public Paint getMPModifierFont()
786    {
787        Paint p = null;
788        try
789        {
790                //need to create a paint and set it's typeface along with it's properties
791                Typeface tf = Typeface.create(_MPModifierFontName, _MPModifierFontType);
792                p = new Paint();
793                p.setTextSize(_MPModifierFontSize);
794                p.setAntiAlias(true);
795                p.setColor(_ColorLabelForeground);
796                        //p.setTextAlign(Align.CENTER);
797                p.setTypeface(tf);
798                
799        }
800        catch(Exception exc)
801        {
802            String message = "font creation error, returning \"" + _MPModifierFontName + "\" font, " + _MPModifierFontSize + "pt. Check font name and type.";
803            ErrorLogger.LogMessage("RendererSettings", "getLabelFont", message);
804            ErrorLogger.LogMessage("RendererSettings", "getLabelFont", exc.getMessage());
805            try
806            {
807                Typeface tf = Typeface.create("arial", Typeface.BOLD);
808                        p = new Paint();
809                        p.setTextSize(12);
810                        p.setAntiAlias(true);
811                        p.setColor(android.graphics.Color.BLACK);
812                        p.setTypeface(tf);
813            }
814            catch(Exception exc2)
815            {
816                //failed to make a default font, return null
817                p=null;
818            }
819        }
820        return p;
821    }
822    
823    /**
824     * the font name to be used for modifier labels
825     * @return name of the label font
826     */
827    public String getMPModifierFontName()
828    {
829        return _MPModifierFontName;
830    }
831    /**
832     * Like Font.BOLD
833     * @return type of the label font
834     */
835    public int getMPModifierFontType()
836    {
837        return _MPModifierFontType;
838    }
839    /**
840     * get font point size
841     * @return size of the label font
842     */
843    public int getMPModifierFontSize()
844    {
845        return _MPModifierFontSize;
846    }
847    
848    public float getKMLLabelScale()
849    {
850        return _KMLLabelScale;
851    }
852
853    /**
854     * Set the cache size as a percentage of VM memory available to the app.
855     * Renderer won't let you set a value greater than 10% of the available VM memory.
856     * @param percentage 
857     */
858    public void setCacheSize(float percentage)
859    {
860        if(percentage > 0.10f)
861            percentage = 0.10f;
862        _CacheSize = Math.round(_VMSize * percentage);
863        throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_CacheSizeChanged));
864    }
865    
866    /**
867     * Set the cache size in bytes.
868     * Renderer won't let you set a value greater than 10% of the available VM memory.
869     * @param bytes 
870     */
871    public void setCacheSize(int bytes)
872    {
873        if(bytes > _VMSize / 10)
874            bytes = _VMSize / 10;
875        _CacheSize = bytes;
876        throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_CacheSizeChanged));
877    }
878    
879    public int getCacheSize()
880    {
881        return _CacheSize;
882    }
883
884    public void setCacheEnabled(boolean active)
885    {
886        if(_CacheEnabled != active)
887        {
888            _CacheEnabled = active;
889            throwEvent(new SettingsChangedEvent(SettingsChangedEvent.EventType_CacheToggled));
890        }
891    }
892
893    public boolean getCacheEnabled()
894    {
895        return _CacheEnabled;
896    }
897    
898    /**
899         ** Get a boolean indicating between the use of ENY labels in all segments (false) or 
900         * to only set 2 labels one at the north and the other one at the south of the graphic (true).
901         * @returns {boolean}
902         */
903        public boolean getTwoLabelOnly()
904        {
905                        return _TwoLabelOnly;
906        }
907        
908        /**
909         * Set a boolean indicating between the use of ENY labels in all segments (false) or 
910         * to only set 2 labels one at the north and the other one at the south of the graphic (true).
911         * @param TwoLabelOnly
912         */
913        public void setTwoLabelOnly(boolean TwoLabelOnly )
914        {
915                _TwoLabelOnly = TwoLabelOnly;
916        }
917
918    /**
919     * Optionally expand multipoint rendering outside bounding box by a scale factor.
920     * Useful when panning map before rendering with updated bounding box.
921     * Only referenced when bounding box is a valid rectangle.
922     * For example, setting overscanScale to 3 would render all shapes within range 3 * the width and 3 * the height of the bounding box
923     * @param overscanScale default is 1 and minimum is 1
924     */
925    public void setOverscanScale(double overscanScale) {
926        this._overscanScale = Math.max(overscanScale, 1);
927    }
928
929    public double getOverscanScale() {
930        return this._overscanScale;
931    }
932
933    /**
934     * Will attempt to adjust the scale if it doesn't seem to make sense with the passed in bbox.
935     * If you wish to have absolute control over the scale, set to false.
936     * @param autoAdjustScale default true
937     */
938    public void setAutoAdjustScale(boolean autoAdjustScale) {
939        this._autoAdjustScale = autoAdjustScale;
940    }
941
942    public boolean getAutoAdjustScale() {
943        return this._autoAdjustScale;
944    }
945
946    /**
947     * get the preferred fill affiliation color for units.
948     *
949     * @return Color like  Color(255, 255, 255)
950     *
951     * */
952    public Color getFriendlyUnitFillColor() {
953        return _friendlyUnitFillColor;
954    }
955    /**
956     * Set the preferred fill affiliation color for units
957     *
958     * @param friendlyUnitFillColor Color like  Color(255, 255, 255)
959     *
960     * */
961    public void setFriendlyUnitFillColor(Color friendlyUnitFillColor) {
962            if (friendlyUnitFillColor != null)
963        _friendlyUnitFillColor = friendlyUnitFillColor;
964    }
965    /**
966     * get the preferred fill affiliation color for units.
967     *
968     * @return Color like  Color(255, 255, 255)
969     *
970     * */
971    public Color getHostileUnitFillColor() {
972        return _hostileUnitFillColor;
973    }
974    /**
975     * Set the preferred fill affiliation color for units
976     *
977     * @param hostileUnitFillColor Color like  Color(255, 255, 255)
978     *
979     * */
980    public void setHostileUnitFillColor(Color hostileUnitFillColor)
981    {
982        if (hostileUnitFillColor != null)
983            _hostileUnitFillColor = hostileUnitFillColor;
984    }
985    /**
986     * get the preferred fill affiliation color for units.
987     *
988     * @return Color like  Color(255, 255, 255)
989     *
990     * */
991    public Color getNeutralUnitFillColor() {
992        return _neutralUnitFillColor;
993    }
994    /**
995     * Set the preferred line affiliation color for units
996     *
997     * @param neutralUnitFillColor Color like  Color(255, 255, 255)
998     *
999     * */
1000    public void setNeutralUnitFillColor(Color neutralUnitFillColor) {
1001        if (neutralUnitFillColor != null)
1002            _neutralUnitFillColor = neutralUnitFillColor;
1003    }
1004    /**
1005     * get the preferred fill affiliation color for units.
1006     *
1007     * @return Color like  Color(255, 255, 255)
1008     *
1009     * */
1010    public Color getUnknownUnitFillColor() {
1011        return _unknownUnitFillColor;
1012    }
1013    /**
1014     * Set the preferred fill affiliation color for units
1015     *
1016     * @param unknownUnitFillColor Color like  Color(255, 255, 255)
1017     *
1018     * */
1019    @SuppressLint("SuspiciousIndentation")
1020    public void setUnknownUnitFillColor(Color unknownUnitFillColor) {
1021        if (unknownUnitFillColor != null)
1022            _unknownUnitFillColor = unknownUnitFillColor;
1023    }
1024    /**
1025     * get the preferred fill affiliation color for graphics.
1026     *
1027     * @return Color like  Color(255, 255, 255)
1028     *
1029     * */
1030    public   Color getHostileGraphicFillColor() {
1031        return _hostileGraphicFillColor;
1032    }
1033    /**
1034     * Set the preferred fill affiliation color for graphics
1035     *
1036     * @param hostileGraphicFillColor Color like  Color(255, 255, 255)
1037     *
1038     * */
1039    public  void setHostileGraphicFillColor(Color hostileGraphicFillColor) {
1040        if (hostileGraphicFillColor != null)
1041           _hostileGraphicFillColor = hostileGraphicFillColor;
1042    }
1043    /**
1044     * get the preferred fill affiliation color for graphics.
1045     *
1046     * @return Color like  Color(255, 255, 255)
1047     *
1048     * */
1049    public Color getFriendlyGraphicFillColor() {
1050        return _friendlyGraphicFillColor;
1051    }
1052    /**
1053     * Set the preferred fill affiliation color for graphics
1054     *
1055     * @param friendlyGraphicFillColor Color like  Color(255, 255, 255)
1056     *
1057     * */
1058    public void setFriendlyGraphicFillColor(Color friendlyGraphicFillColor) {
1059        if (friendlyGraphicFillColor != null)
1060            _friendlyGraphicFillColor = friendlyGraphicFillColor;
1061    }
1062    /**
1063     * get the preferred fill affiliation color for graphics.
1064     *
1065     * @return Color like  Color(255, 255, 255)
1066     *
1067     * */
1068    public Color getNeutralGraphicFillColor() {
1069        return _neutralGraphicFillColor;
1070    }
1071    /**
1072     * Set the preferred fill affiliation color for graphics
1073     *
1074     * @param neutralGraphicFillColor Color like  Color(255, 255, 255)
1075     *
1076     * */
1077    public void setNeutralGraphicFillColor(Color neutralGraphicFillColor) {
1078        if (neutralGraphicFillColor != null)
1079            _neutralGraphicFillColor = neutralGraphicFillColor;
1080    }
1081    /**
1082     * get the preferred fill affiliation color for graphics.
1083     *
1084     * @return Color like  Color(255, 255, 255)
1085     *
1086     * */
1087    public Color getUnknownGraphicFillColor() {
1088        return _unknownGraphicFillColor;
1089    }
1090    /**
1091     * Set the preferred fill affiliation color for graphics
1092     *
1093     * @param unknownGraphicFillColor Color like  Color(255, 255, 255)
1094     *
1095     * */
1096    public void setUnknownGraphicFillColor(Color unknownGraphicFillColor) {
1097        if (unknownGraphicFillColor != null)
1098            _unknownGraphicFillColor = unknownGraphicFillColor;
1099    }
1100    /**
1101     * get the preferred line affiliation color for units.
1102     *
1103     * @return Color like  Color(255, 255, 255)
1104     *
1105     * */
1106    public Color getFriendlyUnitLineColor() {
1107        return _friendlyUnitLineColor;
1108    }
1109    /**
1110     * Set the preferred line affiliation color for units
1111     *
1112     * @param friendlyUnitLineColor Color like  Color(255, 255, 255)
1113     *
1114     * */
1115    public void setFriendlyUnitLineColor(Color friendlyUnitLineColor) {
1116        if (friendlyUnitLineColor != null)
1117            this._friendlyUnitLineColor = friendlyUnitLineColor;
1118    }
1119    /**
1120     * get the preferred line   affiliation color for units.
1121     *
1122     * @return Color like  Color(255, 255, 255)
1123     *
1124     * */
1125    public Color getHostileUnitLineColor() {
1126        return _hostileUnitLineColor;
1127    }
1128    /**
1129     * Set the preferred line affiliation color for units
1130     *
1131     * @param hostileUnitLineColor Color like  Color(255, 255, 255)
1132     *
1133     * */
1134    public void setHostileUnitLineColor(Color hostileUnitLineColor) {
1135        if (hostileUnitLineColor != null)
1136            this._hostileUnitLineColor = hostileUnitLineColor;
1137    }
1138    /**
1139     * get the preferred line affiliation color for units.
1140     *
1141     * @return Color like  Color(255, 255, 255)
1142     *
1143     * */
1144    public Color getNeutralUnitLineColor() {
1145        return _neutralUnitLineColor;
1146    }
1147    /**
1148     * Set the preferred line affiliation color for units
1149     *
1150     * @param neutralUnitLineColor Color like  Color(255, 255, 255)
1151     *
1152     * */
1153    public void setNeutralUnitLineColor(Color neutralUnitLineColor) {
1154        if (neutralUnitLineColor != null)
1155            this._neutralUnitLineColor = neutralUnitLineColor;
1156    }
1157    /**
1158     * get the preferred line affiliation color for units.
1159     *
1160     * @return Color like  Color(255, 255, 255)
1161     *
1162     * */
1163    public Color getUnknownUnitLineColor() {
1164        return _unknownUnitLineColor;
1165    }
1166    /**
1167     * Set the preferred line affiliation color for units
1168     *
1169     * @param unknownUnitLineColor Color like  Color(255, 255, 255)
1170     *
1171     * */
1172    public void setUnknownUnitLineColor(Color unknownUnitLineColor) {
1173        if (unknownUnitLineColor != null)
1174            this._unknownUnitLineColor = unknownUnitLineColor;
1175    }
1176    /**
1177     * get the preferred line affiliation color for graphics.
1178     *
1179     * @return Color like  Color(255, 255, 255)
1180     *
1181     * */
1182    public Color getFriendlyGraphicLineColor() {
1183        return _friendlyGraphicLineColor;
1184    }
1185    /**
1186     * Set the preferred line affiliation color for graphics
1187     *
1188     * @param friendlyGraphicLineColor Color like  Color(255, 255, 255)
1189     *
1190     * */
1191    public void setFriendlyGraphicLineColor(Color friendlyGraphicLineColor) {
1192        if (friendlyGraphicLineColor != null)
1193            this._friendlyGraphicLineColor = friendlyGraphicLineColor;
1194    }
1195    /**
1196     * get the preferred line affiliation color for graphics.
1197     *
1198     * @return Color like  Color(255, 255, 255)
1199     *
1200     * */
1201    public Color getHostileGraphicLineColor() {
1202        return _hostileGraphicLineColor;
1203    }
1204    /**
1205     * Set the preferred line affiliation color for graphics
1206     *
1207     * @param hostileGraphicLineColor Color like  Color(255, 255, 255)
1208     *
1209     * */
1210    public void setHostileGraphicLineColor(Color hostileGraphicLineColor) {
1211        if (hostileGraphicLineColor != null)
1212            this._hostileGraphicLineColor = hostileGraphicLineColor;
1213    }
1214    /**
1215     * get the preferred line affiliation color for graphics.
1216     *
1217     * @return Color like  Color(255, 255, 255)
1218     *
1219     * */
1220    public Color getNeutralGraphicLineColor() {
1221        return _neutralGraphicLineColor;
1222    }
1223    /**
1224     * Set the preferred line affiliation color for graphics
1225     *
1226     * @param neutralGraphicLineColor Color like  Color(255, 255, 255)
1227     *
1228     * */
1229    public void setNeutralGraphicLineColor(Color neutralGraphicLineColor) {
1230        if (neutralGraphicLineColor != null)
1231            this._neutralGraphicLineColor = neutralGraphicLineColor;
1232    }
1233    /**
1234     * get the preferred line affiliation color for graphics.
1235     *
1236     * @return Color like  Color(255, 255, 255)
1237     *
1238     * */
1239    public Color getUnknownGraphicLineColor() {
1240        return _unknownGraphicLineColor;
1241    }
1242    /**
1243     * Set the preferred line affiliation color for graphics
1244     *
1245     * @param unknownGraphicLineColor Color like  Color(255, 255, 255)
1246     *
1247     * */
1248    public void setUnknownGraphicLineColor(Color unknownGraphicLineColor) {
1249        if (unknownGraphicLineColor != null)
1250            this._unknownGraphicLineColor = unknownGraphicLineColor;
1251    }
1252
1253    /**
1254     * Set the preferred line and fill affiliation color for tactical graphics.
1255     *
1256     * @param friendlyGraphicLineColor Color
1257     * @param hostileGraphicLineColor Color
1258     * @param neutralGraphicLineColor Color
1259     * @param unknownGraphicLineColor Color
1260     * @param friendlyGraphicFillColor Color
1261     * @param hostileGraphicFillColor Color
1262     * @param neutralGraphicFillColor Color
1263     * @param unknownGraphicFillColor Color
1264     */
1265    public void setGraphicPreferredAffiliationColors(Color friendlyGraphicLineColor,
1266                                                     Color hostileGraphicLineColor,
1267                                                     Color neutralGraphicLineColor,
1268                                                     Color unknownGraphicLineColor,
1269                                                     Color friendlyGraphicFillColor,
1270                                                     Color hostileGraphicFillColor,
1271                                                     Color neutralGraphicFillColor,
1272                                                     Color unknownGraphicFillColor) {
1273
1274
1275          setFriendlyGraphicLineColor(friendlyGraphicLineColor);
1276          setHostileGraphicLineColor(hostileGraphicLineColor);
1277          setNeutralGraphicLineColor(neutralGraphicLineColor);
1278          setUnknownGraphicLineColor(unknownGraphicLineColor);
1279          setFriendlyGraphicFillColor(friendlyGraphicFillColor);
1280          setHostileGraphicFillColor(hostileGraphicFillColor);
1281          setNeutralGraphicFillColor(neutralGraphicFillColor);
1282          setUnknownGraphicFillColor(unknownGraphicFillColor);
1283    }
1284
1285    /**
1286     * Set the preferred line and fill affiliation color for units and tactical graphics.
1287     *
1288     * @param friendlyUnitLineColor Color like  Color(255, 255, 255). Set to null to ignore setting
1289     * @param hostileUnitLineColor Color
1290     * @param neutralUnitLineColor Color
1291     * @param unknownUnitLineColor Color
1292     * @param friendlyUnitFillColor Color
1293     * @param hostileUnitFillColor Color
1294     * @param neutralUnitFillColor Color
1295     * @param unknownUnitFillColor Color
1296     */
1297    public void setUnitPreferredAffiliationColors(   Color friendlyUnitLineColor,
1298                                                     Color hostileUnitLineColor,
1299                                                     Color neutralUnitLineColor,
1300                                                     Color unknownUnitLineColor,
1301                                                     Color friendlyUnitFillColor,
1302                                                     Color hostileUnitFillColor,
1303                                                     Color neutralUnitFillColor,
1304                                                     Color unknownUnitFillColor) {
1305
1306        setFriendlyUnitLineColor(friendlyUnitLineColor);
1307        setHostileUnitLineColor(hostileUnitLineColor);
1308        setNeutralUnitLineColor(neutralUnitLineColor);
1309        setUnknownUnitLineColor(unknownUnitLineColor);
1310        setFriendlyUnitFillColor(friendlyUnitFillColor);
1311        setHostileUnitFillColor(hostileUnitFillColor);
1312        setNeutralUnitFillColor(neutralUnitFillColor);
1313        setUnknownUnitFillColor(unknownUnitFillColor);
1314    }
1315
1316}