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;
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.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.Tetherable;
import lu.list.itis.dkd.tui.widget.tether.listener.TetherEvent;
......@@ -83,6 +84,65 @@ public class InfoWidget extends TetherableWidget implements TetherListener {
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
......@@ -93,6 +153,7 @@ public class InfoWidget extends TetherableWidget implements TetherListener {
@Override
public void tetherChanged(TetherEvent event) {
switch (event.getState()) {
case UNKNOWN:
break;
......@@ -100,30 +161,15 @@ public class InfoWidget extends TetherableWidget implements TetherListener {
case ESTABLISHED:
LOGGER.info("Tether established!"); //$NON-NLS-1$
Tetherable target = event.getTarget();
if (target instanceof InformationProvider) {
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();
}
}
}
this.setupTether(event);
this.startFading(true);
break;
case TORNDOWN:
LOGGER.info("Tether severed!"); //$NON-NLS-1$
for (HtmlBox corona : getCoronas(HtmlBox.class)) {
corona.fadeOut();
}
this.tearDownTether(event);
this.startFading(false);
break;
default:
......
......@@ -4,6 +4,7 @@ import lu.list.itis.dkd.tui.widget.corona.builder.BaseFadingCoronaBuilder;
import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.Timeline.TimelineState;
import org.pushingpixels.trident.TimelinePropertyBuilder;
import org.pushingpixels.trident.callback.TimelineCallback;
import java.awt.Graphics2D;
......@@ -42,6 +43,9 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
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) *
......@@ -59,7 +63,7 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
this.displayTime = builder.displayTime;
this.fadeWithHandle = builder.fadeWithHandle;
this.fadingEnabled = builder.fadingEnabled;
this.opacity = (this.fadingEnabled) ? 0.0f : 1.0f;
this.opacity = (this.fadingEnabled) ? TRANSPARENT : OPAQUE;
if (this.fadingEnabled && (displayTime > 0)) {
displayTimer = new Timer((int) displayTime, this);
displayTimer.setRepeats(false);
......@@ -84,7 +88,8 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
this.fadeWithHandle = original.fadeWithHandle;
this.opacity = original.opacity;
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.setRepeats(false);
}
......@@ -127,21 +132,23 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
public void fadeIn() {
if (!fadingEnabled) {
this.setOpacity(1.0f);
this.setOpacity(OPAQUE);
return;
}
if ((fadeOutTimeline != null) && (!fadeOutTimeline.isDone()))
fadeOutTimeline.cancel();
if ((fadeInTime > 0) && (this.opacity < 1)) {
if ((fadeInTime > 0) && (this.opacity < OPAQUE)) {
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.addCallback(this);
fadeInTimeline.play();
} else {
this.setOpacity(1.0f);
this.setOpacity(OPAQUE);
if (displayTimer != null)
displayTimer.start();
}
......@@ -152,16 +159,17 @@ public class FadingCorona extends Corona implements TimelineCallback, ActionList
public void fadeOut() {
if (!fadingEnabled) {
this.setOpacity(0.0f);
this.setOpacity(TRANSPARENT);
return;
}
if ((fadeOutTime > 0) && (this.opacity > 0)) {
if ((fadeOutTime > 0) && (this.opacity > TRANSPARENT)) {
if ((fadeInTimeline != null) && (!fadeInTimeline.isDone()))
fadeInTimeline.cancel();
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.play();
}
......
......@@ -178,34 +178,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
}
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
/** {@inheritDoc} */
@Override
public void paint(Graphics2D canvas) {
if (!active)
if (!active || (this.opacity == TRANSPARENT))
return;
Graphics2D localCanvas = (Graphics2D) canvas.create();
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));
AffineTransform transform = this.getTransform(null);
......@@ -266,8 +238,6 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
public void setInformation(String 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 {
@Override
public void paint(Graphics2D canvas) {
if (!active)
if (!active || (this.opacity == TRANSPARENT))
return;
Graphics2D localCanvas = (Graphics2D) canvas.create();
......@@ -238,7 +238,7 @@ public class Sector extends SelectableCorona {
Shape transformed = transform.createTransformedShape(shape);
if (this.opacity < 1.0f)
if (this.opacity < OPAQUE)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
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