Java Code Examples for javafx.scene.shape.Rectangle#relocate()

The following examples show how to use javafx.scene.shape.Rectangle#relocate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeckBuilderWindow.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private void displayCurrentPage() {
	this.cardListBox.getChildren().clear();
	for (CardInfoMessage message : this.pageList.get(this.currentPage)) {
		CardHandDocumentController card = new CardHandDocumentController(message, null);
		Pane cardPane = card.getRootPane();			
		
		Rectangle numberOfCardsBox = new Rectangle(cardPane.getPrefWidth()/3, cardPane.getPrefHeight()/10);
		numberOfCardsBox.setFill(Color.BLUE);
		numberOfCardsBox.setStroke(Color.BLACK);
		int numChosenCards = 0;
		if (this.activeDeckConfig.getChosen().get(message.getId()) != null) {
			numChosenCards = this.activeDeckConfig.getChosen().get(message.getId());
		}
		String id = (String) message.getProperties().get("id");

		Label numberOfCardsLabel = new Label(String.format("%d / %d", numChosenCards, this.activeDeckConfig.getMaxFor(id)));
		numberOfCardsLabel.setTextFill(Color.WHITE);
		numberOfCardsBox.relocate(cardPane.getPrefWidth()/2.6, cardPane.getPrefHeight() - cardPane.getPrefHeight()/18);
		numberOfCardsLabel.relocate(cardPane.getPrefWidth()/2.3, cardPane.getPrefHeight() - cardPane.getPrefHeight()/18);
		cardPane.getChildren().add(numberOfCardsBox);
		cardPane.getChildren().add(numberOfCardsLabel);
		
		cardPane.setOnMouseClicked(e -> {this.addCardToActiveDeck(e, message);});
		cardPane.setOnDragDetected(e -> this.startDragToActiveDeck(e, cardPane, message));
		this.cardListBox.getChildren().add(cardPane);
	}
}
 
Example 2
Source File: GenericButton.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
public void setUpRectangle() {
	this.buttonBackground = new Rectangle(0, 0, this.sizeX, this.sizeY);
	this.buttonBackground.setFill(Color.BLUEVIOLET);
	this.getChildren().add(this.buttonBackground);
	
	Rectangle buttonForeground = new Rectangle(0, 0, this.sizeX * 0.90, this.sizeY * 0.80);
	buttonForeground.relocate(this.sizeX * 0.05, this.sizeY * 0.10);
	buttonForeground.setFill(Color.BLACK);
	this.getChildren().add(buttonForeground);
}
 
Example 3
Source File: CustomPlainAmpSkin.java    From medusademo with Apache License 2.0 4 votes vote down vote up
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);
        }
    }

    ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ticksAndSections       = ticksAndSectionsCanvas.getGraphicsContext2D();

    ledCanvas = new Canvas();
    led       = ledCanvas.getGraphicsContext2D();

    thresholdTooltip = new Tooltip("Threshold\n(" + String.format(locale, formatString, gauge.getThreshold()) + ")");
    thresholdTooltip.setTextAlignment(TextAlignment.CENTER);

    threshold = new Path();
    Helper.enableNode(threshold, gauge.isThresholdVisible());
    Tooltip.install(threshold, thresholdTooltip);

    average = new Path();
    Helper.enableNode(average, gauge.isAverageVisible());

    markerPane = new Pane();

    needleRotate = new Rotate(180 - START_ANGLE);
    needleRotate.setAngle(needleRotate.getAngle() + (gauge.getValue() - oldValue - gauge.getMinValue()) * angleStep);

    needleMoveTo1       = new MoveTo();
    needleCubicCurveTo2 = new CubicCurveTo();
    needleCubicCurveTo3 = new CubicCurveTo();
    needleCubicCurveTo4 = new CubicCurveTo();
    needleLineTo5       = new LineTo();
    needleCubicCurveTo6 = new CubicCurveTo();
    needleClosePath7    = new ClosePath();
    needle              = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleCubicCurveTo6, needleClosePath7);
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.getStyleClass().add("needle");

    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);

    shadowGroup = new Group(needle);
    shadowGroup.setEffect(gauge.isShadowsEnabled() ? dropShadow : null);
    shadowGroup.getStyleClass().add("shadow-group");

    unitText = new Text(gauge.getUnit());
    unitText.setMouseTransparent(true);
    unitText.setTextOrigin(VPos.CENTER);
    unitText.getStyleClass().add("unit");

    lcd = new Rectangle(0.3 * PREFERRED_WIDTH, 0.1 * PREFERRED_HEIGHT);
    lcd.setArcWidth(0.0125 * PREFERRED_HEIGHT);
    lcd.setArcHeight(0.0125 * PREFERRED_HEIGHT);
    lcd.relocate((PREFERRED_WIDTH - lcd.getWidth()) * 0.5, 0.66 * PREFERRED_HEIGHT);
    lcd.getStyleClass().add("lcd");
    Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());

    lcdText = new Label(String.format(locale, "%." + gauge.getDecimals() + "f", gauge.getValue()));
    lcdText.setAlignment(Pos.CENTER_RIGHT);
    lcdText.setVisible(gauge.isValueVisible());
    lcdText.getStyleClass().add("lcd-foreground");

    // Set initial value
    angleStep          = ANGLE_RANGE / gauge.getRange();
    double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
    targetAngle        = clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle);
    needleRotate.setAngle(targetAngle);

    // Add all nodes
    pane = new Pane();
    pane.getChildren().setAll(ticksAndSectionsCanvas,
                              markerPane,
                              ledCanvas,
                              unitText,
                              lcd,
                              lcdText,
                              shadowGroup);
    pane.getStyleClass().add("background-pane");

    getChildren().setAll(pane);
}
 
Example 4
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
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);
        }
    }

    ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ticksAndSections       = ticksAndSectionsCanvas.getGraphicsContext2D();

    ledCanvas = new Canvas();
    led       = ledCanvas.getGraphicsContext2D();

    thresholdTooltip = new Tooltip("Threshold\n(" + String.format(locale, formatString, gauge.getThreshold()) + ")");
    thresholdTooltip.setTextAlignment(TextAlignment.CENTER);

    threshold = new Path();
    Helper.enableNode(threshold, gauge.isThresholdVisible());
    Tooltip.install(threshold, thresholdTooltip);

    average = new Path();
    Helper.enableNode(average, gauge.isAverageVisible());

    markerPane = new Pane();

    needleRotate = new Rotate(180 - START_ANGLE);
    needleRotate.setAngle(needleRotate.getAngle() + (gauge.getValue() - oldValue - gauge.getMinValue()) * angleStep);

    needleMoveTo1       = new MoveTo();
    needleCubicCurveTo2 = new CubicCurveTo();
    needleCubicCurveTo3 = new CubicCurveTo();
    needleCubicCurveTo4 = new CubicCurveTo();
    needleLineTo5       = new LineTo();
    needleCubicCurveTo6 = new CubicCurveTo();
    needleClosePath7    = new ClosePath();
    needle              = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleCubicCurveTo6, needleClosePath7);
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);

    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);

    shadowGroup = new Group(needle);
    shadowGroup.setEffect(gauge.isShadowsEnabled() ? dropShadow : null);

    unitText = new Text(gauge.getUnit());
    unitText.setMouseTransparent(true);
    unitText.setTextOrigin(VPos.CENTER);

    lcd = new Rectangle(0.3 * PREFERRED_WIDTH, 0.1 * PREFERRED_HEIGHT);
    lcd.setArcWidth(0.0125 * PREFERRED_HEIGHT);
    lcd.setArcHeight(0.0125 * PREFERRED_HEIGHT);
    lcd.relocate((PREFERRED_WIDTH - lcd.getWidth()) * 0.5, 0.66 * PREFERRED_HEIGHT);
    Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());

    lcdText = new Label(String.format(locale, "%." + gauge.getDecimals() + "f", gauge.getValue()));
    lcdText.setAlignment(Pos.CENTER_RIGHT);
    lcdText.setVisible(gauge.isValueVisible());

    // Set initial value
    angleStep          = ANGLE_RANGE / gauge.getRange();
    double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
    targetAngle        = clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle);
    needleRotate.setAngle(targetAngle);

    // Add all nodes
    pane = new Pane();
    pane.getChildren().setAll(ticksAndSectionsCanvas,
                              markerPane,
                              ledCanvas,
                              unitText,
                              lcd,
                              lcdText,
                              shadowGroup);

    getChildren().setAll(pane);
}
 
Example 5
Source File: AmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
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);
        }
    }

    ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ticksAndSections       = ticksAndSectionsCanvas.getGraphicsContext2D();

    ledCanvas = new Canvas();
    led       = ledCanvas.getGraphicsContext2D();

    thresholdTooltip = new Tooltip("Threshold\n(" + String.format(locale, formatString, gauge.getThreshold()) + ")");
    thresholdTooltip.setTextAlignment(TextAlignment.CENTER);

    threshold = new Path();
    Helper.enableNode(threshold, gauge.isThresholdVisible());
    Tooltip.install(threshold, thresholdTooltip);

    average = new Path();
    Helper.enableNode(average, gauge.isAverageVisible());

    markerPane = new Pane();

    needleRotate = new Rotate(180 - START_ANGLE);
    needleRotate.setAngle(needleRotate.getAngle() + (gauge.getValue() - oldValue - gauge.getMinValue()) * angleStep);

    needleMoveTo1       = new MoveTo();
    needleCubicCurveTo2 = new CubicCurveTo();
    needleCubicCurveTo3 = new CubicCurveTo();
    needleCubicCurveTo4 = new CubicCurveTo();
    needleLineTo5       = new LineTo();
    needleCubicCurveTo6 = new CubicCurveTo();
    needleClosePath7    = new ClosePath();
    needle              = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleCubicCurveTo6, needleClosePath7);
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);

    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);

    shadowGroup = new Group(needle);
    shadowGroup.setEffect(gauge.isShadowsEnabled() ? dropShadow : null);

    titleText = new Text(gauge.getTitle());
    titleText.setTextOrigin(VPos.CENTER);
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    unitText = new Text(gauge.getUnit());
    unitText.setMouseTransparent(true);
    unitText.setTextOrigin(VPos.CENTER);

    lcd = new Rectangle(0.3 * PREFERRED_WIDTH, 0.1 * PREFERRED_HEIGHT);
    lcd.setArcWidth(0.0125 * PREFERRED_HEIGHT);
    lcd.setArcHeight(0.0125 * PREFERRED_HEIGHT);
    lcd.relocate((PREFERRED_WIDTH - lcd.getWidth()) * 0.5, 0.44 * PREFERRED_HEIGHT);
    Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());

    lcdText = new Label(String.format(locale, "%." + gauge.getDecimals() + "f", gauge.getValue()));
    lcdText.setAlignment(Pos.CENTER_RIGHT);
    lcdText.setVisible(gauge.isValueVisible());

    // Set initial value
    angleStep          = ANGLE_RANGE / gauge.getRange();
    double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
    targetAngle        = clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle);
    needleRotate.setAngle(targetAngle);

    lightEffect = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.65), 2, 0.0, 0.0, 2.0);

    foreground = new SVGPath();
    foreground.setContent("M 26 26.5 C 26 20.2432 26.2432 20 32.5 20 L 277.5 20 C 283.7568 20 284 20.2432 284 26.5 L 284 143.5 C 284 149.7568 283.7568 150 277.5 150 L 32.5 150 C 26.2432 150 26 149.7568 26 143.5 L 26 26.5 ZM 0 6.7241 L 0 253.2758 C 0 260 0 260 6.75 260 L 303.25 260 C 310 260 310 260 310 253.2758 L 310 6.7241 C 310 0 310 0 303.25 0 L 6.75 0 C 0 0 0 0 0 6.7241 Z");
    foreground.setEffect(lightEffect);

    // Add all nodes
    pane = new Pane();
    pane.getChildren().setAll(ticksAndSectionsCanvas,
                              markerPane,
                              ledCanvas,
                              unitText,
                              lcd,
                              lcdText,
                              shadowGroup,
                              foreground,
                              titleText);

    getChildren().setAll(pane);
}
 
Example 6
Source File: LinearSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
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(preferredWidth, preferredHeight);
        }
    }

    barBorder1 = new Line();
    barBorder2 = new Line();

    barBackground = new Rectangle();

    ticksAndSectionsCanvas = new Canvas(preferredWidth, preferredHeight);
    ticksAndSections       = ticksAndSectionsCanvas.getGraphicsContext2D();

    ledCanvas = new Canvas();
    led       = ledCanvas.getGraphicsContext2D();
    Helper.enableNode(ledCanvas, gauge.isLedVisible());

    lcd = new Rectangle(0.3 * preferredWidth, 0.014 * preferredHeight);
    lcd.setArcWidth(0.0125 * preferredHeight);
    lcd.setArcHeight(0.0125 * preferredHeight);
    lcd.relocate((preferredWidth - lcd.getWidth()) * 0.5, 0.44 * preferredHeight);
    Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());

    bar = new Rectangle();
    bar.setStroke(null);

    barHighlight = new Rectangle();
    barHighlight.setStroke(null);
    Helper.enableNode(barHighlight, gauge.isBarEffectEnabled());

    titleText = new Text(gauge.getTitle());
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    unitText  = new Text(gauge.getUnit());
    unitText.setFill(gauge.getUnitColor());
    Helper.enableNode(unitText, !gauge.getUnit().isEmpty());

    valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

    pane = new Pane(barBorder1,
                    barBorder2,
                    barBackground,
                    ticksAndSectionsCanvas,
                    titleText,
                    unitText,
                    ledCanvas,
                    lcd,
                    valueText,
                    bar,
                    barHighlight);
    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);
}
 
Example 7
Source File: DynamicAnchorConnectionSnippet.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Scene createScene() {
	BorderPane root = new BorderPane();
	Scene scene = new Scene(root, 640, 480);

	nodeA = new Rectangle(50, 50);
	nodeA.setFill(Color.RED);

	nodeB = new Rectangle(50, 50);
	nodeB.setFill(Color.BLUE);

	nodeC = new Rectangle(50, 50);
	nodeC.setFill(Color.GREEN);

	Button btnA = new Button("move A");
	btnA.setOnAction(createMoveHandler("A", nodeA, 100, 100, 200));
	btnA.relocate(0, 0);

	Button btnB = new Button("move B");
	btnB.setOnAction(createMoveHandler("B", nodeB, 300, 100, 200));
	btnB.relocate(70, 0);

	Button btnC = new Button("move C");
	btnC.setOnAction(createMoveHandler("C", nodeC, 200, 200, 300));
	btnC.relocate(140, 0);

	Connection connectionAB = new Connection();
	Connection connectionBC = new Connection();

	Group group = new Group(nodeA, nodeB, nodeC, connectionAB, connectionBC,
			btnA, btnB, btnC);
	root.getChildren().add(group);

	anchorA = new DynamicAnchor(nodeA);
	anchorB = new DynamicAnchor(nodeB);
	anchorC = new DynamicAnchor(nodeC);
	connectionAB.setStartAnchor(anchorA);
	connectionAB.setEndAnchor(anchorB);
	connectionBC.setStartAnchor(anchorB);
	connectionBC.setEndAnchor(anchorC);

	nodeA.relocate(100, 100);
	nodeB.relocate(300, 100);
	nodeC.relocate(200, 200);

	return scene;
}
 
Example 8
Source File: DynamicAnchorSnippet.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Scene createScene() {
	BorderPane root = new BorderPane();
	Scene scene = new Scene(root, 400, 400);

	r1 = new Rectangle(50, 50);
	r1.setFill(Color.RED);
	r1.relocate(100, 100);
	r2 = new Rectangle(50, 50);
	r2.setFill(Color.BLUE);
	r2.relocate(200, 200);
	final Line l = new Line();
	l.setStroke(Color.BLACK);

	DynamicAnchor startAnchor = new DynamicAnchor(r1);
	DynamicAnchor endAnchor = new DynamicAnchor(r2);
	final AnchorKey startKey = new AnchorKey(l, "start");
	final AnchorKey endKey = new AnchorKey(l, "end");

	// update start and end point in case provided position values change
	MapChangeListener<AnchorKey, Point> changeListener = new MapChangeListener<AnchorKey, Point>() {

		@Override
		public void onChanged(
				MapChangeListener.Change<? extends AnchorKey, ? extends Point> change) {
			if (change.getKey().equals(startKey)) {
				l.setStartX(change.getMap().get(startKey).x);
				l.setStartY(change.getMap().get(startKey).y);
			}
			if (change.getKey().equals(endKey)) {
				l.setEndX(change.getMap().get(endKey).x);
				l.setEndY(change.getMap().get(endKey).y);
			}
		}
	};

	startAnchor.positionsUnmodifiableProperty().addListener(changeListener);
	endAnchor.positionsUnmodifiableProperty().addListener(changeListener);

	Point r1Center = new Point(
			r1.getLayoutBounds().getMinX() + r1.getLayoutX()
					+ r1.getWidth() / 2,
			r1.getLayoutBounds().getMinY() + r1.getLayoutY()
					+ r1.getHeight() / 2);
	Point r2Center = new Point(
			r2.getLayoutBounds().getMinX() + r2.getLayoutX()
					+ r2.getWidth() / 2,
			r2.getLayoutBounds().getMinY() + r2.getLayoutY()
					+ r2.getHeight() / 2);

	// use static values for dynamic anchor reference points
	startAnchor.getComputationParameter(startKey,
			AnchoredReferencePoint.class).set(r2Center);
	startAnchor.attach(startKey);
	endAnchor.getComputationParameter(endKey,
			AnchoredReferencePoint.class).set(r1Center);
	endAnchor.attach(endKey);

	Group g = new Group(r1, r2, l);
	root.getChildren().add(g);

	return scene;
}