public final class MilitarySymbol extends Object implements AutoCloseable
modifiers
of a military symbol, without having to worry whether the properties are encoded in the symbol code or in textual modifiers.
The modifiers of a military symbol are partly encoded in its symbol code (e.g. the MIL-STD 2525b symbology encodes the affiliation in the second digit of the symbol code) and partly encoded as additional metadata called text modifiers (usually a key-value map). This class exposes all these modifiers and a generic way to retrieve
and set
modifier values.
// 1) create a MIL-STD 2525b "rescue" symbol based on the code from the specification or a MilitarySymbologyNode
var standard = MilitarySymbology.Standard.MilStd2525b;
MilitarySymbol codedRescueSymbol = MilitarySymbol.create(standard, "G*G*GPAR--****X");
// codedRescueSymbol has properties for all applicable code and text modifiers.
// Mask characters have been replaced from the symbol code. Hence, the following statement is true:
assertEquals(codedRescueSymbol.getCode(), "GUG-GPAR------X");
// 2) query the available modifiers
System.out.println("available modifiers:");
for (MilitarySymbol.Modifier modifier : codedRescueSymbol.getModifiers()) {
System.out.println(modifier); // this outputs, among others, MilitarySymbol.Modifier.Affiliation and "AdditionalInformation".
}
// 3) query the possible values of the MilitarySymbol.Modifier.Affiliation modifier
codedRescueSymbol.getPossibleValues(MilitarySymbol.Modifier.Affiliation); // returns an array containing, among others, the value "Friend"
// 4) change the MilitarySymbol.Modifier.Affiliation modifier.
codedRescueSymbol.putValue(MilitarySymbol.Modifier.Affiliation, "Friend");
// The properties of a MilitarySymbol object are read-write and immediately update the values for the code and
// text modifiers. The MilitarySymbol.Modifier.Affiliation modifier is encoded in the symbol code, so the following statement is true:
assertEquals(codedRescueSymbol.getCode(), "GFG-GPAR------X");
// 5) change the "additional information" modifier.
codedRescueSymbol.putValue(MilitarySymbol.Modifier.AdditionalInformation, "This is an example symbol.");
// the "additional information" modifier is stored as a text modifier
Modifier and Type | Class and Description |
---|---|
static class |
MilitarySymbol.Affiliation
The affiliation of a military symbol.
|
static class |
MilitarySymbol.Modifier
Enumeration type for all available MIL-STD 2525 and APP-6 symbol modifiers.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
MilitarySymbol |
copyAndChangeCode(String newCode)
Creates a new military symbol based on the given code.
|
Feature |
copyToFeature(Feature feature,
Geometry geometry)
Creates a new feature based on this military symbol and the given feature.
|
static MilitarySymbol |
create(Feature feature)
Creates an editable military symbol based on the given
Feature . |
static MilitarySymbol |
create(MilitarySymbology.Standard standard,
String sidc)
Creates an returns a military symbol with the given standard and SIDC.
|
protected void |
finalize() |
MilitarySymbol.Affiliation |
getAffiliation()
Returns the affiliation of this symbol.
|
String |
getCode()
Returns the SIDC code of the symbol.
|
List<MilitarySymbol.Modifier> |
getModifiers()
Returns the modifiers of this shape symbol that can have a value associated with it.
|
MilitarySymbologyNode |
getNode()
Returns the symbology node that is represented by this symbol.
|
List<String> |
getPossibleValues(MilitarySymbol.Modifier modifier)
Returns the possible values for a given modifier, if applicable.
|
List<MilitarySymbol.Modifier> |
getSIDCModifiers()
Returns the collection of the possible SIDC modifiers of this symbol, e.g.
|
MilitarySymbology.Standard |
getStandard()
Returns the symbology standard of this symbol.
|
List<MilitarySymbol.Modifier> |
getTextModifiers()
Returns the collection of the possible text modifiers of this symbol.
|
String |
getValue(MilitarySymbol.Modifier modifier)
Returns the value for the given modifier.
|
void |
putValue(MilitarySymbol.Modifier modifier,
String value)
Sets the given (modifier,value) pair.
|
void |
resetValue(MilitarySymbol.Modifier modifier)
Resets the value associated with the given modifier.
|
IIcon |
toIcon(MilitarySymbolStyle style)
Creates an icon based on this military symbol and the given style.
|
public void close()
close
in interface AutoCloseable
@NotNull public static MilitarySymbol create(@NotNull MilitarySymbology.Standard standard, @NotNull String sidc) throws IllegalArgumentException
standard
- the standard of the military symbol.sidc
- the sidc of the military symbol.IllegalArgumentException
- if the SIDC code is not valid.@NotNull public static MilitarySymbol create(@NotNull Feature feature) throws IllegalArgumentException
Feature
.feature
- the feature whose SIDC and modifiers should be usedIllegalArgumentException
- if the military standard or code cannot be derived from the feature.MilitaryDataModel
@NotNull public MilitarySymbol.Affiliation getAffiliation()
This is a convenience method for directly retrieving the affiliation as an enum instance, as opposed to using getValue
.
@NotNull public String getCode()
The code represents the type of the symbol and any configured modifiers.
@NotNull public MilitarySymbology.Standard getStandard()
@NotNull public MilitarySymbologyNode getNode()
@NotNull public List<MilitarySymbol.Modifier> getModifiers()
@NotNull public List<MilitarySymbol.Modifier> getTextModifiers()
There are the modifiers that are not encoded in the symbol code.
@NotNull public List<MilitarySymbol.Modifier> getSIDCModifiers()
the affiliation, status, and so on.
@Nullable public List<String> getPossibleValues(@NotNull MilitarySymbol.Modifier modifier)
modifier
- the modifier whose values to returnnull
if the possible values cannot be enumerated.public void putValue(@NotNull MilitarySymbol.Modifier modifier, @NotNull String value) throws IllegalArgumentException
Accepts both SIDC and text modifiers.
Multi-valued modifiers should be specified by joining the values with a colon character. For instance "value1" and "value2" should be combined as "value1:value2".
modifier
- the key that identifies the text modifiervalue
- the value that will be associated with the text modifierIllegalArgumentException
- when the modifier is invalid (the modifier is not part of the symbology or the value is not part of the acceptable values).public void resetValue(@NotNull MilitarySymbol.Modifier modifier) throws IllegalArgumentException
If the modifier denotes an SIDC modifier, the value is reset to the default value, while for text modifiers, the associated value is simply removed (if any).
modifier
- the key that identifies the text modifier.IllegalArgumentException
- when the modifier is invalid (the modifier is not part of the symbology).@Nullable public String getValue(@NotNull MilitarySymbol.Modifier modifier) throws IllegalArgumentException
Accepts both SIDC and text modifiers.
modifier
- the modifier for which the value needs to be returnednull
if no value is associated with it)IllegalArgumentException
- when the modifier is invalid (the modifier is not part of the symbology).@NotNull public MilitarySymbol copyAndChangeCode(@NotNull String newCode) throws IllegalArgumentException
Modifiers of the current symbol are retained if they are still applicable and not overridden by the given code.
For example, applying this function to an existing MIL-STD 2525b space track with code
SUPP------MYBEX
by passing the code
SFA*------*****
will return a new MIL-STD 2525b air track with code
SFAP------MYBEX
.
newCode
- code representing the new symbol typeIllegalArgumentException
- when using an invalid code.@NotNull public Feature copyToFeature(@NotNull Feature feature, @Nullable Geometry geometry)
feature
- the feature to apply the geometry to. The feature's data type should be the MilitaryDataModel#getSymbolType
.geometry
- the geometry of the featurenull
if the feature does not yet have a geometryMilitaryDataModel
@NotNull public IIcon toIcon(@NotNull MilitarySymbolStyle style) throws IllegalStateException, NullPointerException
Once this military symbol icon is created, its Image
can be easily obtained using an IIconPainter
. The following snippet shows an example:
String code = "SFSPCLCC-------";
MilitarySymbology.Standard standard = MilitarySymbology.Standard.App6b;
MilitarySymbol symbol = MilitarySymbol.create(standard, code);
MilitarySymbolStyle defaultStyle = MilitarySymbolStyle.newBuilder().build();
var symbolType = symbol.getNode().getSymbolType();
if (symbolType == MilitarySymbologyNode.SymbolType.Icon) {
IIcon icon = symbol.toIcon(defaultStyle);
IIconPainter painter = icon.createPainter(new IconPainterContext(1.0));
Image image = painter.paint();
Bitmap bitmap = image.asBitmap();
// ...
}
style
- the styling settings for visualizing this military symbol.IllegalStateException
- when this military symbol is not an MilitarySymbologyNode.SymbolType#Icon
.NullPointerException
- when passing null
for the style.