use of eu.hansolo.medusa.tools.ConicalGradient in project KNOBS by ESSICS.
the class Knob method initComponents.
protected void initComponents() {
angleStepProperty().bind(Bindings.divide(ANGLE_RANGE, Bindings.subtract(maxValueProperty(), minValueProperty())));
backgroundProperty().bind(Bindings.createObjectBinding(() -> Color.TRANSPARENT.equals(getBackgroundColor()) ? Background.EMPTY : new Background(new BackgroundFill(getBackgroundColor(), CornerRadii.EMPTY, Insets.EMPTY)), backgroundColorProperty()));
dropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), PREFERRED_WIDTH * 0.016, 0.0, 0, PREFERRED_WIDTH * 0.028);
highlight = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.20), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008);
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.20), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008);
highlight.setInput(innerShadow);
dropShadow.setInput(highlight);
barGradient = new ConicalGradient(reorderStops(getGradientStops()));
barArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE, 0);
barArc.setType(ArcType.OPEN);
barArc.setStrokeLineCap(StrokeLineCap.ROUND);
barArc.setFill(null);
barArc.setStroke(barGradient.getImagePattern(new Rectangle(0, 0, PREFERRED_WIDTH, PREFERRED_HEIGHT)));
currentValueBarArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE, 0);
currentValueBarArc.setType(ArcType.OPEN);
currentValueBarArc.setStrokeLineCap(StrokeLineCap.ROUND);
currentValueBarArc.setFill(null);
currentValueBarArc.strokeProperty().bind(currentValueColorProperty());
currentValueBarArc.lengthProperty().bind(Bindings.createDoubleBinding(() -> {
double localMin = (isZeroDetentEnabled() && getMinValue() < 0) ? Math.min(0, getMaxValue()) : getMinValue();
double length = getAngleStep() * (localMin - getCurrentValue());
if (length == 0) {
length = getAngleStep() * (getMinValue() - getMaxValue()) / 10000;
}
return length;
}, angleStepProperty(), currentValueProperty(), maxValueProperty(), minValueProperty(), zeroDetentEnabledProperty()));
currentValueBarArc.opacityProperty().bind(Bindings.createDoubleBinding(() -> {
double localMin = (isZeroDetentEnabled() && getMinValue() < 0) ? Math.min(0, getMaxValue()) : getMinValue();
double length = getAngleStep() * (localMin - getCurrentValue());
if (length == 0) {
return 0.6666;
} else {
return 1.0;
}
}, angleStepProperty(), currentValueProperty(), maxValueProperty(), minValueProperty(), zeroDetentEnabledProperty()));
currentValueBarArc.startAngleProperty().bind(Bindings.createDoubleBinding(() -> {
double angle = BAR_START_ANGLE;
if (isZeroDetentEnabled() && getMinValue() < 0) {
angle += Math.max(getAngleStep() * getMinValue(), -ANGLE_RANGE);
}
return angle;
}, angleStepProperty(), minValueProperty(), zeroDetentEnabledProperty()));
double center = PREFERRED_WIDTH * 0.5;
ring = Shape.subtract(new Circle(center, center, PREFERRED_WIDTH * 0.42), new Circle(center, center, PREFERRED_WIDTH * 0.3));
ring.fillProperty().bind(colorProperty());
ring.setEffect(dropShadow);
ring.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
if (!isDisabled() && !isDragDisabled()) {
touchRotate(e.getSceneX(), e.getSceneY());
}
});
ring.addEventHandler(MouseEvent.MOUSE_DRAGGED, e -> {
if (!isDisabled() && !isDragDisabled()) {
touchRotate(e.getSceneX(), e.getSceneY());
}
});
ring.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
if (!isDisabled() && !isDragDisabled()) {
fireTargeValueSet();
}
});
mainCircle = new Circle();
mainCircle.fillProperty().bind(Bindings.createObjectBinding(() -> getColor().darker().darker(), colorProperty()));
mainCircle.setOnMouseClicked(doubleClickHandler);
text = new Text(String.format(format, getCurrentValue()));
text.fillProperty().bind(textColorProperty());
text.setOnMouseClicked(doubleClickHandler);
text.setTextOrigin(VPos.CENTER);
targetText = new Text(String.format(format, getTargetValue()));
targetText.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
targetText.setOnMouseClicked(doubleClickHandler);
targetText.setTextOrigin(VPos.CENTER);
targetText.visibleProperty().bind(Bindings.createBooleanBinding(() -> isTargetValueAlwaysVisible() || !close(getCurrentValue(), getTargetValue(), (getMaxValue() - getMinValue()) * PROXIMITY_ERROR), targetValueAlwaysVisibleProperty(), currentValueProperty(), targetValueProperty(), maxValueProperty(), minValueProperty()));
unitText = new Text(getUnit());
unitText.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
unitText.setOnMouseClicked(doubleClickHandler);
unitText.setTextOrigin(VPos.CENTER);
textMinTag = new Polygon(0.0, 0.7, 0.6, 0.7, 0.6, 0.9, 0.0, 0.9);
textMinTag.fillProperty().bind(Bindings.createObjectBinding(() -> getColor().darker().darker(), colorProperty()));
textMinTag.visibleProperty().bind(extremaVisibleProperty());
textMin = new Text(String.format(format, getMinValue()));
textMin.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
textMin.setTextOrigin(VPos.CENTER);
textMin.visibleProperty().bind(extremaVisibleProperty());
textMaxTag = new Polygon(0.0, 0.7, 0.6, 0.7, 0.6, 0.9, 0.0, 0.9);
textMaxTag.fillProperty().bind(Bindings.createObjectBinding(() -> getColor().darker().darker(), colorProperty()));
textMaxTag.visibleProperty().bind(extremaVisibleProperty());
textMax = new Text(String.format(format, getMaxValue()));
textMax.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
textMax.setTextOrigin(VPos.CENTER);
textMax.visibleProperty().bind(extremaVisibleProperty());
tagBarArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE + 15, 50);
tagBarArc.setType(ArcType.OPEN);
tagBarArc.setStrokeLineCap(StrokeLineCap.ROUND);
tagBarArc.setFill(null);
tagBarArc.strokeProperty().bind(tagColorProperty());
tagBarArc.visibleProperty().bind(tagVisibleProperty());
indicatorRotate = new Rotate(-ANGLE_RANGE * 0.5, center, center);
indicatorGlow = new DropShadow(BlurType.TWO_PASS_BOX, getIndicatorColor(), PREFERRED_WIDTH * 0.020, 0.0, 0, 0);
indicatorInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.50), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008);
indicatorHighlight = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.35), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008);
indicatorRotate.angleProperty().bind(Bindings.subtract(Bindings.multiply(Bindings.subtract(targetValueProperty(), minValueProperty()), angleStepProperty()), ANGLE_RANGE * 0.5));
indicatorGlow.colorProperty().bind(selectionColorProperty());
indicatorHighlight.setInput(indicatorInnerShadow);
indicator = new Circle();
indicator.effectProperty().bind(Bindings.createObjectBinding(() -> isSelected() ? indicatorGlow : null, selectionColorProperty(), selectedProperty()));
indicator.disableProperty().bind(dragDisabledProperty());
indicator.fillProperty().bind(Bindings.createObjectBinding(() -> {
Color c = isSelected() ? getSelectionColor() : getIndicatorColor();
return isDragDisabled() ? c.deriveColor(0, 1, 0.92, 0.6) : c;
}, colorProperty(), dragDisabledProperty(), indicatorColorProperty(), selectionColorProperty(), selectedProperty()));
indicator.strokeProperty().bind(Bindings.createObjectBinding(() -> {
Color c = isSelected() ? getSelectionColor().darker().darker() : getIndicatorColor().darker().darker();
return isDragDisabled() ? c.deriveColor(0, 1, 0.92, 0.6) : c;
}, colorProperty(), dragDisabledProperty(), indicatorColorProperty(), selectionColorProperty(), selectedProperty()));
indicator.setMouseTransparent(true);
indicator.getTransforms().add(indicatorRotate);
Group indicatorGroup = new Group(indicator);
indicatorGroup.setEffect(indicatorHighlight);
pane = new Pane(barArc, currentValueBarArc, ring, mainCircle, text, targetText, unitText, textMinTag, textMin, textMaxTag, textMax, tagBarArc, indicatorGroup);
pane.setPrefSize(PREFERRED_HEIGHT, PREFERRED_HEIGHT);
pane.backgroundProperty().bind(Bindings.createObjectBinding(() -> new Background(new BackgroundFill(getColor().darker(), new CornerRadii(1024), Insets.EMPTY)), colorProperty()));
pane.setEffect(highlight);
Platform.runLater(() -> getChildren().setAll(pane));
}
Aggregations