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