diff --git a/diylc/diylc-core/src/org/diylc/common/ISelectionProcessor.java b/diylc/diylc-core/src/org/diylc/common/ISelectionProcessor.java index 153ac2ef..edba8cc0 100644 --- a/diylc/diylc-core/src/org/diylc/common/ISelectionProcessor.java +++ b/diylc/diylc-core/src/org/diylc/common/ISelectionProcessor.java @@ -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> 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(); } diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index 7f223075..29d3afc9 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -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; diff --git a/diylc/diylc-swing/lib/swing-framework.jar b/diylc/diylc-swing/lib/swing-framework.jar index 12160eb7..cf4c326e 100644 Binary files a/diylc/diylc-swing/lib/swing-framework.jar and b/diylc/diylc-swing/lib/swing-framework.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 2d8ef194..48e19981 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java index 9fbb040d..06595ec1 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java @@ -550,6 +550,16 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { break; case 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; } // } diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index 07dd47a3..9c8abb80 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -1692,6 +1692,22 @@ https://github.com/bancika/diy-layout-creator/releases + + + + 3 + 39 + 0 + + 2017-04-20 20:00:00.000 CET + + + + NEW_FEATURE + Red ticks on both rulers track selection bounds, blue tick tracks cursor position + + + https://github.com/bancika/diy-layout-creator/releases \ No newline at end of file