mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Renumber selected components by X or Y axis
This commit is contained in:
+12
-5
@@ -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<IDIYComponent<?>> 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<PropertyWrapper> 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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 826 B |
+65
@@ -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<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>(getSelectedComponents());
|
||||
// Sort components by their location.
|
||||
Collections.sort(components, new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@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<? extends IDIYComponent<?>>) component.getClass()),
|
||||
currentProject));
|
||||
}
|
||||
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||
.deepClone(currentProject), "Renumber selection");
|
||||
projectFileManager.notifyFileChange();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
public void updateSelection(List<IDIYComponent<?>> newSelection) {
|
||||
this.selectedComponents = newSelection;
|
||||
Map<IDIYComponent<?>, Set<Integer>> controlPointMap = new HashMap<IDIYComponent<?>, Set<Integer>>();
|
||||
|
||||
+25
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-5
@@ -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<Project> 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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user