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; package org.diylc.common;
import java.awt.Point; import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -25,7 +26,8 @@ public interface ISelectionProcessor {
void updateSelection(Collection<IDIYComponent<?>> newSelection); 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 * @param point
* @return * @return
@@ -65,5 +67,18 @@ public interface ISelectionProcessor {
*/ */
void ungroupSelectedComponents(); void ungroupSelectedComponents();
/**
* Mirrors selected components in the given axis.
*
* @param direction
*/
void mirrorSelection(int 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.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.dnd.DnDConstants; import java.awt.dnd.DnDConstants;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -813,6 +815,26 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.REPAINT); 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 @Override
public VersionNumber getCurrentVersionNumber() { public VersionNumber getCurrentVersionNumber() {
return CURRENT_VERSION; return CURRENT_VERSION;
Binary file not shown.
Binary file not shown.
@@ -550,6 +550,16 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
break; break;
case REPAINT: case REPAINT:
canvasPanel.repaint(); canvasPanel.repaint();
// Refresh selection bounds after we're done with painting to ensure we have traced the
// component areas
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds());
}
});
break; break;
} }
// } // }
+16
View File
@@ -1693,5 +1693,21 @@
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>3</major>
<minor>39</minor>
<build>0</build>
</versionNumber>
<releaseDate>2017-04-20 20:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Red ticks on both rulers track selection bounds, blue tick tracks cursor position</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a> </a>
</java.util.Arrays_-ArrayList> </java.util.Arrays_-ArrayList>