Commit d1d1ae23 authored by Nico Mack's avatar Nico Mack

Fixed a bug in tethering mechanism causing Tethers not being

correctly drawn in non-exclusive mode.
parent 4845c2eb
......@@ -208,6 +208,13 @@ public abstract class TetherableMarker extends Marker implements Tetherable {
// ---------------------------------------------------------------------------
@Override
public boolean isExclusive() {
return this.tetherManager.isExclusive();
}
// ---------------------------------------------------------------------------
@Override
public boolean isDraggable() {
return this.draggable;
......
......@@ -299,6 +299,17 @@ public abstract class TetherableWidget extends PointingWidget implements Tethera
*/
// ---------------------------------------------------------------------------
@Override
public boolean isExclusive() {
return this.tetherManager.isExclusive();
}
// ---------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
// ---------------------------------------------------------------------------
@Override
public boolean isDraggable() {
return this.draggable;
......
......@@ -5,7 +5,6 @@ import lu.list.itis.dkd.tui.content.InformationReceiver;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.tether.builder.InformationFeedBuilder;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;
......@@ -41,6 +40,13 @@ public abstract class InformationFeed<T> extends Tether implements InformationPr
listeners = new ArrayList<>();
}
// ---------------------------------------------------------------------------
public InformationFeed(InformationFeed original) {
super(original);
listeners = new ArrayList<>();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
......@@ -85,26 +91,11 @@ public abstract class InformationFeed<T> extends Tether implements InformationPr
// ---------------------------------------------------------------------------
// public void setInformation(String channel, T information) {
// if (channel.equals(this.name)) {
// this.setInformation(information);
// }
// }
// ---------------------------------------------------------------------------
public void setInformation(T information) {
this.information = information;
this.notifyListeners(information);
}
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
// TODO Auto-generated method stub
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
......
......@@ -43,6 +43,15 @@ public class Line extends InformationFeed {
this.strokeColour = builder.strokeColour;
}
// ---------------------------------------------------------------------------
public Line(Line original) {
super(original);
this.strokeWidth = original.strokeWidth;
this.strokeColour = original.strokeColour;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
......@@ -63,10 +72,20 @@ public class Line extends InformationFeed {
Stroke pen = new BasicStroke(strokeWidth);
Shape line = new Line2D.Double(new Point2D.Double(origin.x, origin.y), new Point2D.Double(ending.x, ending.y));
canvas.setStroke(pen);
canvas.setColor(strokeColour);
canvas.draw(line);
Graphics2D localCanvas = (Graphics2D) canvas.create();
localCanvas.setStroke(pen);
localCanvas.setColor(strokeColour);
localCanvas.draw(line);
localCanvas.dispose();
}
// ---------------------------------------------------------------------------
@Override
public Line clone() {
return new Line(this);
}
// ---------------------------------------------------------------------------
......
......@@ -42,6 +42,16 @@ public abstract class Tether {
this.previousEnding = this.ending;
}
// ---------------------------------------------------------------------------
public Tether(Tether original) {
this.name = original.name;
this.origin = original.origin;
this.previousOrigin = this.origin;
this.ending = original.ending;
this.previousEnding = this.ending;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
......@@ -99,6 +109,11 @@ public abstract class Tether {
return this.name;
}
// ---------------------------------------------------------------------------
@Override
public abstract Tether clone();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
......
......@@ -199,14 +199,14 @@ public class TetherManager {
*/
// ---------------------------------------------------------------------------
private void separateFromAll() {
private void separateFromAll(boolean propagate) {
if (this.currentlyTethered.isEmpty())
return;
List<Tetherable> exTethers = new ArrayList<>(this.currentlyTethered);
for (Tetherable exTether : exTethers) {
this.separateFrom(exTether, DO_PROPAGATE);
this.separateFrom(exTether, propagate);
}
this.currentlyTethered.clear();
}
......@@ -544,13 +544,18 @@ public class TetherManager {
if (this.potentialTethers.containsKey(candidate)) {
if (!this.currentlyTethered.contains(candidate)) {
if (this.exclusive) {
if (this.exclusive && !this.currentlyTethered.isEmpty()) {
// If no other tethers are allowed (exclusive mode), then we
// have to separate from previously tethered widgets/objects
this.separateFromAll();
this.separateFromAll(propagate);
}
this.currentlyTethered.add(candidate);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} now tethered with {}!", this.tetherable, candidate);
}
this.tetherListeners.notifyTetherListener(new TetherEvent(this.tetherable, candidate, TetherEvent.TetherState.ESTABLISHED));
if (propagate && !candidate.isTetheredWith(this.tetherable)) {
......@@ -578,6 +583,9 @@ public class TetherManager {
synchronized (this.currentlyTethered) {
if (this.currentlyTethered.contains(tethered)) {
this.currentlyTethered.remove(tethered);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} no longer tethered with {}!", this.tetherable, tethered);
}
this.tetherListeners.notifyTetherListener(new TetherEvent(this.tetherable, tethered, TetherEvent.TetherState.TORNDOWN));
if (propagate && tethered.isTetheredWith(this.tetherable)) {
tethered.separateFrom(this.tetherable, DONT_PROPAGATE);
......@@ -763,7 +771,7 @@ public class TetherManager {
// }
// }
this.separateFromAll();
this.separateFromAll(DO_PROPAGATE);
this.tetherable.setTetherOrigin(null);
}
......
......@@ -56,6 +56,8 @@ public interface Tetherable {
public abstract boolean isDraggable();
public abstract boolean isExclusive();
public abstract boolean rotatesWithTether();
public abstract boolean isTetheredWith(Tetherable otherTetherable);
......
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