public void selectObject(ArrayList arr, int x, int y) {
for (int i = arr.size() - 1; i > -1; i--) {
if (arr.get(i) instanceof Figure) {
AffineTransform rotate = AffineTransform.getRotateInstance(((Figure) arr.get(i)).angle,
((Figure) arr.get(i)).rotatex, ((Figure) arr.get(i)).rotatey);
double oldPoint[] = new double[] {x, y, x, y};
double newPoint[] = new double[] {x, y, x, y};
try {
rotate.inverseTransform(oldPoint, 0, newPoint, 0, 1);
}
catch (NoninvertibleTransformException ex) {
}
AffineTransform move = AffineTransform.getTranslateInstance(((Figure) arr.get(i)).movex,
((Figure) arr.get(i)).movey);
try {
move.inverseTransform(oldPoint, 2, newPoint, 2, 1);
}
catch (NoninvertibleTransformException ex1) {
}
if (((Figure) arr.get(i)).shape.contains(newPoint[0], newPoint[1]) ||
((Figure) arr.get(i)).shape.contains(newPoint[2], newPoint[3])) {
((Figure) arr.get(i)).isSelected = true;
break;
}
}
else if (arr.get(i) instanceof Group) {
boolean isGroup = isGrouped(((Group) arr.get(i)).group, x, y);
if (isGroup == true) {
((BaseObject) arr.get(i)).isSelected = true;
findXY(((Group) arr.get(i)).group, maxX, maxY, minX, minY);
}
}
}
}
public boolean isGrouped(ArrayList arr, int x, int y) {
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) instanceof Group) {
boolean isUnderGroup = isGrouped(((Group) arr.get(i)).group, x, y);
if (isUnderGroup == true) {
return true;
}
}
else {
AffineTransform rotate = AffineTransform.getRotateInstance(((Figure) arr.get(i)).angle,
((Figure) arr.get(i)).rotatex, ((Figure) arr.get(i)).rotatey);
double oldPoint[] = new double[] {x, y, x, y};
double newPoint[] = new double[] {x, y, x, y};
try {
rotate.inverseTransform(oldPoint, 0, newPoint, 0, 1);
}
catch (NoninvertibleTransformException ex) {
}
AffineTransform move = AffineTransform.getTranslateInstance(((Figure) arr.get(i)).movex,
((Figure) arr.get(i)).movey);
try {
move.inverseTransform(oldPoint, 2, newPoint, 2, 1);
}
catch (NoninvertibleTransformException ex1) {
}
if (((Figure) arr.get(i)).shape.contains(newPoint[0], newPoint[1]) ||
((Figure) arr.get(i)).shape.contains(newPoint[2], newPoint[3])) {
((Figure) arr.get(i)).isSelected = true;
return true;
}
}
}
return false;
}
public void findXY(ArrayList arr, double maxX, double maxY, double minX, double minY) {
maxX = ((Figure) arr.get(0)).shape.getBounds().getMaxX();
maxY = ((Figure) arr.get(0)).shape.getBounds().getMaxY();
minX = ((Figure) arr.get(0)).shape.getBounds().getMinX();
minY = ((Figure) arr.get(0)).shape.getBounds().getMinY();
for (int i = 1; i < arr.size(); i++) {
((BaseObject) arr.get(i)).isSelected = true;
double newMaxX = ((Figure) arr.get(i)).shape.getBounds().getMaxX();
double newMaxY = ((Figure) arr.get(i)).shape.getBounds().getMaxY();
double newMinX = ((Figure) arr.get(i)).shape.getBounds().getMinX();
double newMinY = ((Figure) arr.get(i)).shape.getBounds().getMinY();
if (newMaxX > maxX) {
maxX = newMaxX;
}
if (newMaxY > maxY) {
maxY = newMaxY;
}
if (newMinX < minX) {
minX = newMinX;
}
if (newMinY < minY) {
minY = newMinY;
}
if (arr.get(i) instanceof Group) {
findXY(((Group) arr.get(i)).group, maxX, maxY, minX, minY);
}
}
}