Commit d27a789e authored by Nico Mack's avatar Nico Mack

Added ModalMarker

Minor API fixes
parent 82bff2a3
......@@ -32,6 +32,7 @@ CORONAS_NODE=coronas
COUNT_ATTRIBUTE=count
CURSOR_NODE=cursor
CURSORS_NODE=cursors
DEFAULT_NODE=default
DEFINING_SHAPE_NODE=definingShape
DELAY_NODE=delay
DESELECTED_ELEMENT=deselected
......
......@@ -156,12 +156,14 @@ public class CoronaBootstrapper {
public static Multimap<Integer, Corona> getCoronas(Element coronaRootNode, BootstrapContext context, BootstrapCallback callback) throws BuildException {
Multimap<Integer, Corona> coronas = ArrayListMultimap.create();
for (Element coronaNode : coronaRootNode.getChildren(Externalization.CORONA_NODE)) {
int handleId = BootstrappingUtils.getContentAsInteger(coronaNode, Externalization.HANDLE_NODE, BootstrappingUtils.MANDATORY, 0, context);
CoronaFactory<Corona> factory = new CoronaFactory<>(coronaNode, context, callback);
while (factory.hasNext()) {
Corona newInstance = factory.next();
coronas.put(handleId, newInstance);
if (coronaRootNode != null) {
for (Element coronaNode : coronaRootNode.getChildren(Externalization.CORONA_NODE)) {
int handleId = BootstrappingUtils.getContentAsInteger(coronaNode, Externalization.HANDLE_NODE, BootstrappingUtils.MANDATORY, 0, context);
CoronaFactory<Corona> factory = new CoronaFactory<>(coronaNode, context, callback);
while (factory.hasNext()) {
Corona newInstance = factory.next();
coronas.put(handleId, newInstance);
}
}
}
return coronas;
......
......@@ -87,6 +87,39 @@ public abstract class Marker implements Positionable {
}
}
// ---------------------------------------------------------------------------
protected boolean addCoronas(Multimap<Integer, Corona> coronasToAdd) {
boolean added = false;
synchronized (this.coronas) {
for (Entry<Integer, Corona> entry : coronasToAdd.entries()) {
if (!this.coronas.containsEntry(entry.getKey(), entry.getValue())) {
Point centre = this.getPosition(entry.getKey());
if (this.active)
entry.getValue().setHandleCentre(centre);
entry.getValue().onTable();
added |= this.coronas.put(entry.getKey(), entry.getValue());
}
}
}
return added;
}
// ---------------------------------------------------------------------------
protected boolean removeCoronas(Multimap<Integer, Corona> coronasToRemove) {
boolean removed = false;
synchronized (this.coronas) {
for (Entry<Integer, Corona> entry : coronasToRemove.entries()) {
if (this.coronas.containsEntry(entry.getKey(), entry.getValue())) {
entry.getValue().setActive(false);
removed |= this.coronas.remove(entry.getKey(), entry.getValue());
}
}
}
return removed;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......@@ -311,4 +344,5 @@ public abstract class Marker implements Positionable {
}
return comparison;
}
}
This diff is collapsed.
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. 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.marker.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.ModalMarker;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.corona.bundle.CoronaBundle;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import org.jdom2.Element;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 2.5.0
* @param <B>
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseModalMarkerBuilder<B extends BaseModalMarkerBuilder<B>> extends BaseTetherableMarkerBuilder<B> {
public Multimap<String, CoronaBundle> coronaBundles;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
protected BaseModalMarkerBuilder() {
super();
coronaBundles = TreeMultimap.create();
}
// ---------------------------------------------------------------------------
protected BaseModalMarkerBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
protected BaseModalMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
coronaBundles = TreeMultimap.create();
Element bundlesElement = rootElement.getChild(Externalization.BUNDLES_NODE);
if (bundlesElement != null) {
for (Element bundleElement : bundlesElement.getChildren(Externalization.BUNDLE_NODE)) {
CoronaBundle bundle = new CoronaBundle(bundleElement, context, callback);
coronaBundles.put(bundle.getName(), bundle);
}
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract ModalMarker build();
}
......@@ -62,12 +62,12 @@ public abstract class BaseTetherableMarkerBuilder<B extends BaseTetherableMarker
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
......@@ -96,10 +96,9 @@ public abstract class BaseTetherableMarkerBuilder<B extends BaseTetherableMarker
* @param callback
* @throws BuildException
*/
@Override
protected void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super.buildFromBootstrap(rootElement, context, callback);
// super.buildFromBootstrap(rootElement, context, callback);
Element tetherableNode = rootElement.getChild(Externalization.TETHERABLE_NODE);
if (null != tetherableNode) {
......
......@@ -81,7 +81,7 @@ public abstract class MarkerBuilder<B extends MarkerBuilder<B>> {
// ***************************************************************************
// ---------------------------------------------------------------------------
protected void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
positions = new HashMap<>();
coronas = TreeMultimap.create();
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, 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.marker.builder;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.ModalMarker;
import org.jdom2.Element;
/**
* {@link ModalMarkerBuilder} class used to construct an info widget by providing methods to set all
* parameters and permutations thereof.
*
* @author Eric Tobias [eric.tobias@list.lu]
* @since 1.0
* @version 2.3.0
*/
@NonNullByDefault
public final class ModalMarkerBuilder extends BaseModalMarkerBuilder<ModalMarkerBuilder> {
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
public ModalMarkerBuilder() {}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
public ModalMarkerBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
public ModalMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
@Override
public ModalMarker build() {
return new ModalMarker(this);
}
}
\ No newline at end of file
......@@ -67,6 +67,7 @@ public class Externalization extends NLS {
public static String COUNT_ATTRIBUTE;
public static String CURSOR_NODE;
public static String CURSORS_NODE;
public static String DEFAULT_NODE;
public static String DEFINING_SHAPE_NODE;
public static String DELAY_NODE;
public static String DESELECTED_ELEMENT;
......
......@@ -98,6 +98,24 @@ public class PolarCoordinateHelper {
return new Point((float) translatedX, (float) translatedY, origin.getAngle(), origin.getState().getClass());
}
// ---------------------------------------------------------------------------
/**
* @param origin
* @param angle
* @return
*/
public static final Point rotate(Point origin, double angle) {
double x = origin.x;
double y = origin.y;
float distance = (float) Math.sqrt((x * x) + (y * y));
double rotatedX = distance * Math.cos(angle);
double rotatedY = distance * Math.sin(angle);
return new Point((float) rotatedX, (float) rotatedY, 0, origin.getState().getClass());
}
// ---------------------------------------------------------------------------
/**
* converts the specified points to a polar representation. The method computes the euclidean
......
......@@ -193,7 +193,7 @@ public class Body {
// ---------------------------------------------------------------------------
public void setImmobile(boolean immobilizeIt) {
// this.immobile = immobilizeIt;
this.immobile = immobilizeIt;
}
// ---------------------------------------------------------------------------
......
......@@ -31,6 +31,7 @@ import com.google.common.collect.Multimap;
import org.jdom2.Element;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
......@@ -47,7 +48,8 @@ import java.util.List;
public class CoronaBundle implements Comparable<CoronaBundle> {
private String name;
private boolean exclusive;
private boolean isExclusive;
private boolean isDefault;
private Multimap<Integer, Corona> coronas;
// ---------------------------------------------------------------------------
......@@ -62,7 +64,8 @@ public class CoronaBundle implements Comparable<CoronaBundle> {
public CoronaBundle() {
this.name = Externalization.EMPTY_STRING;
this.exclusive = false;
this.isExclusive = false;
this.isDefault = false;
this.coronas = ArrayListMultimap.create();
}
......@@ -106,7 +109,8 @@ public class CoronaBundle implements Comparable<CoronaBundle> {
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
name = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.NAME_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
exclusive = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.EXCLUSIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
isExclusive = BootstrappingUtils.getAttributeAsBoolean(rootElement, Externalization.EXCLUSIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE);
isDefault = BootstrappingUtils.getAttributeAsBoolean(rootElement, Externalization.DEFAULT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE);
coronas = CoronaBootstrapper.getCoronas(rootElement.getChild(Externalization.CORONAS_NODE), context, callback);
}
......@@ -148,7 +152,19 @@ public class CoronaBundle implements Comparable<CoronaBundle> {
// ---------------------------------------------------------------------------
public boolean isExclusive() {
return exclusive;
return isExclusive;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for exclusive.
*
* @return The value of exclusive.
*/
// ---------------------------------------------------------------------------
public boolean isDefault() {
return isDefault;
}
// ---------------------------------------------------------------------------
......@@ -163,6 +179,23 @@ public class CoronaBundle implements Comparable<CoronaBundle> {
return coronas;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for coronas.
*
* @return The value of coronas.
*/
// ---------------------------------------------------------------------------
public Collection<Corona> getCoronas(int handleId) {
if (this.coronas.containsKey(handleId)) {
return this.coronas.get(handleId);
}
return new ArrayList<>();
}
// ---------------------------------------------------------------------------
/**
* Method for retrieving all bundled coronas of a particular class.
......
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