Commit a70c44b5 authored by Nico Mack's avatar Nico Mack

Added additional Bootstrapping properties to Scenario Colour Scales

parent 1b938609
......@@ -12,6 +12,7 @@ LOWER_BOUND_RADIUS_NODE=lowerBoundRadius
LOWER_BOUND_VARIABLE_NODE=lowerBoundVariable
LOWER_STOP_ANGLE_NODE=lowerStopAngle
MAPPING_NODE=mapping
MAPPINGS_NODE=mappings
MAXIMUM_VALUE_NODE=maximumValue
MINIMUM_VALUE_NODE=minimumValue
MODIFY_VALUE_ON_ROTATION_NODE=modifyValueOnRotation
......
......@@ -47,6 +47,7 @@ public class CpsNamespace extends NLS {
public static String LOWER_STOP_ANGLE_NODE;
public static String MAPPING_NODE;
public static String MAPPINGS_NODE;
public static String MAXIMUM_VALUE_NODE;
public static String MINIMUM_VALUE_NODE;
public static String MODIFY_VALUE_ON_ROTATION_NODE;
......
......@@ -15,12 +15,14 @@ package lu.list.itis.dkd.tui.utility.scales;
import lu.list.itis.dkd.dbc.annotation.Nullable;
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.ColorFactory;
import lu.list.itis.dkd.tui.utility.CpsNamespace;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.StringUtils;
import lu.list.itis.dkd.tui.utility.ValueRange;
import lu.list.itis.dkd.tui.widget.corona.ShapeFactory;
import com.jgoodies.common.base.Strings;
......@@ -29,6 +31,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.awt.Font;
import java.awt.Shape;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
......@@ -48,6 +52,11 @@ import java.util.List;
public class ColourScale<T extends Comparable<T>> {
private String name;
private List<ColourMapping<T>> mappings;
private Color titleColour;
private Color labelColour;
private Font titleFont;
private Font labelFont;
private Shape mappingShape;
private Color defaultColour;
private String unit;
private String rangeSeparator;
......@@ -60,6 +69,10 @@ public class ColourScale<T extends Comparable<T>> {
private static final String AUTO = "auto"; //$NON-NLS-1$
private static final String DEFAULT_RANGE_SEPARATOR = "-"; //$NON-NLS-1$
private static final Color DEFAULT_COLOUR = Color.BLACK;
private static final Font DEFAULT_FONT = new Font("Arial", Font.PLAIN, 12);
private static final Shape DEFAULT_SHAPE = ShapeFactory.buildSquare(12);
private static final Logger LOGGER = LoggerFactory.getLogger(ColourScale.class.getSimpleName());
// ---------------------------------------------------------------------------
......@@ -69,6 +82,10 @@ public class ColourScale<T extends Comparable<T>> {
// ---------------------------------------------------------------------------
public ColourScale() {
this.titleFont = DEFAULT_FONT;
this.titleColour = DEFAULT_COLOUR;
this.labelFont = DEFAULT_FONT;
this.labelColour = DEFAULT_COLOUR;
this.mappings = new ArrayList<>();
this.defaultColour = Color.WHITE;
format = new DecimalFormat();
......@@ -118,13 +135,28 @@ public class ColourScale<T extends Comparable<T>> {
defaultColour = new Color(StringUtils.getIntegerValue(BootstrappingUtils.getAttributeAsString(rootElement, Externalization.DEFAULT_NODE, BootstrappingUtils.OPTIONAL, "0xFFFFFF")));
List<Element> mappingElements = rootElement.getChildren(CpsNamespace.MAPPING_NODE);
if ((mappingElements != null) && !mappingElements.isEmpty()) {
List<Color> automaticColours = ColorFactory.makeRainbowColours(mappingElements.size());
Iterator<Color> colourIterator = automaticColours.iterator();
Element titleElement = rootElement.getChild(Externalization.TITLE_NODE);
if (titleElement != null) {
this.titleFont = BootstrappingUtils.getContentAsFont(titleElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, DEFAULT_FONT, null);
this.titleColour = BootstrappingUtils.getContentAsColour(titleElement, Externalization.TEXT_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, DEFAULT_COLOUR, null);
}
Element mappingsElement = rootElement.getChild(CpsNamespace.MAPPINGS_NODE);
if (mappingsElement != null) {
this.labelFont = BootstrappingUtils.getContentAsFont(mappingsElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, DEFAULT_FONT, null);
this.labelColour = BootstrappingUtils.getContentAsColour(mappingsElement, Externalization.TEXT_COLOUR_ELEMENT, BootstrappingUtils.OPTIONAL, DEFAULT_COLOUR, null);
Element shapeElement = mappingsElement.getChild(Externalization.SHAPE_NODE);
this.mappingShape = (shapeElement != null) ? ShapeBootstrapper.getShape(shapeElement, null, null) : DEFAULT_SHAPE;
for (Element mapping : mappingElements) {
this.mappings.add(this.buildValueRange(mapping, colourIterator.next()));
List<Element> mappingElements = mappingsElement.getChildren(CpsNamespace.MAPPING_NODE);
if ((mappingElements != null) && !mappingElements.isEmpty()) {
List<Color> automaticColours = ColorFactory.makeRainbowColours(mappingElements.size());
Iterator<Color> colourIterator = automaticColours.iterator();
for (Element mapping : mappingElements) {
this.mappings.add(this.buildValueRange(mapping, colourIterator.next()));
}
}
}
}
......@@ -172,6 +204,38 @@ public class ColourScale<T extends Comparable<T>> {
public String getUnit() {
return this.unit;
}
// ---------------------------------------------------------------------------
public Font getTitleFont() {
return this.titleFont;
}
// ---------------------------------------------------------------------------
public Color getTitleColour() {
return this.titleColour;
}
// ---------------------------------------------------------------------------
public Shape getMappingShape() {
return this.mappingShape;
}
// ---------------------------------------------------------------------------
public Font getLabelFont() {
return this.labelFont;
}
// ---------------------------------------------------------------------------
public Color getLabelColour() {
return this.labelColour;
}
// ---------------------------------------------------------------------------
public boolean addMapping(ColourMapping<T> mapping) {
......
......@@ -15,7 +15,6 @@ package lu.list.itis.dkd.tui.utility.scales;
import lu.list.itis.dkd.tui.widget.corona.ShapeFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
......@@ -42,9 +41,6 @@ import java.util.List;
public class ColourScaleRenderer {
private ColourScale<?> scale;
private Shape mappingShape;
private Color fontColour;
private Font mappingFont;
private int horizontalGap;
private int verticalGap;
private boolean renderTitle;
......@@ -70,9 +66,6 @@ public class ColourScaleRenderer {
this.scale = scale;
this.horizontalGap = DEFAULT_GAP;
this.verticalGap = DEFAULT_GAP;
this.mappingShape = DEFAULT_SHAPE;
this.mappingFont = DEFAULT_FONT;
this.fontColour = Color.BLACK;
this.renderTitle = true;
}
......@@ -101,13 +94,13 @@ public class ColourScaleRenderer {
List<ColourMapping<T>> mappings = scale.getColourMappings();
Dimension maximum;
Rectangle2D shapeBounds = mappingShape.getBounds2D();
Rectangle2D shapeBounds = scale.getMappingShape().getBounds2D();
maximum = this.getMaxDimension(null, (int) shapeBounds.getWidth(), (int) shapeBounds.getHeight());
FontRenderContext frc = new FontRenderContext(null, false, false);
if (this.renderTitle) {
GlyphVector glyphVector = mappingFont.createGlyphVector(frc, scale.getTitle());
GlyphVector glyphVector = scale.getTitleFont().createGlyphVector(frc, scale.getTitle());
Rectangle2D bounds = glyphVector.getLogicalBounds();
maximum = this.getMaxDimension(maximum, (int) bounds.getWidth(), (int) bounds.getHeight());
}
......@@ -115,7 +108,7 @@ public class ColourScaleRenderer {
for (ColourMapping<T> mapping : mappings) {
String label = scale.getLabelFor(mapping);
GlyphVector glyphVector = mappingFont.createGlyphVector(frc, label);
GlyphVector glyphVector = scale.getLabelFont().createGlyphVector(frc, label);
Rectangle2D bounds = glyphVector.getLogicalBounds();
maximum = this.getMaxDimension(maximum, (int) bounds.getWidth(), (int) bounds.getHeight());
}
......@@ -135,27 +128,29 @@ public class ColourScaleRenderer {
rendered = new BufferedImage(required.width, required.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D offscreen = rendered.createGraphics();
offscreen.setRenderingHints(renderingHints);
FontMetrics metrics = offscreen.getFontMetrics(mappingFont);
FontMetrics metrics = offscreen.getFontMetrics(scale.getTitleFont());
Rectangle2D shapeBounds = mappingShape.getBounds2D();
Rectangle2D shapeBounds = scale.getMappingShape().getBounds2D();
List<ColourMapping<T>> mappings = scale.getColourMappings();
double offset = (double) required.height / ((this.renderTitle) ? mappings.size() + 1 : mappings.size());
double fontBaseLineOffset = metrics.getAscent() / 2;
offscreen.translate(-shapeBounds.getX(), (offset / 2));
offscreen.setFont(mappingFont);
offscreen.setFont(scale.getTitleFont());
if (this.renderTitle) {
offscreen.setPaint(fontColour);
offscreen.setPaint(scale.getTitleColour());
offscreen.drawString(scale.getTitle(), (int) (shapeBounds.getX() + shapeBounds.getWidth() + horizontalGap), (int) fontBaseLineOffset);
offscreen.translate(0, offset);
}
offscreen.setFont(scale.getLabelFont());
for (ColourMapping<T> mapping : mappings) {
offscreen.setPaint(mapping.getColour());
offscreen.fill(mappingShape);
offscreen.setPaint(fontColour);
offscreen.fill(scale.getMappingShape());
offscreen.setPaint(scale.getLabelColour());
offscreen.drawString(scale.getLabelFor(mapping), (int) (shapeBounds.getX() + shapeBounds.getWidth() + horizontalGap), (int) fontBaseLineOffset);
offscreen.translate(0, offset);
}
......@@ -181,24 +176,6 @@ public class ColourScaleRenderer {
// ---------------------------------------------------------------------------
public void setFont(Font font) {
this.mappingFont = font;
}
// ---------------------------------------------------------------------------
public void setFontColour(Color colour) {
this.fontColour = colour;
}
// ---------------------------------------------------------------------------
public void setShape(Shape shape) {
this.mappingShape = shape;
}
// ---------------------------------------------------------------------------
public void setRenderTitle(boolean renderIt) {
this.renderTitle = renderIt;
}
......
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