Commit 04998dd6 authored by Nico Mack's avatar Nico Mack

Changed class hierarchy of selectable and fading coronas.

Added IndexedCoronas. Extended BootstrapCallack interface
parent 0d27fecb
......@@ -80,6 +80,7 @@ ROTATE_WITH_TETHER_NODE=rotateWithTether
DISPLAY_TIME_NODE=displayTime
FADE_IN_TIME_NODE=fadeInTime
FADE_OUT_TIME_NODE=fadeOutTime
FADE_WITH_HANDLE_NODE=fadeWithHandle
INDEX_NODE=index
INNER_RADIUS_NODE=innerRadius
......
......@@ -45,4 +45,10 @@ public interface BootstrapCallback {
*/
public BootstrapContext next(BootstrapContext context);
/**
* @param context
* @return
*/
public BootstrapContext reset(BootstrapContext context);
}
......@@ -82,4 +82,11 @@ public class BootstrapContext {
return context.size();
}
/**
*
*/
public void clear() {
context.clear();
}
}
......@@ -176,7 +176,6 @@ public class CoronaBootstrapper {
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()) {
......
......@@ -58,6 +58,9 @@ public class CoronaFactory<C extends Corona> implements Iterator<C> {
this.index = 0;
this.repeating = BootstrappingUtils.getAttributeAsBoolean(coronaNode, Externalization.REPEAT_ATTRIBUTE, BootstrappingUtils.OPTIONAL, false);
if (this.repeating) {
if (callback != null)
this.context = callback.reset(this.context);
this.indexVariable = BootstrappingUtils.getAttributeAsString(coronaNode, Externalization.INDEX_ATTRIBUTE, BootstrappingUtils.MANDATORY, null);
String countVariable = BootstrappingUtils.getAttributeAsString(coronaNode, Externalization.COUNT_ATTRIBUTE, BootstrappingUtils.MANDATORY, null);
context.setProperty(this.indexVariable, this.index);
......@@ -67,7 +70,9 @@ public class CoronaFactory<C extends Corona> implements Iterator<C> {
}
this.count = Integer.parseInt(countProperty.toString());
} else {
} else
{
this.count = 1;
}
}
......
......@@ -60,11 +60,13 @@ public abstract class CoordinateState {
*/
public void toCoordinates(@NonNull Point context, Class<? extends CoordinateState> targetStateClass) {
Point normalized = this.normalize(context);
context.setState(CoordinateStateFactory.newInstance(targetStateClass, context, normalized.x, normalized.y));
Point transformed = context.getState().transform(normalized);
context.x = transformed.x;
context.y = transformed.y;
if (!this.getClass().equals(targetStateClass)) {
Point normalized = this.normalize(context);
context.setState(CoordinateStateFactory.newInstance(targetStateClass, context, normalized.x, normalized.y));
Point transformed = context.getState().transform(normalized);
context.x = transformed.x;
context.y = transformed.y;
}
}
/**
......
......@@ -121,6 +121,7 @@ public class Externalization extends NLS {
public static String DISPLAY_TIME_NODE;
public static String FADE_IN_TIME_NODE;
public static String FADE_OUT_TIME_NODE;
public static String FADE_WITH_HANDLE_NODE;
public static String INDEX_NODE;
public static String INNER_RADIUS_NODE;
......
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.widget.corona.builder.FadingCoronaBuilder;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseFadingCoronaBuilder;
import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.Timeline.TimelineState;
......@@ -24,10 +24,11 @@ import javax.swing.Timer;
// * Class Definition and Members *
// ***************************************************************************
public class FadingCorona extends SelectableCorona implements TimelineCallback, ActionListener {
public class FadingCorona extends Corona implements TimelineCallback, ActionListener {
private long fadeInTime;
private long fadeOutTime;
private long displayTime;
private boolean fadeWithHandle;
protected float opacity;
protected Timeline fadeInTimeline;
......@@ -38,18 +39,24 @@ public class FadingCorona extends SelectableCorona implements TimelineCallback,
// * Constants *
// ***************************************************************************
private static final String OPACITY_PROPERTY = "opacity"; //$NON-NLS-1$
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public FadingCorona(FadingCoronaBuilder<?> builder) {
/**
* @param builder
*/
public FadingCorona(BaseFadingCoronaBuilder<?> builder) {
super(builder);
this.fadeInTime = builder.fadeInTime;
this.fadeOutTime = builder.fadeOutTime;
this.displayTime = builder.displayTime;
this.fadeWithHandle = builder.fadeWithHandle;
this.opacity = 1.0f;
displayTimer = new Timer((int) displayTime, this);
displayTimer.setRepeats(false);
......@@ -78,9 +85,9 @@ public class FadingCorona extends SelectableCorona implements TimelineCallback,
if ((fadeOutTimeline != null) && (!fadeOutTimeline.isDone()))
fadeOutTimeline.cancel();
if (fadeInTime > 0) {
if ((fadeInTime > 0) && (this.opacity < 1)) {
fadeInTimeline = new Timeline(this);
fadeInTimeline.addPropertyToInterpolate("opacity", 0.0f, 1.0f);
fadeInTimeline.addPropertyToInterpolate(OPACITY_PROPERTY, 0.0f, 1.0f);
fadeInTimeline.setDuration(fadeInTime);
fadeInTimeline.addCallback(this);
fadeInTimeline.play();
......@@ -93,12 +100,12 @@ public class FadingCorona extends SelectableCorona implements TimelineCallback,
// ---------------------------------------------------------------------------
public void fadeOut() {
if (fadeOutTime > 0) {
if ((fadeOutTime > 0) && (this.opacity > 0)) {
if ((fadeInTimeline != null) && (!fadeInTimeline.isDone()))
fadeInTimeline.cancel();
fadeOutTimeline = new Timeline(this);
fadeOutTimeline.addPropertyToInterpolate("opacity", 1.0f, 0.0f);
fadeOutTimeline.addPropertyToInterpolate(OPACITY_PROPERTY, 1.0f, 0.0f);
fadeOutTimeline.setDuration(fadeOutTime);
fadeOutTimeline.play();
}
......@@ -106,6 +113,15 @@ public class FadingCorona extends SelectableCorona implements TimelineCallback,
// ---------------------------------------------------------------------------
/**
* @return
*/
public boolean fadesWithHandle() {
return fadeWithHandle;
}
// ---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas) {}
......
/**
* 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.widget.corona;
import lu.list.itis.dkd.tui.widget.corona.builder.BaseIndexedCoronaBuilder;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public abstract class IndexedCorona extends SelectableCorona {
protected int index;
/**
* @param builder
*/
public IndexedCorona(BaseIndexedCoronaBuilder<?> builder) {
super(builder);
index = builder.index;
}
/**
* Getter for the unique index assigned to this sector
*
* @return the unique index assigned to this sector
*/
public int getIndex() {
return index;
}
}
......@@ -32,7 +32,7 @@ import java.awt.geom.Rectangle2D;
// * Class Definition and Members *
// ***************************************************************************
public class Sector extends FadingCorona {
public class Sector extends IndexedCorona {
private double size;
private double innerRadius;
private double outerRadius;
......
......@@ -23,8 +23,8 @@ import lu.list.itis.dkd.tui.widget.corona.builder.BaseSelectableCoronaBuilder;
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public abstract class SelectableCorona extends Corona {
protected int index;
public abstract class SelectableCorona extends FadingCorona {
// protected int index;
protected boolean isSelected;
/**
......@@ -33,7 +33,7 @@ public abstract class SelectableCorona extends Corona {
public SelectableCorona(BaseSelectableCoronaBuilder<?> builder) {
super(builder);
index = builder.index;
// index = builder.index;
}
/**
......@@ -41,9 +41,9 @@ public abstract class SelectableCorona extends Corona {
*
* @return the unique index assigned to this sector
*/
public int getIndex() {
return index;
}
// public int getIndex() {
// return index;
// }
/**
* @param selectIt
......
/**
* 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.widget.corona.builder;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
/**
* 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>.
*/
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.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.FadingCorona;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
* @param <B>
*/
public abstract class BaseFadingCoronaBuilder<B extends BaseFadingCoronaBuilder<B>> extends CoronaBuilder<B> {
/** Time the fading corona takes to appear, i.e. going from transparent to opaque */
public long fadeInTime;
/** Time the fading corona takes to disappear, i.e. going from opaque to transparent */
public long fadeOutTime;
/**
* Time the corona stays visible if inactive. Once the time expires, the corana will fade out
*/
public long displayTime;
/**
* Field indicating whether the corona is to fade with the handle. Default: <code>true</code>!
*/
public boolean fadeWithHandle;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final int FIVE_SECONDS = 5000;
private static final int ONE_SECOND = 1000;
/**
* @param centre
*/
protected BaseFadingCoronaBuilder(Point centre) {
super(centre);
this.displayTime = FIVE_SECONDS;
this.fadeInTime = 0;
this.fadeOutTime = ONE_SECOND;
this.fadeWithHandle = true;
}
/**
* @param rootElement
* @throws BuildException
*/
public BaseFadingCoronaBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
public BaseFadingCoronaBuilder(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 {
displayTime = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.DISPLAY_TIME_NODE, BootstrappingUtils.OPTIONAL, FIVE_SECONDS, context);
fadeInTime = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.FADE_IN_TIME_NODE, BootstrappingUtils.OPTIONAL, 0, context);
fadeOutTime = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.FADE_OUT_TIME_NODE, BootstrappingUtils.OPTIONAL, ONE_SECOND, context);
fadeWithHandle = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.FADE_WITH_HANDLE_NODE, BootstrappingUtils.OPTIONAL, Boolean.TRUE, context);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param timeInMillis
* @return
*/
@SuppressWarnings("unchecked")
public B withFadeInTime(long timeInMillis) {
this.fadeInTime = timeInMillis;
return (B) this;
}
// ---------------------------------------------------------------------------
/**
* @param timeInMillis
* @return
*/
@SuppressWarnings("unchecked")
public B withFadeOutTime(long timeInMillis) {
this.fadeOutTime = timeInMillis;
return (B) this;
}
// ---------------------------------------------------------------------------
/**
* @param timeInMillis
* @return
*/
@SuppressWarnings("unchecked")
public B withDisplayTime(long timeInMillis) {
this.displayTime = timeInMillis;
return (B) this;
}
// ---------------------------------------------------------------------------
/**
* Method for specifying if the corona is to fade when the centre point is rotated.
*
* @param fades
* <code>True</code> if the corona is to fade with its centre reference,
* <code>false</code> otherwise.
* @return An instance of the builder for chain calling.
*/
@SuppressWarnings("unchecked")
public B fadesWithHandle(boolean fades) {
fadeWithHandle = fades;
return (B) this;
}
@Override
public abstract FadingCorona build() throws BuildException;
}
/**
* 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.widget.corona.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.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.IndexedCorona;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
* @param <B>
*/
public abstract class BaseIndexedCoronaBuilder<B extends BaseIndexedCoronaBuilder<B>> extends BaseSelectableCoronaBuilder<B> {
/**
* specifies the unique index identifying the selectable corona among its peers.
*/
public int index;
/**
* @param centre
*/
protected BaseIndexedCoronaBuilder(Point centre) {
super(centre);
}
/**
* @param rootElement
* @throws BuildException
*/
public BaseIndexedCoronaBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
public BaseIndexedCoronaBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
index = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INDEX_NODE, BootstrappingUtils.MANDATORY, 0, context);
}
/**
* assigns the specified index as the unique identifier for the corona to build
*
* @param index
* specifies the unique identifier to assign to the corona to build
* @return instance of the builder object for chain calling.
*/
@SuppressWarnings("unchecked")
public B withIndex(int index) {
this.index = index;
return (B) this;
}
/** {@inheritDoc} */
@Override
public abstract IndexedCorona build() throws BuildException;
}
......@@ -16,12 +16,9 @@
*/
package lu.list.itis.dkd.tui.widget.corona.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.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
......@@ -33,11 +30,11 @@ import org.jdom2.Element;
* @version [major].[minor].[micro]
* @param <B>
*/
public abstract class BaseSelectableCoronaBuilder<B extends BaseSelectableCoronaBuilder<B>> extends CoronaBuilder<B> {
public abstract class BaseSelectableCoronaBuilder<B extends BaseSelectableCoronaBuilder<B>> extends BaseFadingCoronaBuilder<B> {
/**
* specifies the unique index identifying the selectable corona among its peers.
*/
public int index;
// public int index;
/**
* @param centre
......@@ -52,7 +49,7 @@ public abstract class BaseSelectableCoronaBuilder<B extends BaseSelectableCorona
*/
public BaseSelectableCoronaBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
// this.buildFromBootstrap(rootElement, null, null);
}
/**
......@@ -63,12 +60,14 @@ public abstract class BaseSelectableCoronaBuilder<B extends BaseSelectableCorona
*/
public BaseSelectableCoronaBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
// this.buildFromBootstrap(rootElement, context, callback);
}
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
index = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INDEX_NODE, BootstrappingUtils.MANDATORY, 0, context);
}
// private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context,
// BootstrapCallback callback) throws BuildException {
// index = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INDEX_NODE,
// BootstrappingUtils.MANDATORY, 0, context);
// }
/**
* assigns the specified index as the unique identifier for the corona to build
......@@ -78,11 +77,11 @@ public abstract class BaseSelectableCoronaBuilder<B extends BaseSelectableCorona
* @return instance of the builder object for chain calling.
*/
@SuppressWarnings("unchecked")
public B withIndex(int index) {
this.index = index;
return (B) this;
}
// @SuppressWarnings("unchecked")
// public B withIndex(int index) {
// this.index = index;
// return (B) this;
// }
/** {@inheritDoc} */
@Override
......
package lu.list.itis.dkd.tui.widget.corona.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.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.FadingCorona;
......@@ -13,7 +10,6 @@ import org.jdom2.Element;
/**
* @author nmack
* @param <B>
* @date 18 Jan 2016
*
* <br>
......@@ -24,45 +20,41 @@ import org.jdom2.Element;
// * Class Definition and Members *
// ***************************************************************************
public abstract class FadingCoronaBuilder<B extends FadingCoronaBuilder<B>> extends BaseSelectableCoronaBuilder<B> {
/** Time the fading corona takes to appear, i.e. going from transparent to opaque */
public long fadeInTime;
/** Time the fading corona takes to disappear, i.e. going from opaque to transparent */
public long fadeOutTime;
/**
* Time the corona stays visible if inactive. Once the time expires, the corana will fade out
*/
public long displayTime;
public abstract class FadingCoronaBuilder extends BaseFadingCoronaBuilder<FadingCoronaBuilder> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final int FIVE_SECONDS = 5000;
private static final int ONE_SECOND = 1000;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
protected FadingCoronaBuilder(Point centre) {
/**
* @param centre
*/
public FadingCoronaBuilder(Point centre) {
super(centre);
this.displayTime = FIVE_SECONDS;
this.fadeInTime = 0;
this.fadeOutTime = ONE_SECOND;
}
protected FadingCoronaBuilder(Element rootElement) throws BuildException {
/**
* @param rootElement
* @throws BuildException
*/
public FadingCoronaBuilder(Element rootElement) throws BuildException {
super(rootElement);
this