From 6b7d1c4277366eb7aeee5b4dc4c2c3509f74514d Mon Sep 17 00:00:00 2001 From: bancika Date: Sun, 28 Aug 2011 17:09:10 +0000 Subject: [PATCH] Renumber selected components by X or Y axis --- .../src/org/diylc/common/IPlugInPort.java | 17 +++-- .../src/org/diylc/images/IconLoader.java | 2 +- .../DIYLC/src/org/diylc/images/sort.png | Bin 0 -> 826 bytes .../src/org/diylc/presenter/Presenter.java | 65 ++++++++++++++++++ .../src/org/diylc/swing/ActionFactory.java | 25 +++++++ .../swing/plugins/edit/EditMenuPlugin.java | 34 +++++++-- .../DIYLC/update.xml | 4 ++ 7 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/sort.png diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java index 0249f4e1..feade9ae 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java @@ -100,7 +100,7 @@ public interface IPlugInPort { * Saves the current project into the specified file. * * @param fileName - * @param isBackup + * @param isBackup */ void saveProjectToFile(String fileName, boolean isBackup); @@ -171,7 +171,8 @@ public interface IPlugInPort { * @param altDown * @param clickCount */ - void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown, int clickCount); + void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown, + int clickCount); /** * Notifies the presenter that mouse is moved. @@ -191,7 +192,7 @@ public interface IPlugInPort { * @return */ List> getSelectedComponents(); - + /** * Updates the selection with the specified list of component. Also, updates * control point map with all components that are stuck to the newly @@ -285,9 +286,8 @@ public interface IPlugInPort { */ List getMutualSelectionProperties(); - void editSelection(); - + /** * @return a list of editable properties of the current project. */ @@ -364,4 +364,11 @@ public interface IPlugInPort { * @param theme */ void setSelectedTheme(Theme theme); + + /** + * Renumbers all the selected components. + * + * @param xAxisFirst + */ + void renumberSelectedComponents(boolean xAxisFirst); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java index 991ba3dc..baef6933 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java @@ -31,7 +31,7 @@ public enum IconLoader { "donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium( "icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent( "edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png"), Pens( - "pens.png"); + "pens.png"), Sort("sort.png"); protected String name; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/sort.png b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/sort.png new file mode 100644 index 0000000000000000000000000000000000000000..e7f4364711d0698333b3d054e5a7ee9f65c57d7b GIT binary patch literal 826 zcmV-A1I7G_P)WdKcYATc)}MrC3kGB7YRATcyLGd4OfFd!>1F)%QXa*yr+000McNliru z)&&<0Gc?eew-NvV010qNS#tmY3h)2`3h)6!tTdPa000DMK}|sb0I`n?{9y$E00NRp zL_t(|+Le<{NK|1IhM$=`b7!tIPA2}9XhB6r^lMZI3SnZ479~NEM6H505k#975m6!$ zR%C^X7PV-VM$oE^5JHJE7a3BPn&nL651LNS@4eIcuA_<6q6_cke&;*i`@QEq=W6`V zbBPmFaDy_w^Nz4YQreOf$6qk_T*E`0rxIDqFr)Mll<1UeA)&T4ikWs|S+cN9%p`Oi zE0e{jAV!k&xQNKTedv@*tXMGQoIjsaT;M%=yh7hnyIn8Zz0q*^4MW0pf&v=Jk(*D` z!CeeAR+1}mpFm$wplAE!Qj1vJBx$;EXSqngD%mnHIVl7&_Has8%ZV}|@oa&6p1|P| zf)xRs;4)Q0l(^5U2%MDQ70G9L#YLXr<`DVR$Q%3u*Mb69z)wNIO;IFGp(jCbB6rTz zZ&Lj^lovY%(>!8a@WNImU2xDi9WC*i-qj+geuK`3aEjFIPdfX9{ICLyr~EOqp>(Sx zCzR{9Jjha23npD8yAOu6^0qVUJVqp8;x{xjBaiZEga==JQS)J4izM#i9!I1HK5+tR zCtTpLlBn_We%J~mhn_hr_Ewj8^gNHo*whp)pR}miQr*f(@1*4Qu!df`7!(H%Fv%FN z1rSz)l%lV5828NQcD<@*bG}<|>Y1H2?^He}JTM~r?KZ)P9NsT(#Id+7F;o12FNz>- zi|T(fOnT;1mt$L%*<9I1cu-B+bNjHW{W90Z&K)$-EM+J!x&@&>qpDga^CZ|LSTFb} zcyAxR#Z{4APa9VVNoOqHN&#x`*J6VCf5DgOaYQA^6c&ockge0q7&s$E+@wLi#+DK+ zCQ2_-re=R%X8slNgrHa9Uj$3Z)X?M$yqQ?i9x5sCH^l?ovsU1WH~;_u07*qoM6N<$ Eg7<`J2><{9 literal 0 HcmV?d00001 diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java index e7171464..041b2de6 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -1066,6 +1067,70 @@ public class Presenter implements IPlugInPort { drawingManager.setTheme(theme); } + @Override + public void renumberSelectedComponents(final boolean xAxisFirst) { + if (getSelectedComponents().isEmpty()) { + return; + } + Project oldProject = cloner.deepClone(currentProject); + List> components = new ArrayList>(getSelectedComponents()); + // Sort components by their location. + Collections.sort(components, new Comparator>() { + + @Override + public int compare(IDIYComponent o1, IDIYComponent o2) { + Area area1 = drawingManager.getComponentArea(o1); + Area area2 = drawingManager.getComponentArea(o2); + if (area1 != null && area2 != null) { + Point point1 = area1.getBounds().getLocation(); + Point point2 = area2.getBounds().getLocation(); + if (xAxisFirst) { + if (point1.y < point2.y) { + return -1; + } else if (point1.y > point2.y) { + return 1; + } else { + if (point1.x < point1.x) { + return -1; + } else if (point1.x > point1.x) { + return 1; + } + } + } else { + if (point1.x < point2.x) { + return -1; + } else if (point1.x > point2.x) { + return 1; + } else { + if (point1.y < point1.y) { + return -1; + } else if (point1.y > point1.y) { + return 1; + } + } + } + } + return 0; + } + }); + // Clear names. + for (IDIYComponent component : components) { + component.setName(""); + } + // Assign new ones. + for (IDIYComponent component : components) { + component.setName(instantiationManager.createUniqueName(ComponentProcessor + .getInstance().extractComponentTypeFrom( + (Class>) component.getClass()), + currentProject)); + } + + messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner + .deepClone(currentProject), "Renumber selection"); + projectFileManager.notifyFileChange(); + messageDispatcher.dispatchMessage(EventType.REPAINT); + } + public void updateSelection(List> newSelection) { this.selectedComponents = newSelection; Map, Set> controlPointMap = new HashMap, Set>(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java index 12827fbc..4fd80d3a 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java @@ -146,6 +146,10 @@ public class ActionFactory { public ThemeAction createThemeAction(IPlugInPort plugInPort, Theme theme) { return new ThemeAction(plugInPort, theme); } + + public RenumberAction createRenumberAction(IPlugInPort plugInPort, boolean xAxisFirst) { + return new RenumberAction(plugInPort, xAxisFirst); + } // File menu actions. @@ -842,4 +846,25 @@ public class ActionFactory { plugInPort.setSelectedTheme(theme); } } + + public static class RenumberAction extends AbstractAction { + + private static final long serialVersionUID = 1L; + + private IPlugInPort plugInPort; + private boolean xAxisFirst; + + public RenumberAction(IPlugInPort plugInPort, boolean xAxisFirst) { + super(); + this.plugInPort = plugInPort; + this.xAxisFirst = xAxisFirst; + putValue(AbstractAction.NAME, xAxisFirst ? "X Axis First" : "Y Axis First"); + } + + @Override + public void actionPerformed(ActionEvent e) { + LOG.info(getValue(AbstractAction.NAME) + " triggered"); + plugInPort.renumberSelectedComponents(xAxisFirst); + } + } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java index 0d612fd1..9be4addb 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java @@ -12,6 +12,7 @@ import org.diylc.common.EventType; import org.diylc.common.IPlugIn; import org.diylc.common.IPlugInPort; import org.diylc.core.Project; +import org.diylc.images.IconLoader; import org.diylc.swing.ActionFactory; import org.diylc.swing.ISwingUI; @@ -21,7 +22,8 @@ import com.diyfever.gui.undo.UndoHandler; public class EditMenuPlugin implements IPlugIn, ClipboardOwner { private static final String EDIT_TITLE = "Edit"; - + private static final String RENUMBER_TITLE = "Renumber Selection"; + private IPlugInPort plugInPort; private ISwingUI swingUI; @@ -36,6 +38,8 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { private ActionFactory.UngroupAction ungroupAction; private ActionFactory.SendToBackAction sendToBackAction; private ActionFactory.BringToFrontAction bringToFrontAction; + private ActionFactory.RenumberAction renumberXAxisAction; + private ActionFactory.RenumberAction renumberYAxisAction; private UndoHandler undoHandler; @@ -115,14 +119,14 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { } return ungroupAction; } - + public ActionFactory.SendToBackAction getSendToBackAction() { if (sendToBackAction == null) { sendToBackAction = ActionFactory.getInstance().createSendToBackAction(plugInPort); } return sendToBackAction; } - + public ActionFactory.BringToFrontAction getBringToFrontAction() { if (bringToFrontAction == null) { bringToFrontAction = ActionFactory.getInstance().createBringToFrontAction(plugInPort); @@ -130,10 +134,26 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { return bringToFrontAction; } + public ActionFactory.RenumberAction getRenumberXAxisAction() { + if (renumberXAxisAction == null) { + renumberXAxisAction = ActionFactory.getInstance() + .createRenumberAction(plugInPort, true); + } + return renumberXAxisAction; + } + + public ActionFactory.RenumberAction getRenumberYAxisAction() { + if (renumberYAxisAction == null) { + renumberYAxisAction = ActionFactory.getInstance().createRenumberAction(plugInPort, + false); + } + return renumberYAxisAction; + } + @Override public void connect(IPlugInPort plugInPort) { this.plugInPort = plugInPort; - + ActionFactory actionFactory = ActionFactory.getInstance(); swingUI.injectMenuAction(undoHandler.getUndoAction(), EDIT_TITLE); @@ -151,8 +171,12 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner { swingUI.injectMenuAction(getSendToBackAction(), EDIT_TITLE); swingUI.injectMenuAction(getBringToFrontAction(), EDIT_TITLE); swingUI.injectMenuAction(null, EDIT_TITLE); + swingUI.injectSubmenu(RENUMBER_TITLE, IconLoader.Sort.getIcon(), EDIT_TITLE); + swingUI.injectMenuAction(getRenumberXAxisAction(), RENUMBER_TITLE); + swingUI.injectMenuAction(getRenumberYAxisAction(), RENUMBER_TITLE); + swingUI.injectMenuAction(null, EDIT_TITLE); swingUI.injectMenuAction(actionFactory.createEditProjectAction(plugInPort), EDIT_TITLE); - + refreshActions(); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml index c4ed1e71..b788f728 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml @@ -358,6 +358,10 @@ NEW_FEATURE Double click on a component button in the toolbar selects all components of that type + + NEW_FEATURE + Renumber selected components by X or Y axis + http://code.google.com/p/diy-layout-creator/downloads/list