Commit bcedad68 authored by Nico Mack's avatar Nico Mack

Harmonization and Cleanup of Coronas and respective Builders.

Deprecation of obsolete Coronas
parent 31f0e344
......@@ -109,6 +109,7 @@ STROKE_COLOUR_ELEMENT=strokeColour
LABEL_COLOUR_ELEMENT=labelColour
FACE_COLOUR_ELEMENT=faceColour
BEZEL_COLOUR_ELEMENT=bezelColour
TICKMARK_COLOUR_NODE=tickMarkColour
SELECTED_ELEMENT=selected
DESELECTED_ELEMENT=deselected
ABOVE_ELEMENT=above
......
......@@ -632,14 +632,14 @@ public class BootstrappingUtils {
* @param rootElement
* @param childName
* @param optional
* @param defaultColour
* @param defaultAngle
* @return
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public static double getContentAsAngle(Element rootElement, String childName, boolean optional, double defaultAngle) throws BuildException {
return getContentAsAngle(rootElement, childName, optional, defaultAngle, null);
public static double getContentAsRadians(Element rootElement, String childName, boolean optional, Double defaultAngle) throws BuildException {
return getContentAsRadians(rootElement, childName, optional, defaultAngle, null);
}
// ---------------------------------------------------------------------------
......@@ -647,14 +647,29 @@ public class BootstrappingUtils {
* @param rootElement
* @param childName
* @param optional
* @param defaultColour
* @param defaultAngle
* @return
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public static double getContentAsDegrees(Element rootElement, String childName, boolean optional, Double defaultAngle) throws BuildException {
return getContentAsDegrees(rootElement, childName, optional, defaultAngle, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param childName
* @param optional
* @param defaultAngle
* @param context
* @return
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public static double getContentAsAngle(Element rootElement, String childName, boolean optional, double defaultAngle, BootstrapContext context) throws BuildException {
public static double getContentAsRadians(Element rootElement, String childName, boolean optional, Double defaultAngle, BootstrapContext context) throws BuildException {
double value = 0;
String contentAsString = Strings.nullToEmpty(getContent(rootElement, childName, context));
if (contentAsString.length() > 0) {
......@@ -682,4 +697,44 @@ public class BootstrappingUtils {
return value;
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param childName
* @param optional
* @param defaultAngle
* @param context
* @return
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public static double getContentAsDegrees(Element rootElement, String childName, boolean optional, Double defaultAngle, BootstrapContext context) throws BuildException {
double value = 0;
String contentAsString = Strings.nullToEmpty(getContent(rootElement, childName, context));
if (contentAsString.length() > 0) {
Matcher angleMatcher = ANGLE_PATTERN.matcher(contentAsString);
if (angleMatcher.matches()) {
String angle = angleMatcher.group(1);
String unit = angleMatcher.group(2);
unit = (Strings.isNullOrEmpty(unit)) ? "deg" : unit.toLowerCase(); //$NON-NLS-1$
try {
value = Double.parseDouble(angle);
} catch (NumberFormatException exception) {
throw new BuildException("Value provide for " + childName + " node must be a decimal number. Specified value " + angle + " could not be interpreted as such!"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
if ("rad".equals(unit)) { //$NON-NLS-1$
value = Math.toDegrees(value);
}
}
} else {
if (optional)
value = defaultAngle;
else
throw new BuildException("Node " + childName + " is mandatory and MUST be provided!"); //$NON-NLS-1$//$NON-NLS-2$
}
return value;
}
}
......@@ -57,6 +57,7 @@ public class Externalization extends NLS {
public static String EDGE_COLOUR_NODE;
public static String EMPTY_STRING;
public static String FILL_COLOUR_NODE;
public static String TICKMARK_COLOUR_NODE;
public static String FONT_NODE;
public static String FONT_SIZE_NODE;
public static String GLOBAL_STATE_LISTENER_NODE;
......
......@@ -243,7 +243,7 @@ public class Point extends Float implements KdComparator<Point> {
this.x = (float) BootstrappingUtils.getContentAsDouble(rootNode, Externalization.X_NODE, BootstrappingUtils.OPTIONAL, 0.0, context);
this.y = (float) BootstrappingUtils.getContentAsDouble(rootNode, Externalization.Y_NODE, BootstrappingUtils.OPTIONAL, 0.0, context);
this.angle = (float) BootstrappingUtils.getContentAsAngle(rootNode, Externalization.Z_NODE, BootstrappingUtils.OPTIONAL, 0.0, context);
this.angle = (float) BootstrappingUtils.getContentAsRadians(rootNode, Externalization.Z_NODE, BootstrappingUtils.OPTIONAL, 0.0, context);
this.state = CoordinateStateBootstrapper.getCoordinateState(rootNode, this, context, callback);
//
//
......
......@@ -41,6 +41,7 @@ import java.awt.image.BufferedImage;
* @since 1.0
* @version 2.3.0
*/
@Deprecated
@NonNullByDefault
public class Radius extends Corona {
/** The radius of the ellipse {@link Shape}. */
......
package lu.list.itis.dkd.tui.widget.corona;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.widget.corona.builder.ScaleBuilder;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
......@@ -11,77 +14,83 @@ import eu.hansolo.steelseries.gauges.AbstractRadial;
import eu.hansolo.steelseries.gauges.Radial;
import eu.hansolo.steelseries.tools.BackgroundImageFactory;
import eu.hansolo.steelseries.tools.FrameType;
import eu.hansolo.steelseries.tools.GaugeType;
import eu.hansolo.steelseries.tools.Model;
import eu.hansolo.steelseries.tools.Orientation;
import eu.hansolo.steelseries.tools.TickmarkImageFactory;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.corona.builder.ScaleBuilder;
/**
* @author nmack
* @date 27 Apr 2015
*
* <br>$Log: Gauge.java,v $
* <br>
* $Log: Gauge.java,v $
*/
//***************************************************************************
//* Class Definition and Members *
//***************************************************************************
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class Scale extends Corona
{
AbstractRadial scale;
int width;
int height;
public class Scale extends Corona {
protected AbstractRadial scale;
protected int width;
protected int height;
protected Color fillColour;
protected Color tickMarkColour;
BufferedImage rendered;
Rectangle bounds;
protected BufferedImage rendered;
protected Point scaleCentre;
//***************************************************************************
//* Constants *
//***************************************************************************
// ***************************************************************************
// * Constants *
// ***************************************************************************
protected static final TickmarkImageFactory TICKMARK_FACTORY = TickmarkImageFactory.INSTANCE;
protected static final BackgroundImageFactory BACKGROUND_FACTORY = BackgroundImageFactory.INSTANCE;
private static final int imageType = BufferedImage.TYPE_INT_ARGB; // BufferedImage.TYPE_4BYTE_ABGR; //BufferedImage.TYPE_INT_ARGB
private static final int imageType = BufferedImage.TYPE_INT_ARGB;
//---------------------------------------------------------------------------
//***************************************************************************
//* Constructor(s) *
//***************************************************************************
//---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public Scale(ScaleBuilder builder)
{
/**
* @param builder
*/
public Scale(ScaleBuilder builder) {
super(builder);
width = (int)builder.width;
height = (int)builder.height;
width = (int) builder.width;
height = (int) builder.height;
tickMarkColour = builder.tickMarkColour;
scale = new Radial();
scale.setMinValue(builder.lowerBound);
scale.setMaxValue(builder.upperBound);
scale.setFrameType (FrameType.ROUND);
scale.setFrameType(FrameType.ROUND);
scale.setFrameVisible(false);
scale.setPostsVisible(false);
scale.setLcdVisible(false);
scale.setVisible(true);
scale.setSize(width, height);
scale.setLedVisible(false);
if (tickMarkColour != null) {
scale.setTickmarkColor(tickMarkColour);
scale.setTickmarkColorFromThemeEnabled(false);
}
Model model = scale.getModel();
rendered = new BufferedImage(width,height,imageType);
bounds = new Rectangle (0,0,width,height);
BACKGROUND_FACTORY.createRadialBackground(width,
scale.getBackgroundColor(),
model.getCustomBackground(),
model.getTextureColor(),
rendered);
rendered = new BufferedImage(width, height, imageType);
scaleCentre = new Point(width / 2, height / 2, 0, ScreenCoordinates.class);
// BACKGROUND_FACTORY.createRadialBackground(width,
// scale.getBackgroundColor(),
// model.getCustomBackground(),
// model.getTextureColor(),
// rendered);
TICKMARK_FACTORY.create_RADIAL_TICKMARKS_Image(width,
model.getNiceMinValue(),
......@@ -107,7 +116,7 @@ public Scale(ScaleBuilder builder)
scale.getSections(),
0.33f,
-0.04f,
new Point2D.Double((width/2),(height/2)),
new Point2D.Double((width / 2), (height / 2)),
new Point2D.Double(0, 0),
Orientation.NORTH,
model.getTicklabelOrientation(),
......@@ -116,39 +125,30 @@ public Scale(ScaleBuilder builder)
rendered);
}
//---------------------------------------------------------------------------
//***************************************************************************
//* Primitives *
//***************************************************************************
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//***************************************************************************
//* Class Body *
//***************************************************************************
//---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas)
{
if (!active) return;
centre.toScreenCoordinates();
if(initialTranslation != null) initialTranslation.toScreenCoordinates();
Point drawAt = centre.add(initialTranslation);
AffineTransform rotation = new AffineTransform();
rotation.translate(drawAt.x, drawAt.y);
canvas.drawImage(rendered, rotation, null);
// clippingRegion.reset();
// clippingRegion.add(new Area(rotation.createTransformedShape(bounds)));
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas) {
if (!active)
return;
AffineTransform transform = this.getTransform(scaleCentre);
canvas.drawImage(rendered, transform, null);
}
//---------------------------------------------------------------------------
//***************************************************************************
//* End of Class *
//***************************************************************************
//---------------------------------------------------------------------------
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
......@@ -41,7 +41,6 @@ public class Sector extends IndexedCorona {
private ColorPair fillColour;
private ColorPair strokeColour;
private ColorPair textColour;
private String label;
private Shape curvedText;
private Stroke borderStroke;
......@@ -65,7 +64,6 @@ public class Sector extends IndexedCorona {
public Sector(SectorBuilder builder) {
super(builder);
// index = builder.index;
outerRadius = builder.outerRadius;
innerRadius = builder.innerRadius;
fillColour = builder.fillColour;
......@@ -128,7 +126,6 @@ public class Sector extends IndexedCorona {
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* toggles selection state of this sector.
*
......@@ -136,6 +133,8 @@ public class Sector extends IndexedCorona {
* specify <code>true</code> to select this sector, <code>false</code> to de-select this
* sector
*/
// ---------------------------------------------------------------------------
@Override
public void setSelected(boolean selectIt) {
super.setSelected(selectIt);
......@@ -154,19 +153,6 @@ public class Sector extends IndexedCorona {
Graphics2D localCanvas = (Graphics2D) canvas.create();
localCanvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// centre.toScreenCoordinates();
// if (initialTranslation != null) {
// initialTranslation.toScreenCoordinates();
// }
//
// Point drawAt = centre.add(initialTranslation);
//
// AffineTransform sectorTransform = new AffineTransform();
// sectorTransform.translate(drawAt.x, drawAt.y);
// if (this.rotateWithHandle)
// sectorTransform.rotate(drawAt.getAngle());
// Shape transformed = sectorTransform.createTransformedShape(sector);
AffineTransform transform = this.getTransform(null);
Shape transformed = transform.createTransformedShape(sector);
......
......@@ -37,6 +37,7 @@ import java.awt.geom.AffineTransform;
* @since 1.0
* @version 2.3.0
*/
@Deprecated
@NonNullByDefault
public class Shadow extends Corona {
/**
......
......@@ -44,6 +44,7 @@ import java.awt.geom.AffineTransform;
* @since 1.0
* @version 2.3.0
*/
@Deprecated
@NonNullByDefault
public class TextBox extends Corona implements ContextEventListener, InformationReceiver<String> {
/** Field holding the text to visualise. */
......
......@@ -143,7 +143,7 @@ public abstract class CoronaBuilder<B extends CoronaBuilder<B>> {
}
drawPriority = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.DRAW_PRIORITY_NODE, BootstrappingUtils.MANDATORY, 0, context);
initialRotation = BootstrappingUtils.getContentAsAngle(rootElement, Externalization.INITIAL_ROTATION_NODE, BootstrappingUtils.OPTIONAL, 0.0, context);
initialRotation = BootstrappingUtils.getContentAsRadians(rootElement, Externalization.INITIAL_ROTATION_NODE, BootstrappingUtils.OPTIONAL, 0.0, context);
initialTranslation = new Point(rootElement.getChild(Externalization.INITIAL_TRANSLATION_NODE), context, callback);
......
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;
......@@ -8,6 +11,8 @@ import lu.list.itis.dkd.tui.widget.corona.Scale;
import org.jdom2.Element;
import java.awt.Color;
/**
* @author nmack
* @date 28 Apr 2015
......@@ -21,10 +26,16 @@ import org.jdom2.Element;
// ***************************************************************************
public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
/** */
public double width;
/** */
public double height;
/** */
public double lowerBound;
/** */
public double upperBound;
/** */
public Color tickMarkColour;
// ***************************************************************************
// * Constants *
......@@ -35,55 +46,67 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param centre
*/
// ---------------------------------------------------------------------------
public ScaleBuilder(Point centre) {
super(centre);
// TODO Auto-generated constructor stub
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public ScaleBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
/** Mandatory fields */
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
width = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.WIDTH_NODE, BootstrappingUtils.MANDATORY, null);
height = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.HEIGHT_NODE, BootstrappingUtils.MANDATORY, null);
lowerBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.LOWER_BOUND_NODE, BootstrappingUtils.MANDATORY, null);
upperBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.UPPER_BOUND_NODE, BootstrappingUtils.MANDATORY, null);
public ScaleBuilder(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 {
width = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.WIDTH_NODE, BootstrappingUtils.MANDATORY, null, context);
height = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.HEIGHT_NODE, BootstrappingUtils.MANDATORY, null, context);
lowerBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.LOWER_BOUND_NODE, BootstrappingUtils.MANDATORY, null, context);
upperBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.UPPER_BOUND_NODE, BootstrappingUtils.MANDATORY, null, context);
tickMarkColour = BootstrappingUtils.getContentAsColour(rootElement, Externalization.TICKMARK_COLOUR_NODE, BootstrappingUtils.OPTIONAL, Color.BLACK, context);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public Scale build() throws BuildException {
// TODO Auto-generated method stub
return new Scale(this);
}
// ---------------------------------------------------------------------------
/**
* Method used to set the dimensions of the gauge
* Method used to set the dimensions of the scale
*
* @param width
* The width of the gauge
* @param upperBound
* The height of the gauge
* The width of the scale
* @param height
* The height of the scale
* @return An instance of the builder for chain-calling.
*/
// ---------------------------------------------------------------------------
......@@ -97,12 +120,12 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
// ---------------------------------------------------------------------------
/**
* Method used to set the upper and lower bound of the dial
* Method used to set the upper and lower bound of the scale
*
* @param lowerBound
* The lower bound of the dial
* The lower bound of the scale
* @param upperBound
* The upper bound of the dial
* The upper bound of the scale
* @return An instance of the builder for chain-calling.
*/
// ---------------------------------------------------------------------------
......@@ -114,6 +137,30 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
return this;
}
// ---------------------------------------------------------------------------
/**
* Method used to set the colour of the scales' tick marks
*
* @param colour
* The new tick mark colour
* @return An instance of the builder for chain-calling.
*/
// ---------------------------------------------------------------------------
public ScaleBuilder withTickMarkColour(Color colour) {
this.tickMarkColour = colour;
return this;
}
// ---------------------------------------------------------------------------
@Override
public Scale build() throws BuildException {
// TODO Auto-generated method stub
return new Scale(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
......
......@@ -28,19 +28,30 @@ import java.awt.Font;
// ***************************************************************************
public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
public int index;
/** Specifies the inner radius of the sector to build */
public double innerRadius;
/** Specifies the outer radius of the sector to build */
public double outerRadius;
/** Specifies the angle in degrees where the sector starts from */
public int startAngle;
/** Specifies the length of the arc expressed in degrees */
public int arcSpan;
/** Specifies an optional gap (spacer) on both ends of the sector to build */
public int gap;
/** Specifies the color pair (selected / unselected) to be used for filling the sector */
public ColorPair fillColour;
/**
* Specifies the color pair (selected / unselected) to be used for the outline (stroke) of the
* sector
*/
public ColorPair strokeColour;
/** Specifies the color pair (selected / unselected) to be used for the title of the sector */
public ColorPair textColour;
/** Specifies the title to be shown inside the sector */
public String title;
/** Specifies the width of the stroke to be used to paint the outline of the sector */
public int strokeWidth;
/** Specifies the font to be used for rendering the title */
public Font textFont;
// ***************************************************************************
......@@ -60,22 +71,26 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
}