mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
building blocks improvement
This commit is contained in:
@@ -111,7 +111,8 @@ public class InstantiationManager {
|
|||||||
return changeMade;
|
return changeMade;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
|
||||||
|
Size gridSpacing) {
|
||||||
// Adjust location of components so they are centered under the mouse
|
// Adjust location of components so they are centered under the mouse
|
||||||
// cursor
|
// cursor
|
||||||
int minX = Integer.MAX_VALUE;
|
int minX = Integer.MAX_VALUE;
|
||||||
@@ -213,7 +214,7 @@ public class InstantiationManager {
|
|||||||
// Instantiate the component.
|
// Instantiate the component.
|
||||||
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
|
||||||
|
|
||||||
component.setName(createUniqueName(componentType, currentProject));
|
component.setName(createUniqueName(componentType, currentProject.getComponents()));
|
||||||
|
|
||||||
// Translate them to the desired location.
|
// Translate them to the desired location.
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
@@ -251,11 +252,20 @@ public class InstantiationManager {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createUniqueName(ComponentType componentType, Project currentProject) {
|
|
||||||
|
/**
|
||||||
|
* * Creates a unique component name for the specified type taking existing components into
|
||||||
|
* account.
|
||||||
|
*
|
||||||
|
* @param componentType
|
||||||
|
* @param currentProject
|
||||||
|
* @param additionalComponents
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String createUniqueName(ComponentType componentType, List<IDIYComponent<?>> components) {
|
||||||
boolean exists = true;
|
boolean exists = true;
|
||||||
List<IDIYComponent<?>> components = currentProject.getComponents();
|
|
||||||
String[] takenNames = new String[components.size()];
|
String[] takenNames = new String[components.size()];
|
||||||
for (int j = 0; j < currentProject.getComponents().size(); j++) {
|
for (int j = 0; j < components.size(); j++) {
|
||||||
takenNames[j] = components.get(j).getName();
|
takenNames[j] = components.get(j).getName();
|
||||||
}
|
}
|
||||||
Arrays.sort(takenNames);
|
Arrays.sort(takenNames);
|
||||||
|
|||||||
@@ -1540,7 +1540,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
// Assign new ones.
|
// Assign new ones.
|
||||||
for (IDIYComponent<?> component : components) {
|
for (IDIYComponent<?> component : components) {
|
||||||
component.setName(instantiationManager.createUniqueName(ComponentProcessor.getInstance()
|
component.setName(instantiationManager.createUniqueName(ComponentProcessor.getInstance()
|
||||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass()), currentProject));
|
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass()), currentProject
|
||||||
|
.getComponents()));
|
||||||
}
|
}
|
||||||
|
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(),
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(),
|
||||||
@@ -2077,11 +2078,13 @@ public class Presenter implements IPlugInPort {
|
|||||||
throw new InvalidBlockException();
|
throw new InvalidBlockException();
|
||||||
// clone components
|
// clone components
|
||||||
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
|
List<IDIYComponent<?>> clones = new ArrayList<IDIYComponent<?>>();
|
||||||
|
List<IDIYComponent<?>> testComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
|
||||||
for (IDIYComponent<?> c : components)
|
for (IDIYComponent<?> c : components)
|
||||||
try {
|
try {
|
||||||
IDIYComponent<?> clone = c.clone();
|
IDIYComponent<?> clone = c.clone();
|
||||||
clone.setName(instantiationManager.createUniqueName(ComponentProcessor.getInstance()
|
clone.setName(instantiationManager.createUniqueName(ComponentProcessor.getInstance()
|
||||||
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clone.getClass()), currentProject));
|
.extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clone.getClass()), testComponents));
|
||||||
|
testComponents.add(clone);
|
||||||
clones.add(clone);
|
clones.add(clone);
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
LOG.error("Could not clone component: " + c);
|
LOG.error("Could not clone component: " + c);
|
||||||
|
|||||||
Reference in New Issue
Block a user