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