001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package armyc2.c5isr.renderer.utilities; 006 007import java.util.ArrayList; 008import java.util.HashMap; 009import java.util.Map; 010 011import armyc2.c5isr.graphics2d.Point2D; 012import armyc2.c5isr.graphics2d.TexturePaint; 013 014/** 015 * Object that holds information on how to draw a multipoint symbol after {@link armyc2.c5isr.web.render.WebRenderer#RenderMultiPointAsMilStdSymbol(String, String, String, String, String, String, double, String, Map, Map)} is called. 016 */ 017public class MilStdSymbol 018{ 019 020 //private SymbolDef _symbolDefinition = null; 021 //private UnitDef _unitDefinition = null; 022 /** 023 * modifiers 024 */ 025 private Map<String,String> _Properties = null; 026 027 //for tactical graphics 028 private ArrayList<Double> _X_Altitude = null; 029 private ArrayList<Double> _AM_Distance = null; 030 private ArrayList<Double> _AN_Azimuth = null; 031 032 private String _symbolID = ""; 033 034 /** 035 * unique ID for this symbol, for client use 036 */ 037 private String _UUID = null; 038 039 private ArrayList<ShapeInfo> _SymbolShapes; 040 041 /** 042 * collection of shapes for the modifiers 043 */ 044 private ArrayList<ShapeInfo> _ModifierShapes; 045 046 private ArrayList<Point2D> _Coordinates; 047 048 private int _UnitSize = 100; 049 private double _scale = 0; 050 private Boolean _KeepUnitRatio = true; 051 052 Integer _LineWidth = 3; 053 Color _LineColor = null; 054 Color _FillColor = null; 055 Color _TextColor = null; 056 Color _TextBackgroundColor = null; 057 058 double _Rotation = 0.0;//DEGREES 059 060 //outline singlepoint TGs 061 boolean _Outline = false; 062 //if null, renderer determines outline Color. 063 Color _OutLineColor = null; 064 int _OutLineWidth = 0; 065 TexturePaint _tp = null; 066 boolean _fs = true; 067 068 int _patternFillType = 0; 069 070 private double patternScale = 1; 071 072 private static String _AltitudeMode = ""; 073 074 private static DistanceUnit _AltitudeUnit = null; 075 076 private static DistanceUnit _DistanceUnit = null; 077 078 private static boolean _useDashArray = true; 079 080 private static boolean _hideOptionalLabels = false; 081 082 private static boolean _DrawAffiliationModifierAsLabel = true; 083 084 private static boolean _UseLineInterpolation = false; 085 086 Object _Tag = null; 087 088 /* 089 * Used to hold metadata for each segment of the symbol for multi-point 090 * symbols. Each segment can contain one object. 091 */ 092 //private Map _segmentData; 093 // Constants for dynamic properties 094/* 095 public static final String SYMBOL_ID = "Symbol ID"; 096 //public static final String SOURCE = "Source"; 097 //public static final String EDITOR_CLASS_TYPE = "Editor Class Type"; 098 public static final String URN = "URN"; 099 public static final String UIC = "UIC"; 100 public static final String ANGLE_OF_ROTATION = "Angle of Rotation"; 101 public static final String LENGTH = "Length"; 102 public static final String WIDTH = "Width"; 103 public static final String RADIUS = "Radius"; 104 public static final String SEGMENT_DATA = "Segment Data"; 105 */ 106 107 /* 108 public static final String GEO_POINT = "point"; 109 public static final String GEO_LINE = "line"; 110 public static final String GEO_POLYGON = "area"; 111 public static final String GEO_TEXT = "text"; 112 public static final String GEO_CIRCLE = "circle"; 113 public static final String GEO_RECTANGLE = "rectangle"; 114 public static final String GEO_ARC = "arc"; 115 public static final String GEO_SQUARE = "square"; 116 */ 117 /* 118 private static final String _COORDINATES = "Coordinates"; 119 private static final String _GEOMETRY = "Geometry"; 120 private static final String _FILL_COLOR = "Fill Color"; 121 private static final String _FILL_ALPHA = "Fill Alpha"; 122 private static final String _FILL_STYLE = "Fill Style"; 123 private static final String _LINE_WIDTH = "Line Width"; 124 private static final String _LINE_COLOR = "Line Color"; 125 private static final String _LINE_ALPHA = "Line Alpha"; 126 private static final String _TEXT_BACKGROUND_COLOR = "Background Color"; 127 private static final String _TEXT_FOREGROUND_COLOR = "Foreground Color"; 128 private static final String _USE_FILL = "Use Fill"; 129 */ 130 /* 131 protected static const _COORDINATES:String = "Coordinates"; 132 protected static const _GEOMETRY:String = "Geometry"; 133 protected static const _FILL_COLOR:String = "Fill Color"; 134 protected static const _FILL_ALPHA:String = "Fill Alpha"; 135 private int _FILL_STYLE:String = "Fill Style"; 136 protected static const _LINE_WIDTH:String = 0; 137 private Color _LINE_COLOR = Color.BLACK; 138 private int _LINE_ALPHA:String = 0; 139 private Color _TEXT_BACKGROUND_COLOR = Color.WHITE; 140 private Color _TEXT_FOREGROUND_COLOR = Color.BLACK; 141 private bool _USE_FILL:String = "Use Fill";*/ 142 143 /** 144 * Creates a new MilStdSymbol. 145 * 146 * @param symbolID code, 20-30 digits long that represents the symbol 147 * @param uniqueID for the client's use 148 * @param modifiers use keys from Modifiers. 149 * @param Coordinates 150 * modifiers 151 */ 152 public MilStdSymbol(String symbolID, String uniqueID, ArrayList<Point2D> Coordinates, Map<String,String> modifiers) 153 { 154 this(symbolID, uniqueID, Coordinates, modifiers, true); 155 } 156 157 /** 158 * 159 * @param symbolID code, 20-30 digits long that represents the symbol 160 * @param uniqueID for the client's use 161 * @param modifiers use keys from Modifiers. 162 * @param Coordinates 163 * @param keepUnitRatio - default TRUE 164 * modifiers 165 */ 166 public MilStdSymbol(String symbolID, String uniqueID, ArrayList<Point2D> Coordinates, Map<String,String> modifiers, Boolean keepUnitRatio) 167 { 168 169 if (modifiers == null) 170 { 171 _Properties = new HashMap<>(); 172 } 173 else 174 { 175 _Properties = modifiers; 176 } 177 178 _UUID = uniqueID; 179 setCoordinates(Coordinates); 180 181 // Set the given symbol id 182 setSymbolID(symbolID); 183 184 // Set up default line fill and text colors 185 setLineColor(SymbolUtilities.getDefaultLineColor(_symbolID)); 186 setTextColor(SymbolUtilities.getLineColorOfAffiliation(symbolID)); 187 //if(SymbolUtilities.isWarfighting(_symbolID)) 188 if (SymbolUtilities.hasDefaultFill(_symbolID)) 189 { 190 setFillColor(SymbolUtilities.getFillColorOfAffiliation(_symbolID)); 191 } 192 //if(SymbolUtilities.isNBC(_symbolID) && !(SymbolUtilities.isDeconPoint(symbolID))) 193 // setFillColor(SymbolUtilities.getFillColorOfAffiliation(_symbolID)); 194 195 _DrawAffiliationModifierAsLabel = RendererSettings.getInstance().getDrawAffiliationModifierAsLabel(); 196 197 _UseLineInterpolation = RendererSettings.getInstance().getUseLineInterpolation(); 198 199 _KeepUnitRatio = keepUnitRatio; 200 } 201 202 public TexturePaint getFillStyle() 203 { 204 return _tp; 205 } 206 207 public void setFillStyle(TexturePaint value) 208 { 209 _tp = value; 210 } 211 212 public boolean getUseFillPattern() 213 { 214 return _fs; 215 } 216 217 public void setUseFillPattern(boolean value) 218 { 219 _fs = value; 220 } 221 222 /** 223 * @deprecated 224 */ 225 public int getPatternFillType() 226 { 227 return _patternFillType; 228 } 229 230 /** 231 * 0=Solid, 2=ForwardHatch, 3=BackwardHatch, 4=verticalHatch, 5=horizonalHatch, 8=CrossHatch 232 * Only affects Basic Shapes. Will not apply to MilStd Symbology so as to not confuse some 233 * symbols with others. 234 * @param value 235 * 236 * @deprecated 237 */ 238 public void setPatternFillType(int value) 239 { 240 _patternFillType = value; 241 } 242 243 public String getAltitudeMode() 244 { 245 return _AltitudeMode; 246 } 247 248 public void setAltitudeMode(String value) 249 { 250 _AltitudeMode = value; 251 } 252 253 public DistanceUnit getAltitudeUnit(){ 254 return _AltitudeUnit; 255 } 256 257 public void setAltitudeUnit(DistanceUnit unit){ 258 _AltitudeUnit = unit; 259 } 260 261 public DistanceUnit getDistanceUnit(){ 262 return _DistanceUnit; 263 } 264 265 public void setDistanceUnit(DistanceUnit unit){ 266 _DistanceUnit = unit; 267 } 268 269 public boolean getUseDashArray() 270 { 271 return _useDashArray; 272 } 273 274 public void setUseDashArray(boolean value) 275 { 276 _useDashArray = value; 277 } 278 279 public boolean getHideOptionalLabels() 280 { 281 return _hideOptionalLabels; 282 } 283 284 public void setHideOptionalLabels(boolean value) 285 { 286 _hideOptionalLabels = value; 287 } 288 289 public void setUseLineInterpolation(boolean value) 290 { 291 _UseLineInterpolation = value; 292 } 293 294 public boolean getUseLineInterpolation() 295 { 296 return _UseLineInterpolation; 297 } 298 299 //Set size for area's internal icon (LAA, mine and CBRN areas) 300 public void setUnitSize(int pixelSize){_UnitSize = pixelSize;} 301 302 public int getUnitSize(){return _UnitSize;} 303 304 public void setKeepUnitRatio(boolean value) {_KeepUnitRatio = value;} 305 306 public boolean getKeepUnitRatio() {return _KeepUnitRatio;} 307 308 /** 309 * Determines how to draw the Affiliation Modifier. True to draw as modifier 310 * label in the "E/F" location. False to draw at the top right corner of the 311 * symbol 312 * 313 * @deprecated 314 */ 315 public void setDrawAffiliationModifierAsLabel(boolean value) 316 { 317 _DrawAffiliationModifierAsLabel = value; 318 } 319 320 /** 321 * True to draw as modifier label in the "E/F" location. False to draw at 322 * the top right corner of the symbol 323 * 324 * @deprecated 325 */ 326 public boolean getDrawAffiliationModifierAsLabel() 327 { 328 return _DrawAffiliationModifierAsLabel; 329 } 330 331 /** 332 * 333 * @return 334 */ 335 public Map<String,String> getModifierMap() 336 { 337 return _Properties; 338 } 339 340 /** 341 * 342 * @param modifiers 343 */ 344 public void setModifierMap(Map<String,String> modifiers) 345 { 346 _Properties = modifiers; 347 } 348 349 /** 350 * 351 * @param modifier 352 * @return 353 */ 354 public String getModifier(String modifier) 355 { 356 if (_Properties.containsKey(modifier)) 357 { 358 return _Properties.get(modifier); 359 } 360 else 361 { 362 return getModifier(modifier, 0); 363 } 364 } 365 366 /** 367 * 368 * @param modifier 369 * @param value 370 */ 371 public void setModifier(String modifier, String value) 372 { 373 if (value.equals("") == false) 374 { 375 if (!(modifier == Modifiers.AM_DISTANCE) 376 || modifier == (Modifiers.AN_AZIMUTH) 377 || modifier == (Modifiers.X_ALTITUDE_DEPTH)) 378 { 379 _Properties.put(modifier, value); 380 } 381 else 382 { 383 setModifier(modifier, value, 0); 384 } 385 } 386 } 387 388 /** 389 * 390 * @param modifier 391 * @param index 392 * @return 393 */ 394 public String getModifier(String modifier, int index) 395 { 396 if (_Properties.containsKey(modifier)) 397 { 398 return _Properties.get(modifier); 399 } 400 else if (modifier == (Modifiers.AM_DISTANCE) 401 || modifier == (Modifiers.AN_AZIMUTH) 402 || modifier == (Modifiers.X_ALTITUDE_DEPTH)) 403 { 404 String value = String.valueOf(getModifier_AM_AN_X(modifier, index)); 405 if (value != null && !value.equalsIgnoreCase("null") && !value.equalsIgnoreCase("")) 406 { 407 return value; 408 } 409 else 410 { 411 return null; 412 } 413 } 414 else 415 { 416 return null; 417 } 418 419 } 420 421 /** 422 * 423 * @param modifier 424 * @param index 425 * @return 426 */ 427 public Double getModifier_AM_AN_X(String modifier, int index) 428 { 429 ArrayList<Double> modifiers = null; 430 if (modifier == (Modifiers.AM_DISTANCE)) 431 { 432 modifiers = _AM_Distance; 433 } 434 else if (modifier == (Modifiers.AN_AZIMUTH)) 435 { 436 modifiers = _AN_Azimuth; 437 } 438 else if (modifier == (Modifiers.X_ALTITUDE_DEPTH)) 439 { 440 modifiers = _X_Altitude; 441 } 442 else 443 { 444 return null; 445 } 446 447 if (modifiers != null && modifiers.size() > index) 448 { 449 Double value = null; 450 value = modifiers.get(index); 451 if (value != null) 452 { 453 return value; 454 } 455 else 456 { 457 return null; 458 } 459 } 460 else 461 { 462 return null; 463 } 464 } 465 466 /** 467 * Modifiers must be added in order. No setting index 2 without first 468 * setting index 0 and 1. If setting out of order is attempted, the value 469 * will just be added to the end of the list. 470 * 471 * @param modifier 472 * @param value 473 * @param index 474 */ 475 public void setModifier(String modifier, String value, int index) 476 { 477 if (value.equals("") == false) 478 { 479 if (!(modifier == (Modifiers.AM_DISTANCE) 480 || modifier == (Modifiers.AN_AZIMUTH) 481 || modifier == (Modifiers.X_ALTITUDE_DEPTH))) 482 { 483 _Properties.put(modifier, value); 484 } 485 else 486 { 487 Double dblValue = Double.valueOf(value); 488 if (dblValue != null) 489 { 490 setModifier_AM_AN_X(modifier, dblValue, index); 491 } 492 } 493 } 494 } 495 496 public void setModifier_AM_AN_X(String modifier, Double value, int index) 497 { 498 if ((modifier == (Modifiers.AM_DISTANCE) 499 || modifier == (Modifiers.AN_AZIMUTH) 500 || modifier == (Modifiers.X_ALTITUDE_DEPTH))) 501 { 502 ArrayList<Double> modifiers = null; 503 if (modifier == (Modifiers.AM_DISTANCE)) 504 { 505 if (_AM_Distance == null) 506 { 507 _AM_Distance = new ArrayList<Double>(); 508 } 509 modifiers = _AM_Distance; 510 } 511 else if (modifier == (Modifiers.AN_AZIMUTH)) 512 { 513 if (_AN_Azimuth == null) 514 { 515 _AN_Azimuth = new ArrayList<Double>(); 516 } 517 modifiers = _AN_Azimuth; 518 } 519 else if (modifier == (Modifiers.X_ALTITUDE_DEPTH)) 520 { 521 if (_X_Altitude == null) 522 { 523 _X_Altitude = new ArrayList<Double>(); 524 } 525 modifiers = _X_Altitude; 526 } 527 if (index + 1 > modifiers.size()) 528 { 529 modifiers.add(value); 530 } 531 else 532 { 533 modifiers.set(index, value); 534 } 535 } 536 } 537 538 public ArrayList<Double> getModifiers_AM_AN_X(String modifier) 539 { 540 if (modifier == (Modifiers.AM_DISTANCE)) 541 { 542 return _AM_Distance; 543 } 544 else if (modifier == (Modifiers.AN_AZIMUTH)) 545 { 546 return _AN_Azimuth; 547 } 548 else if (modifier == (Modifiers.X_ALTITUDE_DEPTH)) 549 { 550 return _X_Altitude; 551 } 552 553 return null; 554 } 555 556 public void setModifiers_AM_AN_X(String modifier, ArrayList<Double> modifiers) 557 { 558 if (modifier == (Modifiers.AM_DISTANCE)) 559 { 560 _AM_Distance = modifiers; 561 } 562 else if (modifier == (Modifiers.AN_AZIMUTH)) 563 { 564 _AN_Azimuth = modifiers; 565 } 566 else if (modifier == (Modifiers.X_ALTITUDE_DEPTH)) 567 { 568 _X_Altitude = modifiers; 569 } 570 } 571 572 /** 573 * 574 * @param value 575 */ 576 public void setFillColor(Color value) 577 { 578 _FillColor = value; 579 } 580 581 /** 582 * 583 * @return 584 */ 585 public Color getFillColor() 586 { 587 return _FillColor; 588 } 589 590 /** 591 * 592 * @param value 593 */ 594 public void setTextColor(Color value) 595 { 596 _TextColor = value; 597 if(RendererSettings.getInstance().getTextBackgroundMethod() != RendererSettings.TextBackgroundMethod_NONE && _TextBackgroundColor == null) 598 { 599 //If text background enabled and a background color has not been set yet: 600 _TextBackgroundColor = RendererUtilities.getIdealOutlineColor(_TextColor); 601 } 602 603 } 604 605 /** 606 * 607 * @return 608 */ 609 public Color getTextColor() 610 { 611 return _TextColor; 612 } 613 614 /** 615 * 616 * @param value 617 */ 618 public void setTextBackgroundColor(Color value) 619 { 620 _TextBackgroundColor = value; 621 } 622 623 /** 624 * 625 * @return 626 */ 627 public Color getTextBackgroundColor() 628 { 629 return _TextBackgroundColor; 630 } 631 632 /** 633 * 634 * @param value 635 */ 636 public void setLineWidth(int value) 637 { 638 _LineWidth = value; 639 } 640 641 /** 642 * 643 * @return 644 */ 645 public int getLineWidth() 646 { 647 return _LineWidth; 648 } 649 650 /** 651 * If value is null or SymbolUtilities.isGreenProtectionGraphic() is true then value is ignored 652 * 653 * @param value 654 */ 655 public void setLineColor(Color value) 656 { 657 if (SymbolUtilities.isGreenProtectionGraphic(getSymbolID())) { 658 _LineColor = AffiliationColors.ObstacleGreen;// new Color(0,166,81); // Green from SymbolUtilities.getLineColorOfAffiliation() 659 } else if (value != null) { 660 _LineColor = value; 661 } 662 } 663 664 /** 665 * 666 * @return 667 */ 668 public Color getLineColor() 669 { 670 return _LineColor; 671 } 672 673 /** 674 * if null, renderer will use white or black for the outline based on the color 675 * of the symbol. Otherwise, it will used the passed color value. 676 * 677 * @param value 678 */ 679 public void setOutlineColor(Color value) 680 { 681 _OutLineColor = value; 682 } 683 684 public Color getOutlineColor() 685 { 686 return _OutLineColor; 687 } 688 689 /** 690 * Extra value for client. defaults to null. Not used for rendering by 691 * JavaRenderer 692 * 693 * @param value 694 * @deprecated 695 */ 696 public void setTag(Object value) 697 { 698 _Tag = value; 699 } 700 701 /** 702 * Extra value for client. defaults to null. Not used for rendering by 703 * JavaRenderer 704 * 705 * @return 706 * @deprecated 707 */ 708 public Object getTag() 709 { 710 return _Tag; 711 } 712 713 /** 714 * 715 * @param value 716 */ 717 public void setCoordinates(ArrayList<Point2D> value) 718 { 719 _Coordinates = value; 720 } 721 722 /** 723 * 724 * @return 725 */ 726 public ArrayList<Point2D> getCoordinates() 727 { 728 return _Coordinates; 729 } 730 731 /** 732 * Shapes that represent the symbol modifiers 733 * 734 * @param value ArrayList<Shape> 735 */ 736 public void setModifierShapes(ArrayList<ShapeInfo> value) 737 { 738 _ModifierShapes = value; 739 } 740 741 /** 742 * Shapes that represent the symbol modifiers 743 * 744 * @return 745 */ 746 public ArrayList<ShapeInfo> getModifierShapes() 747 { 748 return _ModifierShapes; 749 } 750 751 /** 752 * the java shapes that make up the symbol 753 * 754 * @param value ArrayList<ShapeInfo> 755 */ 756 public void setSymbolShapes(ArrayList<ShapeInfo> value) 757 { 758 _SymbolShapes = value; 759 } 760 761 /** 762 * the java shapes that make up the symbol 763 * 764 * @return 765 */ 766 public ArrayList<ShapeInfo> getSymbolShapes() 767 { 768 return _SymbolShapes; 769 } 770 771 /** 772 * The Symbol Id of the MilStdSymbol. 773 * 774 * @return 775 */ 776 public String getSymbolID() 777 { 778 return _symbolID; 779 } 780 781 /** 782 * Unique ID of the Symbol. For client use. 783 * 784 * @return 785 */ 786 public String getUUID() 787 { 788 return _UUID; 789 } 790 791 /** 792 * Unique ID of the Symbol. For client use. 793 * 794 * @param ID 795 */ 796 public void setUUID(String ID) 797 { 798 _UUID = ID; 799 } 800 801 /** 802 * Sets the Symbol ID for the symbol. Should be a 20-30 digit string from 803 * the milstd. 804 * 805 * @param value 806 */ 807 public void setSymbolID(String value) 808 { 809 810 String current = _symbolID; 811 812 try 813 { 814 //set symbolID 815 if (value != null && !value.equals("") && !current.equals(value)) 816 { 817 _symbolID = value; 818 } 819 820 821 }// End try 822 catch (Exception e) 823 { 824 // Log Error 825 ErrorLogger.LogException("MilStdSymbol", "setSymbolID" + " - Did not fall under TG or FE", e); 826 } 827 } // End set SymbolID 828 private boolean _wasClipped=false; 829 public void set_WasClipped(boolean value) 830 { 831 _wasClipped=value; 832 } 833 public boolean get_WasClipped() 834 { 835 return _wasClipped; 836 } 837 838 /** 839 * Multipoint features and patterns scale with line width ({@link #getLineWidth()}). 840 * {@link #patternScale} is the ratio of how much to increase features and patterns by with line width. 841 * default value is 1.0. Can be set with {@link RendererSettings#setPatternScale(double)} and {@link MilStdAttributes#PatternScale} 842 * @param scale 843 */ 844 public void setPatternScale(double scale) { 845 patternScale = scale; 846 } 847 848 public double getPatternScale() { 849 return patternScale; 850 } 851 852}