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}. */
......
package lu.list.itis.dkd.tui.widget.corona; 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.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
...@@ -11,144 +14,141 @@ import eu.hansolo.steelseries.gauges.AbstractRadial; ...@@ -11,144 +14,141 @@ import eu.hansolo.steelseries.gauges.AbstractRadial;
import eu.hansolo.steelseries.gauges.Radial; import eu.hansolo.steelseries.gauges.Radial;
import eu.hansolo.steelseries.tools.BackgroundImageFactory; import eu.hansolo.steelseries.tools.BackgroundImageFactory;
import eu.hansolo.steelseries.tools.FrameType; import eu.hansolo.steelseries.tools.FrameType;
import eu.hansolo.steelseries.tools.GaugeType;
import eu.hansolo.steelseries.tools.Model; import eu.hansolo.steelseries.tools.Model;
import eu.hansolo.steelseries.tools.Orientation; import eu.hansolo.steelseries.tools.Orientation;
import eu.hansolo.steelseries.tools.TickmarkImageFactory; 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 * @author nmack
* @date 27 Apr 2015 * @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 public class Scale extends Corona {
{ protected AbstractRadial scale;
AbstractRadial scale; protected int width;
int width; protected int height;
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;
protected static final TickmarkImageFactory TICKMARK_FACTORY = TickmarkImageFactory.INSTANCE;
private static final int imageType = BufferedImage.TYPE_INT_ARGB; // BufferedImage.TYPE_4BYTE_ABGR; //BufferedImage.TYPE_INT_ARGB protected static final BackgroundImageFactory BACKGROUND_FACTORY = BackgroundImageFactory.INSTANCE;
//--------------------------------------------------------------------------- private static final int imageType = BufferedImage.TYPE_INT_ARGB;
//***************************************************************************
//* Constructor(s) * // ---------------------------------------------------------------------------
//*************************************************************************** // ***************************************************************************
//--------------------------------------------------------------------------- // * Constructor(s) *
// ***************************************************************************
public Scale(ScaleBuilder builder) // ---------------------------------------------------------------------------
{
super(builder); /**
* @param builder
width = (int)builder.width; */
height = (int)builder.height; public Scale(ScaleBuilder builder) {
super(builder);
scale = new Radial();
scale.setMinValue(builder.lowerBound); width = (int) builder.width;
scale.setMaxValue(builder.upperBound); height = (int) builder.height;
scale.setFrameType (FrameType.ROUND); tickMarkColour = builder.tickMarkColour;
scale.setFrameVisible(false);
scale.setPostsVisible(false); scale = new Radial();
scale.setLcdVisible(false); scale.setMinValue(builder.lowerBound);
scale.setVisible(true); scale.setMaxValue(builder.upperBound);
scale.setSize(width, height); scale.setFrameType(FrameType.ROUND);
scale.setLedVisible(false); scale.setFrameVisible(false);
scale.setPostsVisible(false);
Model model = scale.getModel(); scale.setLcdVisible(false);
scale.setVisible(true);
rendered = new BufferedImage(width,height,imageType); scale.setSize(width, height);
bounds = new Rectangle (0,0,width,height); scale.setLedVisible(false);
if (tickMarkColour != null) {
BACKGROUND_FACTORY.createRadialBackground(width, scale.setTickmarkColor(tickMarkColour);
scale.getBackgroundColor(), scale.setTickmarkColorFromThemeEnabled(false);
model.getCustomBackground(), }
model.getTextureColor(),
rendered); Model model = scale.getModel();
rendered = new BufferedImage(width, height, imageType);
TICKMARK_FACTORY.create_RADIAL_TICKMARKS_Image(width, scaleCentre = new Point(width / 2, height / 2, 0, ScreenCoordinates.class);
model.getNiceMinValue(),
model.getNiceMaxValue(), // BACKGROUND_FACTORY.createRadialBackground(width,
model.getMaxNoOfMinorTicks(), // scale.getBackgroundColor(),
model.getMaxNoOfMajorTicks(), // model.getCustomBackground(),
model.getMinorTickSpacing(), // model.getTextureColor(),
model.getMajorTickSpacing(), // rendered);
scale.getGaugeType(),
scale.getMinorTickmarkType(), TICKMARK_FACTORY.create_RADIAL_TICKMARKS_Image(width,
scale.getMajorTickmarkType(), model.getNiceMinValue(),
scale.isTickmarksVisible(), model.getNiceMaxValue(),
scale.isTicklabelsVisible(), model.getMaxNoOfMinorTicks(),
model.isMinorTickmarksVisible(), model.getMaxNoOfMajorTicks(),
model.isMajorTickmarksVisible(), model.getMinorTickSpacing(),
scale.getLabelNumberFormat(), model.getMajorTickSpacing(),
scale.isTickmarkSectionsVisible(), scale.getGaugeType(),
scale.getBackgroundColor(), scale.getMinorTickmarkType(),
scale.getTickmarkColor(), scale.getMajorTickmarkType(),
scale.isTickmarkColorFromThemeEnabled(), scale.isTickmarksVisible(),
scale.getTickmarkSections(), scale.isTicklabelsVisible(),
scale.isSectionTickmarksOnly(), model.isMinorTickmarksVisible(),
scale.getSections(), model.isMajorTickmarksVisible(),
0.33f, scale.getLabelNumberFormat(),
-0.04f, scale.isTickmarkSectionsVisible(),
new Point2D.Double((width/2),(height/2)), scale.getBackgroundColor(),
new Point2D.Double(0, 0), scale.getTickmarkColor(),
Orientation.NORTH, scale.isTickmarkColorFromThemeEnabled(),
model.getTicklabelOrientation(), scale.getTickmarkSections(),
model.isNiceScale(), scale.isSectionTickmarksOnly(),
model.isLogScale(), scale.getSections(),
rendered); 0.33f,
} -0.04f,
new Point2D.Double((width / 2), (height / 2)),
//--------------------------------------------------------------------------- new Point2D.Double(0, 0),
//*************************************************************************** Orientation.NORTH,
//* Primitives * model.getTicklabelOrientation(),
//*************************************************************************** model.isNiceScale(),
//--------------------------------------------------------------------------- model.isLogScale(),
rendered);
//--------------------------------------------------------------------------- }
//***************************************************************************
//* Class Body * // ---------------------------------------------------------------------------
//*************************************************************************** // ***************************************************************************
//--------------------------------------------------------------------------- // * Primitives *
// ***************************************************************************
@Override // ---------------------------------------------------------------------------
public void paint(Graphics2D canvas)
{ // ---------------------------------------------------------------------------
if (!active) return; // ***************************************************************************
// * Class Body *
centre.toScreenCoordinates(); // ***************************************************************************
if(initialTranslation != null) initialTranslation.toScreenCoordinates(); // ---------------------------------------------------------------------------
Point drawAt = centre.add(initialTranslation);
@Override
AffineTransform rotation = new AffineTransform(); public void paint(Graphics2D canvas) {
rotation.translate(drawAt.x, drawAt.y); if (!active)
return;
canvas.drawImage(rendered, rotation, null);
AffineTransform transform = this.getTransform(scaleCentre);
// clippingRegion.reset(); canvas.drawImage(rendered, transform, null);
// clippingRegion.add(new Area(rotation.createTransformedShape(bounds))); }
}
// ---------------------------------------------------------------------------
//--------------------------------------------------------------------------- // ***************************************************************************
//*************************************************************************** // * End of Class *
//* End of Class * // ***************************************************************************
//*************************************************************************** // ---------------------------------------------------------------------------
//--------------------------------------------------------------------------- }
}
...@@ -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;