TextAttributes placeAttrs = new TextAttributes() .setTypeface(Typeface.DEFAULT_BOLD) // Override the normal Typeface .setTextSize(28f) // default size is 24 .setTextOffset(Offset.bottomRight()); // anchor the label's bottom-right corner at its position TextAttributes lakeAttrs = new TextAttributes() .setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC)) .setTextSize(32f) // default size is 24 .setTextColor(new Color(0f, 1f, 1f, 0.70f)) // cyan, with 7% opacity .setTextOffset(Offset.center()); // center the label over its position
public TextCacheKey set(String text, TextAttributes attributes) { this.text = text; if (attributes != null) { this.textColor = (this.textColor != null) ? this.textColor.set(attributes.getTextColor()) : new Color(attributes.getTextColor()); this.textSize = attributes.getTextSize(); this.typeface = attributes.getTypeface(); this.enableOutline = attributes.isEnableOutline(); this.outlineColor = (this.outlineColor != null) ? this.outlineColor.set(attributes.getOutlineColor()) : new Color(attributes.getOutlineColor()); this.outlineWidth = attributes.getOutlineWidth(); } else { this.textColor = null; this.textSize = 0; this.typeface = null; this.enableOutline = false; this.outlineColor = null; this.outlineWidth = 0; } return this; }
@Test public void testSetTypeface_Null() throws Exception { TextAttributes attributes = new TextAttributes(); attributes.setTypeface(null); assertEquals(null, attributes.typeface); }
@Test public void testModifiedAttrs() { // Common Text Attributes TextAttributes attrs = new TextAttributes(); attrs.setEnableOutline(true); attrs.setOutlineColor(new Color(0.5f, 0.2f, 0.3f, 1)); attrs.setOutlineWidth(15); attrs.setTextColor(new Color(1, 1, 0.2f, 1)); attrs.setTextSize(90); // Common Text String text = "Testing"; // Cache Key 1 RenderContext.TextCacheKey textCacheKeyOne = new RenderContext.TextCacheKey().set(text, attrs); // Modify color property Color outlineColor = attrs.getOutlineColor().set(1, 1, 0.3f, 1); attrs.setOutlineColor(outlineColor); // Cache Key 2 RenderContext.TextCacheKey textCacheKeyTwo = new RenderContext.TextCacheKey().set(text, attrs); assertFalse("TextCacheKey modified attributes equals", textCacheKeyOne.equals(textCacheKeyTwo)); assertFalse("TextCacheKey modified attributes hashcode", textCacheKeyOne.hashCode() == textCacheKeyTwo.hashCode()); } }
TextAttributes attrs = new TextAttributes(); attrs.setTextColor(new Color(0, 0, 0, 1)); // black text via r,g,b,a attrs.setOutlineColor(new Color(1, 1, 1, 1)); // white outline via r,g,b,a attrs.setOutlineWidth(5); // thicken the white outline label = new Label(new Position(38.881389, -77.036944, 0), "Thomas Jefferson Memorial", attrs); layer.addRenderable(label); attrs = new TextAttributes(); attrs.setTextOffset(Offset.bottomRight()); label = new Label(new Position(38.8893, -77.050111, 0), "Lincoln Memorial", attrs); layer.addRenderable(label); attrs = new TextAttributes(); attrs.setTextOffset(Offset.bottomLeft()); label = new Label(new Position(38.889803, -77.009114, 0), "United States Capitol", attrs); layer.addRenderable(label); attrs = new TextAttributes(); attrs.setTypeface(Typeface.DEFAULT_BOLD); // system default bold typeface attrs.setTextSize(48); // 48 screen pixels label = new Label(new Position(38.907192, -77.036871, 0), "Washington", attrs); layer.addRenderable(label);
@Test public void testHashCode() throws Exception { // Three differing sets of attributes TextAttributes a = new TextAttributes(); TextAttributes b = new TextAttributes(); TextAttributes c = new TextAttributes(); b.setTextColor(new Color(0, 0, 0, 0)); c.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); int aHash = a.hashCode(); int bHash = b.hashCode(); int cHash = c.hashCode(); assertNotEquals("a hash vs b hash", bHash, aHash); assertNotEquals("b hash vs c hash", cHash, bHash); assertNotEquals("c hash vs a hash", aHash, cHash); }
@Test public void testSetOutlineWidth() throws Exception { TextAttributes attributes = new TextAttributes(); float width = 0.0f; attributes.setOutlineWidth(width); assertEquals(width, attributes.outlineWidth, 0.0f); } }
/** * Constructs a label that displays text at a geographic position. * * @param position the position where the label is displayed * @param text the text to display, or null to display nothing * * @throws IllegalArgumentException If the position is null */ public Label(Position position, String text) { if (position == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Label", "constructor", "missingPosition")); } this.position.set(position); this.text = text; this.attributes = new TextAttributes(); }
@Test(expected = IllegalArgumentException.class) public void testSet_WithNull() throws Exception { TextAttributes attributes = new TextAttributes(); attributes.set(null); fail("Expected an IllegalArgumentException to be thrown."); }
@Test public void testSetTextSize() throws Exception { TextAttributes attributes = new TextAttributes(); float size = 2.5f; attributes.setTextSize(size); assertEquals(size, attributes.textSize, 0.0f); }
@Test public void testSetTextColor() throws Exception { TextAttributes attributes = new TextAttributes(); Color black = new Color(0, 0, 0, 1); attributes.setTextColor(black); // Verify that the object is an equivalent deep copy. assertEquals(black, attributes.textColor); assertTrue(black != attributes.textColor); }
@Test public void testSetTextOffset() throws Exception { TextAttributes attributes = new TextAttributes(); Offset lowerLeft = new Offset(WorldWind.OFFSET_PIXELS, 0, WorldWind.OFFSET_PIXELS, 0); attributes.setTextOffset(lowerLeft); // Verify that the object is an equivalent deep copy. assertEquals(lowerLeft, attributes.textOffset); assertTrue(lowerLeft != attributes.textOffset); }
@Test public void testGetTypeface_Null() throws Exception { TextAttributes attributes = new TextAttributes(); attributes.typeface = null; assertEquals(null, attributes.getTypeface()); }
@Test public void testGetTextSize() throws Exception { TextAttributes attributes = new TextAttributes(); float size = 2.5f; attributes.textSize = size; assertEquals(size, attributes.getTextSize(), 1.0e-15); }
@Test public void testGetOutlineWidth() throws Exception { TextAttributes attributes = new TextAttributes(); float width = 0.0f; attributes.outlineWidth = width; assertEquals(width, attributes.getOutlineWidth(), 1.0e-15); }
@Test public void testGetEnableOutline() throws Exception { TextAttributes attributes = new TextAttributes(); boolean enable = false; attributes.enableOutline = enable; assertEquals(enable, attributes.isEnableOutline()); }
@Test public void testGetTextColor() throws Exception { TextAttributes attributes = new TextAttributes(); Color black = new Color(0, 0, 0, 1); attributes.textColor = black; assertEquals(black, attributes.getTextColor()); }
@Test public void testSetEnableDepthTest() throws Exception { TextAttributes attributes = new TextAttributes(); boolean enable = false; attributes.setEnableDepthTest(enable); assertEquals(enable, attributes.enableDepthTest); }
@Test public void testSetEnableOutline() throws Exception { TextAttributes attributes = new TextAttributes(); boolean enable = false; attributes.setEnableOutline(enable); assertEquals(enable, attributes.enableOutline); }
@Test public void testGetEnableDepthTest() throws Exception { TextAttributes attributes = new TextAttributes(); boolean enable = false; attributes.enableDepthTest = enable; assertEquals(enable, attributes.isEnableDepthTest()); }