Commit e90a6339 authored by Eric Tobias's avatar Eric Tobias

2.1.2 - Added ShapeCorona and related builders.

parent 8c3c1a4d
# Properties for the Logger
logger.event.output.location = log.txt
logger.event.output.enabled = false
logger.level = SEVERE
logger.level = ALL
logger.event.configuration = logger.xml
# Widget IDs to be mapped
......
......@@ -17,9 +17,12 @@
package lu.list.itis.dkd.tui.space;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.TangibleObjectManager;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import java.util.ArrayList;
import java.util.List;
/**
* @author Eric Tobias [eric.tobias@list.lu]
......@@ -41,7 +44,7 @@ public class SpatialMatrix {
* @param object
* The object to add.
*/
public void add(TangibleObject object) {
public synchronized void add(TangibleObject object) {
horizontal.add(findHorizontalIndexFor(object), object);
vertical.add(findVerticalIndexFor(object), object);
}
......@@ -53,7 +56,7 @@ public class SpatialMatrix {
* @param object
* The object to remove.
*/
public void remove(TangibleObject object) {
public synchronized void remove(TangibleObject object) {
horizontal.remove(object);
vertical.remove(object);
}
......@@ -81,7 +84,7 @@ public class SpatialMatrix {
* @return The index to add the element or the size of the list if the element should be added
* at the end.
*/
private int findHorizontalIndexFor(TangibleObject object) {
private synchronized int findHorizontalIndexFor(TangibleObject object) {
for (int index = 0; index < horizontal.size(); index++) {
if (Double.compare(object.getPosition().toScreenCoordinates().getX(), horizontal.get(index).getPosition().toScreenCoordinates().getX()) <= 0) {
return index;
......@@ -90,6 +93,28 @@ public class SpatialMatrix {
return horizontal.size();
}
/**
* Method used to find the index of the first horizontal object whose x-axis coordinate is
* bigger than this object's. Returns the size of the horizontal list if no such element could
* be found.
*
* @param objectId
* The ID of the object to look up the insertion index for.
* @return The index to add the element or the size of the list if the element should be added
* at the end.
*/
private synchronized int findHorizontalIndexFor(int objectId) {
BaseWidget widget = TangibleObjectManager.getWidget(objectId);
for (int index = 0; index < horizontal.size(); index++) {
if (Double.compare(widget.getPosition(objectId).toScreenCoordinates().getX(), horizontal.get(index).getPosition().toScreenCoordinates().getX()) <= 0) {
return index;
}
}
return horizontal.size();
}
/**
* Method used to find the index of the first horizontal object whose x-axis coordinate is
* bigger than this object's. Returns the size of the horizontal list if no such element could
......@@ -100,7 +125,7 @@ public class SpatialMatrix {
* @return The index to add the element or the size of the list if the element should be added
* at the end.
*/
private int findVerticalIndexFor(TangibleObject object) {
private synchronized int findVerticalIndexFor(TangibleObject object) {
for (int index = 0; index < vertical.size(); index++) {
if (Double.compare(object.getPosition().toScreenCoordinates().getY(), vertical.get(index).getPosition().toScreenCoordinates().getY()) <= 0) {
return index;
......@@ -109,14 +134,66 @@ public class SpatialMatrix {
return vertical.size();
}
public void printLists() {
/**
* Method used to find the index of the first horizontal object whose x-axis coordinate is
* bigger than this object's. Returns the size of the horizontal list if no such element could
* be found.
*
* @param objectId
* The ID of the object to look up the insertion index for.
* @return The index to add the element or the size of the list if the element should be added
* at the end.
*/
private synchronized int findVerticalIndexFor(int objectId) {
BaseWidget widget = TangibleObjectManager.getWidget(objectId);
for (int index = 0; index < vertical.size(); index++) {
if (Double.compare(widget.getPosition(objectId).toScreenCoordinates().getY(), vertical.get(index).getPosition().toScreenCoordinates().getY()) <= 0) {
return index;
}
}
return vertical.size();
}
/**
* Method used to retrieve all {@link TangibleObject} instances to the left of the parameterized
* object (by ID). The method will return a new list build from the sublist of the horizontal
* space.<br />
* To determine whether something is "left", the method will make a sub-list of all elements
* with a lower index in the list than the parameterized object.
*
* @param objectId
* The object for which to retrieve all objects to the left of.
* @return A {@link List} of {@link TangibleObject} instances which are considered to be to the
* left of the given object.
*/
public synchronized List<TangibleObject> leftOf(int objectId) {
int index = findHorizontalIndexFor(objectId);
return new ArrayList<>(horizontal.subList(index, horizontal.size()));
}
public synchronized List<TangibleObject> rightOf(int objectId) {
int index = findHorizontalIndexFor(objectId);
return new ArrayList<>(horizontal.subList(0, index));
}
public synchronized List<TangibleObject> above(int objectId) {
int index = findVerticalIndexFor(objectId);
return new ArrayList<>(vertical.subList(0, index));
}
public synchronized List<TangibleObject> below(int objectId) {
int index = findHorizontalIndexFor(objectId);
return new ArrayList<>(horizontal.subList(index, vertical.size()));
}
String printLists() {
StringBuilder verticalBuilder = new StringBuilder();
StringBuilder horizontalbuilder = new StringBuilder();
vertical.forEach(object -> verticalBuilder.append(object.getObjectId() + ", ")); //$NON-NLS-1$
horizontal.forEach(object -> horizontalbuilder.append(object.getObjectId() + ", ")); //$NON-NLS-1$
System.out.println("Vertical : " + verticalBuilder.toString()); //$NON-NLS-1$
System.out.println("Horizontal : " + horizontalbuilder.toString()); //$NON-NLS-1$
return "Vertical : " + verticalBuilder.toString() + "\n" + "Horizontal : " + horizontalbuilder.toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
\ No newline at end of file
......@@ -107,6 +107,6 @@ public class SpatialPositioningManager implements SpatialEventListener {
logger.log(Level.SEVERE, "Spatial event type \"" + event.getType() + "\" not recognized!"); //$NON-NLS-1$ //$NON-NLS-2$
break;
}
spatialMatrix.printLists();
System.out.println(spatialMatrix.printLists());
}
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2015. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseShapeCoronaBuilder;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.1
* @version 2.1.2
*/
public class ShapeCorona extends Corona {
private Color colour = Color.GRAY;
private int borderWidth = 20;
/**
* Constructor building all fields and calling the implicit super constructor using a
* {@link BaseShapeCoronaBuilder} instance holding all values.
*
* @param builder
* The {@link BaseShapeCoronaBuilder} instance holding all values.
*/
public ShapeCorona(BaseShapeCoronaBuilder<?> builder) {
super(builder);
}
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
if (!active) {
return;
}
centre.toScreenCoordinates();
if (initialTranslation != null) {
initialTranslation.toScreenCoordinates();
}
Point drawAt = centre.add(initialTranslation);
AffineTransform transformation = new AffineTransform();
transformation.translate(drawAt.getX(), drawAt.getY());
if (rotateWithHandle) {
transformation.rotate(drawAt.getAngle());
}
Stroke oldStroke = canvas.getStroke();
canvas.setStroke(new BasicStroke(borderWidth));
canvas.draw(shape);
canvas.setStroke(oldStroke);
canvas.setPaint(colour);
canvas.fill(transformation.createTransformedShape(shape));
}
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2015. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.corona.builder;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.Corona;
import lu.list.itis.dkd.tui.widget.corona.ShapeCorona;
import java.awt.Color;
/**
* {@link CoronaBuilder} extension building {@link ShapeCorona} coronas.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.1
* @version 2.1.2
* @param <B>
* The concrete builder.
*/
public abstract class BaseShapeCoronaBuilder<B extends BaseShapeCoronaBuilder<B>> extends CoronaBuilder<B> {
public Color colour = Color.GRAY;
public int borderWidth = 20;
/**
* Constructor setting the centre of the corona.
*
* @param centre
* The centre of the corona, usually the centre of the handle.
*/
protected BaseShapeCoronaBuilder(Point centre) {
super(centre);
}
/**
* Method for setting the colour of the shape drawn for this {@link Corona}.
*
* @param color
* The colour the shape should be filled with.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withColor(Color color) {
this.colour = color;
return (B) this;
}
/**
* Method for setting the width of the border to draw around the shape.
*
* @param width
* The width of the line to draw the border with.
* @return An instance of this builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B withBorderWidth(int width) {
this.borderWidth = width;
return (B) this;
}
/** {@inheritDoc} */
@Override
public abstract ShapeCorona build();
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2015. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.corona.builder;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.ShapeCorona;
/**
* {@link ShapeCoronaBuilder} class used to construct a {@link ShapeCorona} corona by providing
* methods to set all parameters and permutations thereof.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.1
* @version 2.1.2
*/
public class ShapeCoronaBuilder extends BaseShapeCoronaBuilder<ShapeCoronaBuilder> {
/**
* Constructor setting the centre of the corona.
*
* @param centre
* The centre of the corona, usually the centre of the handle.
*/
protected ShapeCoronaBuilder(Point centre) {
super(centre);
}
/** {@inheritDoc} */
@Override
public ShapeCorona build() {
return new ShapeCorona(this);
}
}
\ No newline at end of file
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