Commit 1e0cd7f6 authored by Nico Mack's avatar Nico Mack

Changes required by move of CPS related Externalization entries into

dedicated CpsNamespace (TULIP-CPS) package
parent 9bd42244
ABOVE_ELEMENT=above
ACTIVATE_WITH_HANDLE_NODE=activateWithHandle
ALPHA_NODE=alpha
ANIMATED_PROPERTIES_ELEMENT=animatedProperties
......@@ -9,14 +8,12 @@ ASSIGNABLE_NODE=assignable
BACKGROUND_COLOUR_NODE=backgroundColour
BASE_VALUE_NODE=baseValue
BEGIN_NODE=begin
BELOW_ELEMENT=below
BEZEL_COLOUR_ELEMENT=bezelColour
BLOBS_NODE=blobs
BORDER_THICKNESS_NODE=borderThickness
BORDER_WIDTH_NODE=borderWidth
BOUNDS_NODE=bounds
BUILDER_CLASS_POSTFIX=Builder
CAPPED_DISPLAY_NODE=cappedDisplay
CENTER_ON_ZOOM_NODE=centerOnZoom
CENTRE_NODE=centre
CENTRED_NODE=centred
......@@ -84,17 +81,12 @@ LINE_WIDTH_NODE=lineWidth
LOCATION_NODE=location
LOOPING_NODE=looping
LOWER_BOUND_NODE=lowerBound
LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable
LOWER_STOP_ANGLE_NODE=lowerStopAngle
MAGNIFICATION_NODE=magnification
MAGNIFIER_SHAPE_NODE=magnifierShape
MARKER_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.marker.builder
MARKER_NODE=marker
MARKERS_NODE=markers
MAXIMUM_VALUE_NODE=maximumValue
MEDIA_NODE=media
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
MULTIPLE_INSTANCES_NODE=multipleInstances
NAME_ATTRIBUTE=name
NAME_NODE=name
......@@ -119,8 +111,6 @@ RADIUS_NODE=radius
RAMPING_TIME_NODE=rampingTime
RECEIVER_NODE=receiver
RECEIVERS_NODE=receivers
REFERENCE_NODE=reference
RELATIVE_NODE=relative
REPEAT_ATTRIBUTE=repeat
REVERSING_NODE=reversing
RGB_COLOUR_NODE=rgb
......@@ -148,7 +138,6 @@ STAGESET_NODE=stageSet
START_ANGLE_NODE=startAngle
START_NODE=start
STATE_NODE=state
STEP_SIZE_NODE=stepSize
STOP_NODE=stop
STROKE_COLOUR_ELEMENT=strokeColour
STROKE_WIDTH_NODE=strokeWidth
......@@ -175,10 +164,6 @@ TRIGGERS_NODE=triggers
TYPE_NODE=type
UNIT_NODE=unit
UPPER_BOUND_NODE=upperBound
UPPER_BOUND_VARIABLE_NODE=upperBoundVariable
UPPER_STOP_ANGLE_NODE=upperStopAngle
VARIABLE_NODE=variable
VARIABLES_NODE=variables
VOLUME_NODE=volume
WIDGET_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.widget.builder
WIDTH_NODE=width
......
......@@ -405,7 +405,7 @@ public abstract class TangibleObjectManager {
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public <T> List<T> getWidgets(Class<T> clazz) {
public static synchronized <T> List<T> getWidgets(Class<T> clazz) {
List<T> results = new ArrayList<>();
for (BaseWidget widget : objectMap.values()) {
......
......@@ -32,6 +32,8 @@ import org.jdom2.Element;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/**
* @author Eric Tobias [eric.tobias@list.lu]
......@@ -40,47 +42,7 @@ import java.lang.reflect.InvocationTargetException;
*/
public class CoronaBootstrapper {
/**
* Method used to determine the appropriate builder for a given corona and then issue a build
* call.
*
* @param coronaNode
* The node from a larger document that contains, as children, all the necessary
* information to resolve the correct builder and build the final, concrete, corona.
* @return The final concrete corona as defined by the children of the element node.
* @throws ClassNotFoundException
* Thrown when the class of the builder for the corona could not be found.
* @throws SecurityException
* Thrown when the constructor cannot be retrieved due to some security constraints.
* @throws NoSuchMethodException
* Thrown when no constructor with the given parameter type is available.
* @throws InvocationTargetException
* Thrown if the invocation of any constructor through reflection throws an exception.
* @throws IllegalArgumentException
* Thrown when the provided argument is not eligible for the builder's constructor.
* @throws IllegalAccessException
* Thrown if this Constructor object is enforcing Java language access control and the
* underlying constructor is inaccessible.
* @throws InstantiationException
* Thrown if the class that declares the underlying constructor represents an abstract
* class.
* @throws BuildException
* Thrown if building the corona did not succeed due to an internal error such as a
* violation of precondition(s) or unavailable but required resources.
*/
// private static Corona getCorona(Element coronaNode) throws ClassNotFoundException,
// InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException,
// IllegalArgumentException, InvocationTargetException, BuildException {
// Element type = coronaNode.getChild(Externalization.TYPE_NODE);
// Class<?> builder = Class.forName(Externalization.CORONA_BUILDER_NAMESPACE +
// Externalization.NAMESPACE_SEPARATOR + type.getValue() +
// Externalization.BUILDER_CLASS_POSTFIX);
// @SuppressWarnings("unchecked")
// Constructor<CoronaBuilder<?>> constructor = (Constructor<CoronaBuilder<?>>)
// builder.getConstructor(new Class[] {Element.class});
// return constructor.newInstance(new Object[] {coronaNode}).build();
// }
// ---------------------------------------------------------------------------
/**
* Method used to determine the appropriate builder for a given object and then issue a build
* call.
......@@ -111,6 +73,8 @@ public class CoronaBootstrapper {
* class.
* @throws BuildException
*/
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public static Corona buildCoronaFromElement(Element coronaNode, BootstrapContext bootstrapContext, BootstrapCallback callback) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, BuildException {
......@@ -130,6 +94,7 @@ public class CoronaBootstrapper {
return instance;
}
// ---------------------------------------------------------------------------
/**
* Method used for bootstrapping all coronas found as child nodes of a root node. The method
* will look for child nodes names <code>corona</code>.
......@@ -141,8 +106,9 @@ public class CoronaBootstrapper {
* @throws BuildException
* Thrown when a corona was not associated to any handle.
*/
// ---------------------------------------------------------------------------
public static Multimap<Integer, Corona> getCoronas(Element coronaRootNode) throws BuildException {
// Multimap<Integer, Corona> coronas = TreeMultimap.create();
Multimap<Integer, Corona> coronas = ArrayListMultimap.create();
for (Element coronaNode : coronaRootNode.getChildren(Externalization.CORONA_NODE)) {
......@@ -159,9 +125,11 @@ public class CoronaBootstrapper {
return coronas;
}
// ---------------------------------------------------------------------------
/**
* Method used for bootstrapping all coronas found as child nodes of a root node. The method
* will look for child nodes names <code>corona</code>.
* will look for child nodes names <code>corona</code>. The method returns a map, using the
* coronas' <code>handleId</code> property as the key and the corona itself as the value.
*
* @param coronaRootNode
* The root node that holds all <code>corona</code> child nodes.
......@@ -172,6 +140,8 @@ public class CoronaBootstrapper {
* @throws BuildException
* Thrown when a corona was not associated to any handle.
*/
// ---------------------------------------------------------------------------
public static Multimap<Integer, Corona> getCoronas(Element coronaRootNode, BootstrapContext context, BootstrapCallback callback) throws BuildException {
Multimap<Integer, Corona> coronas = ArrayListMultimap.create();
......@@ -187,5 +157,36 @@ public class CoronaBootstrapper {
return coronas;
}
// ---------------------------------------------------------------------------
/**
* Method used for bootstrapping all coronas found as child nodes of a root node. The method
* will look for child nodes names <code>corona</code>. The method returns a list of corona
* instances build from the definitions found under the coronaRootNode.
*
* @param coronaRootNode
* The root node that holds all <code>corona</code> child nodes.
* @param context
* @param callback
* @return A list containing all concrete {@link Corona} instances that could be build from the
* provided root node.
* @throws BuildException
* Thrown when a corona couldn't be build.
*/
// ---------------------------------------------------------------------------
public static List<Corona> getListOfCoronas(Element coronaRootNode, BootstrapContext context, BootstrapCallback callback) throws BuildException {
List<Corona> coronas = new ArrayList<>();
for (Element coronaNode : coronaRootNode.getChildren(Externalization.CORONA_NODE)) {
CoronaFactory<Corona> factory = new CoronaFactory<>(coronaNode, context, callback);
while (factory.hasNext()) {
Corona newInstance = factory.next();
coronas.add(newInstance);
}
}
return coronas;
}
}
\ No newline at end of file
......@@ -126,6 +126,13 @@ public abstract class Marker implements Comparable<Marker> {
}
}
// ---------------------------------------------------------------------------
public @Nullable Point getPosition(Integer handleId) {
return positions.get(handleId);
}
// ---------------------------------------------------------------------------
public HashMap<Integer, Point> getPositions() {
......
......@@ -3,7 +3,8 @@ package lu.list.itis.dkd.tui.utility;
import com.google.common.base.Preconditions;
import java.awt.Color;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;
/**
* Color generator using three out of phase sine waves to produce a rainbow effect. see
......@@ -72,14 +73,14 @@ public class ColorFactory {
*
* @return a vector containing the generated colors
*/
public static Vector<Color> makeColorGradient(int number, float redFreq, float greenFreq, float blueFreq,
public static List<Color> makeColorGradient(int number, float redFreq, float greenFreq, float blueFreq,
float redPhase, float greenPhase, float bluePhase, int center, int spread) {
Preconditions.checkArgument((center > 0) && (center < 255), "Center should be in the range 0 < center < 255"); //$NON-NLS-1$
Preconditions.checkArgument((spread > 0) && (spread < center), "Spread should be in the range 0 < spread < center"); //$NON-NLS-1$
Vector<Color> gradient = new Vector<>(number);
List<Color> gradient = new ArrayList<>(number);
for (int i = 0; i < number; ++i) {
int red = (int) (Math.sin(redFreq * i + redPhase) * spread + center);
......@@ -100,7 +101,7 @@ public class ColorFactory {
* specifies the number of colors to generate
* @return a vector containing the generated colors
*/
public static Vector<Color> makeRainbowColours(int number) {
public static List<Color> makeRainbowColours(int number) {
float frequency = (float) (Math.PI / number);
return makeColorGradient(number, frequency, frequency, frequency, 0f, 2f, 4f, 128, 127);
......
......@@ -33,7 +33,6 @@ import org.eclipse.osgi.util.NLS;
public class Externalization extends NLS {
private static final String BUNDLE_NAME = "externalization"; //$NON-NLS-1$
public static String ABOVE_ELEMENT;
public static String ACTIVATE_WITH_HANDLE_NODE;
public static String ALPHA_NODE;
public static String ANIMATED_PROPERTIES_ELEMENT;
......@@ -44,14 +43,12 @@ public class Externalization extends NLS {
public static String BACKGROUND_COLOUR_NODE;
public static String BASE_VALUE_NODE;
public static String BEGIN_NODE;
public static String BELOW_ELEMENT;
public static String BEZEL_COLOUR_ELEMENT;
public static String BLOBS_NODE;
public static String BORDER_THICKNESS_NODE;
public static String BORDER_WIDTH_NODE;
public static String BOUNDS_NODE;
public static String BUILDER_CLASS_POSTFIX;
public static String CAPPED_DISPLAY_NODE;
public static String CENTER_ON_ZOOM_NODE;
public static String CENTRE_NODE;
public static String CENTRED_NODE;
......@@ -119,17 +116,12 @@ public class Externalization extends NLS {
public static String LOCATION_NODE;
public static String LOOPING_NODE;
public static String LOWER_BOUND_NODE;
public static String LOWER_BOUND_VARIABLE_NODE;
public static String LOWER_STOP_ANGLE_NODE;
public static String MAGNIFICATION_NODE;
public static String MAGNIFIER_SHAPE_NODE;
public static String MARKER_BUILDER_NAMESPACE;
public static String MARKER_NODE;
public static String MARKERS_NODE;
public static String MAXIMUM_VALUE_NODE;
public static String MEDIA_NODE;
public static String MINIMUM_VALUE_NODE;
public static String MODIFY_VALUE_ON_ROTATION_NODE;
public static String MULTIPLE_INSTANCES_NODE;
public static String NAME_ATTRIBUTE;
public static String NAME_NODE;
......@@ -154,8 +146,6 @@ public class Externalization extends NLS {
public static String RAMPING_TIME_NODE;
public static String RECEIVER_NODE;
public static String RECEIVERS_NODE;
public static String REFERENCE_NODE;
public static String RELATIVE_NODE;
public static String REPEAT_ATTRIBUTE;
public static String REVERSING_NODE;
public static String RGB_COLOUR_NODE;
......@@ -183,7 +173,6 @@ public class Externalization extends NLS {
public static String START_ANGLE_NODE;
public static String START_NODE;
public static String STATE_NODE;
public static String STEP_SIZE_NODE;
public static String STOP_NODE;
public static String STROKE_COLOUR_ELEMENT;
public static String STROKE_WIDTH_NODE;
......@@ -210,10 +199,6 @@ public class Externalization extends NLS {
public static String TYPE_NODE;
public static String UNIT_NODE;
public static String UPPER_BOUND_NODE;
public static String UPPER_BOUND_VARIABLE_NODE;
public static String UPPER_STOP_ANGLE_NODE;
public static String VARIABLE_NODE;
public static String VARIABLES_NODE;
public static String VOLUME_NODE;
public static String WIDGET_BUILDER_NAMESPACE;
public static String WIDTH_NODE;
......
......@@ -45,6 +45,7 @@ public class TextStroke implements Stroke {
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final float FLATNESS = 1;
// ---------------------------------------------------------------------------
......@@ -105,7 +106,6 @@ public class TextStroke implements Stroke {
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Controls whether the text is to be flipped, i.e. rendered upside down.
*
......@@ -113,12 +113,13 @@ public class TextStroke implements Stroke {
* specify <code>true</code> to render text upside down, <code>false</code> if text is to
* be rendered normally
*/
// ---------------------------------------------------------------------------
public void setFlipped(boolean flipIt) {
this.flipped = flipIt;
}
// ---------------------------------------------------------------------------
/**
* renders the text using the font specified at construction time along the specified shape
*
......@@ -126,11 +127,12 @@ public class TextStroke implements Stroke {
* specifies the shape to render the text along
* @return the rendered text following the specified path
*/
// ---------------------------------------------------------------------------
@Override
public Shape createStrokedShape(Shape shape) {
FontRenderContext frc = new FontRenderContext(null, true, true);
LineMetrics metrics = font.getLineMetrics(this.text, frc);
LineMetrics metrics = font.getLineMetrics(text, frc);
GlyphVector glyphVector = font.createGlyphVector(frc, text);
GeneralPath result = new GeneralPath();
......@@ -152,8 +154,10 @@ public class TextStroke implements Stroke {
float lengthOfText = (float) glyphVector.getLogicalBounds().getWidth();
float factor = stretchToFit ? lengthOfPath / lengthOfText : 1.0f;
float advance = (glyphVector.getNumGlyphs() > 0) ? glyphVector.getGlyphMetrics(0).getAdvance() : 0;
float offset = centered ? (1.2f * (lengthOfPath - lengthOfText)) / 2 : 0.0f;
float offset = centered ? ((lengthOfPath - lengthOfText) / 2) : 0.0f;
// float offset = centered ? (1.2f * (lengthOfPath - lengthOfText)) / 2 : 0.0f;
// float offset = centered ? ((lengthOfPath - lengthOfText)) / 2: 0.0f;
float nextAdvance = 0;
......@@ -184,11 +188,11 @@ public class TextStroke implements Stroke {
float dy = thisY - lastY;
totX += Math.abs(dx);
totY += Math.abs(dy);
if (Math.sqrt(totX * totX + totY * totY) > offset) {
if (Math.sqrt(totX * totX + totY * totY) >= offset) {
float distance = (float) Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
float angle = (float) Math.atan2(dy, dx);
double angle = Math.atan2(dy, dx);
while (currentChar < length && distance >= next) {
Shape glyph = glyphVector.getGlyphOutline(currentChar);
Point2D p = glyphVector.getGlyphPosition(currentChar);
......@@ -199,7 +203,7 @@ public class TextStroke implements Stroke {
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
float advance = nextAdvance;
advance = nextAdvance;
nextAdvance = currentChar < length - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
t.setToTranslation(x, y);
t.rotate(angle);
......
......@@ -61,6 +61,7 @@ public class Vector2D {
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param scale
......@@ -72,6 +73,18 @@ public class Vector2D {
return new Vector2D(scale * (Math.random() - 0.5), scale * (Math.random() - 0.5));
}
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public Vector2D zero() {
this.x = 0;
this.y = 0;
return this;
}
// ---------------------------------------------------------------------------
/**
* @param operand
......
......@@ -220,6 +220,45 @@ public class ForceDirectedGraph implements GraphListener, Runnable {
this.updatePositions(graphBodies, timestep);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public boolean inEquilibrum() {
List<Body> graphBodies = this.getGraphBodies();
return (this.getTotalEnergy(graphBodies) < this.energyThreshold);
}
// ---------------------------------------------------------------------------
/**
* @param node
* @return
*/
// ---------------------------------------------------------------------------
public Body getBody(@NonNull Node node) {
Preconditions.checkArgument(node != null, "Node MUST not be null!"); //$NON-NLS-1$
assert node != null;
Body body = null;
if (!this.bodies.containsKey(node.getId())) {
double mass = node.getMass();
body = new Body(Vector2D.random(10), mass);
this.bodies.put(node.getId(), body);
} else {
body = this.bodies.get(node.getId());
}
return body;
}
// ---------------------------------------------------------------------------
/**
* @param edge
......@@ -227,7 +266,7 @@ public class ForceDirectedGraph implements GraphListener, Runnable {
*/
// ---------------------------------------------------------------------------
private Spring getSpring(@NonNull Edge edge) {
public Spring getSpring(@NonNull Edge edge) {
Preconditions.checkArgument(edge != null, "Edge MUST not be null!"); //$NON-NLS-1$
assert edge != null;
......@@ -265,44 +304,6 @@ public class ForceDirectedGraph implements GraphListener, Runnable {
return this.springs.get(edge.getId());
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @return
*/
// ---------------------------------------------------------------------------
public boolean inEquilibrum() {
List<Body> graphBodies = this.getGraphBodies();
return (this.getTotalEnergy(graphBodies) < this.energyThreshold);
}
// ---------------------------------------------------------------------------
/**
* @param node
* @return
*/
// ---------------------------------------------------------------------------
public Body getBody(@NonNull Node node) {
Preconditions.checkArgument(node != null, "Node MUST not be null!"); //$NON-NLS-1$
assert node != null;
Body body = null;
if (!this.bodies.containsKey(node.getId())) {
double mass = node.getMass();
body = new Body(Vector2D.random(10), mass);
this.bodies.put(node.getId(), body);
} else {
body = this.bodies.get(node.getId());
}
return body;
}
// ---------------------------------------------------------------------------
/**
* @param position
......
......@@ -316,7 +316,7 @@ public class BaseWidget implements Touchable {
public void paint(Graphics2D canvas) {
clippingRegion.reset();
for (Corona corona : coronas.values()) {
if (corona.isInvalidated()) {
if ((corona != null) && corona.isInvalidated()) {
corona.paint(canvas);
clippingRegion.add(new Area(corona.getClippingRegion().getBounds()));
corona.validate();
......@@ -475,7 +475,6 @@ public class BaseWidget implements Touchable {
return networkAdapter;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for definingShape.
......
......@@ -557,30 +557,6 @@ public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable
return Integer.compare(drawPriority, corona.getDrawPriority());
}
// ---------------------------------------------------------------------------
// @Override
// public boolean equals(@Nullable Object object) {
// if (object == null)
// return false;
//
// if (object == this)
// return true;
//
// if (object instanceof Corona) {
// Corona corona = (Corona) object;
// return drawPriority == corona.getDrawPriority();
// }
// return false;
// }
// ---------------------------------------------------------------------------
// @Override
// public int hashCode() {
// return Objects.hashCode(drawPriority);
// }
// ---------------------------------------------------------------------------
/**
* Method used to get a relative position to the corona's centre.
......@@ -593,24 +569,13 @@ public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable
// ---------------------------------------------------------------------------
public Point getPointRelativeToCentre(Point point) {
Point relativePoint = new Point(0, 0, 0, ScreenCoordinates.class);
AffineTransform transform = this.getTransform(null);
try {
transform.inverseTransform(point.toScreenCoordinates(), relativePoint);
transform.inverseTransform(point.toCoordinates(ScreenCoordinates.class), relativePoint);
} catch (NoninvertibleTransformException e) {
LOGGER.error("Failed to get point relative to centre", e); //$NON-NLS-1$
}
// Point relativePoint =
// point.clone().toScreenCoordinates().subtract(centre.toScreenCoordinates(), false);
//
// AffineTransform rotation = new AffineTransform();
// rotation.rotate(-centre.getAngle(), 0, 0);
// rotation.transform(new Point2D.Double(relativePoint.getX(), relativePoint.getY()),
// relativePoint);
return relativePoint;
}
......
......@@ -155,7 +155,6 @@ public class TouchManager {
return (corona.getShape().contains(touchPosition));
}
// ---------------------------------------------------------------------------
/**
* Assuming the specified touch event affected the corona, the touch method will perform a state
......
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