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;
......@@ -212,7 +213,7 @@ public class Externalization extends NLS {
public static String MARKER_BUILDER_NAMESPACE;
public static String POINTING_OFFSET_NODE;
public static String PATH_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}. */
......
......@@ -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> {
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public SectorBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public SectorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
......@@ -89,8 +104,8 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
index = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.INDEX_NODE, BootstrappingUtils.MANDATORY, null, context);
startAngle = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.START_ANGLE_NODE, BootstrappingUtils.MANDATORY, null, context);
arcSpan = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context);
startAngle = (int) BootstrappingUtils.getContentAsDegrees(rootElement, Externalization.START_ANGLE_NODE, BootstrappingUtils.MANDATORY, null, context);
arcSpan = (int) BootstrappingUtils.getContentAsDegrees(rootElement, Externalization.ARC_SPAN_NODE, BootstrappingUtils.MANDATORY, null, context);
innerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.INNER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context);
outerRadius = BootstrappingUtils.getContentAsDouble(rootElement, Externalization.OUTER_RADIUS_NODE, BootstrappingUtils.MANDATORY, null, context);
......@@ -128,24 +143,12 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param index
* @return An instance of the builder for chain calling.
*/
public SectorBuilder withIndex(int index) {
this.index = index;
return this;
}
// ---------------------------------------------------------------------------
/**
* @param inner
* @param outer
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withRadii(double inner, double outer) {
innerRadius = inner;
......@@ -154,23 +157,25 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
}
// ---------------------------------------------------------------------------
/**
* @param gap
* @param width
* @return An instance of the builder for chain calling.
*/
public SectorBuilder withGap(int gap) {
this.gap = gap;
// ---------------------------------------------------------------------------
public SectorBuilder withGap(int width) {
this.gap = width;
return this;
}
// ---------------------------------------------------------------------------
/**
* @param start
* @param span
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withAngles(int start, int span) {
this.startAngle = start;
this.arcSpan = span;
......@@ -178,7 +183,6 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
}
// ---------------------------------------------------------------------------
/**
* Method for setting the color to be used as background for this corona.
*
......@@ -188,13 +192,14 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
* specifies the fill color to be used when sector is not selected.
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withFillColours(Color selectedColour, Color deselectedColour) {
fillColour = new ColorPair(selectedColour, deselectedColour);
return this;
}
// ---------------------------------------------------------------------------
/**
* Method for setting the colour to be used for drawing edges for this corona.
*
......@@ -204,13 +209,14 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
* specifies the stroke color to be used when sector is not selected.
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withStrokeColours(Color selectedColour, Color deselectedColour) {
strokeColour = new ColorPair(selectedColour, deselectedColour);
return this;
}
// ---------------------------------------------------------------------------
/**
* Method for setting the colour to be used for drawing edges for this corona.
*
......@@ -220,29 +226,32 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
* specifies the text color to be used when sector is not selected.
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withTextColours(Color selectedColour, Color deselectedColour) {
textColour = new ColorPair(selectedColour, deselectedColour);
return this;
}
// ---------------------------------------------------------------------------
/**
* @param title
* @param newTitle
* @return An instance of the builder for chain calling.
*/
public SectorBuilder withTitle(String title) {
this.title = title;
// ---------------------------------------------------------------------------
public SectorBuilder withTitle(String newTitle) {
this.title = newTitle;
return this;
}
// ---------------------------------------------------------------------------
/**
* @param font
* specifies the font to be used for rendering the title
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withFont(Font font) {
this.textFont = font;
......@@ -250,12 +259,13 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder<SectorBuilder> {
}
// ---------------------------------------------------------------------------
/**
* @param width
* specifies the stroke width to be used for drawing the outline
* @return An instance of the builder for chain calling.
*/
// ---------------------------------------------------------------------------
public SectorBuilder withStrokeWidth(int width) {
this.strokeWidth = width;
return this;
......
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