mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Allow drag and drop reordering in project explorer
This commit is contained in:
@@ -342,16 +342,6 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
// */
|
||||
// Rectangle2D getSelectedAreaRect();
|
||||
|
||||
/**
|
||||
* Sends each of the selected components one step back.
|
||||
*/
|
||||
void sendSelectionToBack();
|
||||
|
||||
/**
|
||||
* Brings each of the selected components one step to front.
|
||||
*/
|
||||
void bringSelectionToFront();
|
||||
|
||||
/**
|
||||
* Causes the display to refresh.
|
||||
*/
|
||||
|
||||
@@ -137,5 +137,21 @@ public interface ISelectionProcessor {
|
||||
*
|
||||
* @param model
|
||||
*/
|
||||
void applyModelToSelection(String[] model);
|
||||
void applyModelToSelection(String[] model);
|
||||
|
||||
/**
|
||||
* Sends each of the selected components one step back.
|
||||
*/
|
||||
void sendSelectionToBack();
|
||||
|
||||
/**
|
||||
* Brings each of the selected components one step to front.
|
||||
*/
|
||||
void bringSelectionToFront();
|
||||
|
||||
/**
|
||||
* Move selected components to z index starting from the provided value
|
||||
* @param zIndex
|
||||
*/
|
||||
void moveSelectionToZIndex(int zIndex);
|
||||
}
|
||||
|
||||
@@ -1946,6 +1946,42 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveSelectionToZIndex(int zIndex) {
|
||||
LOG.info(String.format("moveSelectionToZIndex(%d)", zIndex));
|
||||
Project oldProject = currentProject.clone();
|
||||
|
||||
// sort the selection in Z-order
|
||||
List<IDIYComponent<?>> selection = new ArrayList<IDIYComponent<?>>(selectedComponents);
|
||||
Collections.sort(selection, new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
return new Integer(currentProject.getComponents().indexOf(o1))
|
||||
.compareTo(currentProject.getComponents().indexOf(o2));
|
||||
}
|
||||
});
|
||||
|
||||
for (IDIYComponent<?> component : selection) {
|
||||
int index = currentProject.getComponents().indexOf(component);
|
||||
if (index < 0) {
|
||||
LOG.warn("Component not found in the project: " + component.getName());
|
||||
} else {
|
||||
if (index < zIndex)
|
||||
zIndex--;
|
||||
|
||||
currentProject.getComponents().remove(index);
|
||||
currentProject.getComponents().add(zIndex, component);
|
||||
}
|
||||
}
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject,
|
||||
"Change Z-order");
|
||||
projectFileManager.notifyFileChange();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
|
||||
Reference in New Issue
Block a user