1 6 7 package com.thoughtriver.open.vectorvisuals; 8 9 import java.awt.*; 10 11 23 public class Brush { 24 25 26 private Paint paint = null; 27 28 29 private Composite composite = null; 30 31 32 private Stroke stroke = null; 33 34 45 public Brush(final Paint paint, final Composite composite, final Stroke stroke) { 46 setPaint(paint); 47 setComposite(composite); 48 setStroke(stroke); 49 } 50 51 56 public Paint getPaint() { 57 return paint; 58 } 59 60 65 public Stroke getStroke() { 66 return stroke; 67 } 68 69 74 public Composite getComposite() { 75 return composite; 76 } 77 78 84 public void setPaint(final Paint paint) { 85 if (paint == null) { 86 this.paint = Color.BLACK; 87 } 88 else { 89 this.paint = paint; 90 } 91 } 92 93 99 public void setStroke(final Stroke stroke) { 100 if (stroke == null) { 101 this.stroke = new BasicStroke(); 102 } 103 else { 104 this.stroke = stroke; 105 } 106 } 107 108 115 public void setComposite(final Composite composite) { 116 if (composite == null) { 117 this.composite = AlphaComposite.Src; 118 } 119 else { 120 this.composite = composite; 121 } 122 } 123 124 130 public void useOn(final Graphics2D g) { 131 g.setPaint(paint); 132 g.setStroke(stroke); 133 g.setComposite(composite); 134 } 135 136 144 @Override 145 public boolean equals(final Object obj) { 146 Brush otherBrush = (Brush) obj; 147 148 if (!otherBrush.getPaint().equals(paint)) { 149 return false; 150 } 151 152 if (!otherBrush.getStroke().equals(stroke)) { 153 return false; 154 } 155 156 if (!otherBrush.getComposite().equals(composite)) { 157 return false; 158 } 159 160 return true; 161 } 162 163 170 @Override 171 public int hashCode() { 172 int hash = paint.hashCode() + stroke.hashCode() + composite.hashCode(); 173 174 return hash; 175 } 176 177 } 178 | Popular Tags |