diff --git a/widgets/nebulaslider/org.eclipse.nebula.widgets.nebulaslider/src/org/eclipse/nebula/widgets/opal/nebulaslider/NebulaSlider.java b/widgets/nebulaslider/org.eclipse.nebula.widgets.nebulaslider/src/org/eclipse/nebula/widgets/opal/nebulaslider/NebulaSlider.java index acd2c922e..a15fc090c 100644 --- a/widgets/nebulaslider/org.eclipse.nebula.widgets.nebulaslider/src/org/eclipse/nebula/widgets/opal/nebulaslider/NebulaSlider.java +++ b/widgets/nebulaslider/org.eclipse.nebula.widgets.nebulaslider/src/org/eclipse/nebula/widgets/opal/nebulaslider/NebulaSlider.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.nebula.widgets.opal.nebulaslider; +import java.util.function.IntFunction; + import org.eclipse.nebula.widgets.opal.commons.SelectionListenerUtil; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTException; @@ -47,6 +49,8 @@ public class NebulaSlider extends Canvas { private boolean moving = false; + private IntFunction format; + /** * Constructs a new instance of this class given its parent and a style value * describing its behavior and appearance. @@ -181,7 +185,7 @@ private void drawSelector(final GC gc) { // And the value gc.setForeground(renderer.getSelectorTextColor()); gc.setFont(renderer.getTextFont()); - final String valueAsString = String.valueOf(value); + final String valueAsString = stringValueOf(value); final Point textSize = gc.textExtent(valueAsString); final int xText = hMargin + xPosition + selectorWidth / 2; @@ -190,6 +194,23 @@ private void drawSelector(final GC gc) { gc.drawText(valueAsString, xText - textSize.x / 2, yText - textSize.y / 2, true); } + private String stringValueOf(int value) { + if(format != null) { + return format.apply(value); + } + return String.valueOf(value); + } + + /** + * Set the format that should be used to format the given number to a string. + * + * @param format + * the format or null to use the default format. + */ + public void setLabelFormatProvider(IntFunction format) { + this.format = format; + } + private void addMouseListeners() { addListener(SWT.MouseDown, e -> {