mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added group/ungroup
This commit is contained in:
+6
-4
@@ -169,11 +169,9 @@ public interface IPlugInPort {
|
|||||||
ComponentSelection getSelectedComponents();
|
ComponentSelection getSelectedComponents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes component selection.
|
* Selects all components in the project.
|
||||||
*
|
|
||||||
* @param selection
|
|
||||||
*/
|
*/
|
||||||
void setSelectedComponents(ComponentSelection selection);
|
void selectAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Area} occupied by the component.
|
* Returns the {@link Area} occupied by the component.
|
||||||
@@ -306,4 +304,8 @@ public interface IPlugInPort {
|
|||||||
* @param isMetric
|
* @param isMetric
|
||||||
*/
|
*/
|
||||||
void setMetric(boolean isMetric);
|
void setMetric(boolean isMetric);
|
||||||
|
|
||||||
|
void groupSelectedComponents();
|
||||||
|
|
||||||
|
void ungroupSelectedComponents();
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -2,7 +2,9 @@ package org.diylc.core;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
@@ -29,9 +31,11 @@ public class Project implements Serializable {
|
|||||||
private Size width;
|
private Size width;
|
||||||
private Size height;
|
private Size height;
|
||||||
private List<IDIYComponent<?>> components;
|
private List<IDIYComponent<?>> components;
|
||||||
|
private Set<Set<IDIYComponent<?>>> groups;
|
||||||
|
|
||||||
public Project() {
|
public Project() {
|
||||||
components = new ArrayList<IDIYComponent<?>>();
|
components = new ArrayList<IDIYComponent<?>>();
|
||||||
|
groups = new HashSet<Set<IDIYComponent<?>>>();
|
||||||
title = DEFAULT_TITLE;
|
title = DEFAULT_TITLE;
|
||||||
author = System.getProperty("user.name");
|
author = System.getProperty("user.name");
|
||||||
width = DEFAULT_WIDTH;
|
width = DEFAULT_WIDTH;
|
||||||
@@ -39,7 +43,7 @@ public class Project implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Project(String title, String author, String description, Size width, Size height,
|
public Project(String title, String author, String description, Size width, Size height,
|
||||||
List<IDIYComponent<?>> components) {
|
List<IDIYComponent<?>> components, Set<Set<IDIYComponent<?>>> groups) {
|
||||||
super();
|
super();
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
@@ -47,6 +51,7 @@ public class Project implements Serializable {
|
|||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.components = components;
|
this.components = components;
|
||||||
|
this.groups = groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
@@ -103,6 +108,15 @@ public class Project implements Serializable {
|
|||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set of grouped components.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Set<IDIYComponent<?>>> getGroups() {
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ public enum IconLoader {
|
|||||||
"csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy("copy.png"), Paste(
|
"csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy("copy.png"), Paste(
|
||||||
"paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard(
|
"paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard(
|
||||||
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
|
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
|
||||||
"wrench.png"), ;
|
"wrench.png"), Group("group.png"), Ungroup("ungroup.png");
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 771 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 883 B |
+42
-2
@@ -76,6 +76,9 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
plugInPort.injectMenuAction(pasteAction, EDIT_TITLE);
|
plugInPort.injectMenuAction(pasteAction, EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||||
plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
|
plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
|
||||||
|
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||||
|
plugInPort.injectMenuAction(new GroupAction(), EDIT_TITLE);
|
||||||
|
plugInPort.injectMenuAction(new UngroupAction(), EDIT_TITLE);
|
||||||
|
|
||||||
refreshActions();
|
refreshActions();
|
||||||
}
|
}
|
||||||
@@ -187,8 +190,45 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
LOG.info("Select All triggered");
|
LOG.info("Select All triggered");
|
||||||
plugInPort.setSelectedComponents(new ComponentSelection(plugInPort.getCurrentProject()
|
plugInPort.selectAll();
|
||||||
.getComponents()));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GroupAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public GroupAction() {
|
||||||
|
super();
|
||||||
|
putValue(AbstractAction.NAME, "Group Selection");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Group.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Group Selection triggered");
|
||||||
|
plugInPort.groupSelectedComponents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UngroupAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public UngroupAction() {
|
||||||
|
super();
|
||||||
|
putValue(AbstractAction.NAME, "Ungroup Selection");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U,
|
||||||
|
ActionEvent.CTRL_MASK));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Ungroup.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Ungroup Selection triggered");
|
||||||
|
plugInPort.ungroupSelectedComponents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+60
-7
@@ -13,9 +13,11 @@ import java.awt.geom.Area;
|
|||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -384,14 +386,14 @@ public class Presenter implements IPlugInPort {
|
|||||||
// cursor.
|
// cursor.
|
||||||
if (ctrlDown) {
|
if (ctrlDown) {
|
||||||
if (selectedComponents.contains(component)) {
|
if (selectedComponents.contains(component)) {
|
||||||
selectedComponents.remove(component);
|
selectedComponents.removeAll(findAllGroupedComponents(component));
|
||||||
} else {
|
} else {
|
||||||
selectedComponents.add(component);
|
selectedComponents.addAll(findAllGroupedComponents(component));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise just select that one component.
|
// Otherwise just select that one component.
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
selectedComponents.add(component);
|
selectedComponents.addAll(findAllGroupedComponents(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
@@ -454,8 +456,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSelectedComponents(ComponentSelection selection) {
|
public void selectAll() {
|
||||||
this.selectedComponents = new ComponentSelection(selection);
|
this.selectedComponents = new ComponentSelection(currentProject.getComponents());
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
||||||
calculateSelectionDimension());
|
calculateSelectionDimension());
|
||||||
@@ -502,7 +504,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
// it into the only selected component.
|
// it into the only selected component.
|
||||||
if (!selectedComponents.contains(component)) {
|
if (!selectedComponents.contains(component)) {
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
selectedComponents.add(component);
|
selectedComponents.addAll(findAllGroupedComponents(component));
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
|
||||||
calculateSelectionDimension());
|
calculateSelectionDimension());
|
||||||
@@ -587,7 +589,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||||
Area area = componentAreaMap.get(component);
|
Area area = componentAreaMap.get(component);
|
||||||
if ((area != null) && (selectionRect != null) && area.intersects(selectionRect)) {
|
if ((area != null) && (selectionRect != null) && area.intersects(selectionRect)) {
|
||||||
selectedComponents.add(component);
|
selectedComponents.addAll(findAllGroupedComponents(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectionRect = null;
|
selectionRect = null;
|
||||||
@@ -622,6 +624,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
public void deleteSelectedComponents() {
|
public void deleteSelectedComponents() {
|
||||||
LOG.debug("deleteSelectedComponents()");
|
LOG.debug("deleteSelectedComponents()");
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
|
// Remove selected components from any groups.
|
||||||
|
ungroupComponents(selectedComponents);
|
||||||
currentProject.getComponents().removeAll(selectedComponents);
|
currentProject.getComponents().removeAll(selectedComponents);
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
.deepClone(currentProject), "Delete");
|
.deepClone(currentProject), "Delete");
|
||||||
@@ -673,6 +677,55 @@ public class Presenter implements IPlugInPort {
|
|||||||
calculateSelectionDimension());
|
calculateSelectionDimension());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void groupSelectedComponents() {
|
||||||
|
LOG.debug("groupSelectedComponents()");
|
||||||
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
|
// First remove the selected components from other groups.
|
||||||
|
ungroupComponents(selectedComponents);
|
||||||
|
// Then group them together
|
||||||
|
currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(selectedComponents));
|
||||||
|
// Notify the listeners.
|
||||||
|
if (!oldProject.equals(currentProject)) {
|
||||||
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
|
.deepClone(currentProject), "Group");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ungroupSelectedComponents() {
|
||||||
|
LOG.debug("ungroupSelectedComponents()");
|
||||||
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
|
ungroupComponents(selectedComponents);
|
||||||
|
// Notify the listeners.
|
||||||
|
if (!oldProject.equals(currentProject)) {
|
||||||
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
|
.deepClone(currentProject), "Group");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ungroupComponents(Collection<IDIYComponent<?>> components) {
|
||||||
|
Iterator<Set<IDIYComponent<?>>> groupIterator = currentProject.getGroups().iterator();
|
||||||
|
while (groupIterator.hasNext()) {
|
||||||
|
Set<IDIYComponent<?>> group = groupIterator.next();
|
||||||
|
group.removeAll(components);
|
||||||
|
if (group.isEmpty()) {
|
||||||
|
groupIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<IDIYComponent<?>> findAllGroupedComponents(IDIYComponent<?> component) {
|
||||||
|
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
|
||||||
|
components.add(component);
|
||||||
|
for (Set<IDIYComponent<?>> group : currentProject.getGroups()) {
|
||||||
|
if (group.contains(component)) {
|
||||||
|
components.addAll(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return components;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return selection size expressed in either inches or centimeters, based
|
* @return selection size expressed in either inches or centimeters, based
|
||||||
* on the user preference.
|
* on the user preference.
|
||||||
|
|||||||
Reference in New Issue
Block a user