use of javafx.scene.shape.Circle in project JFoenix by jfoenixadmin.
the class JFXRippler method getMask.
// methods that can be changed by extending the rippler class
/**
* generate the clipping mask
* @return the mask node
*/
protected Node getMask() {
double borderWidth = ripplerPane.getBorder() != null ? ripplerPane.getBorder().getInsets().getTop() : 0;
Bounds bounds = control.getBoundsInParent();
double width = control.getLayoutBounds().getWidth();
double height = control.getLayoutBounds().getHeight();
double diffMinX = Math.abs(control.getBoundsInLocal().getMinX() - control.getLayoutBounds().getMinX());
double diffMinY = Math.abs(control.getBoundsInLocal().getMinY() - control.getLayoutBounds().getMinY());
double diffMaxX = Math.abs(control.getBoundsInLocal().getMaxX() - control.getLayoutBounds().getMaxX());
double diffMaxY = Math.abs(control.getBoundsInLocal().getMaxY() - control.getLayoutBounds().getMaxY());
Node mask;
switch(getMaskType()) {
case RECT:
// -0.1 to prevent resizing the anchor pane
mask = new Rectangle(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY, width - 0.1 - 2 * borderWidth, height - 0.1 - 2 * borderWidth);
break;
case CIRCLE:
double radius = Math.min((width / 2) - 0.1 - 2 * borderWidth, (height / 2) - 0.1 - 2 * borderWidth);
mask = new Circle((bounds.getMinX() + diffMinX + bounds.getMaxX() - diffMaxX) / 2, (bounds.getMinY() + diffMinY + bounds.getMaxY() - diffMaxY) / 2, radius, Color.BLUE);
break;
default:
// -0.1 to prevent resizing the anchor pane
mask = new Rectangle(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY, width - 0.1 - 2 * borderWidth, height - 0.1 - 2 * borderWidth);
break;
}
if (control instanceof Shape || (control instanceof Region && ((Region) control).getShape() != null)) {
mask = new StackPane();
((Region) mask).setShape((control instanceof Shape) ? (Shape) control : ((Region) control).getShape());
((Region) mask).setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
mask.resize(width, height);
mask.relocate(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY);
}
return mask;
}
use of javafx.scene.shape.Circle in project JFoenix by jfoenixadmin.
the class JFXSliderSkinOLD method initialize.
private void initialize() {
isHorizontal = getSkinnable().getOrientation() == Orientation.HORIZONTAL;
thumb = new Circle();
thumb.setStrokeWidth(2);
thumb.setRadius(7);
thumb.setFill(thumbColor);
thumb.setStroke(thumbColor);
thumb.getStyleClass().setAll("thumb");
track = new Line();
track.setStroke(trackColor);
track.setStrokeWidth(3);
track.getStyleClass().setAll("track");
coloredTrack = new Line();
coloredTrack.strokeProperty().bind(thumb.strokeProperty());
coloredTrack.strokeWidthProperty().bind(track.strokeWidthProperty());
sliderValue = new Text();
sliderValue.setStroke(Color.WHITE);
sliderValue.setFont(new Font(10));
sliderValue.getStyleClass().setAll("sliderValue");
animatedThumb = new StackPane();
animatedThumb.getChildren().add(sliderValue);
getChildren().clear();
getChildren().addAll(track, coloredTrack, animatedThumb, thumb);
}
use of javafx.scene.shape.Circle in project JFoenix by jfoenixadmin.
the class JFXTimePickerContent method createContentPane.
protected BorderPane createContentPane(LocalTime time) {
Circle circle = new Circle(contentCircleRadius);
circle.setFill(Color.rgb(224, 224, 224, 0.67));
EventHandler<? super MouseEvent> mouseActionHandler = (event) -> {
double dx = event.getX();
double dy = event.getY();
double theta = Math.atan2(dy, dx);
int index = (int) Math.round((180 + Math.toDegrees(theta)) / angle.get());
pointerRotate.get().setAngle(index * angle.get());
int timeValue = (index + 9) % 12 == 0 ? 12 : (index + 9) % 12;
if (unit.get() == TimeUnit.MINUTES)
timeValue = (index + 45) % 60 == 0 ? 0 : (index + 45) % 60;
timeLabel.get().setText(unit.get() == TimeUnit.MINUTES ? unitConverter.toString(timeValue) : timeValue + "");
updateValue();
};
circle.setOnMousePressed(mouseActionHandler);
circle.setOnMouseDragged(mouseActionHandler);
hoursContent = createHoursContent(time);
hoursContent.setMouseTransparent(true);
minutesContent = createMinutesContent(time);
minutesContent.setOpacity(0);
minutesContent.setMouseTransparent(true);
StackPane contentPane = new StackPane();
contentPane.getChildren().addAll(circle, hoursContent, minutesContent);
contentPane.setPadding(new Insets(12));
BorderPane contentContainer = new BorderPane();
contentContainer.setCenter(contentPane);
contentContainer.setMinHeight(50);
contentContainer.setPadding(new Insets(2, 12, 2, 12));
return contentContainer;
}
use of javafx.scene.shape.Circle in project JFoenix by jfoenixadmin.
the class JFXTimePickerContent method createHoursContent.
private StackPane createHoursContent(LocalTime time) {
// create hours content
StackPane hoursPointer = new StackPane();
Circle selectionCircle = new Circle(contentCircleRadius / 6);
selectionCircle.fillProperty().bind(timePicker.defaultColorProperty());
double shift = 9;
Line line = new Line(shift, 0, contentCircleRadius, 0);
line.fillProperty().bind(timePicker.defaultColorProperty());
line.strokeProperty().bind(line.fillProperty());
line.setStrokeWidth(1.5);
hoursPointer.getChildren().addAll(line, selectionCircle);
StackPane.setAlignment(selectionCircle, Pos.CENTER_LEFT);
Group pointerGroup = new Group();
pointerGroup.getChildren().add(hoursPointer);
pointerGroup.setTranslateX((-contentCircleRadius + shift) / 2);
hoursPointerRotate = new Rotate(0, contentCircleRadius - shift, selectionCircle.getRadius());
pointerRotate.set(hoursPointerRotate);
pointerGroup.getTransforms().add(hoursPointerRotate);
Pane clockLabelsContainer = new Pane();
// inner circle radius
double radius = contentCircleRadius - shift - selectionCircle.getRadius();
for (int i = 0; i < 12; i++) {
// create the label and its container
int val = (i + 3) % 12 == 0 ? 12 : (i + 3) % 12;
Label label = new Label(val + "");
label.setFont(Font.font("Roboto", FontWeight.BOLD, 12));
// init color
if (val == time.getHour() % 12 || (val == 12 && time.getHour() % 12 == 0))
label.setTextFill(Color.rgb(255, 255, 255, 0.87));
else
label.setTextFill(Color.rgb(0, 0, 0, 0.87));
selectedHourLabel.textProperty().addListener((o, oldVal, newVal) -> {
if (Integer.parseInt(newVal) == Integer.parseInt(label.getText())) {
label.setTextFill(Color.rgb(255, 255, 255, 0.87));
} else {
label.setTextFill(Color.rgb(0, 0, 0, 0.87));
}
});
// create label container
StackPane labelContainer = new StackPane();
labelContainer.getChildren().add(label);
double labelSize = (selectionCircle.getRadius() / Math.sqrt(2)) * 2;
labelContainer.setMinSize(labelSize, labelSize);
// position the label on the circle
double angle = 2 * i * Math.PI / 12;
double xOffset = radius * Math.cos(angle);
double yOffset = radius * Math.sin(angle);
final double startx = contentCircleRadius + xOffset;
final double starty = contentCircleRadius + yOffset;
labelContainer.setLayoutX(startx - labelContainer.getMinWidth() / 2);
labelContainer.setLayoutY(starty - labelContainer.getMinHeight() / 2);
// add label to the parent node
clockLabelsContainer.getChildren().add(labelContainer);
// init pointer angle
if (val == time.getHour() % 12 || (val == 12 && time.getHour() % 12 == 0))
hoursPointerRotate.setAngle(180 + Math.toDegrees(angle));
}
return new StackPane(pointerGroup, clockLabelsContainer);
}
use of javafx.scene.shape.Circle in project JFoenix by jfoenixadmin.
the class JFXColorPickerSkin method updateColor.
private void updateColor() {
final ColorPicker colorPicker = (ColorPicker) getSkinnable();
// update picker box color
Circle ColorCircle = new Circle();
ColorCircle.setFill(colorPicker.getValue());
ColorCircle.setLayoutX(pickerColorBox.getWidth() / 4);
ColorCircle.setLayoutY(pickerColorBox.getHeight() / 2);
pickerColorBox.getChildren().add(ColorCircle);
Timeline animateColor = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(ColorCircle.radiusProperty(), 200, Interpolator.EASE_BOTH)));
animateColor.setOnFinished((finish) -> {
pickerColorBox.setBackground(new Background(new BackgroundFill(ColorCircle.getFill(), pickerColorBox.getBackground().getFills().get(0).getRadii(), pickerColorBox.getBackground().getFills().get(0).getInsets())));
pickerColorBox.getChildren().remove(ColorCircle);
});
animateColor.play();
// update label color
displayNode.setTextFill(colorPicker.getValue().grayscale().getRed() < 0.5 ? Color.valueOf("rgba(255, 255, 255, 0.87)") : Color.valueOf("rgba(0, 0, 0, 0.87)"));
if (colorLabelVisible.get())
displayNode.setText(colorDisplayName(colorPicker.getValue()));
else
displayNode.setText("");
}
Aggregations