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 ...@@ -109,6 +109,7 @@ STROKE_COLOUR_ELEMENT=strokeColour
LABEL_COLOUR_ELEMENT=labelColour LABEL_COLOUR_ELEMENT=labelColour
FACE_COLOUR_ELEMENT=faceColour FACE_COLOUR_ELEMENT=faceColour
BEZEL_COLOUR_ELEMENT=bezelColour BEZEL_COLOUR_ELEMENT=bezelColour
TICKMARK_COLOUR_NODE=tickMarkColour
SELECTED_ELEMENT=selected SELECTED_ELEMENT=selected
DESELECTED_ELEMENT=deselected DESELECTED_ELEMENT=deselected
ABOVE_ELEMENT=above ABOVE_ELEMENT=above
......
...@@ -632,14 +632,14 @@ public class BootstrappingUtils { ...@@ -632,14 +632,14 @@ public class BootstrappingUtils {
* @param rootElement * @param rootElement
* @param childName * @param childName
* @param optional * @param optional
* @param defaultColour * @param defaultAngle
* @return * @return
* @throws BuildException * @throws BuildException
*/ */
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public static double getContentAsAngle(Element rootElement, String childName, boolean optional, double defaultAngle) throws BuildException { public static double getContentAsRadians(Element rootElement, String childName, boolean optional, Double defaultAngle) throws BuildException {
return getContentAsAngle(rootElement, childName, optional, defaultAngle, null); return getContentAsRadians(rootElement, childName, optional, defaultAngle, null);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -647,14 +647,29 @@ public class BootstrappingUtils { ...@@ -647,14 +647,29 @@ public class BootstrappingUtils {
* @param rootElement * @param rootElement
* @param childName * @param childName
* @param optional * @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 * @param context
* @return * @return
* @throws BuildException * @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; double value = 0;
String contentAsString = Strings.nullToEmpty(getContent(rootElement, childName, context)); String contentAsString = Strings.nullToEmpty(getContent(rootElement, childName, context));
if (contentAsString.length() > 0) { if (contentAsString.length() > 0) {
...@@ -682,4 +697,44 @@ public class BootstrappingUtils { ...@@ -682,4 +697,44 @@ public class BootstrappingUtils {
return value; 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 { ...@@ -57,6 +57,7 @@ public class Externalization extends NLS {
public static String EDGE_COLOUR_NODE; public static String EDGE_COLOUR_NODE;
public static String EMPTY_STRING; public static String EMPTY_STRING;
public static String FILL_COLOUR_NODE; public static String FILL_COLOUR_NODE;
public static String TICKMARK_COLOUR_NODE;
public static String FONT_NODE; public static String FONT_NODE;
public static String FONT_SIZE_NODE; public static String FONT_SIZE_NODE;
public static String GLOBAL_STATE_LISTENER_NODE; public static String GLOBAL_STATE_LISTENER_NODE;
...@@ -212,7 +213,7 @@ public class Externalization extends NLS { ...@@ -212,7 +213,7 @@ public class Externalization extends NLS {
public static String MARKER_BUILDER_NAMESPACE; public static String MARKER_BUILDER_NAMESPACE;
public static String POINTING_OFFSET_NODE; public static String POINTING_OFFSET_NODE;
public static String PATH_NODE; public static String PATH_NODE;
......
...@@ -243,7 +243,7 @@ public class Point extends Float implements KdComparator<Point> { ...@@ -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.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.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); this.state = CoordinateStateBootstrapper.getCoordinateState(rootNode, this, context, callback);
// //
// //
......
...@@ -41,6 +41,7 @@ import java.awt.image.BufferedImage; ...@@ -41,6 +41,7 @@ import java.awt.image.BufferedImage;
* @since 1.0 * @since 1.0
* @version 2.3.0 * @version 2.3.0
*/ */
@Deprecated
@NonNullByDefault @NonNullByDefault
public class Radius extends Corona { public class Radius extends Corona {
/** The radius of the ellipse {@link Shape}. */ /** The radius of the ellipse {@link Shape}. */
......
...@@ -41,7 +41,6 @@ public class Sector extends IndexedCorona { ...@@ -41,7 +41,6 @@ public class Sector extends IndexedCorona {
private ColorPair fillColour; private ColorPair fillColour;
private ColorPair strokeColour; private ColorPair strokeColour;
private ColorPair textColour; private ColorPair textColour;
private String label; private String label;
private Shape curvedText; private Shape curvedText;
private Stroke borderStroke; private Stroke borderStroke;
...@@ -65,7 +64,6 @@ public class Sector extends IndexedCorona { ...@@ -65,7 +64,6 @@ public class Sector extends IndexedCorona {
public Sector(SectorBuilder builder) { public Sector(SectorBuilder builder) {
super(builder); super(builder);
// index = builder.index;
outerRadius = builder.outerRadius; outerRadius = builder.outerRadius;
innerRadius = builder.innerRadius; innerRadius = builder.innerRadius;
fillColour = builder.fillColour; fillColour = builder.fillColour;
...@@ -128,7 +126,6 @@ public class Sector extends IndexedCorona { ...@@ -128,7 +126,6 @@ public class Sector extends IndexedCorona {
// * Class Body * // * Class Body *
// *************************************************************************** // ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** /**
* toggles selection state of this sector. * toggles selection state of this sector.
* *
...@@ -136,6 +133,8 @@ public class Sector extends IndexedCorona { ...@@ -136,6 +133,8 @@ public class Sector extends IndexedCorona {
* specify <code>true</code> to select this sector, <code>false</code> to de-select this * specify <code>true</code> to select this sector, <code>false</code> to de-select this
* sector * sector
*/ */
// ---------------------------------------------------------------------------
@Override @Override
public void setSelected(boolean selectIt) { public void setSelected(boolean selectIt) {
super.setSelected(selectIt); super.setSelected(selectIt);
...@@ -154,19 +153,6 @@ public class Sector extends IndexedCorona { ...@@ -154,19 +153,6 @@ public class Sector extends IndexedCorona {
Graphics2D localCanvas = (Graphics2D) canvas.create(); Graphics2D localCanvas = (Graphics2D) canvas.create();
localCanvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 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); AffineTransform transform = this.getTransform(null);
Shape transformed = transform.createTransformedShape(sector); Shape transformed = transform.createTransformedShape(sector);
......
...@@ -37,6 +37,7 @@ import java.awt.geom.AffineTransform; ...@@ -37,6 +37,7 @@ import java.awt.geom.AffineTransform;
* @since 1.0 * @since 1.0
* @version 2.3.0 * @version 2.3.0
*/ */
@Deprecated
@NonNullByDefault @NonNullByDefault
public class Shadow extends Corona { public class Shadow extends Corona {
/** /**
......
...@@ -44,6 +44,7 @@ import java.awt.geom.AffineTransform; ...@@ -44,6 +44,7 @@ import java.awt.geom.AffineTransform;
* @since 1.0 * @since 1.0
* @version 2.3.0 * @version 2.3.0
*/ */
@Deprecated
@NonNullByDefault @NonNullByDefault
public class TextBox extends Corona implements ContextEventListener, InformationReceiver<String> { public class TextBox extends Corona implements ContextEventListener, InformationReceiver<String> {
/** Field holding the text to visualise. */ /** Field holding the text to visualise. */
......
...@@ -143,7 +143,7 @@ public abstract class CoronaBuilder<B extends CoronaBuilder<B>> { ...@@ -143,7 +143,7 @@ public abstract class CoronaBuilder<B extends CoronaBuilder<B>> {
} }
drawPriority = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.DRAW_PRIORITY_NODE, BootstrappingUtils.MANDATORY, 0, context); 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); initialTranslation = new Point(rootElement.getChild(Externalization.INITIAL_TRANSLATION_NODE), context, callback);
......
package lu.list.itis.dkd.tui.widget.corona.builder; 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.BootstrappingUtils;
import lu.list.itis.dkd.tui.exception.BuildException; import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization; import lu.list.itis.dkd.tui.utility.Externalization;
...@@ -8,6 +11,8 @@ import lu.list.itis.dkd.tui.widget.corona.Scale; ...@@ -8,6 +11,8 @@ import lu.list.itis.dkd.tui.widget.corona.Scale;
import org.jdom2.Element; import org.jdom2.Element;
import java.awt.Color;
/** /**
* @author nmack * @author nmack
* @date 28 Apr 2015 * @date 28 Apr 2015
...@@ -21,10 +26,16 @@ import org.jdom2.Element; ...@@ -21,10 +26,16 @@ import org.jdom2.Element;
// *************************************************************************** // ***************************************************************************
public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> { public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
/** */
public double width; public double width;
/** */
public double height; public double height;
/** */
public double lowerBound; public double lowerBound;
/** */
public double upperBound; public double upperBound;
/** */
public Color tickMarkColour;
// *************************************************************************** // ***************************************************************************
// * Constants * // * Constants *
...@@ -35,55 +46,67 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> { ...@@ -35,55 +46,67 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
// * Constructor(s) * // * Constructor(s) *
// *************************************************************************** // ***************************************************************************
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** /**
* @param centre * @param centre
*/ */
// ---------------------------------------------------------------------------
public ScaleBuilder(Point centre) { public ScaleBuilder(Point centre) {
super(centre); super(centre);
// TODO Auto-generated constructor stub
} }
// ---------------------------------------------------------------------------
/** /**
* @param rootElement * @param rootElement
* @throws BuildException * @throws BuildException
*/ */
// ---------------------------------------------------------------------------
public ScaleBuilder(Element rootElement) throws BuildException { public ScaleBuilder(Element rootElement) throws BuildException {
super(rootElement); 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); public ScaleBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
height = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.HEIGHT_NODE, BootstrappingUtils.MANDATORY, null); super(rootElement, context, callback);
lowerBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.LOWER_BOUND_NODE, BootstrappingUtils.MANDATORY, null); this.buildFromBootstrap(rootElement, context, callback);
upperBound = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.UPPER_BOUND_NODE, BootstrappingUtils.MANDATORY, null);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Primitives * // * 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 * // * 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 * @param width
* The width of the gauge * The width of the scale
* @param upperBound * @param height
* The height of the gauge * The height of the scale
* @return An instance of the builder for chain-calling. * @return An instance of the builder for chain-calling.
*/ */
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -97,12 +120,12 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> { ...@@ -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 * @param lowerBound
* The lower bound of the dial * The lower bound of the scale
* @param upperBound * @param upperBound
* The upper bound of the dial * The upper bound of the scale
* @return An instance of the builder for chain-calling. * @return An instance of the builder for chain-calling.
*/ */
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -114,6 +137,30 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> { ...@@ -114,6 +137,30 @@ public class ScaleBuilder extends CoronaBuilder<ScaleBuilder> {
return this; 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 * // * End of Class *
......
...@@ -28,19 +28,30 @@ import java.awt.Font; ...@@ -28,19 +28,30 @@ import java.awt.Font;
// *************************************************************************** // ***************************************************************************
public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> { public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
public int index; /** Specifies the inner radius of the sector to build */
public double innerRadius; public double innerRadius;
/** Specifies the outer radius of the sector to build */
public double outerRadius; public double outerRadius;
/** Specifies the angle in degrees where the sector starts from */
public int startAngle; public int startAngle;
/** Specifies the length of the arc expressed in degrees */
public int arcSpan; public int arcSpan;
/** Specifies an optional gap (spacer) on both ends of the sector to build */
public int gap; public int gap;
/** Specifies the color pair (selected / unselected) to be used for filling the sector */
public ColorPair fillColour; public ColorPair fillColour;
/**
* Specifies the color pair (selected / unselected) to be used for the outline (stroke) of the
* sector
*/
public ColorPair strokeColour; public ColorPair strokeColour;
/** Specifies the color pair (selected / unselected) to be used for the title of the sector */
public ColorPair textColour; public ColorPair textColour;
/** Specifies the title to be shown inside the sector */
public String title; public String title;
/** Specifies the width of the stroke to be used to paint the outline of the sector */
public int strokeWidth; public int strokeWidth;
/** Specifies the font to be used for rendering the title */
public Font textFont; public Font textFont;
// *************************************************************************** // ***************************************************************************
...@@ -60,22 +71,26 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> { ...@@ -60,22 +71,26 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** /**
* @param rootElement * @param rootElement
* @throws BuildException * @throws BuildException
*/ */
// ---------------------------------------------------------------------------
public SectorBuilder(Element rootElement) throws BuildException { public SectorBuilder(Element rootElement) throws BuildException {
super(rootElement); super(rootElement);
this.buildFromBootstrap(rootElement, null, null); this.buildFromBootstrap(rootElement, null, null);
} }
// ---------------------------------------------------------------------------
/** /**
* @param rootElement * @param rootElement
* @param context * @param context
* @param callback * @param callback
* @throws BuildException * @throws BuildException
*/ */
// ---------------------------------------------------------------------------
public SectorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException { public SectorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback); super(rootElement, context, callback);