Skip to content

Commit

Permalink
Impl #59 - Extend PercentageBarDecorator to override getting the data
Browse files Browse the repository at this point in the history
Signed-off-by: Dirk Fauth <[email protected]>
  • Loading branch information
fipro78 committed Feb 14, 2024
1 parent 976a10d commit 32cc40a
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2020 Original authors and others.
* Copyright (c) 2012, 2024 Original authors and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -47,7 +47,7 @@ public PercentageBarDecorator(ICellPainter interiorPainter) {
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
Pattern originalBackgroundPattern = gc.getBackgroundPattern();

double factor = Math.min(1.0, ((Number) cell.getDataValue()).doubleValue());
double factor = Math.min(1.0, convertDataType(cell).doubleValue());
factor = Math.max(0.0, factor);

Rectangle bar = new Rectangle(
Expand Down Expand Up @@ -102,4 +102,21 @@ public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegist
super.paintCell(cell, gc, rectangle, configRegistry);
}

/**
* Converts the data type to a {@link Number}. If the value is not a
* {@link Number} it will simply return 0.
*
* @param cell
* The cell for which the {@link Number} value is requested.
* @return The {@link Number} value to show. Should be a factor value <= 1.0
* to be interpreted as a percentage.
* @since 2.3
*/
protected Number convertDataType(ILayerCell cell) {
if (cell.getDataValue() instanceof Number) {
return (Number) cell.getDataValue();
}
return Double.valueOf(0);
}

}

0 comments on commit 32cc40a

Please sign in to comment.