show selection bounds on rulers

This commit is contained in:
bancika
2017-04-20 14:12:00 +02:00
parent dc8612a167
commit b3d63e9f22
6 changed files with 66 additions and 3 deletions
@@ -1,6 +1,7 @@
package org.diylc.common;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
import java.util.List;
@@ -25,7 +26,8 @@ public interface ISelectionProcessor {
void updateSelection(Collection<IDIYComponent<?>> newSelection);
/**
* Finds all components at the specified location, sorted by z-index from top to bottom.
* Finds all components at the specified location, sorted by z-index from top to bottom. Location
* depends on the current zoom level.
*
* @param point
* @return
@@ -54,7 +56,7 @@ public interface ISelectionProcessor {
* @param direction 1 for clockwise, -1 for counter-clockwise
*/
void rotateSelection(int direction);
/**
* Groups all selected components.
*/
@@ -64,6 +66,19 @@ public interface ISelectionProcessor {
* Ungroups all selected components.
*/
void ungroupSelectedComponents();
/**
* Mirrors selected components in the given axis.
*
* @param direction
*/
void mirrorSelection(int direction);
/**
* Returns the minimum rectangle containing all selected components, or null if none exists.
* Rectangle is scaled by the current zoom level.
*
* @return
*/
Rectangle2D getSelectionBounds();
}
@@ -6,8 +6,10 @@ import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.dnd.DnDConstants;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -813,6 +815,26 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
@Override
public Rectangle2D getSelectionBounds() {
if (selectedComponents == null || selectedComponents.isEmpty())
return null;
Area totalArea = new Area();
for (IDIYComponent<?> c : selectedComponents) {
Area compArea = drawingManager.getComponentArea(c);
if (compArea != null)
totalArea.add(compArea);
else
LOG.info("Area is null");
}
if (drawingManager.getZoomLevel() != 1) {
totalArea
.transform(AffineTransform.getScaleInstance(drawingManager.getZoomLevel(), drawingManager.getZoomLevel()));
}
return totalArea.getBounds2D();
}
@Override
public VersionNumber getCurrentVersionNumber() {
return CURRENT_VERSION;