|
@ -27,11 +27,38 @@ public class TextView implements Drawable |
|
|
this.anchor = AnchorType.Center; |
|
|
this.anchor = AnchorType.Center; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setText(String newText) |
|
|
|
|
|
{ |
|
|
|
|
|
text = newText; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setVisibility(boolean visibility) |
|
|
|
|
|
{ |
|
|
|
|
|
visible = visibility; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setAnchor(AnchorType newAnchor) |
|
|
|
|
|
{ |
|
|
|
|
|
anchor = newAnchor; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void draw(Graphics g) |
|
|
public void draw(Graphics g) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(visible) |
|
|
|
|
|
{ |
|
|
|
|
|
FontMetrics fontMetrics = g.getFontMetrics(); |
|
|
|
|
|
int x = position.x; |
|
|
|
|
|
int y = position.y + fontMetrics.getHeight(); |
|
|
|
|
|
|
|
|
|
|
|
if (anchor == AnchorType.Center) |
|
|
|
|
|
x -= fontMetrics.stringWidth(text); |
|
|
|
|
|
else if (anchor == AnchorType.Right) |
|
|
|
|
|
x -= fontMetrics.stringWidth(text); |
|
|
|
|
|
|
|
|
|
|
|
g.setColor(Color.WHITE); |
|
|
|
|
|
g.drawString(text, x, y); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |