1 6 7 package com.thoughtriver.open.vectorvisuals.example.meta; 8 9 import java.awt.*; 10 import java.awt.geom.*; 11 12 import com.thoughtriver.open.vectorvisuals.*; 13 14 22 public class ArmyTank extends VisualObject { 23 24 25 private VisualObject turret = null; 26 27 28 protected Color bodyColor = null; 29 30 31 protected Color highlightColor = null; 32 33 34 protected Color objectColor = Color.BLACK; 35 36 40 public ArmyTank() { 41 this(new Color(0, 170, 0)); 42 } 43 44 51 public ArmyTank(final Color themeColor) { 52 super(new RoundRectangle2D.Double(-20, -30, 40, 60, 5, 5), new Brush(themeColor.brighter(), null, null), new Brush(themeColor, null, null)); 53 54 bodyColor = themeColor; 55 highlightColor = themeColor.brighter(); 56 57 buildParts(); 58 } 59 60 68 public VisualObject getTurret() { 69 return turret; 70 } 71 72 77 public void rotateTurret(final double theta) { 78 Point2D rotationPoint = turret.getRotationPoint(); 79 AffineTransform transform = turret.getTransform(); 80 transform.rotate(theta, rotationPoint.getX(), rotationPoint.getY()); 81 turret.setTransform(transform); 82 } 83 84 88 protected void buildParts() { 89 90 Shape turretShape = new RoundRectangle2D.Double(-15, -15, 30, 30, 7, 7); 92 turret = new VisualObject(turretShape, new Brush(objectColor, null, null), new Brush(highlightColor, null, null)); 93 add(turret); 94 turret.setLayer(2); 95 96 Shape cannonShape1 = new Rectangle2D.Double(-10, -45, 5, 30); 98 VisualObject cannon1 = new VisualObject(cannonShape1, new Brush(objectColor, null, null), new Brush(highlightColor, null, null)); 99 turret.add(cannon1); 100 101 Shape cannonShape2 = new Rectangle2D.Double(5, -45, 5, 30); 102 VisualObject cannon2 = new VisualObject(cannonShape2, new Brush(objectColor, null, null), new Brush(highlightColor, null, null)); 103 turret.add(cannon2); 104 105 Shape hatchShape1 = new Rectangle2D.Double(-12, 17, 7, 10); 107 VisualObject hatch1 = new VisualObject(hatchShape1, new Brush(objectColor, null, null), new Brush(bodyColor, null, null)); 108 add(hatch1); 109 110 Shape hatchShape2 = new Rectangle2D.Double(5, 17, 7, 10); 111 VisualObject hatch2 = new VisualObject(hatchShape2, new Brush(objectColor, null, null), new Brush(bodyColor, null, null)); 112 add(hatch2); 113 114 Shape panelShape = new Rectangle2D.Double(-17, -27, 34, 12); 116 VisualObject panel = new VisualObject(panelShape, new Brush(objectColor, null, null), new Brush(bodyColor, null, null)); 117 add(panel); 118 } 119 120 } 121 | Popular Tags |