mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Some components can be placed in any layer using Send to Back/Bring to Front
This commit is contained in:
+7
-1
@@ -24,12 +24,13 @@ public class ComponentType {
|
||||
private Icon icon;
|
||||
private Class<? extends IDIYComponent<?>> instanceClass;
|
||||
private double zOrder;
|
||||
private boolean flexibleZOrder;
|
||||
private boolean stretchable;
|
||||
private BomPolicy bomPolicy;
|
||||
|
||||
public ComponentType(String name, String description, CreationMethod creationMethod,
|
||||
String category, String namePrefix, String author, Icon icon,
|
||||
Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
|
||||
Class<? extends IDIYComponent<?>> instanceClass, double zOrder, boolean flexibleZOrder,
|
||||
boolean stretchable, BomPolicy bomPolicy) {
|
||||
super();
|
||||
this.name = name;
|
||||
@@ -41,6 +42,7 @@ public class ComponentType {
|
||||
this.icon = icon;
|
||||
this.instanceClass = instanceClass;
|
||||
this.zOrder = zOrder;
|
||||
this.flexibleZOrder = flexibleZOrder;
|
||||
this.stretchable = stretchable;
|
||||
this.bomPolicy = bomPolicy;
|
||||
}
|
||||
@@ -81,6 +83,10 @@ public class ComponentType {
|
||||
return zOrder;
|
||||
}
|
||||
|
||||
public boolean isFlexibleZOrder() {
|
||||
return flexibleZOrder;
|
||||
}
|
||||
|
||||
public boolean isStretchable() {
|
||||
return stretchable;
|
||||
}
|
||||
|
||||
+7
@@ -53,6 +53,13 @@ public @interface ComponentDescriptor {
|
||||
*/
|
||||
double zOrder();
|
||||
|
||||
/**
|
||||
* @return true if the component may go beyond it's predefined layer. In
|
||||
* that case, <code>zOrder</code> is used as initial z order of the
|
||||
* component.
|
||||
*/
|
||||
boolean flexibleZOrder() default false;
|
||||
|
||||
/**
|
||||
* @return when false, moving one control point will cause all the others to
|
||||
* move together with it.
|
||||
|
||||
+48
-31
@@ -33,7 +33,8 @@ import com.rits.cloning.Cloner;
|
||||
*/
|
||||
public class ComponentProcessor {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ComponentProcessor.class);
|
||||
private static final Logger LOG = Logger
|
||||
.getLogger(ComponentProcessor.class);
|
||||
|
||||
private static ComponentProcessor instance;
|
||||
|
||||
@@ -58,7 +59,8 @@ public class ComponentProcessor {
|
||||
this.propertyValidatorCache = new HashMap<String, IPropertyValidator>();
|
||||
}
|
||||
|
||||
public ComponentType extractComponentTypeFrom(Class<? extends IDIYComponent<?>> clazz) {
|
||||
public ComponentType extractComponentTypeFrom(
|
||||
Class<? extends IDIYComponent<?>> clazz) {
|
||||
if (componentTypeMap.containsKey(clazz.getName())) {
|
||||
return componentTypeMap.get(clazz.getName());
|
||||
}
|
||||
@@ -70,10 +72,12 @@ public class ComponentProcessor {
|
||||
String author;
|
||||
Icon icon;
|
||||
double zOrder;
|
||||
boolean flexibleZOrder;
|
||||
boolean stretchable;
|
||||
BomPolicy bomPolicy;
|
||||
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
||||
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
|
||||
ComponentDescriptor annotation = clazz
|
||||
.getAnnotation(ComponentDescriptor.class);
|
||||
name = annotation.name();
|
||||
description = annotation.description();
|
||||
creationMethod = annotation.creationMethod();
|
||||
@@ -81,6 +85,7 @@ public class ComponentProcessor {
|
||||
namePrefix = annotation.instanceNamePrefix();
|
||||
author = annotation.author();
|
||||
zOrder = annotation.zOrder();
|
||||
flexibleZOrder = annotation.flexibleZOrder();
|
||||
stretchable = annotation.stretchable();
|
||||
bomPolicy = annotation.bomPolicy();
|
||||
} else {
|
||||
@@ -91,28 +96,30 @@ public class ComponentProcessor {
|
||||
namePrefix = "Unknown";
|
||||
author = "Unknown";
|
||||
zOrder = IDIYComponent.COMPONENT;
|
||||
flexibleZOrder = false;
|
||||
stretchable = true;
|
||||
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
|
||||
}
|
||||
icon = null;
|
||||
// Draw component icon.
|
||||
try {
|
||||
IDIYComponent<?> componentInstance = (IDIYComponent<?>) clazz.newInstance();
|
||||
Image image = new BufferedImage(Presenter.ICON_SIZE, Presenter.ICON_SIZE,
|
||||
IDIYComponent<?> componentInstance = (IDIYComponent<?>) clazz
|
||||
.newInstance();
|
||||
Image image = new BufferedImage(Presenter.ICON_SIZE,
|
||||
Presenter.ICON_SIZE,
|
||||
java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2d = (Graphics2D) image.getGraphics();
|
||||
g2d
|
||||
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
componentInstance.drawIcon(g2d, Presenter.ICON_SIZE, Presenter.ICON_SIZE);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
componentInstance.drawIcon(g2d, Presenter.ICON_SIZE,
|
||||
Presenter.ICON_SIZE);
|
||||
icon = new ImageIcon(image);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ComponentType componentType = new ComponentType(name, description, creationMethod,
|
||||
category, namePrefix, author, icon, clazz, zOrder, stretchable, bomPolicy);
|
||||
ComponentType componentType = new ComponentType(name, description,
|
||||
creationMethod, category, namePrefix, author, icon, clazz,
|
||||
zOrder, flexibleZOrder, stretchable, bomPolicy);
|
||||
componentTypeMap.put(clazz.getName(), componentType);
|
||||
return componentType;
|
||||
}
|
||||
@@ -133,7 +140,8 @@ public class ComponentProcessor {
|
||||
try {
|
||||
if (method.isAnnotationPresent(EditableProperty.class)
|
||||
&& !method.isAnnotationPresent(Deprecated.class)) {
|
||||
EditableProperty annotation = method.getAnnotation(EditableProperty.class);
|
||||
EditableProperty annotation = method
|
||||
.getAnnotation(EditableProperty.class);
|
||||
String name;
|
||||
if (annotation.name().equals("")) {
|
||||
name = method.getName().substring(3);
|
||||
@@ -142,16 +150,18 @@ public class ComponentProcessor {
|
||||
}
|
||||
IPropertyValidator validator = getPropertyValidator(annotation
|
||||
.validatorClass());
|
||||
Method setter = clazz.getMethod("set" + method.getName().substring(3),
|
||||
method.getReturnType());
|
||||
Method setter = clazz.getMethod("set"
|
||||
+ method.getName().substring(3), method
|
||||
.getReturnType());
|
||||
PropertyWrapper property = new PropertyWrapper(name,
|
||||
method.getReturnType(), method.getName(), setter.getName(),
|
||||
annotation.defaultable(), validator);
|
||||
method.getReturnType(), method.getName(),
|
||||
setter.getName(), annotation.defaultable(),
|
||||
validator);
|
||||
properties.add(property);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
LOG.debug("No matching setter found for \"" + method.getName()
|
||||
+ "\". Skipping...");
|
||||
LOG.debug("No matching setter found for \""
|
||||
+ method.getName() + "\". Skipping...");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,7 +191,8 @@ public class ComponentProcessor {
|
||||
}
|
||||
for (int i = 1; i < selectedComponents.size(); i++) {
|
||||
IDIYComponent<?> component = selectedComponents.get(i);
|
||||
List<PropertyWrapper> newProperties = extractProperties(component.getClass());
|
||||
List<PropertyWrapper> newProperties = extractProperties(component
|
||||
.getClass());
|
||||
for (PropertyWrapper property : newProperties) {
|
||||
property.readFrom(component);
|
||||
}
|
||||
@@ -190,11 +201,14 @@ public class ComponentProcessor {
|
||||
// their values match.
|
||||
for (PropertyWrapper oldProperty : properties) {
|
||||
if (newProperties.contains(oldProperty)) {
|
||||
PropertyWrapper newProperty = newProperties.get(newProperties
|
||||
.indexOf(oldProperty));
|
||||
if ((newProperty.getValue() != null && newProperty.getValue() == null)
|
||||
|| !newProperty.getValue().equals(oldProperty.getValue())) {
|
||||
// Values don't match, so the property is not unique valued.
|
||||
PropertyWrapper newProperty = newProperties
|
||||
.get(newProperties.indexOf(oldProperty));
|
||||
if ((newProperty.getValue() != null && newProperty
|
||||
.getValue() == null)
|
||||
|| !newProperty.getValue().equals(
|
||||
oldProperty.getValue())) {
|
||||
// Values don't match, so the property is not unique
|
||||
// valued.
|
||||
oldProperty.setUnique(false);
|
||||
}
|
||||
}
|
||||
@@ -208,11 +222,13 @@ public class ComponentProcessor {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Collections.sort(properties, ComparatorFactory.getInstance().getPropertyNameComparator());
|
||||
Collections.sort(properties, ComparatorFactory.getInstance()
|
||||
.getPropertyNameComparator());
|
||||
return properties;
|
||||
}
|
||||
|
||||
private IPropertyValidator getPropertyValidator(Class<? extends IPropertyValidator> clazz) {
|
||||
private IPropertyValidator getPropertyValidator(
|
||||
Class<? extends IPropertyValidator> clazz) {
|
||||
if (propertyValidatorCache.containsKey(clazz.getName())) {
|
||||
return propertyValidatorCache.get(clazz.getName());
|
||||
}
|
||||
@@ -220,7 +236,8 @@ public class ComponentProcessor {
|
||||
try {
|
||||
validator = clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not instantiate validator for " + clazz.getName(), e);
|
||||
LOG.error("Could not instantiate validator for " + clazz.getName(),
|
||||
e);
|
||||
return null;
|
||||
}
|
||||
propertyValidatorCache.put(clazz.getName(), validator);
|
||||
|
||||
+22
-24
@@ -56,8 +56,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
||||
|
||||
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 10,
|
||||
0);
|
||||
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3,
|
||||
11, 0);
|
||||
public static final String DEFAULTS_KEY_PREFIX = "default.";
|
||||
|
||||
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections
|
||||
@@ -77,7 +77,7 @@ public class Presenter implements IPlugInPort {
|
||||
private Set<IDIYComponent<?>> lockedComponents;
|
||||
|
||||
// Utilities
|
||||
//private Cloner cloner;
|
||||
// private Cloner cloner;
|
||||
private DrawingManager drawingManager;
|
||||
private ProjectFileManager projectFileManager;
|
||||
private InstantiationManager instantiationManager;
|
||||
@@ -107,7 +107,7 @@ public class Presenter implements IPlugInPort {
|
||||
selectedComponents = new ArrayList<IDIYComponent<?>>();
|
||||
lockedComponents = new HashSet<IDIYComponent<?>>();
|
||||
currentProject = new Project();
|
||||
//cloner = new Cloner();
|
||||
// cloner = new Cloner();
|
||||
drawingManager = new DrawingManager(messageDispatcher);
|
||||
projectFileManager = new ProjectFileManager(messageDispatcher);
|
||||
instantiationManager = new InstantiationManager();
|
||||
@@ -503,7 +503,8 @@ public class Presenter implements IPlugInPort {
|
||||
// Notify the listeners.
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(
|
||||
EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), "Add "
|
||||
EventType.PROJECT_MODIFIED, oldProject,
|
||||
currentProject.clone(), "Add "
|
||||
+ componentTypeSlot.getName());
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
@@ -1222,8 +1223,9 @@ public class Presenter implements IPlugInPort {
|
||||
.extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) componentBefore
|
||||
.getClass());
|
||||
if (componentBeforeType.getZOrder() < componentType
|
||||
.getZOrder())
|
||||
if (!componentType.isFlexibleZOrder()
|
||||
&& componentBeforeType.getZOrder() < componentType
|
||||
.getZOrder())
|
||||
break;
|
||||
Collections.swap(currentProject.getComponents(), index,
|
||||
index - 1);
|
||||
@@ -1232,8 +1234,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
||||
oldProject, currentProject.clone(),
|
||||
"Send to Back");
|
||||
oldProject, currentProject.clone(), "Send to Back");
|
||||
projectFileManager.notifyFileChange();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
@@ -1261,8 +1262,9 @@ public class Presenter implements IPlugInPort {
|
||||
.extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) componentAfter
|
||||
.getClass());
|
||||
if (componentAfterType.getZOrder() > componentType
|
||||
.getZOrder())
|
||||
if (!componentType.isFlexibleZOrder()
|
||||
&& componentAfterType.getZOrder() > componentType
|
||||
.getZOrder())
|
||||
break;
|
||||
Collections.swap(currentProject.getComponents(), index,
|
||||
index + 1);
|
||||
@@ -1271,8 +1273,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
||||
oldProject, currentProject.clone(),
|
||||
"Bring to Front");
|
||||
oldProject, currentProject.clone(), "Bring to Front");
|
||||
projectFileManager.notifyFileChange();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
@@ -1366,8 +1367,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
||||
oldProject, currentProject.clone(),
|
||||
"Renumber selection");
|
||||
oldProject, currentProject.clone(), "Renumber selection");
|
||||
projectFileManager.notifyFileChange();
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
@@ -1535,15 +1535,15 @@ public class Presenter implements IPlugInPort {
|
||||
*/
|
||||
private void addComponent(IDIYComponent<?> component,
|
||||
ComponentType componentType, boolean canCreatePads) {
|
||||
int index = 0;
|
||||
while (index < currentProject.getComponents().size()
|
||||
&& componentType.getZOrder() >= ComponentProcessor
|
||||
int index = currentProject.getComponents().size();
|
||||
while (index > 0
|
||||
&& componentType.getZOrder() < ComponentProcessor
|
||||
.getInstance()
|
||||
.extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) currentProject
|
||||
.getComponents().get(index).getClass())
|
||||
.getComponents().get(index - 1).getClass())
|
||||
.getZOrder()) {
|
||||
index++;
|
||||
index--;
|
||||
}
|
||||
if (index < currentProject.getComponents().size()) {
|
||||
currentProject.getComponents().add(index, component);
|
||||
@@ -1610,8 +1610,7 @@ public class Presenter implements IPlugInPort {
|
||||
// Notify the listeners.
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
||||
oldProject, currentProject.clone(),
|
||||
"Edit Selection");
|
||||
oldProject, currentProject.clone(), "Edit Selection");
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
@@ -1653,8 +1652,7 @@ public class Presenter implements IPlugInPort {
|
||||
// Notify the listeners.
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
||||
oldProject, currentProject.clone(),
|
||||
"Edit Project");
|
||||
oldProject, currentProject.clone(), "Edit Project");
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
drawingManager.fireZoomChanged();
|
||||
|
||||
Reference in New Issue
Block a user