From bcedad680b6e82e22d85adfaceb13855e499cb37 Mon Sep 17 00:00:00 2001 From: Nico Mack Date: Tue, 18 Jul 2017 15:22:37 +0200 Subject: [PATCH] Harmonization and Cleanup of Coronas and respective Builders. Deprecation of obsolete Coronas --- TULIP/config/externalization.properties | 1 + .../tui/bootstrapping/BootstrappingUtils.java | 65 ++++- .../itis/dkd/tui/utility/Externalization.java | 3 +- .../lu/list/itis/dkd/tui/utility/Point.java | 2 +- .../itis/dkd/tui/widget/corona/Radius.java | 1 + .../itis/dkd/tui/widget/corona/Scale.java | 266 +++++++++--------- .../itis/dkd/tui/widget/corona/Sector.java | 18 +- .../itis/dkd/tui/widget/corona/Shadow.java | 1 + .../itis/dkd/tui/widget/corona/TextBox.java | 1 + .../widget/corona/builder/CoronaBuilder.java | 2 +- .../widget/corona/builder/ScaleBuilder.java | 91 ++++-- .../widget/corona/builder/SectorBuilder.java | 76 ++--- 12 files changed, 315 insertions(+), 212 deletions(-) diff --git a/TULIP/config/externalization.properties b/TULIP/config/externalization.properties index 0800b90..3a8e279 100644 --- a/TULIP/config/externalization.properties +++ b/TULIP/config/externalization.properties @@ -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 diff --git a/TULIP/src/lu/list/itis/dkd/tui/bootstrapping/BootstrappingUtils.java b/TULIP/src/lu/list/itis/dkd/tui/bootstrapping/BootstrappingUtils.java index 8b7008c..e065953 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/bootstrapping/BootstrappingUtils.java +++ b/TULIP/src/lu/list/itis/dkd/tui/bootstrapping/BootstrappingUtils.java @@ -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; + } + } diff --git a/TULIP/src/lu/list/itis/dkd/tui/utility/Externalization.java b/TULIP/src/lu/list/itis/dkd/tui/utility/Externalization.java index 0ef5af1..cf384ba 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/utility/Externalization.java +++ b/TULIP/src/lu/list/itis/dkd/tui/utility/Externalization.java @@ -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; diff --git a/TULIP/src/lu/list/itis/dkd/tui/utility/Point.java b/TULIP/src/lu/list/itis/dkd/tui/utility/Point.java index 8121fe7..010c4dc 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/utility/Point.java +++ b/TULIP/src/lu/list/itis/dkd/tui/utility/Point.java @@ -243,7 +243,7 @@ public class Point extends Float implements KdComparator { 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); // // diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Radius.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Radius.java index 3489cc6..8acecde 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Radius.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Radius.java @@ -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}. */ diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Scale.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Scale.java index a4eb444..47366da 100755 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Scale.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Scale.java @@ -1,9 +1,12 @@ 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,144 +14,141 @@ 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 * - *
$Log: Gauge.java,v $ + *
+ * $Log: Gauge.java,v $ */ -//*************************************************************************** -//* Class Definition and Members * -//*************************************************************************** - -public class Scale extends Corona - { - AbstractRadial scale; - int width; - int height; - - BufferedImage rendered; - Rectangle bounds; - -//*************************************************************************** -//* 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 - -//--------------------------------------------------------------------------- -//*************************************************************************** -//* Constructor(s) * -//*************************************************************************** -//--------------------------------------------------------------------------- - -public Scale(ScaleBuilder builder) - { - super(builder); - - width = (int)builder.width; - height = (int)builder.height; - - scale = new Radial(); - scale.setMinValue(builder.lowerBound); - scale.setMaxValue(builder.upperBound); - scale.setFrameType (FrameType.ROUND); - scale.setFrameVisible(false); - scale.setPostsVisible(false); - scale.setLcdVisible(false); - scale.setVisible(true); - scale.setSize(width, height); - scale.setLedVisible(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); - - - TICKMARK_FACTORY.create_RADIAL_TICKMARKS_Image(width, - model.getNiceMinValue(), - model.getNiceMaxValue(), - model.getMaxNoOfMinorTicks(), - model.getMaxNoOfMajorTicks(), - model.getMinorTickSpacing(), - model.getMajorTickSpacing(), - scale.getGaugeType(), - scale.getMinorTickmarkType(), - scale.getMajorTickmarkType(), - scale.isTickmarksVisible(), - scale.isTicklabelsVisible(), - model.isMinorTickmarksVisible(), - model.isMajorTickmarksVisible(), - scale.getLabelNumberFormat(), - scale.isTickmarkSectionsVisible(), - scale.getBackgroundColor(), - scale.getTickmarkColor(), - scale.isTickmarkColorFromThemeEnabled(), - scale.getTickmarkSections(), - scale.isSectionTickmarksOnly(), - scale.getSections(), - 0.33f, - -0.04f, - new Point2D.Double((width/2),(height/2)), - new Point2D.Double(0, 0), - Orientation.NORTH, - model.getTicklabelOrientation(), - model.isNiceScale(), - model.isLogScale(), - 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))); - } - -//--------------------------------------------------------------------------- -//*************************************************************************** -//* End of Class * -//*************************************************************************** -//--------------------------------------------------------------------------- - } +// *************************************************************************** +// * Class Definition and Members * +// *************************************************************************** + +public class Scale extends Corona { + protected AbstractRadial scale; + protected int width; + protected int height; + protected Color fillColour; + protected Color tickMarkColour; + + protected BufferedImage rendered; + protected Point scaleCentre; + + + // *************************************************************************** + // * 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; + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Constructor(s) * + // *************************************************************************** + // --------------------------------------------------------------------------- + + /** + * @param builder + */ + public Scale(ScaleBuilder builder) { + super(builder); + + 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.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); + 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(), + model.getNiceMaxValue(), + model.getMaxNoOfMinorTicks(), + model.getMaxNoOfMajorTicks(), + model.getMinorTickSpacing(), + model.getMajorTickSpacing(), + scale.getGaugeType(), + scale.getMinorTickmarkType(), + scale.getMajorTickmarkType(), + scale.isTickmarksVisible(), + scale.isTicklabelsVisible(), + model.isMinorTickmarksVisible(), + model.isMajorTickmarksVisible(), + scale.getLabelNumberFormat(), + scale.isTickmarkSectionsVisible(), + scale.getBackgroundColor(), + scale.getTickmarkColor(), + scale.isTickmarkColorFromThemeEnabled(), + scale.getTickmarkSections(), + scale.isSectionTickmarksOnly(), + scale.getSections(), + 0.33f, + -0.04f, + new Point2D.Double((width / 2), (height / 2)), + new Point2D.Double(0, 0), + Orientation.NORTH, + model.getTicklabelOrientation(), + model.isNiceScale(), + model.isLogScale(), + rendered); + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * 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 * + // *************************************************************************** + // --------------------------------------------------------------------------- +} diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Sector.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Sector.java index 8d7e1c3..8ae8cac 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Sector.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Sector.java @@ -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 true to select this sector, false 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); diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Shadow.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Shadow.java index 4341d47..48381aa 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Shadow.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/Shadow.java @@ -37,6 +37,7 @@ import java.awt.geom.AffineTransform; * @since 1.0 * @version 2.3.0 */ +@Deprecated @NonNullByDefault public class Shadow extends Corona { /** diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/TextBox.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/TextBox.java index aabc7ce..bcbd3a4 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/TextBox.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/TextBox.java @@ -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 { /** Field holding the text to visualise. */ diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/CoronaBuilder.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/CoronaBuilder.java index 30ac1dd..e207d20 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/CoronaBuilder.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/CoronaBuilder.java @@ -143,7 +143,7 @@ public abstract class CoronaBuilder> { } 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); diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/ScaleBuilder.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/ScaleBuilder.java index 8d8e69e..84e02ca 100755 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/ScaleBuilder.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/ScaleBuilder.java @@ -1,5 +1,8 @@ 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 { + /** */ 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 { // * 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 { // --------------------------------------------------------------------------- /** - * 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 { 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 * diff --git a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/SectorBuilder.java b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/SectorBuilder.java index 1c925d9..910cf1a 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/SectorBuilder.java +++ b/TULIP/src/lu/list/itis/dkd/tui/widget/corona/builder/SectorBuilder.java @@ -28,19 +28,30 @@ import java.awt.Font; // *************************************************************************** public class SectorBuilder extends BaseIndexedCoronaBuilder { - 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 { } // --------------------------------------------------------------------------- - /** * @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 { 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 { // * 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 { } // --------------------------------------------------------------------------- - /** - * @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 { } // --------------------------------------------------------------------------- - /** * Method for setting the color to be used as background for this corona. * @@ -188,13 +192,14 @@ public class SectorBuilder extends BaseIndexedCoronaBuilder { * 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 { * 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 { * 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 { } // --------------------------------------------------------------------------- - /** * @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; -- GitLab