Merge branch 'master' into resize-tooltip

This commit is contained in:
Bane Stojkovic
2025-12-31 15:04:30 +01:00
3 changed files with 56 additions and 23 deletions
@@ -30,8 +30,6 @@ import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import org.diylc.core.IDIYComponent;
@@ -55,7 +53,6 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
private static final long serialVersionUID = 1L;
protected String name = "";
protected UUID id;
public static Color SELECTION_COLOR = Color.red;
public static Color LABEL_COLOR = Color.black;
@@ -69,14 +66,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public static Color FR4_LIGHT_COLOR = Color.decode("#BABE71");
public static Color PHENOLIC_COLOR = Color.decode("#F8EBB3");
public static Color PHENOLIC_DARK_COLOR = Color.decode("#CD8500");
public UUID getId() {
if (id == null) {
id = UUID.randomUUID();
}
return id;
}
@EditableProperty(defaultable = false)
@Override
public String getName() {
@@ -123,7 +113,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
/**
* Returns the closest odd number, i.e. x when x is odd, or x + 1 when x is even.
*
* @param s
* @param x
* @return
*/
protected int getClosestOdd(Size s) {
@@ -227,14 +217,53 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
@Override
public boolean equalsTo(IDIYComponent<?> other) {
return Objects.equals(getId(), other.getId());
if (other == null)
return false;
if (!other.getClass().equals(this.getClass()))
return false;
Class<?> clazz = this.getClass();
while (AbstractComponent.class.isAssignableFrom(clazz)) {
Field[] fields = clazz.getDeclaredFields();
clazz = clazz.getSuperclass();
// fields = this.getClass().getDeclaredFields();
// Copy over all non-static, non-final and non-transient fields that are declared
// in
// AbstractComponent or one of it's child classes
for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers()) &&
!Modifier.isTransient(field.getModifiers())) {
field.setAccessible(true);
try {
Object value = field.get(this);
Object otherValue = field.get(other);
if (!compareObjects(value, otherValue))
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
return true;
}
@Override
public int hashCode() {
return getId().hashCode();
private boolean compareObjects(Object o1, Object o2) {
if (o1 == null && o2 == null)
return true;
if (o1 == null || o2 == null)
return false;
if (o1.getClass().isArray()) {
if (o1.getClass().getComponentType() == byte.class)
return Arrays.equals((byte[]) o1, (byte[]) o2);
if (o1.getClass().getComponentType() == double.class)
return Arrays.equals((double[]) o1, (double[]) o2);
if (o1.getClass().getComponentType() == int.class)
return Arrays.equals((int[]) o1, (int[]) o2);
return Arrays.equals((Object[]) o1, (Object[]) o2);
}
return o1.equals(o2);
}
@Override
public String getControlPointNodeName(int index) {
return Integer.toString(index + 1);
@@ -25,7 +25,6 @@ import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.UUID;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@@ -56,8 +55,6 @@ public interface IDIYComponent<T> extends Serializable, Cloneable {
public static final int WIRING = 5;
public static final int TEXT = 6;
UUID getId();
/**
* @return component instance name.
*/
@@ -24,7 +24,13 @@ package org.diylc.presenter;
import java.awt.geom.Point2D;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
@@ -329,14 +335,15 @@ public class InstantiationManager {
* account.
*
* @param componentType
* @param components
* @param currentProject
* @param additionalComponents
* @return
*/
public String createUniqueName(ComponentType componentType, List<IDIYComponent<?>> components) {
boolean exists = true;
Set<String> takenNames = components.stream()
.map(IDIYComponent::getName)
.map(x -> x.getName())
.filter(Objects::nonNull)
.collect(Collectors.toSet());
int i = 0;