mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Fixed an issue that would cause capacitors to fail when creating, editing, moving or deleting
This commit is contained in:
@@ -160,9 +160,9 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public IDIYComponent<T> clone() throws CloneNotSupportedException {
|
||||
try {
|
||||
// Instantiate object of the same type
|
||||
AbstractComponent<T> newInstance = (AbstractComponent<T>) this.getClass().getConstructors()[0].newInstance();
|
||||
// Instantiate object of the same type
|
||||
Class<?> clazz = this.getClass();
|
||||
AbstractComponent<T> newInstance = (AbstractComponent<T>) clazz.newInstance();
|
||||
while (AbstractComponent.class.isAssignableFrom(clazz)) {
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
clazz = clazz.getSuperclass();
|
||||
@@ -180,8 +180,9 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
&& value.getClass().getComponentType().isAssignableFrom(Point2D.class)) {
|
||||
Object newArray = Array.newInstance(value.getClass().getComponentType(), Array.getLength(value));
|
||||
for (int i = 0; i < Array.getLength(value); i++) {
|
||||
Point2D p = (Point2D) Array.get(value, i);
|
||||
Array.set(newArray, i, new Point2D.Double(p.getX(), p.getY()));
|
||||
Point2D p = (Point2D) Array.get(value, i);
|
||||
if (p != null)
|
||||
Array.set(newArray, i, new Point2D.Double(p.getX(), p.getY()));
|
||||
}
|
||||
value = newArray;
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class Defaults {
|
||||
private Defaults() {}
|
||||
|
||||
private static final Map<Class<?>, Object> DEFAULTS;
|
||||
|
||||
static {
|
||||
// Only add to this map via put(Map, Class<T>, T)
|
||||
Map<Class<?>, Object> map = new HashMap<Class<?>, Object>();
|
||||
put(map, boolean.class, false);
|
||||
put(map, Boolean.class, false);
|
||||
put(map, char.class, '\0');
|
||||
put(map, byte.class, (byte) 0);
|
||||
put(map, Byte.class, (byte) 0);
|
||||
put(map, short.class, (short) 0);
|
||||
put(map, Short.class, (short) 0);
|
||||
put(map, int.class, 0);
|
||||
put(map, Integer.class, 0);
|
||||
put(map, long.class, 0L);
|
||||
put(map, Long.class, 0L);
|
||||
put(map, float.class, 0f);
|
||||
put(map, Float.class, 0f);
|
||||
put(map, double.class, 0d);
|
||||
put(map, Double.class, 0d);
|
||||
DEFAULTS = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
private static <T> void put(Map<Class<?>, Object> map, Class<T> type, T value) {
|
||||
map.put(type, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value of {@code type} as defined by JLS --- {@code 0} for numbers,
|
||||
* {@code false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types
|
||||
* and {@code void}, {@code null} is returned.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T defaultValue(Class<T> type) throws Exception {
|
||||
// Primitives.wrap(type).cast(...) would avoid the warning, but we can't use that from here
|
||||
// the put method enforces this key-value relationship
|
||||
T t = (T) DEFAULTS.get(type);
|
||||
if (t == null) {
|
||||
return (T) type.getConstructors()[0].newInstance();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -4154,6 +4154,10 @@
|
||||
<releaseDate>2022-11-11 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Fixed an issue that would cause capacitors to fail when creating, editing, moving or deleting</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added standard models in the drop down menu of the component toolbar</description>
|
||||
|
||||
Reference in New Issue
Block a user