kaas
This commit is contained in:
+88
-62
@@ -1,4 +1,5 @@
|
||||
package Applicatie;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -12,8 +13,8 @@ import java.awt.geom.Rectangle2D;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
|
||||
public abstract class DrawObject {
|
||||
public abstract class DrawObject
|
||||
{
|
||||
Point2D position;
|
||||
double rotation;
|
||||
double scale;
|
||||
@@ -39,17 +40,19 @@ public abstract class DrawObject {
|
||||
rotation = 0;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
|
||||
public void draw(Graphics2D g)
|
||||
{
|
||||
AffineTransform tx = getTransform();
|
||||
g.drawImage(image, tx, null);
|
||||
if(selected) {
|
||||
// g.rotate(Math.toRadians(rotation), image.getWidth(null)/2, image.getHeight(null)/2);
|
||||
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null)/2, position.getY() +image.getHeight(null)/2);
|
||||
if (selected)
|
||||
{
|
||||
// g.rotate(Math.toRadians(rotation), image.getWidth(null)/2,
|
||||
// image.getHeight(null)/2);
|
||||
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(rotation), position.getX() + image.getWidth(null) / 2, position.getY() + image.getHeight(null) / 2);
|
||||
g.transform(rotate);
|
||||
g.setColor(Color.BLACK);
|
||||
g.setStroke(new BasicStroke(7));
|
||||
@@ -58,31 +61,32 @@ public abstract class DrawObject {
|
||||
rektAngle.setFrame(tx.createTransformedShape(rektAngle).getBounds());
|
||||
g.draw(rektAngle);
|
||||
g.setColor(Color.YELLOW);
|
||||
upperLeftCorner = new Rectangle2D.Double(rektAngle.getX()-7,rektAngle.getY()-7,15,15);
|
||||
upperRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth()-8,rektAngle.getY()-7,15,15);
|
||||
bottomLeftCorner = new Rectangle2D.Double(rektAngle.getX()-7,rektAngle.getY() + rektAngle.getHeight()-8,15,15);
|
||||
bottomRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth()-8,rektAngle.getY() + rektAngle.getHeight()-8,15,15);
|
||||
g.fill(upperLeftCorner); //upperleft
|
||||
g.fill(upperRightCorner); //upperright
|
||||
g.fill(bottomLeftCorner); //bottomleft
|
||||
g.fill(bottomRightCorner); //bottomright
|
||||
upperLeftCorner = new Rectangle2D.Double(rektAngle.getX() - 7, rektAngle.getY() - 7, 15, 15);
|
||||
upperRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth() - 8, rektAngle.getY() - 7, 15, 15);
|
||||
bottomLeftCorner = new Rectangle2D.Double(rektAngle.getX() - 7, rektAngle.getY() + rektAngle.getHeight() - 8, 15, 15);
|
||||
bottomRightCorner = new Rectangle2D.Double(rektAngle.getX() + rektAngle.getWidth() - 8, rektAngle.getY() + rektAngle.getHeight() - 8, 15, 15);
|
||||
g.fill(upperLeftCorner); // upperleft
|
||||
g.fill(upperRightCorner); // upperright
|
||||
g.fill(bottomLeftCorner); // bottomleft
|
||||
g.fill(bottomRightCorner); // bottomright
|
||||
g.setColor(Color.RED);
|
||||
rotateDot = new Ellipse2D.Double((rektAngle.getX() + (rektAngle.getWidth()/2))-8,rektAngle.getY()-8,15,15);
|
||||
rotateDot = new Ellipse2D.Double((rektAngle.getX() + (rektAngle.getWidth() / 2)) - 8, rektAngle.getY() - 8, 15, 15);
|
||||
g.fill(rotateDot);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected AffineTransform getTransform() {
|
||||
protected AffineTransform getTransform()
|
||||
{
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
tx.translate(position.getX(), position.getY());
|
||||
tx.rotate(Math.toRadians(rotation), image.getWidth(null) / 2, image.getHeight(null) / 2);
|
||||
return tx;
|
||||
}
|
||||
|
||||
protected AffineTransform getTransformSelection() {
|
||||
|
||||
protected AffineTransform getTransformSelection()
|
||||
{
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
tx.translate(position.getX(), position.getY());
|
||||
@@ -90,47 +94,59 @@ public abstract class DrawObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Special transformation for the selection rectangle, because the translation of the image one places the rectangle translated from the image.
|
||||
* Special transformation for the selection rectangle, because the
|
||||
* translation of the image one places the rectangle translated from the
|
||||
* image.
|
||||
*
|
||||
* @return affineTransform
|
||||
*/
|
||||
private AffineTransform getTransformRectangle() {
|
||||
private AffineTransform getTransformRectangle()
|
||||
{
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.scale(scale, scale);
|
||||
return tx;
|
||||
}
|
||||
|
||||
public boolean contains(Point2D clickPoint) {
|
||||
|
||||
public boolean contains(Point2D clickPoint)
|
||||
{
|
||||
Shape shape;
|
||||
if(rektAngle == null) {
|
||||
shape = new Rectangle2D.Double(0,0,image.getWidth(null), image.getHeight(null));
|
||||
if (rektAngle == null)
|
||||
{
|
||||
shape = new Rectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null));
|
||||
return getTransform().createTransformedShape(shape).contains(clickPoint);
|
||||
}
|
||||
else {
|
||||
shape = new Rectangle2D.Double(-7,-7,image.getWidth(null)+7, image.getHeight(null)+7);
|
||||
} else
|
||||
{
|
||||
shape = new Rectangle2D.Double(-7, -7, image.getWidth(null) + 7, image.getHeight(null) + 7);
|
||||
return getTransformSelection().createTransformedShape(shape).contains(clickPoint);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Point2D getObjectPoint(Point2D point) {
|
||||
try {
|
||||
|
||||
public Point2D getObjectPoint(Point2D point)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getTransform().inverseTransform(point, null);
|
||||
} catch (NoninvertibleTransformException e) {
|
||||
} catch (NoninvertibleTransformException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method checks if the place thats clicked is inside one of the corners.
|
||||
* This method checks if the place thats clicked is inside one of the
|
||||
* corners.
|
||||
*
|
||||
* @param point
|
||||
* @param corner
|
||||
* @return if the clicked point is inside one of the corners
|
||||
*/
|
||||
public boolean containsCorner(Point2D point, int corner) {
|
||||
public boolean containsCorner(Point2D point, int corner)
|
||||
{
|
||||
Rectangle2D chosenCorner = null;
|
||||
switch(corner) {
|
||||
switch (corner)
|
||||
{
|
||||
case 0:
|
||||
chosenCorner = upperLeftCorner;
|
||||
break;
|
||||
@@ -144,65 +160,75 @@ public abstract class DrawObject {
|
||||
chosenCorner = bottomRightCorner;
|
||||
break;
|
||||
case 4:
|
||||
if(point.getX() > rotateDot.getX() && point.getX() < rotateDot.getX() + rotateDot.getWidth()
|
||||
&& point.getY() > rotateDot.getY() && point.getY() < rotateDot.getY() + rotateDot.getHeight())
|
||||
if (point.getX() > rotateDot.getX() && point.getX() < rotateDot.getX() + rotateDot.getWidth() && point.getY() > rotateDot.getY() && point.getY() < rotateDot.getY() + rotateDot.getHeight())
|
||||
return true;
|
||||
else
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if(point.getX() > chosenCorner.getX() && point.getX() < chosenCorner.getX() + chosenCorner.getWidth()
|
||||
&& point.getY() > chosenCorner.getY() && point.getY() < chosenCorner.getY() + chosenCorner.getHeight())
|
||||
if (point.getX() > chosenCorner.getX() && point.getX() < chosenCorner.getX() + chosenCorner.getWidth() && point.getY() > chosenCorner.getY() && point.getY() < chosenCorner.getY() + chosenCorner.getHeight())
|
||||
return true;
|
||||
else
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSelected(boolean b) {
|
||||
|
||||
public void setSelected(boolean b)
|
||||
{
|
||||
selected = b;
|
||||
}
|
||||
|
||||
public Point2D getPosition() {
|
||||
public Point2D getPosition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Point2D position) {
|
||||
public void setPosition(Point2D position)
|
||||
{
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public double getRotation() {
|
||||
public double getRotation()
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public void setRotation(double rotation) {
|
||||
public void setRotation(double rotation)
|
||||
{
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public double getScale() {
|
||||
public double getScale()
|
||||
{
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setScale(double scale) {
|
||||
public void setScale(double scale)
|
||||
{
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
public Image getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(Image image) {
|
||||
public void setImage(Image image)
|
||||
{
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
public boolean isSelected()
|
||||
{
|
||||
return selected;
|
||||
}
|
||||
|
||||
public Rectangle2D getRectangle() {
|
||||
|
||||
public Rectangle2D getRectangle()
|
||||
{
|
||||
return rektAngle;
|
||||
}
|
||||
|
||||
public void setRectangle(Rectangle2D rectangle) {
|
||||
|
||||
public void setRectangle(Rectangle2D rectangle)
|
||||
{
|
||||
rektAngle = rectangle;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user