From 6344542b10b51a1136290298c9022277e30887d9 Mon Sep 17 00:00:00 2001 From: Emux Date: Wed, 7 Dec 2016 20:13:54 +0200 Subject: [PATCH] SymbolStyle: add style builder #214 --- .../org/oscim/theme/styles/SymbolStyle.java | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/vtm/src/org/oscim/theme/styles/SymbolStyle.java b/vtm/src/org/oscim/theme/styles/SymbolStyle.java index 2abb3c5a..e1d77315 100644 --- a/vtm/src/org/oscim/theme/styles/SymbolStyle.java +++ b/vtm/src/org/oscim/theme/styles/SymbolStyle.java @@ -26,15 +26,27 @@ import org.oscim.renderer.atlas.TextureRegion; */ public final class SymbolStyle extends RenderStyle { - public Bitmap bitmap; - public TextureRegion texture; + public final Bitmap bitmap; + public final TextureRegion texture; - public SymbolStyle(Bitmap symbol) { - this.bitmap = symbol; + public SymbolStyle(Bitmap bitmap) { + this.bitmap = bitmap; + this.texture = null; } - public SymbolStyle(TextureRegion symbol) { - this.texture = symbol; + public SymbolStyle(TextureRegion texture) { + this.bitmap = null; + this.texture = texture; + } + + public SymbolStyle(SymbolBuilder b) { + this.bitmap = b.bitmap; + this.texture = b.texture; + } + + @Override + public SymbolStyle current() { + return (SymbolStyle) mCurrent; } @Override @@ -53,8 +65,47 @@ public final class SymbolStyle extends RenderStyle { cb.renderSymbol(this); } - @Override - public SymbolStyle current() { - return (SymbolStyle) mCurrent; + public static class SymbolBuilder> extends StyleBuilder { + + public Bitmap bitmap; + public TextureRegion texture; + + public SymbolBuilder() { + } + + public T set(SymbolStyle symbol) { + if (symbol == null) + return reset(); + + this.bitmap = symbol.bitmap; + this.texture = symbol.texture; + + return self(); + } + + public T bitmap(Bitmap bitmap) { + this.bitmap = bitmap; + return self(); + } + + public T texture(TextureRegion texture) { + this.texture = texture; + return self(); + } + + public T reset() { + bitmap = null; + texture = null; + return self(); + } + + public SymbolStyle build() { + return new SymbolStyle(this); + } + } + + @SuppressWarnings("rawtypes") + public static SymbolBuilder builder() { + return new SymbolBuilder(); } }