Commit 50212979 authored by Nico Mack's avatar Nico Mack

Moved InfoMarker and DisplayMarker from TLUP-GIS package into TULIP-CPS

package
parent e7b303ef
package lu.list.itis.dkd.tui.marker;
import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.marker.builder.BaseDisplayMarkerBuilder;
import lu.list.itis.dkd.tui.widget.corona.ValueCorona;
import org.python.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
@SuppressWarnings("rawtypes")
public class DisplayMarker extends InfoMarker implements InputChangeListener {
private HashMap<String, NumericalVariable> variables;
HashMap<String, ValueCorona> dispatcher;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static Logger LOGGER = LoggerFactory.getLogger(DisplayMarker.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public DisplayMarker(BaseDisplayMarkerBuilder<?> builder) {
super(builder);
if (builder.variables != null) {
this.setVariables(builder.variables);
}
this.dispatcher = new HashMap<String, ValueCorona>();
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
dispatcher.put(variable.getName(), display);
}
}
// TODO Auto-generated constructor stub
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public void setVariables(Collection<Variable<?>> newVariables) {
Preconditions.checkArgument(variables == null, "Set of variables can't be null!"); //$NON-NLS-1$
this.variables = new HashMap<String, NumericalVariable>();
for (Variable<?> variable : newVariables) {
this.variables.put(variable.getName(), (NumericalVariable) variable);
}
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
String variableName = variable.getName();
if (this.variables.containsKey(variableName)) {
display.setVariable(this.variables.get(variableName));
} else {
LOGGER.warn("Corona requires variable {} unkown to display widget!", variableName); //$NON-NLS-1$
}
}
}
}
// ---------------------------------------------------------------------------
public Collection<Variable<?>> getVariables() {
Collection<Variable<?>> variables = new ArrayList<>();
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
Variable<?> variable = display.getVariable();
if (variable != null) {
variables.add(variable);
}
}
return variables;
}
// ---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas) {
super.paint(canvas);
}
// ---------------------------------------------------------------------------
@Override
public void inputChanged(InputEvent input) {
String variableName = input.getSource().getName();
ValueCorona display = dispatcher.get(variableName);
NumericalVariable variable = display.getVariable();
if (variable != null) {
display.setInformation(variable.getValue());
} else {
LOGGER.warn("Corona requires variable {} unkown to display marker!", variableName); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import lu.list.itis.dkd.tui.content.InformationProvider;
import lu.list.itis.dkd.tui.content.InformationReceiver;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.marker.builder.BaseInfoMarkerBuilder;
import lu.list.itis.dkd.tui.marker.builder.InfoMarkerBuilder;
import lu.list.itis.dkd.tui.utility.Point;
//***************************************************************************
//* Class Definition and Members *
//***************************************************************************
public class InfoMarker<T> extends TetherableMarker implements InformationReceiver<T>, InformationProvider<T> {
private T information;
private Variable<T> variable;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// private static Logger LOGGER = LoggerFactory.getLogger(InfoMarker.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public InfoMarker(BaseInfoMarkerBuilder<InfoMarkerBuilder> builder) {
super(builder);
this.information = (T) builder.information;
this.variable = (Variable<T>) builder.variable;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public T getInformation(Point position) {
return this.getInformation();
}
// ---------------------------------------------------------------------------
@Override
public T getInformation() {
if (this.variable != null) {
return this.variable.getValue();
} else {
return this.information;
}
}
// ---------------------------------------------------------------------------
@Override
public void setInformation(T information) {
if (this.variable != null) {
this.variable.setValue(information);
} else {
this.information = information;
}
}
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import java.util.Collection;
import java.util.Vector;
import org.jdom2.Element;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.DisplayMarker;
//***************************************************************************
//* Class Definition and Members *
//***************************************************************************
public abstract class BaseDisplayMarkerBuilder<B extends BaseDisplayMarkerBuilder<B>> extends BaseInfoMarkerBuilder<B> {
public Collection<Variable<?>> variables;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
protected BaseDisplayMarkerBuilder() {}
// ---------------------------------------------------------------------------
protected BaseDisplayMarkerBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public BaseDisplayMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
public B withVariables(Collection<Variable<?>> variables) {
this.variables = new Vector<Variable<?>>();
this.variables.addAll(variables);
return (B) this;
}
// ---------------------------------------------------------------------------
@Override
public abstract DisplayMarker build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import org.jdom2.Element;
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.bootstrapping.VariableBootstrapper;
import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.InfoMarker;
import lu.list.itis.dkd.tui.utility.Externalization;
//***************************************************************************
//* Class Definition and Members *
//***************************************************************************
public abstract class BaseInfoMarkerBuilder<B extends BaseInfoMarkerBuilder<B>> extends BaseTetherableMarkerBuilder<B> {
public Object information;
public Variable<?> variable;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
protected BaseInfoMarkerBuilder() {}
// ---------------------------------------------------------------------------
protected BaseInfoMarkerBuilder(Element rootElement) throws BuildException {
super (rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
protected BaseInfoMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
protected void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super.buildFromBootstrap(rootElement, context, callback);
Element informationElement = rootElement.getChild(Externalization.INFORMATION);
if (informationElement != null) {
Element variableElement = informationElement.getChild(Externalization.VARIABLE_NODE);
if (variableElement != null) {
variable = VariableBootstrapper.buildVariableFromElement(variableElement, context, callback);
}
} else {
this.information = BootstrappingUtils.getContentAsString(informationElement, null, BootstrappingUtils.OPTIONAL, null, context);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract InfoMarker<?> build();
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import org.jdom2.Element;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.DisplayMarker;
public class DisplayMarkerBuilder extends BaseDisplayMarkerBuilder<DisplayMarkerBuilder> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public DisplayMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public DisplayMarker build() {
return new DisplayMarker(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.marker.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.marker.InfoMarker;
import org.jdom2.Element;
public class InfoMarkerBuilder extends BaseInfoMarkerBuilder<InfoMarkerBuilder> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all
* the information on fields to initialize.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all
* fields of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
public InfoMarkerBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public InfoMarker<?> build() {
return new InfoMarker(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
......@@ -14,7 +14,6 @@
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.builder.ShapeGraphBuilder;
import org.pushingpixels.trident.Timeline;
......@@ -46,7 +45,7 @@ public class ShapeGraph extends ValueCorona {
protected ColorPair fillColour;
protected ColorPair strokeColour;
protected int strokeWidth;
protected Shape graphShape;
// protected Shape graphShape;
protected Timeline blinkingTimeline;
protected Timeline balisticTimeline;
......@@ -71,7 +70,7 @@ public class ShapeGraph extends ValueCorona {
this.fillColour = builder.fillColour;
this.strokeColour = builder.strokeColour;
this.strokeWidth = builder.strokeWidth;
this.graphShape = builder.graphShape;
this.shape = builder.graphShape;
borderStroke = (builder.strokeWidth > 0) ? new BasicStroke(builder.strokeWidth) : null;
......@@ -95,7 +94,7 @@ public class ShapeGraph extends ValueCorona {
this.fillColour = original.fillColour;
this.strokeColour = original.strokeColour;
this.strokeWidth = original.strokeWidth;
this.graphShape = original.graphShape;
this.shape = original.shape;
borderStroke = (original.strokeWidth > 0) ? new BasicStroke(original.strokeWidth) : null;
......@@ -131,7 +130,6 @@ public class ShapeGraph extends ValueCorona {
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
public void setShownValue(double value) {
shownValue = value;
......@@ -150,6 +148,15 @@ public class ShapeGraph extends ValueCorona {
// ---------------------------------------------------------------------------
@Override
public Shape getShape() {
AffineTransform transform = this.getTransform(null);
transform.scale(scale, scale);
return transform.createTransformedShape(super.getShape());
}
// ---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas) {
if (!active)
......@@ -157,35 +164,40 @@ public class ShapeGraph extends ValueCorona {
Graphics2D localCanvas = (Graphics2D) canvas.create();
centre.toScreenCoordinates();
if (initialTranslation != null)
initialTranslation.toScreenCoordinates();
Point drawAt = centre.add(initialTranslation);
if (this.rotateWithHandle) {
angle = (float) (drawAt.getAngle() % TWO_PI);
}
AffineTransform translation = new AffineTransform();
translation.translate(drawAt.x, drawAt.y);
translation.rotate(angle);
translation.scale(scale, scale);
localCanvas.setTransform(translation);
// centre.toScreenCoordinates();
// if (initialTranslation != null)
// initialTranslation.toScreenCoordinates();
// Point drawAt = centre.add(initialTranslation);
//
// if (this.rotateWithHandle) {
// angle = (float) (drawAt.getAngle() % TWO_PI);
// }
//
// AffineTransform translation = new AffineTransform();
// translation.translate(drawAt.x, drawAt.y);
// translation.rotate(angle);
// translation.scale(scale, scale);
// localCanvas.setTransform(translation);
AffineTransform transform = this.getTransform(null);
transform.scale(scale, scale);
localCanvas.setTransform(transform);
if (this.opacity < 1.0f)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
if (graphShape != null) {
if (shape != null) {
if (fillColour != null) {
localCanvas.setPaint(fillColour.getColor());
localCanvas.fill(graphShape);
localCanvas.fill(shape);
}
if (strokeColour != null) {
localCanvas.setPaint(strokeColour.getColor());
if (borderStroke != null) {
localCanvas.setStroke(borderStroke);
localCanvas.draw(graphShape);
localCanvas.draw(shape);
}
}
}
......
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