|
|
@@ -0,0 +1,101 @@
|
|
|
+package gui.simulator;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.geom.AffineTransform;
|
|
|
+import java.awt.geom.Point2D;
|
|
|
+import java.awt.geom.Rectangle2D;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by gjoosen on 07/03/15.
|
|
|
+ * Edited by master D Mathijssen on 17-3-2015 and some other days
|
|
|
+ */
|
|
|
+public abstract class Draw {
|
|
|
+
|
|
|
+ private Image image;
|
|
|
+ public double x, y, rotation, scale;
|
|
|
+ private double distanceToOtherObjects;
|
|
|
+
|
|
|
+ public Draw(String image, int x, int y, double scale, double distanceToOtherObjects){
|
|
|
+ try{
|
|
|
+ this.image = ImageIO.read(getClass().getResource(image));
|
|
|
+ }catch(IOException ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ this.x = x;
|
|
|
+ this.y = y;
|
|
|
+ this.scale = scale;
|
|
|
+ this.distanceToOtherObjects = distanceToOtherObjects;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AffineTransform getAffineTransform(){
|
|
|
+ AffineTransform transform = new AffineTransform();
|
|
|
+ transform.translate(this.x, this.y);
|
|
|
+ transform.scale(this.scale, this.scale);
|
|
|
+ transform.rotate(Math.toRadians(this.rotation), this.image.getWidth(null) /2 , this.image.getHeight(null) / 2);
|
|
|
+ return transform;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void draw(Graphics2D g){
|
|
|
+ g.drawImage(this.image, this.getAffineTransform(), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean contains(Point2D point){
|
|
|
+ Shape shape = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
|
|
|
+ return this.getAffineTransform().createTransformedShape(shape).contains(point);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Image getImage(){
|
|
|
+ return image;
|
|
|
+ }
|
|
|
+
|
|
|
+ //getters and setters down here
|
|
|
+ public double getX() {
|
|
|
+ return x;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getY() {
|
|
|
+ return y;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setX(double x){
|
|
|
+ this.x = x;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setY(double y){
|
|
|
+ this.y = y;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRotation(double rotation) {
|
|
|
+ this.rotation = rotation;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getScale() {
|
|
|
+ return scale;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setScale(double scale) {
|
|
|
+ this.scale = scale;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getWidth(){
|
|
|
+ return this.image.getWidth(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getHeight(){
|
|
|
+ return this.image.getHeight(null);
|
|
|
+ }
|
|
|
+ public double getRotation() {
|
|
|
+ return rotation;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getDistanceToOtherObjects() {
|
|
|
+ return distanceToOtherObjects;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Rectangle2D.Double getRect(){
|
|
|
+ return new Rectangle2D.Double(-distanceToOtherObjects, - distanceToOtherObjects, image.getWidth(null) + 2* distanceToOtherObjects, image.getHeight(null) + 2*distanceToOtherObjects);
|
|
|
+ }
|
|
|
+}
|