mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Component templates save shape of the component (for wires and such)
This commit is contained in:
+19
-1
@@ -1,16 +1,20 @@
|
|||||||
package org.diylc.core;
|
package org.diylc.core;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Template {
|
public class Template {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Map<String, Object> values;
|
private Map<String, Object> values;
|
||||||
|
private List<Point> points;
|
||||||
|
|
||||||
public Template(String name, Map<String, Object> values) {
|
public Template(String name, Map<String, Object> values, List<Point> points) {
|
||||||
super();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.values = values;
|
this.values = values;
|
||||||
|
this.points = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -29,11 +33,20 @@ public class Template {
|
|||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Point> getPoints() {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoints(List<Point> points) {
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
result = prime * result + ((points == null) ? 0 : points.hashCode());
|
||||||
result = prime * result + ((values == null) ? 0 : values.hashCode());
|
result = prime * result + ((values == null) ? 0 : values.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -52,6 +65,11 @@ public class Template {
|
|||||||
return false;
|
return false;
|
||||||
} else if (!name.equals(other.name))
|
} else if (!name.equals(other.name))
|
||||||
return false;
|
return false;
|
||||||
|
if (points == null) {
|
||||||
|
if (other.points != null)
|
||||||
|
return false;
|
||||||
|
} else if (!points.equals(other.points))
|
||||||
|
return false;
|
||||||
if (values == null) {
|
if (values == null) {
|
||||||
if (other.values != null)
|
if (other.values != null)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+10
@@ -233,6 +233,16 @@ public class InstantiationManager {
|
|||||||
component.setControlPoint(controlPoint, j);
|
component.setControlPoint(controlPoint, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Make the component into shape from the template
|
||||||
|
if (template != null && template.getPoints() != null
|
||||||
|
&& template.getPoints().size() >= component
|
||||||
|
.getControlPointCount()) {
|
||||||
|
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||||
|
Point p = new Point(component.getControlPoint(0));
|
||||||
|
p.translate(template.getPoints().get(i).x, template.getPoints().get(i).y);
|
||||||
|
component.setControlPoint(p, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fillWithDefaultProperties(component, template);
|
fillWithDefaultProperties(component, template);
|
||||||
|
|
||||||
|
|||||||
+14
-2
@@ -1741,7 +1741,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
templateName));
|
templateName));
|
||||||
if (selectedComponents.size() != 1) {
|
if (selectedComponents.size() != 1) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Can only save a single component at a time.");
|
"Can only save a single component as a template at once.");
|
||||||
}
|
}
|
||||||
IDIYComponent<?> component = selectedComponents.iterator().next();
|
IDIYComponent<?> component = selectedComponents.iterator().next();
|
||||||
ComponentType type = ComponentProcessor.getInstance()
|
ComponentType type = ComponentProcessor.getInstance()
|
||||||
@@ -1772,7 +1772,19 @@ public class Presenter implements IPlugInPort {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Template template = new Template(templateName, values);
|
List<Point> points = new ArrayList<Point>();
|
||||||
|
|
||||||
|
for (int i = 0; i< component.getControlPointCount(); i++) {
|
||||||
|
Point p = new Point(component.getControlPoint(i));
|
||||||
|
points.add(p);
|
||||||
|
}
|
||||||
|
int x = points.iterator().next().x;
|
||||||
|
int y = points.iterator().next().y;
|
||||||
|
for (Point point : points) {
|
||||||
|
point.translate(-x, -y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Template template = new Template(templateName, values, points);
|
||||||
boolean exists = false;
|
boolean exists = false;
|
||||||
for (Template t : templates) {
|
for (Template t : templates) {
|
||||||
if (t.getName().equalsIgnoreCase(templateName)) {
|
if (t.getName().equalsIgnoreCase(templateName)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user