Commit 2a4e31f5 authored by Nico Mack's avatar Nico Mack

Implemented Indicator Corona (+builders)

Fixed a bug in DisplayMarker to support multiple ValueCoronas per
variable
parent 91bdf8d9
......@@ -13,6 +13,7 @@ LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable
LOWER_STOP_ANGLE_NODE=lowerStopAngle
MAPPING_NODE=mapping
MAPPINGS_NODE=mappings
MAINTAIN_ASPECT_RATIO_NODE=maintainAspectRatio
MAXIMUM_VALUE_NODE=maximumValue
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
......@@ -25,6 +26,7 @@ SCALES_NODE=scales
SELECTED_ITEMS_VARIABLE_NODE=selectedItemsVariable
SELECTED_RADIUS_NODE=selectedRadius
STEP_SIZE_NODE=stepSize
STRETCH_TO_FIT_NODE=stretchToFit
UPPER_BOUND_RADIUS_NODE=upperBoundRadius
UPPER_BOUND_VARIABLE_NODE=upperBoundVariable
UPPER_STOP_ANGLE_NODE=upperStopAngle
......
......@@ -8,6 +8,9 @@ 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 com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import org.python.google.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -26,7 +29,7 @@ import java.util.Map;
public class DisplayMarker extends InfoMarker implements InputChangeListener, VariableBased {
private HashMap<String, Variable<?>> variables;
HashMap<String, ValueCorona> dispatcher;
private Multimap<String, ValueCorona> dispatcher;
// ***************************************************************************
// * Constants *
......@@ -45,7 +48,7 @@ public class DisplayMarker extends InfoMarker implements InputChangeListener, Va
super(builder);
this.variables = new HashMap<>();
this.dispatcher = new HashMap<>();
this.dispatcher = TreeMultimap.create();
}
// ---------------------------------------------------------------------------
......@@ -70,7 +73,7 @@ public class DisplayMarker extends InfoMarker implements InputChangeListener, Va
private void setupDispatcher() {
this.variables = new HashMap<>();
this.dispatcher = new HashMap<>();
this.dispatcher = TreeMultimap.create();
List<ValueCorona> displays = this.getCoronas(ValueCorona.class);
for (ValueCorona display : displays) {
......@@ -108,12 +111,14 @@ public class DisplayMarker extends InfoMarker implements InputChangeListener, Va
@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$
Collection<ValueCorona> displays = dispatcher.get(variableName);
for (ValueCorona display : displays) {
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$
}
}
}
......
......@@ -48,6 +48,7 @@ public class CpsNamespace extends NLS {
public static String MAPPING_NODE;
public static String MAPPINGS_NODE;
public static String MAINTAIN_ASPECT_RATIO_NODE;
public static String MAXIMUM_VALUE_NODE;
public static String MINIMUM_VALUE_NODE;
public static String MODIFY_VALUE_ON_ROTATION_NODE;
......@@ -65,6 +66,7 @@ public class CpsNamespace extends NLS {
public static String SELECTED_RADIUS_NODE;
public static String STEP_SIZE_NODE;
public static String STRETCH_TO_FIT_NODE;
public static String UPPER_BOUND_RADIUS_NODE;
public static String UPPER_BOUND_VARIABLE_NODE;
......
This diff is collapsed.
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
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.bootstrapping.ShapeBootstrapper;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.ColorPair;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.Indicator;
import org.jdom2.Element;
import java.awt.Color;
import java.awt.Font;
import java.awt.Shape;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseIndicatorBuilder<B extends ValueCoronaBuilder<B>> extends ValueCoronaBuilder<B> {
public ColorPair strokeColour;
public ColorPair fillColour;
public ColorPair textColour;
public Shape labelShape;
public Font textFont;
public int strokeWidth;
public String labelFormat;
public boolean stretchToFit;
public boolean maintainAspectRatio;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param centre
*/
// ---------------------------------------------------------------------------
public BaseIndicatorBuilder(Point centre) {
super(centre);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseIndicatorBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseIndicatorBuilder(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 {
fillColour = buildColorPair(rootElement.getChild(Externalization.FILL_COLOUR_ELEMENT), BootstrappingUtils.MANDATORY, context);
strokeColour = buildColorPair(rootElement.getChild(Externalization.STROKE_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
textColour = buildColorPair(rootElement.getChild(Externalization.TEXT_COLOUR_ELEMENT), BootstrappingUtils.OPTIONAL, context);
labelShape = ShapeBootstrapper.getShape(rootElement.getChild(Externalization.LABEL_SHAPE_NODE), context, callback);
stretchToFit = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.STRETCH_TO_FIT_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE);
maintainAspectRatio = BootstrappingUtils.getContentAsBoolean(rootElement, CpsNamespace.MAINTAIN_ASPECT_RATIO_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE);
labelFormat = BootstrappingUtils.getContentAsString(rootElement, Externalization.LABEL_FORMAT_NODE, BootstrappingUtils.OPTIONAL, null);
textFont = BootstrappingUtils.getContentAsFont(rootElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, new Font("Monospaced", Font.BOLD, 14), context);
}
// ---------------------------------------------------------------------------
private ColorPair buildColorPair(Element rootElement, boolean optional, BootstrapContext context) throws BuildException {
ColorPair color = null;
if (rootElement == null)
return null;
Color selectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.SELECTED_ELEMENT, optional, null, context);
Color deselectedColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.DESELECTED_ELEMENT, optional, null, context);
color = new ColorPair(selectedColour, deselectedColour);
return color;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public abstract Indicator build() throws BuildException;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.widget.corona.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.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.Indicator;
import org.jdom2.Element;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 2.5.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class IndicatorBuilder<B extends IndicatorBuilder<B>> extends BaseIndicatorBuilder<B> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public IndicatorBuilder(Point centre) {
super(centre);
}
public IndicatorBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
public IndicatorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public Indicator build() {
return new Indicator(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
\ No newline at end of file
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