From a5bd532e47ec8eb174ba1c66e6bd69949a6cd82e Mon Sep 17 00:00:00 2001 From: bancika Date: Thu, 27 Apr 2017 12:05:34 +0200 Subject: [PATCH] force components to go to front or back --- .../core/annotations/ComponentDescriptor.java | 3 +- .../src/org/diylc/presenter/Presenter.java | 48 +++++++++++++++++-- diylc/diylc-swing/update.xml | 4 ++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java b/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java index 8c926d7c..1d05103b 100644 --- a/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java +++ b/diylc/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java @@ -57,8 +57,7 @@ public @interface ComponentDescriptor { double zOrder(); /** - * @return true if the component may go beyond it's predefined layer. In that case, - * zOrder is used as initial z order of the component. + * @return true if the component may go beyond it's predefined layer without warning the user. */ boolean flexibleZOrder() default false; diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index cc5d6a10..198b3327 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -739,7 +739,7 @@ public class Presenter implements IPlugInPort { public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) { if (point == null) return; - + if (shiftDown) { dragAction = IPlugInPort.DND_TOGGLE_SNAP; } else { @@ -1512,8 +1512,21 @@ public class Presenter implements IPlugInPort { @Override public void sendSelectionToBack() { LOG.info("sendSelectionToBack()"); + int forceConfirmation = -1; Project oldProject = currentProject.clone(); - for (IDIYComponent component : selectedComponents) { + + // sort the selection in the reversed Z-order to preserve the order after moving to the back + List> selection = new ArrayList>(selectedComponents); + Collections.sort(selection, new Comparator>() { + + @Override + public int compare(IDIYComponent o1, IDIYComponent o2) { + return new Integer(currentProject.getComponents().indexOf(o2)).compareTo(currentProject.getComponents() + .indexOf(o1)); + } + }); + + for (IDIYComponent component : selection) { ComponentType componentType = ComponentProcessor.getInstance().extractComponentTypeFrom( (Class>) component.getClass()); @@ -1527,7 +1540,13 @@ public class Presenter implements IPlugInPort { ComponentProcessor.getInstance().extractComponentTypeFrom( (Class>) componentBefore.getClass()); if (!componentType.isFlexibleZOrder() - && Math.round(componentBeforeType.getZOrder()) < Math.round(componentType.getZOrder())) + && Math.round(componentBeforeType.getZOrder()) < Math.round(componentType.getZOrder()) + && forceConfirmation != IView.YES_OPTION + && (forceConfirmation = + this.view + .showConfirmDialog( + "Selected component(s) have reached the bottom of their layer. Do you want to force the selection to the back?", + "Send Selection to Back", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE)) != IView.YES_OPTION) break; Collections.swap(currentProject.getComponents(), index, index - 1); index--; @@ -1544,8 +1563,21 @@ public class Presenter implements IPlugInPort { @Override public void bringSelectionToFront() { LOG.info("bringSelectionToFront()"); + int forceConfirmation = -1; Project oldProject = currentProject.clone(); - for (IDIYComponent component : selectedComponents) { + + // sort the selection in Z-order + List> selection = new ArrayList>(selectedComponents); + Collections.sort(selection, new Comparator>() { + + @Override + public int compare(IDIYComponent o1, IDIYComponent o2) { + return new Integer(currentProject.getComponents().indexOf(o1)).compareTo(currentProject.getComponents() + .indexOf(o2)); + } + }); + + for (IDIYComponent component : selection) { ComponentType componentType = ComponentProcessor.getInstance().extractComponentTypeFrom( (Class>) component.getClass()); @@ -1559,7 +1591,13 @@ public class Presenter implements IPlugInPort { ComponentProcessor.getInstance().extractComponentTypeFrom( (Class>) componentAfter.getClass()); if (!componentType.isFlexibleZOrder() - && Math.round(componentAfterType.getZOrder()) > Math.round(componentType.getZOrder())) + && Math.round(componentAfterType.getZOrder()) > Math.round(componentType.getZOrder()) + && forceConfirmation != IView.YES_OPTION + && (forceConfirmation = + this.view + .showConfirmDialog( + "Selected component(s) have reached the bottom of their layer. Do you want to force the selection to the back?", + "Send Selection to Back", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE)) != IView.YES_OPTION) break; Collections.swap(currentProject.getComponents(), index, index + 1); index++; diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index cc5d304b..fbbb91bc 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -1766,6 +1766,10 @@ NEW_FEATURE 'Tilde' key repeats the last added component + + NEW_FEATURE + Ability to force components to the front or back of other components even outisde their designated layer + IMPROVEMENT Do not block the UI while checking for new version at startup (can be problematic when there's connectivity issues)