Commit a4d572b4 authored by Nico Mack's avatar Nico Mack

Added Scriptable interface.

Corona now implements Scriptable interface
parent 57cb8da6
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.scripting;
import java.lang.reflect.Field;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public interface Scriptable {
Field getProperty(String property);
void setProperty(Field property, Object value);
}
......@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.scripting.Scriptable;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.PolarCoordinateHelper;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
......@@ -40,6 +41,7 @@ import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.NoninvertibleTransformException;
import java.lang.reflect.Field;
/**
* The top class in a hierarchy of backgrounds that a tangible widget's handle can show.
......@@ -55,7 +57,7 @@ import java.awt.geom.NoninvertibleTransformException;
// ***************************************************************************
@NonNullByDefault
public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable {
public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable, Scriptable {
/** Field holding the base of the corona's centre. */
protected Point centre;
/** Field holding the initial translation respective to the corona's centre. */
......@@ -693,6 +695,31 @@ public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable
// ---------------------------------------------------------------------------
@Override
public Field getProperty(String property) {
Field field = null;
try {
field = this.getClass().getDeclaredField(property);
} catch (NoSuchFieldException | SecurityException e) {
LOGGER.error("No such property {}!", property, e); //$NON-NLS-1$
}
return field;
}
// ---------------------------------------------------------------------------
@Override
public void setProperty(Field property, Object value) {
try {
property.set(this, value);
} catch (IllegalArgumentException | IllegalAccessException e) {
LOGGER.error("Failed to set property {} to value {}!", property.getName(), value, e); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
@Override
public abstract Corona clone();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment