if (rootViewLocation.getX() + rootViewSize.getWidth() + PADDING + requiredSize.getWidth() < workspaceSize.getWidth()) {
newLocation.add(rootViewSize.getWidth() + PADDING, 0);
} else if (rootViewLocation.getY() + rootViewSize.getHeight() + PADDING + requiredSize.getHeight() < workspaceSize.getHeight()) {
newLocation.add(0, rootViewSize.getHeight() + PADDING);
} else if (requiredSize.getWidth() + PADDING < rootViewLocation.getX()) {
newLocation.subtract(requiredSize.getWidth() + PADDING, 0);
} else if (requiredSize.getHeight() + PADDING < rootViewLocation.getY()) {
newLocation.subtract(0, requiredSize.getHeight() + PADDING);
} else {
newLocation.add(PADDING * 6, PADDING * 6);
}