下面列出了javafx.scene.shape.Arc#setType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Shape getSelfEdgeShape(Edge pEdge)
{
Line line = getSelfEdgeConnectionPoints(pEdge);
Arc arc = new Arc();
arc.setRadiusX(SELF_EDGE_OFFSET*2);
arc.setRadiusY(SELF_EDGE_OFFSET*2);
arc.setLength(DEGREES_270);
arc.setType(ArcType.OPEN);
if( getPosition(pEdge) == 1 )
{
arc.setCenterX(line.getX1());
arc.setCenterY(line.getY1()-SELF_EDGE_OFFSET);
arc.setStartAngle(DEGREES_270);
}
else
{
arc.setCenterX(line.getX1()-SELF_EDGE_OFFSET);
arc.setCenterY(line.getY1()-SELF_EDGE_OFFSET*2);
arc.setStartAngle(1);
}
return arc;
}
@Override
public void initializeParts() {
double center = ARTBOARD_HEIGHT * 0.5;
border = new Circle(center, center, center);
border.getStyleClass().add("border");
pieSlice = new Arc(center, center, center - 1, center - 1, 90, 0);
pieSlice.getStyleClass().add("pieSlice");
pieSlice.setType(ArcType.ROUND);
valueField = new TextField();
valueField.relocate(ARTBOARD_HEIGHT + 5, 2);
valueField.setPrefWidth(ARTBOARD_WIDTH - ARTBOARD_HEIGHT - 5);
valueField.getStyleClass().add("valueField");
// always needed
drawingPane = new Pane();
drawingPane.setMaxSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
drawingPane.setMinSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
drawingPane.setPrefSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
}
public CenterArc() {
fillColor = Color.color(Math.random(), Math.random(), Math.random());
strokeColor = Color.YELLOW;
width = 120;
height = 120;
x = (Game.getInstance().getRender().getWidth() - width) / 2;
y = (Game.getInstance().getRender().getHeight() - height) / 2;
for (int i = 0; i < 4; i++) {
Arc arc = new Arc(x, y, width, height, i * 90, 30);
arc.setType(ArcType.ROUND);
shapes.add(arc);
}
effect = new GaussianBlur();
start();
}
private void drawSections() {
if (sections.isEmpty()) return;
sectionLayer.getChildren().clear();
double centerX = width * 0.5;
double centerY = height * 0.85;
double barRadius = height * 0.54210526;
double barWidth = width * 0.28472222;
List<Arc> sectionBars = new ArrayList<>(sections.size());
for (Section section : sections) {
Arc sectionBar = new Arc(centerX, centerY, barRadius, barRadius, angleRange * 0.5 + 90 - (section.getStart() * angleStep), -((section.getStop() - section.getStart()) - minValue) * angleStep);
sectionBar.setType(ArcType.OPEN);
sectionBar.setStroke(section.getColor());
sectionBar.setStrokeWidth(barWidth);
sectionBar.setStrokeLineCap(StrokeLineCap.BUTT);
sectionBar.setFill(null);
Tooltip sectionTooltip = new Tooltip(new StringBuilder(section.getText()).append("\n").append(String.format(Locale.US, "%.2f", section.getStart())).append(" - ").append(String.format(Locale.US, "%.2f", section.getStop())).toString());
sectionTooltip.setTextAlignment(TextAlignment.CENTER);
Tooltip.install(sectionBar, sectionTooltip);
sectionBars.add(sectionBar);
}
sectionLayer.getChildren().addAll(sectionBars);
}
/** Add four arcs to a pane and place them in a stack pane */
private void getBlades() {
double angle = 0;
for (int i = 0; i < 4; i++) {
arc = new Arc();
arc.centerXProperty().bind(widthProperty().divide(2));
arc.centerYProperty().bind(heightProperty().divide(2));
arc.radiusXProperty().bind(circle.radiusProperty().multiply(.90));
arc.radiusYProperty().bind(circle.radiusProperty().multiply(.90));
arc.setStartAngle(angle + 90);
arc.setLength(50);
arc.setFill(Color.BLACK);
arc.setType(ArcType.ROUND);
paneForBlades.getChildren().add(arc);
angle += 90;
}
}
private void initializeParts() {
double cx = ARTBOARD_WIDTH * 0.5;
separator = new Line(25, 15, 225, 15);
separator.getStyleClass().add("separator");
separator.setStrokeLineCap(StrokeLineCap.ROUND);
titleLabel = createCenteredText(cx, 19, "title");
titleLabel.setTextOrigin(VPos.TOP);
valueLabel = createCenteredText(cx, 150, "value");
unitLabel = createCenteredText(cx, 188, "unit");
unitLabel.setTextOrigin(VPos.TOP);
barBackground = new Circle(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, RADIUS);
barBackground.getStyleClass().add("barBackground");
bar = new Arc(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, RADIUS, RADIUS, START_ANGLE, 0);
bar.getStyleClass().add("bar");
bar.setType(ArcType.OPEN);
thumb = new Circle(7);
thumb.getStyleClass().add("thumb");
// always needed
drawingPane = new Pane();
drawingPane.setMaxSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
drawingPane.setMinSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
drawingPane.setPrefSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
}
/** Return a Arc of specified properties */
private Arc getArc(Circle c) {
Arc a = new Arc(c.getRadius(), c.getRadius() * 1.30,
c.getRadius() / 2, c.getRadius() / 4, 0, -180);
a.setType(ArcType.OPEN);
a.setFill(Color.WHITE);
a.setStroke(Color.BLACK);
return a;
}
@Override protected void initGraphics() {
super.initGraphics();
if (tile.isAutoScale()) tile.calcAutoScale();
oldValue = tile.getValue();
sectionMap = new HashMap<>(sections.size());
for(Section section : sections) { sectionMap.put(section, new Arc()); }
barColor = tile.getBarColor();
thresholdColor = tile.getThresholdColor();
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(barColor);
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
thresholdBar.setType(ArcType.OPEN);
thresholdBar.setStroke(tile.getThresholdColor());
thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
thresholdBar.setFill(null);
Helper.enableNode(thresholdBar, !tile.getSectionsVisible());
sectionPane = new Pane();
Helper.enableNode(sectionPane, tile.getSectionsVisible());
if (sectionsVisible) { drawSections(); }
alertIcon = new Path();
alertIcon.setFillRule(FillRule.EVEN_ODD);
alertIcon.setFill(Color.YELLOW);
alertIcon.setStroke(null);
Helper.enableNode(alertIcon, tile.isAlert());
alertTooltip = new Tooltip(tile.getAlertMessage());
Tooltip.install(alertIcon, alertTooltip);
needleRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRect = new Rectangle();
needleRect.setFill(tile.getBackgroundColor());
needleRect.getTransforms().setAll(needleRectRotate);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(tile.getNeedleColor());
needle.setStrokeWidth(0);
needle.setStroke(Color.TRANSPARENT);
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
valueText.setFill(tile.getValueColor());
valueText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
unitText = new Text(tile.getUnit());
unitText.setFill(tile.getUnitColor());
unitText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(unitText, tile.isValueVisible() && !tile.isAlert());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
minValueText.setFill(tile.getTitleColor());
maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
maxValueText.setFill(tile.getTitleColor());
thresholdRect = new Rectangle();
thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
Helper.enableNode(thresholdRect, tile.isThresholdVisible());
thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
Helper.enableNode(thresholdText, tile.isThresholdVisible());
getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, minValueText, maxValueText, thresholdRect, thresholdText);
}
private void drawTimeSections() {
if (sectionMap.isEmpty()) return;
ZonedDateTime time = tile.getTime();
DayOfWeek day = time.getDayOfWeek();
boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0;
double offset = 90;
double angleStep = 360.0 / 60.0;
boolean highlightSections = tile.isHighlightSections();
for (TimeSection section : sectionMap.keySet()) {
LocalTime start = section.getStart();
LocalTime stop = section.getStop();
boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0;
boolean draw = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM);
if (!section.getDays().contains(day)) { draw = false; }
if (!section.isActive()) { draw = false; }
if (draw) {
double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;
double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); }
Arc arc = sectionMap.get(section);
arc.setCenterX(clockSize * 0.5);
arc.setCenterY(clockSize * 0.5);
arc.setRadiusX(clockSize * 0.45);
arc.setRadiusY(clockSize * 0.45);
arc.setStartAngle(-(offset + sectionStartAngle));
arc.setLength(-sectionAngleExtend);
arc.setType(ArcType.OPEN);
arc.setStrokeWidth(clockSize * 0.04);
arc.setStrokeLineCap(StrokeLineCap.BUTT);
arc.setFill(null);
if (highlightSections) {
arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
} else {
arc.setStroke(section.getColor());
}
}
}
}
@Override // Override the start method in the Applicaton class
public void start(Stage primaryStage) {
// Create a pane
Pane pane = new Pane();
// Create an ellipse and set its properties
Ellipse ellipse = new Ellipse(75, 40, 50, 20);
ellipse.setStroke(Color.BLACK);
ellipse.setFill(Color.WHITE);
// Create two Arcs and set their properties
Arc arc1 = new Arc(ellipse.getCenterX(), 150, ellipse.getRadiusX(),
ellipse.getRadiusY(), 0, -180);
arc1.setType(ArcType.OPEN);
arc1.setFill(Color.WHITE);
arc1.setStroke(Color.BLACK);
Arc arc2 = new Arc(ellipse.getCenterX(), arc1.getCenterY(),
ellipse.getRadiusX(), ellipse.getRadiusY(), 0, 180);
arc2.setType(ArcType.OPEN);
arc2.setFill(Color.WHITE);
arc2.setStroke(Color.BLACK);
arc2.getStrokeDashArray().addAll(6.0, 21.0);
// Create two lines and set thier properties
Line line1 = new Line(ellipse.getCenterX() - ellipse.getRadiusX(),
ellipse.getCenterY(), ellipse.getCenterX() - ellipse.getRadiusX(),
arc1.getCenterY());
Line line2 = new Line((ellipse.getCenterX() - ellipse.getRadiusX()) +
ellipse.getRadiusX() * 2, ellipse.getCenterY(),
(ellipse.getCenterX() - ellipse.getRadiusX())
+ ellipse.getRadiusX() * 2, arc1.getCenterY());
// Place nodes in pane
pane.getChildren().addAll(ellipse, arc1, arc2, line1, line2);
// Create a scene and place it in the stage
Scene scene = new Scene(pane, 150, 200);
primaryStage.setTitle("Exercise_14_10"); // Set the stage title
primaryStage.setScene(scene); // Place the scenen in the stage
primaryStage.show(); // Display the stage
}
@Override
protected void clipPath(final Arc arc) {
if(!model.getArcStyle().supportArrow()) {
arc.setClip(null);
return;
}
final double width = Math.max(arc.getRadiusX() * 2d, 1d);
double sAngle = model.getAngleStart();
double eAngle = model.getAngleEnd();
Arrow arr = model.getArrowAt(1);
final double gap = Math.atan(arr.getArrowShapeLength() / width);
if(arr.getArrowStyle().isReducingShape()) {
if(eAngle > sAngle) {
eAngle -= gap;
}else {
eAngle += gap;
}
}
arr = model.getArrowAt(0);
if(arr.getArrowStyle().isReducingShape()) {
if(eAngle > sAngle) {
sAngle += gap;
}else {
sAngle -= gap;
}
}
sAngle = Math.toDegrees(sAngle % (2d * Math.PI));
eAngle = Math.toDegrees(eAngle % (2d * Math.PI));
if(MathUtils.INST.equalsDouble(sAngle, eAngle)) {
eAngle += 0.1;
}
final Arc clip = new Arc(arc.getCenterX(), arc.getCenterY(), arc.getRadiusX(), arc.getRadiusY(), sAngle, eAngle - sAngle);
clip.setType(arc.getType());
clip.setStrokeWidth(arc.getStrokeWidth());
arc.setClip(clip);
}
private void initGraphics() {
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.2), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008);
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.2), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008);
highlight.setInput(innerShadow);
dropShadow.setInput(highlight);
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(barColor.get());
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.setFill(color.get());
ring.setEffect(dropShadow);
mainCircle = new Circle();
mainCircle.setFill(color.get().darker().darker());
text = new Text(String.format(Locale.US, formatString, getTargetValue()));
text.setFill(Color.WHITE);
text.setTextOrigin(VPos.CENTER);
indicatorRotate = new Rotate(-ANGLE_RANGE * 0.5, center, center);
indicatorGlow = new DropShadow(BlurType.TWO_PASS_BOX, getIndicatorColor(), PREFERRED_WIDTH * 0.02, 0.0, 0, 0);
indicatorInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.5), 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);
indicatorHighlight.setInput(indicatorInnerShadow);
indicator = new Circle();
indicator.setFill(color.get().darker());
indicator.setStroke(color.get().darker().darker());
indicator.setMouseTransparent(true);
indicator.getTransforms().add(indicatorRotate);
Group indicatorGroup = new Group(indicator);
indicatorGroup.setEffect(indicatorHighlight);
symbol = new Region();
symbol.getStyleClass().setAll("symbol");
symbol.setCacheHint(CacheHint.SPEED);
icon = new FontIcon();
icon.setTextOrigin(VPos.CENTER);
iconPane = new StackPane(symbol, icon);
pane = new Pane(barArc, ring, mainCircle, text, indicatorGroup, iconPane);
pane.setPrefSize(PREFERRED_HEIGHT, PREFERRED_HEIGHT);
pane.setBackground(new Background(new BackgroundFill(color.get().darker(), new CornerRadii(1024), Insets.EMPTY)));
pane.setEffect(highlight);
getChildren().setAll(pane);
}
@Override protected void initGraphics() {
super.initGraphics();
if (tile.isAutoScale()) tile.calcAutoScale();
gradientLookup = new GradientLookup(tile.getGradientStops());
noOfGradientStops = tile.getGradientStops().size();
sectionsVisible = tile.getSectionsVisible();
colorGradientEnabled = tile.isStrokeWithGradient();
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getValue()));
valueText.setFill(tile.getValueColor());
Helper.enableNode(valueText, tile.isValueVisible());
upperUnitText = new Text("");
upperUnitText.setFill(tile.getUnitColor());
Helper.enableNode(upperUnitText, !tile.getUnit().isEmpty());
fractionLine = new Line();
unitText = new Text(tile.getUnit());
unitText.setFill(tile.getUnitColor());
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
unitFlow = new VBox(upperUnitText, unitText);
unitFlow.setAlignment(Pos.CENTER_RIGHT);
valueUnitFlow = new HBox(valueText, unitFlow);
valueUnitFlow.setAlignment(Pos.CENTER);
valueUnitFlow.setMouseTransparent(true);
text = new Text(tile.getText());
text.setTextOrigin(VPos.TOP);
text.setFill(tile.getTextColor());
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, 0, ANGLE_RANGE);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(tile.getBarBackgroundColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.125);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, 270, 0);
bar.setType(ArcType.OPEN);
bar.setStroke(tile.getBarColor());
bar.setStrokeWidth(PREFERRED_WIDTH * 0.125);
bar.setStrokeLineCap(StrokeLineCap.BUTT);
bar.setFill(null);
lowerThreshold = new Line();
lowerThreshold.setStroke(tile.getLowerThresholdColor());
lowerThreshold.setStrokeLineCap(StrokeLineCap.BUTT);
Helper.enableNode(lowerThreshold, tile.isLowerThresholdVisible());
lowerThresholdText = new Text(String.format(locale, formatString, tile.getLowerThreshold()));
Helper.enableNode(lowerThresholdText, tile.isLowerThresholdVisible());
threshold = new Line();
threshold.setStroke(tile.getThresholdColor());
threshold.setStrokeLineCap(StrokeLineCap.BUTT);
Helper.enableNode(threshold, tile.isThresholdVisible());
thresholdText = new Text(String.format(locale, formatString, tile.getThreshold()));
Helper.enableNode(thresholdText, tile.isThresholdVisible());
minValueText = new Text();
maxValueText = new Text();
getPane().getChildren().addAll(barBackground, bar, lowerThreshold, lowerThresholdText, threshold, thresholdText, minValueText, maxValueText, titleText, valueUnitFlow, fractionLine, text);
}
@Override protected void initGraphics() {
super.initGraphics();
duration = tile.getTimePeriod();
minValue = 0;
maxValue = duration.getSeconds();
range = duration.getSeconds();
angleStep = ANGLE_RANGE / range;
locale = tile.getLocale();
titleText = new Text();
titleText.setFill(tile.getTitleColor());
enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getTextColor());
enableNode(text, tile.isTextVisible());
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 360);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(tile.getBarBackgroundColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.1);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 0);
bar.setType(ArcType.OPEN);
bar.setStroke(tile.getBarColor());
bar.setStrokeWidth(PREFERRED_WIDTH * 0.1);
bar.setStrokeLineCap(StrokeLineCap.BUTT);
bar.setFill(null);
separator = new Line(PREFERRED_WIDTH * 0.5, 1, PREFERRED_WIDTH * 0.5, 0.16667 * PREFERRED_HEIGHT);
separator.setStroke(tile.getBackgroundColor());
separator.setFill(Color.TRANSPARENT);
durationText = new Text();
durationText.setFont(Fonts.latoRegular(PREFERRED_WIDTH * 0.27333));
durationText.setFill(tile.getValueColor());
durationText.setTextOrigin(VPos.CENTER);
durationFlow = new TextFlow(durationText);
durationFlow.setTextAlignment(TextAlignment.CENTER);
timeText = new Text(DTF.format(LocalTime.now().plus(tile.getTimePeriod().getSeconds(), ChronoUnit.SECONDS)));
timeText.setFont(Fonts.latoRegular(PREFERRED_WIDTH * 0.27333));
timeText.setFill(tile.getValueColor());
timeText.setTextOrigin(VPos.CENTER);
enableNode(timeText, tile.isValueVisible());
timeFlow = new TextFlow(timeText);
timeFlow.setTextAlignment(TextAlignment.CENTER);
runningListener = (o, ov, nv) -> {
if (nv) {
timeText.setText(DTF.format(LocalTime.now().plus(duration.getSeconds(), ChronoUnit.SECONDS)));
}
};
timeListener = e -> {
if (TimeEventType.SECOND == e.TYPE) {
updateBar();
}
};
getPane().getChildren().addAll(barBackground, bar, separator, titleText, text, durationFlow, timeFlow);
}
private void initGraphics() {
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.2), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008);
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.2), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008);
highlight.setInput(innerShadow);
dropShadow.setInput(highlight);
Stop[] stops = { new Stop(0.0, Color.rgb(255,255,0)),
new Stop(0.125, Color.rgb(255,0,0)),
new Stop(0.375, Color.rgb(255,0,255)),
new Stop(0.5, Color.rgb(0,0,255)),
new Stop(0.625, Color.rgb(0,255,255)),
new Stop(0.875, Color.rgb(0,255,0)),
new Stop(1.0, Color.rgb(255,255,0)) };
List<Stop> reorderedStops = reorderStops(stops);
gradientLookup = new GradientLookup(stops);
barGradient = new ConicalGradient(reorderedStops);
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)));
buttonOn = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, -125, 34.75);
buttonOn.setFill(null);
buttonOn.setStroke(color.get());
buttonOn.setStrokeLineCap(StrokeLineCap.BUTT);
buttonOn.setStrokeWidth(PREFERRED_WIDTH * 0.072);
buttonOn.setEffect(dropShadow);
buttonOff = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, -89.75, 34.75);
buttonOff.setFill(null);
buttonOff.setStroke(color.get());
buttonOff.setStrokeLineCap(StrokeLineCap.BUTT);
buttonOff.setStrokeWidth(PREFERRED_WIDTH * 0.072);
buttonOff.setEffect(dropShadow);
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.setFill(color.get());
ring.setEffect(highlight);
mainCircle = new Circle();
mainCircle.setFill(color.get().darker().darker());
textOn = new Text("ON");
textOn.setFill(textColor.get());
textOn.setTextOrigin(VPos.CENTER);
textOn.setMouseTransparent(true);
textOn.setRotate(17);
textOff = new Text("OFF");
textOff.setFill(textColor.get());
textOff.setTextOrigin(VPos.CENTER);
textOff.setMouseTransparent(true);
textOff.setRotate(-17);
indicatorRotate = new Rotate(-ANGLE_RANGE * 0.5, center, center);
indicatorGlow = new DropShadow(BlurType.TWO_PASS_BOX, getIndicatorColor(), PREFERRED_WIDTH * 0.02, 0.0, 0, 0);
indicatorInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.5), 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);
indicatorHighlight.setInput(indicatorInnerShadow);
indicator = new Circle();
indicator.setFill(color.get().darker());
indicator.setStroke(color.get().darker().darker());
indicator.setMouseTransparent(true);
indicator.getTransforms().add(indicatorRotate);
Group indicatorGroup = new Group(indicator);
indicatorGroup.setEffect(indicatorHighlight);
innerRing = Shape.subtract(new Circle(center, center, PREFERRED_WIDTH * 0.24),
new Circle(center, center, PREFERRED_WIDTH * 0.2));
innerRing.setFill(color.get());
currentColorCircle = new Circle();
currentColorCircle.setFill(targetColor.get());
currentColorCircle.setVisible(isOn());
pane = new Pane(barArc, ring, mainCircle, currentColorCircle, innerRing, indicatorGroup, buttonOn, textOn, buttonOff, textOff);
pane.setPrefSize(PREFERRED_HEIGHT, PREFERRED_HEIGHT);
pane.setBackground(new Background(new BackgroundFill(color.get().darker(), new CornerRadii(1024), Insets.EMPTY)));
pane.setEffect(highlight);
getChildren().setAll(pane);
}
private void initGraphics() {
// Set initial size
if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
} else {
gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(gauge.getBarColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
thresholdBar.setType(ArcType.OPEN);
thresholdBar.setStroke(gauge.getThresholdColor());
thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
thresholdBar.setFill(null);
enableNode(thresholdBar, !gauge.getSectionsVisible());
sectionPane = new Pane();
enableNode(sectionPane, gauge.getSectionsVisible());
if (sectionsVisible) { drawSections(); }
alertIcon = new Path();
alertIcon.setFillRule(FillRule.EVEN_ODD);
alertIcon.setFill(Color.YELLOW);
alertIcon.setStroke(null);
enableNode(alertIcon, gauge.isAlert());
alertTooltip = new Tooltip(gauge.getAlertMessage());
Tooltip.install(alertIcon, alertTooltip);
needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needleRectRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needleRect = new Rectangle();
needleRect.setFill(gauge.getBackgroundPaint());
needleRect.getTransforms().setAll(needleRectRotate);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(gauge.getNeedleColor());
needle.setStrokeWidth(0);
needle.setStroke(Color.TRANSPARENT);
titleText = new Text(gauge.getTitle());
titleText.setFill(gauge.getTitleColor());
enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, gauge.getCurrentValue()));
valueText.setFill(gauge.getValueColor());
enableNode(valueText, gauge.isValueVisible() && !gauge.isAlert());
unitText = new Text(gauge.getUnit());
unitText.setFill(gauge.getUnitColor());
enableNode(unitText, gauge.isValueVisible() && !gauge.isAlert());
minValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMinValue()));
minValueText.setFill(gauge.getTitleColor());
maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
maxValueText.setFill(gauge.getTitleColor());
thresholdRect = new Rectangle();
thresholdRect.setFill(sectionsVisible ? GRAY : gauge.getThresholdColor());
enableNode(thresholdRect, gauge.isThresholdVisible());
thresholdText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getThreshold()));
thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : gauge.getBackgroundPaint());
enableNode(thresholdText, gauge.isThresholdVisible());
pane = new Pane(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueText, unitText, minValueText, maxValueText, thresholdRect, thresholdText);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));
getChildren().setAll(pane);
}
private void initGraphics() {
// Set initial size
if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
} else {
gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(gauge.getBarColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
thresholdBar.setType(ArcType.OPEN);
thresholdBar.setStroke(gauge.getThresholdColor());
thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
thresholdBar.setFill(null);
needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(gauge.getNeedleColor());
needle.setStrokeWidth(0);
needle.setStroke(Color.TRANSPARENT);
titleText = new Text(gauge.getTitle());
titleText.setFill(gauge.getTitleColor());
Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
valueText.setFill(gauge.getValueColor());
Helper.enableNode(valueText, gauge.isValueVisible());
minValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMinValue()));
minValueText.setFill(gauge.getTitleColor());
maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
maxValueText.setFill(gauge.getTitleColor());
thresholdText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getThreshold()));
thresholdText.setFill(gauge.getTitleColor());
Helper.enableNode(thresholdText, Double.compare(gauge.getThreshold(), gauge.getMinValue()) != 0 && Double.compare(gauge.getThreshold(), gauge.getMaxValue()) != 0);
pane = new Pane(barBackground, thresholdBar, needle, titleText, valueText, minValueText, maxValueText, thresholdText);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));
getChildren().setAll(pane);
}
private void initGraphics() {
// Set initial size
if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
} else {
gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, ANGLE_RANGE * 0.5 + 90, -ANGLE_RANGE);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(gauge.getBarBackgroundColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionCtx = sectionCanvas.getGraphicsContext2D();
needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needleMoveTo1 = new MoveTo();
needleCubicCurveTo2 = new CubicCurveTo();
needleCubicCurveTo3 = new CubicCurveTo();
needleCubicCurveTo4 = new CubicCurveTo();
needleCubicCurveTo5 = new CubicCurveTo();
needleClosePath6 = new ClosePath();
needleMoveTo7 = new MoveTo();
needleCubicCurveTo8 = new CubicCurveTo();
needleCubicCurveTo9 = new CubicCurveTo();
needleCubicCurveTo10 = new CubicCurveTo();
needleCubicCurveTo11 = new CubicCurveTo();
needleClosePath12 = new ClosePath();
needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleCubicCurveTo5, needleClosePath6,
needleMoveTo7, needleCubicCurveTo8, needleCubicCurveTo9, needleCubicCurveTo10, needleCubicCurveTo11, needleClosePath12);
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(gauge.getNeedleColor());
needle.setStrokeType(StrokeType.INSIDE);
needle.setStrokeWidth(1);
needle.setStroke(gauge.getBackgroundPaint());
needleTooltip = new Tooltip(String.format(locale, formatString, gauge.getValue()));
needleTooltip.setTextAlignment(TextAlignment.CENTER);
Tooltip.install(needle, needleTooltip);
pane = new Pane(barBackground, sectionCanvas, needle);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));
getChildren().setAll(pane);
}
DeterminateIndicator(TxConfidenceIndicator control, StaticProgressIndicatorSkin s,
Paint fillOverride) {
this.control = control;
getStyleClass().add("determinate-indicator");
intProgress = (int) Math.round(control.getProgress() * 100.0);
degProgress = (int) (360 * control.getProgress());
InvalidationListener progressListener = valueModel -> updateProgress();
control.progressProperty().addListener(progressListener);
getChildren().clear();
// The circular background for the progress pie piece
indicator = new StackPane();
indicator.setScaleShape(false);
indicator.setCenterShape(false);
indicator.getStyleClass().setAll("indicator");
indicatorCircle = new Circle();
indicator.setShape(indicatorCircle);
// The shape for our progress pie piece
arcShape = new Arc();
arcShape.setType(ArcType.ROUND);
arcShape.setStartAngle(90.0F);
// Our progress pie piece
progress = new StackPane();
progress.getStyleClass().setAll("progress");
progress.setScaleShape(false);
progress.setCenterShape(false);
progress.setShape(arcShape);
progress.getChildren().clear();
setFillOverride(fillOverride);
// The check mark that's drawn at 100%
tick = new StackPane();
tick.getStyleClass().setAll("tick");
getChildren().setAll(indicator, progress, /*text,*/ tick);
updateProgress();
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane
Pane pane = new Pane();
double[] scores = {20, 10, 30, 40};
String[] grades = {"Project", "Quiz", "Midterm", "Final"};
// Create four text objects
Text t1 = new Text(110, 80, grades[0] + " -- " + scores[0] + "%");
Text t2 = new Text(80, 15, grades[1] + " -- " + scores[1] + "%");
Text t3 = new Text(5, 100, grades[2] + " -- " + scores[2] + "%");
Text t4 = new Text(100, 180, grades[3] + " -- " + scores[3] + "%");
// Create four Arcs
Arc arc1 = new Arc(100, 100, 80, 80, 0, 360 * (scores[0] / 100));
arc1.setFill(Color.RED);
arc1.setType(ArcType.ROUND);
Arc arc2 = new Arc(100, 100, 80, 80, arc1.getStartAngle() +
arc1.getLength(), 360 * (scores[1] / 100));
arc2.setFill(Color.BLUE);
arc2.setType(ArcType.ROUND);
Arc arc3 = new Arc(100, 100, 80, 80, arc2.getStartAngle() +
arc2.getLength(), 360 * (scores[2] / 100));
arc3.setFill(Color.GREEN);
arc3.setType(ArcType.ROUND);
Arc arc4 = new Arc(100, 100, 80, 80, arc3.getStartAngle() +
arc3.getLength(), 360 * (scores[3] / 100));
arc4.setFill(Color.ORANGE);
arc4.setType(ArcType.ROUND);
pane.getChildren().addAll(arc1, arc2, arc3, arc4, t1, t2, t3, t4);
// Create a Scene and place it in the Stage;
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise_14_13"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}