Commit 117815a9 authored by Nico Mack's avatar Nico Mack

Minor improvements and API changes

parent cbccc937
......@@ -9,12 +9,14 @@ import lu.list.itis.dkd.tui.widget.corona.Corona;
import com.google.common.collect.Multimap;
import com.google.common.collect.Ordering;
import com.google.common.collect.TreeMultimap;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
// ***************************************************************************
// * Class Definition and Members *
......@@ -50,6 +52,15 @@ public abstract class Marker implements Positionable {
// this.drawPriority = builder.drawPriority;
}
// ---------------------------------------------------------------------------
public Marker(Marker original) {
this.name = original.name;
this.coronas = original.cloneCoronas();
this.positions = original.clonePositions();
// this.drawPriority = builder.drawPriority;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
......@@ -115,11 +126,31 @@ public abstract class Marker implements Positionable {
}
// ---------------------------------------------------------------------------
/**
* returns a multimap containing copies of every single corona associated with this widget. The map
* uses the widgets' potential handle IDs a keys and the corresponding coronas as values.
*
* @return a map containing a copy of all coronas handled by this widget.
*/
// ---------------------------------------------------------------------------
public Multimap<Integer, Corona> cloneCoronas() {
Multimap<Integer, Corona> clonedCoronas = TreeMultimap.create();
for (Entry<Integer, Corona> entry : coronas.entries()) {
Corona cloned = entry.getValue().clone();
clonedCoronas.put(entry.getKey(), cloned);
}
return clonedCoronas;
}
// ---------------------------------------------------------------------------
/**
* @param handleId
* @param position
*/
// ---------------------------------------------------------------------------
public void setPosition(Integer handleId, Point position) {
if (positions.containsKey(handleId)) {
positions.put(handleId, position);
......@@ -153,6 +184,24 @@ public abstract class Marker implements Positionable {
return positions;
}
// ---------------------------------------------------------------------------
/**
* returns a hashmap containing copies of every single position associated with this widget. The map
* uses the widgets' potential handle IDs a keys and the corresponding {@link Point} as value.
*
* @return a map containing a copy of all positions handled by this widget.
*/
// ---------------------------------------------------------------------------
public HashMap<Integer, Point> clonePositions() {
HashMap<Integer, Point> clonedPositions = new HashMap<>();
for (Entry<Integer, Point> entry : positions.entrySet()) {
Point cloned = entry.getValue().clone();
clonedPositions.put(entry.getKey(), cloned);
}
return clonedPositions;
}
// ---------------------------------------------------------------------------
/**
* Method used for returning the main handle, i.e. the handle with the lowest ID.
......
......@@ -33,10 +33,11 @@ public abstract class TetherableMarker extends Marker implements Tetherable {
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param builder
*/
// ---------------------------------------------------------------------------
public TetherableMarker(BaseTetherableMarkerBuilder<?> builder) {
super(builder);
this.tetherManager = new TetherManager(this, builder.exclusive);
......@@ -48,6 +49,24 @@ public abstract class TetherableMarker extends Marker implements Tetherable {
this.rotatesWithTether = builder.rotatesWithTether;
}
// ---------------------------------------------------------------------------
/**
* @param original
*/
// ---------------------------------------------------------------------------
public TetherableMarker(TetherableMarker original) {
super(original);
this.tetherManager = new TetherManager(this, original.tetherManager.isExclusive());
this.tetherManager.setProviders(original.tetherManager.getProviders());
this.tetherManager.setReceivers(original.tetherManager.getReceivers());
this.tetherOrigin = original.tetherOrigin.clone();
this.tetheringDistance = original.tetheringDistance;
this.draggable = original.draggable;
this.rotatesWithTether = original.rotatesWithTether;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
......@@ -90,6 +109,7 @@ public abstract class TetherableMarker extends Marker implements Tetherable {
@Override
public void setActive(boolean isActive) {
super.setActive(isActive);
this.tetherManager.enableTethering(isActive);
if (!isActive) {
this.tetherManager.lift();
}
......
......@@ -39,9 +39,6 @@ public class Graph {
private Map<Integer, Map<Integer, List<Edge>>> neighbours;
private List<Node> nodes;
private List<Edge> edges;
private int nextNodeId;
private int nextEdgeId;
private List<GraphListener> listeners;
// ---------------------------------------------------------------------------
......@@ -59,8 +56,6 @@ public class Graph {
this.neighbours = new HashMap<>();
this.nodes = new ArrayList<>();
this.edges = new ArrayList<>();
this.nextNodeId = 0;
this.nextEdgeId = 0;
this.listeners = new ArrayList<>();
}
......@@ -87,8 +82,9 @@ public class Graph {
}
}
this.edges.removeAll(edgesToRemove);
this.notifyListeners();
for (Edge edge : edgesToRemove) {
this.removeEdge(edge);
}
}
// ---------------------------------------------------------------------------
......@@ -162,7 +158,7 @@ public class Graph {
assert nodeToRemove != null;
this.nodesLookup.remove(nodeToRemove);
this.nodesLookup.remove(nodeToRemove.getId());
this.nodes.remove(nodeToRemove);
this.detachNode(nodeToRemove);
}
......
......@@ -131,6 +131,16 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
this.tetherManager.enableTethering(enableIt);
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public void clearPotentialTethers() {
this.tetherManager.clearPotentialTethers();
}
// ---------------------------------------------------------------------------
/**
* {@inheritDoc}
......
......@@ -182,7 +182,6 @@ public class TetherManager {
Point tetherEnding = tethered.getTetherOrigin().toScreenCoordinates();
shortest = Math.min(this.distance(tetherOrigin, tetherEnding), shortest);
}
return shortest;
}
......@@ -303,7 +302,6 @@ public class TetherManager {
*/
// ---------------------------------------------------------------------------
public void setProviders(List<String> providers) {
this.providers = providers;
}
......@@ -435,6 +433,17 @@ public class TetherManager {
this.tetherListeners.removeTetherListener(listener);
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public void clearPotentialTethers() {
this.potentialTethers.clear();
this.currentlyTethered.clear();
}
// ---------------------------------------------------------------------------
/**
* @param potentials
......@@ -443,7 +452,8 @@ public class TetherManager {
// ---------------------------------------------------------------------------
public void setPotentialTethers(HashMap<Tetherable, Tether> potentials) {
this.potentialTethers = potentials;
this.potentialTethers.clear();
this.potentialTethers.putAll(potentials);
}
// ---------------------------------------------------------------------------
......@@ -458,8 +468,6 @@ public class TetherManager {
return new HashMap<>(this.potentialTethers);
}
// ---------------------------------------------------------------------------
/**
* Adds the specified tetherable object as a potential tether.
......
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