Commit 271349d8 authored by Nico Mack's avatar Nico Mack

Switch from deprecated animation API to new one for fading coronas

Generalization of tether handling in InfoWidget
parent ae913517
...@@ -25,7 +25,8 @@ import lu.list.itis.dkd.tui.content.InformationProvider; ...@@ -25,7 +25,8 @@ import lu.list.itis.dkd.tui.content.InformationProvider;
import lu.list.itis.dkd.tui.content.InformationReceiver; import lu.list.itis.dkd.tui.content.InformationReceiver;
import lu.list.itis.dkd.tui.widget.builder.BaseInfoBuilder; import lu.list.itis.dkd.tui.widget.builder.BaseInfoBuilder;
import lu.list.itis.dkd.tui.widget.builder.InfoWidgetBuilder; import lu.list.itis.dkd.tui.widget.builder.InfoWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.HtmlBox; import lu.list.itis.dkd.tui.widget.corona.FadingCorona;
import lu.list.itis.dkd.tui.widget.tether.InformationFeed;
import lu.list.itis.dkd.tui.widget.tether.Tether; import lu.list.itis.dkd.tui.widget.tether.Tether;
import lu.list.itis.dkd.tui.widget.tether.Tetherable; import lu.list.itis.dkd.tui.widget.tether.Tetherable;
import lu.list.itis.dkd.tui.widget.tether.listener.TetherEvent; import lu.list.itis.dkd.tui.widget.tether.listener.TetherEvent;
...@@ -83,6 +84,65 @@ public class InfoWidget extends TetherableWidget implements TetherListener { ...@@ -83,6 +84,65 @@ public class InfoWidget extends TetherableWidget implements TetherListener {
this.addTetherListener(this); this.addTetherListener(this);
} }
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives
// ***************************************************************************
// ---------------------------------------------------------------------------
private void startFading(boolean fadeIn) {
for (FadingCorona fadable : getCoronas(FadingCorona.class)) {
if (fadeIn) {
fadable.setActive(true);
fadable.fadeIn();
} else {
fadable.fadeOut();
}
}
}
// ---------------------------------------------------------------------------
@SuppressWarnings({"rawtypes", "unchecked"})
private void setupTether(TetherEvent event) {
Tetherable target;
target = event.getTarget();
if (target instanceof InformationProvider) {
InformationProvider provider = (InformationProvider) target;
Object information = provider.getInformation();
if (information != null) {
Tether tether = this.getTetherFor(target);
if (tether instanceof InformationFeed) {
InformationFeed feed = (InformationFeed) tether;
for (InformationReceiver receiver : getCoronas(InformationReceiver.class)) {
feed.addDataListener(receiver);
receiver.setInformation(information);
}
feed.setInformation(information);
}
}
}
}
// ---------------------------------------------------------------------------
@SuppressWarnings({"rawtypes", "unchecked"})
private void tearDownTether(TetherEvent event) {
Tetherable target;
target = event.getTarget();
Tether tether = this.getTetherFor(target);
if (tether instanceof InformationFeed) {
InformationFeed feed = (InformationFeed) tether;
for (InformationReceiver<?> receiver : getCoronas(InformationReceiver.class)) {
feed.removeDataListener(receiver);
}
}
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Class Body // * Class Body
...@@ -93,6 +153,7 @@ public class InfoWidget extends TetherableWidget implements TetherListener { ...@@ -93,6 +153,7 @@ public class InfoWidget extends TetherableWidget implements TetherListener {
@Override @Override
public void tetherChanged(TetherEvent event) { public void tetherChanged(TetherEvent event) {
switch (event.getState()) { switch (event.getState()) {
case UNKNOWN: case UNKNOWN:
break; break;
...@@ -100,30 +161,15 @@ public class InfoWidget extends TetherableWidget implements TetherListener { ...@@ -100,30 +161,15 @@ public class InfoWidget extends TetherableWidget implements TetherListener {
case ESTABLISHED: case ESTABLISHED:
LOGGER.info("Tether established!"); //$NON-NLS-1$ LOGGER.info("Tether established!"); //$NON-NLS-1$
Tetherable target = event.getTarget(); this.setupTether(event);
if (target instanceof InformationProvider) { this.startFading(true);
Object info = ((InformationProvider<?>) target).getInformation();
if (info != null) {
Tether tether = this.getTetherFor(target);
if (tether instanceof InformationReceiver) {
((InformationReceiver) tether).setInformation(info);
}
for (HtmlBox corona : getCoronas(HtmlBox.class)) {
corona.setInformation(info.toString());
corona.setActive(true);
corona.fadeIn();
}
}
}
break; break;
case TORNDOWN: case TORNDOWN:
LOGGER.info("Tether severed!"); //$NON-NLS-1$ LOGGER.info("Tether severed!"); //$NON-NLS-1$
for (HtmlBox corona : getCoronas(HtmlBox.class)) { this.tearDownTether(event);
corona.fadeOut(); this.startFading(false);
}
break; break;
default: default:
......
...@@ -4,6 +4,7 @@ import lu.list.itis.dkd.tui.widget.corona.builder.BaseFadingCoronaBuilder; ...@@ -4,6 +4,7 @@ import lu.list.itis.dkd.tui.widget.corona.builder.BaseFadingCoronaBuilder;
import org.pushingpixels.trident.Timeline; import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.Timeline.TimelineState; import org.pushingpixels.trident.Timeline.TimelineState;
import org.pushingpixels.trident.TimelinePropertyBuilder;
import org.pushingpixels.trident.callback.TimelineCallback; import org.pushingpixels.trident.callback.TimelineCallback;
import java.awt.Graphics2D; import java.awt.Graphics2D;
...@@ -42,6 +43,9 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList ...@@ -42,6 +43,9 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
private static final String OPACITY_PROPERTY = "opacity"; //$NON-NLS-1$ private static final String OPACITY_PROPERTY = "opacity"; //$NON-NLS-1$
protected static final Float TRANSPARENT = Float.valueOf(0f);
protected static final Float OPAQUE = Float.valueOf(1f);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Constructor(s) * // * Constructor(s) *
...@@ -59,7 +63,7 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList ...@@ -59,7 +63,7 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
this.displayTime = builder.displayTime; this.displayTime = builder.displayTime;
this.fadeWithHandle = builder.fadeWithHandle; this.fadeWithHandle = builder.fadeWithHandle;
this.fadingEnabled = builder.fadingEnabled; this.fadingEnabled = builder.fadingEnabled;
this.opacity = (this.fadingEnabled) ? 0.0f : 1.0f; this.opacity = (this.fadingEnabled) ? TRANSPARENT : OPAQUE;
if (this.fadingEnabled && (displayTime > 0)) { if (this.fadingEnabled && (displayTime > 0)) {
displayTimer = new Timer((int) displayTime, this); displayTimer = new Timer((int) displayTime, this);
displayTimer.setRepeats(false); displayTimer.setRepeats(false);
...@@ -84,7 +88,8 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList ...@@ -84,7 +88,8 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
this.fadeWithHandle = original.fadeWithHandle; this.fadeWithHandle = original.fadeWithHandle;
this.opacity = original.opacity; this.opacity = original.opacity;
this.fadingEnabled = original.fadingEnabled; this.fadingEnabled = original.fadingEnabled;
if (displayTime > 0) { this.opacity = (this.fadingEnabled) ? TRANSPARENT : OPAQUE;
if (this.fadingEnabled && (displayTime > 0)) {
displayTimer = new Timer((int) displayTime, this); displayTimer = new Timer((int) displayTime, this);
displayTimer.setRepeats(false); displayTimer.setRepeats(false);
} }
...@@ -127,21 +132,23 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList ...@@ -127,21 +132,23 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
public void fadeIn() { public void fadeIn() {
if (!fadingEnabled) { if (!fadingEnabled) {
this.setOpacity(1.0f); this.setOpacity(OPAQUE);
return; return;
} }
if ((fadeOutTimeline != null) && (!fadeOutTimeline.isDone())) if ((fadeOutTimeline != null) && (!fadeOutTimeline.isDone()))
fadeOutTimeline.cancel(); fadeOutTimeline.cancel();
if ((fadeInTime > 0) && (this.opacity < 1)) { if ((fadeInTime > 0) && (this.opacity < OPAQUE)) {
fadeInTimeline = new Timeline(this); fadeInTimeline = new Timeline(this);
fadeInTimeline.addPropertyToInterpolate(OPACITY_PROPERTY, this.opacity, 1.0f);
TimelinePropertyBuilder<?> opacityProperty = Timeline.property(OPACITY_PROPERTY).from(Float.valueOf(this.opacity)).to(OPAQUE);
fadeInTimeline.addPropertyToInterpolate(opacityProperty);
fadeInTimeline.setDuration(fadeInTime); fadeInTimeline.setDuration(fadeInTime);
fadeInTimeline.addCallback(this); fadeInTimeline.addCallback(this);
fadeInTimeline.play(); fadeInTimeline.play();
} else { } else {
this.setOpacity(1.0f); this.setOpacity(OPAQUE);
if (displayTimer != null) if (displayTimer != null)
displayTimer.start(); displayTimer.start();
} }
...@@ -152,16 +159,17 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList ...@@ -152,16 +159,17 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
public void fadeOut() { public void fadeOut() {
if (!fadingEnabled) { if (!fadingEnabled) {
this.setOpacity(0.0f); this.setOpacity(TRANSPARENT);
return; return;
} }
if ((fadeOutTime > 0) && (this.opacity > 0)) { if ((fadeOutTime > 0) && (this.opacity > TRANSPARENT)) {
if ((fadeInTimeline != null) && (!fadeInTimeline.isDone())) if ((fadeInTimeline != null) && (!fadeInTimeline.isDone()))
fadeInTimeline.cancel(); fadeInTimeline.cancel();
fadeOutTimeline = new Timeline(this); fadeOutTimeline = new Timeline(this);
fadeOutTimeline.addPropertyToInterpolate(OPACITY_PROPERTY, this.opacity, 0.0f); TimelinePropertyBuilder<?> opacityProperty = Timeline.property(OPACITY_PROPERTY).from(Float.valueOf(this.opacity)).to(TRANSPARENT);
fadeOutTimeline.addPropertyToInterpolate(opacityProperty);
fadeOutTimeline.setDuration(fadeOutTime); fadeOutTimeline.setDuration(fadeOutTime);
fadeOutTimeline.play(); fadeOutTimeline.play();
} }
......
...@@ -178,34 +178,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str ...@@ -178,34 +178,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
} }
this.rendered = null; this.rendered = null;
// bounds = canvas.getBounds2D();
// renderedHtml = new BufferedImage((int) bounds.getWidth() - (2 * insetBorder), (int)
// bounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
// Graphics2D offscreen = renderedHtml.createGraphics();
// offscreen.setRenderingHints(renderingHints);
//
// AffineTransform translate = AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY());
// offscreen.setClip(translate.createTransformedShape(canvas));
//
// editor.invalidate();
// editor.paint(offscreen);
// offscreen.dispose();
// int reference = renderedHtml.getRGB(0, 0);
// boolean different = false;
// for (int x = 0; x < renderedHtml.getWidth(); x++) {
// for (int y = 0; y < renderedHtml.getHeight(); y++) {
// int current = renderedHtml.getRGB(x, y);
// different |= (current != reference);
// }
// }
//
// if (!different) {
// LOGGER.warn("Rendered an empty Picture!");
// }
// return renderedHtml;
} }
...@@ -218,13 +190,13 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str ...@@ -218,13 +190,13 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void paint(Graphics2D canvas) { public void paint(Graphics2D canvas) {
if (!active) if (!active || (this.opacity == TRANSPARENT))
return; return;
Graphics2D localCanvas = (Graphics2D) canvas.create(); Graphics2D localCanvas = (Graphics2D) canvas.create();
localCanvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localCanvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (this.opacity < 1.0f) if (this.opacity < OPAQUE)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity)); localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
AffineTransform transform = this.getTransform(null); AffineTransform transform = this.getTransform(null);
...@@ -266,8 +238,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str ...@@ -266,8 +238,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
public void setInformation(String information) { public void setInformation(String information) {
this.renderHtml(information); this.renderHtml(information);
// renderedCentre = new Point(((float) rendered.getWidth() / 2), ((float) rendered.getHeight() / 2),
// 0f, ScreenCoordinates.class);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -228,7 +228,7 @@ public class Sector extends SelectableCorona { ...@@ -228,7 +228,7 @@ public class Sector extends SelectableCorona {
@Override @Override
public void paint(Graphics2D canvas) { public void paint(Graphics2D canvas) {
if (!active) if (!active || (this.opacity == TRANSPARENT))
return; return;
Graphics2D localCanvas = (Graphics2D) canvas.create(); Graphics2D localCanvas = (Graphics2D) canvas.create();
...@@ -238,7 +238,7 @@ public class Sector extends SelectableCorona { ...@@ -238,7 +238,7 @@ public class Sector extends SelectableCorona {
Shape transformed = transform.createTransformedShape(shape); Shape transformed = transform.createTransformedShape(shape);
if (this.opacity < 1.0f) if (this.opacity < OPAQUE)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity)); localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
if (fillColour != null) { if (fillColour != null) {
......
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