Java Code Examples for javafx.scene.control.Label#setAlignment()

The following examples show how to use javafx.scene.control.Label#setAlignment() . 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: MainScene.java    From mars-sim with GNU General Public License v3.0 8 votes vote down vote up
/**
 * Creates the pause box to be displayed on the root pane.
 * 
 * @return VBox
 */
private VBox createPausePaneContent() {
	VBox vbox = new VBox();
	vbox.setPrefSize(150, 150);

	Label label = new Label("||");
	label.setAlignment(Pos.CENTER);
	label.setPadding(new Insets(10));
	label.setStyle("-fx-font-size: 48px; -fx-text-fill: cyan;");
	// label.setMaxWidth(250);
	label.setWrapText(true);

	Label label1 = new Label("ESC to resume");
	label1.setAlignment(Pos.CENTER);
	label1.setPadding(new Insets(2));
	label1.setStyle(" -fx-font: bold 11pt 'Corbel'; -fx-text-fill: cyan;");
	vbox.getChildren().addAll(label, label1);
	vbox.setAlignment(Pos.CENTER);

	return vbox;
}
 
Example 2
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
public Label createLabelLeft(String name, String tip) {
	Label l = new Label(name);
	// upTimeLabel0.setEffect(blend);
	l.setAlignment(Pos.CENTER_RIGHT);
	l.setTextAlignment(TextAlignment.RIGHT);
	l.setStyle(LABEL_CSS_STYLE);
	l.setPadding(new Insets(1, 1, 1, 2));
	setQuickToolTip(l, tip);
	return l;
}
 
Example 3
Source File: DateTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    final ZonedDateTime TIME = tile.getTime();

    titleText = new Text(DAY_FORMATTER.format(TIME));
    titleText.setFill(tile.getTitleColor());

    description = new Label(Integer.toString(TIME.getDayOfMonth()));
    description.setAlignment(Pos.CENTER);
    description.setTextAlignment(TextAlignment.CENTER);
    description.setWrapText(true);
    description.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
    description.setTextFill(tile.getTextColor());
    description.setPrefSize(PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.72);
    description.setFont(Fonts.latoLight(PREFERRED_HEIGHT * 0.65));

    text = new Text(MONTH_YEAR_FORMATTER.format(TIME));
    text.setFill(tile.getTextColor());

    getPane().getChildren().addAll(titleText, text, description);
}
 
Example 4
Source File: StatusPanel.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new status panel.
 * <p/>
 * @param group the group this panel is part of.
 * @param labelText the text to put on the label on this panel.
 * @param index the index of this panel on the group.
 */
StatusPanel(StatusPanelGroup group, String labelText, int index) {
    setAlignment(Pos.CENTER);
    setSpacing(5);
    this.group = group;
    this.index = index;
    label = new Label(labelText);
    label.setAlignment(Pos.CENTER);
    label.setMaxHeight(Double.MAX_VALUE);
    HBox.setMargin(label, new Insets(5));
    progressBar = new ProgressBar();
    progressBar.setMaxWidth(Double.MAX_VALUE); //Allow progress bar to fill space.
    HBox.setHgrow(progressBar, Priority.ALWAYS);
    cancelButton = new Button("", new ImageView(new Image("file:icons/cross.png", 13, 13, false, true)));
    Utils.setToolbarButtonStyle(cancelButton);
    cancelButton.setAlignment(Pos.CENTER);
    getChildren().add(label);
    getChildren().add(progressBar);
    getChildren().add(cancelButton);
}
 
Example 5
Source File: ChooseConfigClassDialog.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
public CategoryNode() {
	setAlignment(Pos.TOP_CENTER);

	taComment.setEditable(false);

	Label lblComment = new Label(bundle.getString("Popups.ChooseCustomControl.Category.All.comment"));
	lblComment.setAlignment(Pos.TOP_CENTER);

	VBox vbox = new VBox(5, lblComment, stackPaneComment);
	VBox.setVgrow(stackPaneComment, Priority.ALWAYS);
	stackPaneComment.setAlignment(Pos.TOP_CENTER);
	vbox.setAlignment(Pos.TOP_CENTER);
	vbox.setFillWidth(true);
	getChildren().add(vbox);
}
 
Example 6
Source File: AboutStage.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private HBox createBlurbTitle() {
    Label bulrbTitleLabel = createLabel(versionInfo.getBlurbTitle());
    bulrbTitleLabel.setId("blurbTitle");
    bulrbTitleLabel.setAlignment(Pos.TOP_CENTER);

    HBox titleBox = new HBox();
    titleBox.setId("titleBar");
    titleBox.setAlignment(Pos.TOP_CENTER);
    titleBox.getChildren().addAll(bulrbTitleLabel);
    return titleBox;
}
 
Example 7
Source File: MarsNode.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Label createEach(Settlement settlement) {
	Label l = new Label(settlement.getName());

	l.setPadding(new Insets(20));
	l.setAlignment(Pos.CENTER);
	l.setMaxWidth(Double.MAX_VALUE);

	l.setId("settlement-node");
	l.getStylesheets().add("/fxui/css/settlementnode.css");

	l.setOnMouseClicked(new EventHandler<MouseEvent>() {
     	PopOver popOver = null;
         @Override
         public void handle(MouseEvent evt) {
       	if (popOver == null ) {
                popOver = createPopOver(l, settlement);
         	}
       	else if (evt.getClickCount() >= 1) {
               popOver.hide(Duration.seconds(.5));
        	}
       	else if (popOver.isShowing()) {
         		popOver.hide(Duration.seconds(.5));
         	}
       	else if (!popOver.isShowing()) {
         		popOver = createPopOver(l, settlement);
         	}
         }
     });
	return l;
}
 
Example 8
Source File: MetaPanel.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static void formatLabels(final Label... labels)
{
	for (Label label : labels) {
		label.setAlignment(Pos.BASELINE_CENTER);
		label.setPrefWidth(TEXTFIELD_WIDTH);
	}
}
 
Example 9
Source File: ViewText.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Node constructContent() {
    VBox vboxroot = new VBox();
    vboxroot.setSpacing(10.0);        
    
    level = new Label();
    level.setAlignment(Pos.CENTER_RIGHT);
    level.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    level.getStyleClass().add("unitmaintext");
    
    vboxroot.getChildren().add(level);
    
    initialize();
    return vboxroot;
}
 
Example 10
Source File: HeadlessController.java    From ShootOFF with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void autocalibrationTimedOut() {
	calibrated = false;

	final Label calibrationLabel = new Label("Calibration Failed!");
	calibrationLabel.setFont(Font.font(48));
	calibrationLabel.setTextFill(Color.web("#f5a807"));
	calibrationLabel.setLayoutX(6);
	calibrationLabel.setLayoutY(6);
	calibrationLabel.setPrefSize(628, 90);
	calibrationLabel.setAlignment(Pos.CENTER);

	arenaPane.getCanvasManager().getCanvasGroup().getChildren().add(calibrationLabel);
}
 
Example 11
Source File: ViewSimple.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Node constructContent() {
    content = new Label(null);
    content.setContentDisplay(ContentDisplay.TOP);
    content.setAlignment(Pos.CENTER);
    content.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    VBox.setVgrow(content, Priority.SOMETIMES);
    return content;
}
 
Example 12
Source File: UnitsContainerEmpty.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
public UnitsContainerEmpty(String label) {
    message = new Label(label);
    message.setAlignment(Pos.TOP_CENTER);
    message.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    message.getStyleClass().add("unitsempty");
    VBox.setVgrow(message, Priority.SOMETIMES);                    
}
 
Example 13
Source File: SliderSimple.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Node constructContent() {
    
    VBox vboxroot = new VBox();
    vboxroot.setSpacing(10.0);
    
    boxview = new HBox();
    boxview.setSpacing(6.0);
    
    level = new Label();
    level.setAlignment(Pos.CENTER_RIGHT);
    level.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    level.getStyleClass().add("unitmaintext");
    HBox.setHgrow(level, Priority.SOMETIMES);
    
    boxview.getChildren().add(level);
    
    slider = new Slider();
    slider.setFocusTraversable(false);
    StackPane.setAlignment(slider, Pos.BOTTOM_CENTER);        
    
    StackPane stack = new StackPane(slider);
    VBox.setVgrow(stack, Priority.SOMETIMES);
    vboxroot.getChildren().addAll(boxview, stack);
    
    initialize();
    
    return vboxroot;
}
 
Example 14
Source File: ListTile.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateText() {
    textBox.getChildren().clear();
    for (int i = 0; i <= 2; i++) {
        Label label = new Label(textProperty.get(i));
        label.setWrapText(true);
        label.setMaxHeight(Double.MAX_VALUE);
        label.setAlignment(Pos.TOP_LEFT);
        if (i == 0) {
            label.getStyleClass().add("primary");
        }
        textBox.getChildren().add(label);
        VBox.setVgrow(label, Priority.ALWAYS);
    }
}
 
Example 15
Source File: ZoomerSample.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
@Override
public void start(final Stage primaryStage) {
    final FlowPane root = new FlowPane();
    root.setAlignment(Pos.CENTER);

    DataSet testDataSet = generateData();

    Label label = new Label("left-click-hold-drag for zooming. middle-button for panning.\n"
                            + "Tip: drag horizontally/vertically/diagonally for testing; try to select the outlier");
    label.setFont(Font.font(20));
    label.setAlignment(Pos.CENTER);
    label.setContentDisplay(ContentDisplay.CENTER);
    label.setPrefWidth(2.0 * PREF_WIDTH);

    // chart with default zoom
    final Chart chart1 = getTestChart("default zoom", testDataSet);
    Zoomer zoomer1 = new Zoomer();
    registerZoomerChangeListener(zoomer1, chart1.getTitle());
    chart1.getPlugins().add(zoomer1);

    // chart with auto xy zoom
    final Chart chart2 = getTestChart("auto xy zoom", testDataSet);
    final Zoomer zoomer2 = new Zoomer();
    zoomer2.setAutoZoomEnabled(true);
    registerZoomerChangeListener(zoomer2, chart2.getTitle());
    chart2.getPlugins().add(zoomer2);

    // chart with x-only zoom
    final Chart chart3 = getTestChart("x-only zoom", testDataSet);
    Zoomer zoomer3 = new Zoomer(AxisMode.X);
    registerZoomerChangeListener(zoomer3, chart3.getTitle());
    chart3.getPlugins().add(zoomer3);

    // chart with x-only zoom
    final Chart chart4 = getTestChart("y-only zoom", testDataSet);
    Zoomer zoomer4 = new Zoomer(AxisMode.Y);
    registerZoomerChangeListener(zoomer4, chart4.getTitle());
    chart4.getPlugins().add(zoomer4);

    root.getChildren().addAll(chart1, chart2, chart3, chart4, label);

    primaryStage.setTitle(this.getClass().getSimpleName());
    primaryStage.setScene(new Scene(root));
    primaryStage.setOnCloseRequest(evt -> Platform.exit());
    primaryStage.show();
}
 
Example 16
Source File: ProjectorArenaPane.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
public ProjectorArenaPane(Stage arenaStage, Stage shootOffStage, Pane trainingExerciseContainer, Resetter resetter,
		ObservableList<ShotEntry> shotTimerModel) {
	config = Configuration.getConfig();

	arenaCanvasGroup = new Group();
	calibrationLabel = new Label("Needs Calibration");
	calibrationLabel.setFont(Font.font(48));
	calibrationLabel.setTextFill(Color.web("#f5a807"));
	calibrationLabel.setLayoutX(6);
	calibrationLabel.setLayoutY(6);
	calibrationLabel.setPrefSize(628, 90);
	calibrationLabel.setAlignment(Pos.CENTER);

	getChildren().addAll(arenaCanvasGroup, calibrationLabel);

	this.shootOffStage = shootOffStage;
	this.arenaStage = arenaStage;
	this.trainingExerciseContainer = trainingExerciseContainer;

	if (config.isHeadless()) {
		canvasManager = new CanvasManager(arenaCanvasGroup, resetter, "arena", shotTimerModel);
	} else {
		canvasManager = new MirroredCanvasManager(arenaCanvasGroup, resetter, "arena", shotTimerModel, this);
	}

	setPrefSize(640, 480);

	setOnKeyPressed((event) -> canvasKeyPressed(event));

	setOnMouseEntered((event) -> requestFocus());

	setOnMouseClicked((event) -> {
		canvasManager.toggleTargetSelection(Optional.empty());
	});

	arenaStage.widthProperty().addListener((e) -> {
		canvasManager.setBackgroundFit(arenaStage.getWidth(), arenaStage.getHeight());
	});

	arenaStage.heightProperty().addListener((e) -> {
		canvasManager.setBackgroundFit(arenaStage.getWidth(), arenaStage.getHeight());
	});

	setStyle("-fx-background-color: #333333;");
}
 
Example 17
Source File: CombinationLayout.java    From redtorch with MIT License 4 votes vote down vote up
private void createLayout() {
	hBox.getChildren().clear();

	VBox leftVbox = new VBox();

	Label allTodayProfitLabel = new Label("今日盈亏(率):");
	allTodayProfitLabel.setMinWidth(labelWidth);
	allTodayProfitLabel.setAlignment(Pos.CENTER_RIGHT);
	allTodayProfitLabel.getStyleClass().add("trade-label");

	HBox allTodayProfitHBox = new HBox();
	allTodayProfitHBox.getChildren().add(allTodayProfitLabel);
	allTodayProfitHBox.getChildren().add(allTodayProfitText);
	leftVbox.getChildren().add(allTodayProfitHBox);

	Label allBalanceLabel = new Label("资金:");
	allBalanceLabel.setMinWidth(labelWidth);
	allBalanceLabel.setAlignment(Pos.CENTER_RIGHT);
	allBalanceLabel.getStyleClass().add("trade-label");
	HBox allBalanceHBox = new HBox();
	allBalanceHBox.getChildren().add(allBalanceLabel);
	allBalanceHBox.getChildren().add(allBalanceText);
	leftVbox.getChildren().add(allBalanceHBox);

	Label allOpenPositionProfitLabel = new Label("持仓盈亏:");
	allOpenPositionProfitLabel.setMinWidth(labelWidth);
	allOpenPositionProfitLabel.setAlignment(Pos.CENTER_RIGHT);
	allOpenPositionProfitLabel.getStyleClass().add("trade-label");
	HBox allOpenPositionProfitHBox = new HBox();
	allOpenPositionProfitHBox.getChildren().add(allOpenPositionProfitLabel);
	allOpenPositionProfitHBox.getChildren().add(allOpenPositionProfitText);
	leftVbox.getChildren().add(allOpenPositionProfitHBox);

	hBox.getChildren().add(leftVbox);
	HBox.setHgrow(leftVbox, Priority.ALWAYS);

	VBox centerVbox = new VBox();

	Label allPositionProfitLabel = new Label("盯市持仓盈亏:");
	allPositionProfitLabel.setMinWidth(labelWidth);
	allPositionProfitLabel.setAlignment(Pos.CENTER_RIGHT);
	allPositionProfitLabel.getStyleClass().add("trade-label");
	HBox allPositionProfitHBox = new HBox();
	allPositionProfitHBox.getChildren().add(allPositionProfitLabel);
	allPositionProfitHBox.getChildren().add(allPositionProfitText);
	centerVbox.getChildren().add(allPositionProfitHBox);

	Label allMarginLabel = new Label("保证金(率):");
	allMarginLabel.setMinWidth(labelWidth);
	allMarginLabel.setAlignment(Pos.CENTER_RIGHT);
	allMarginLabel.getStyleClass().add("trade-label");
	HBox allMarginHBox = new HBox();
	allMarginHBox.getChildren().add(allMarginLabel);
	allMarginHBox.getChildren().add(allMarginText);
	centerVbox.getChildren().add(allMarginHBox);

	Label allCommissionLabel = new Label("佣金:");
	allCommissionLabel.setMinWidth(labelWidth);
	allCommissionLabel.setAlignment(Pos.CENTER_RIGHT);
	allCommissionLabel.getStyleClass().add("trade-label");
	HBox allCommissionHBox = new HBox();
	allCommissionHBox.getChildren().add(allCommissionLabel);
	allCommissionHBox.getChildren().add(allCommissionText);
	centerVbox.getChildren().add(allCommissionHBox);

	hBox.getChildren().add(centerVbox);
	HBox.setHgrow(centerVbox, Priority.ALWAYS);

	VBox rightVbox = new VBox();

	Label allCloseProfitLabel = new Label("盯市平仓盈亏:");
	allCloseProfitLabel.setMinWidth(labelWidth);
	allCloseProfitLabel.setAlignment(Pos.CENTER_RIGHT);
	allCloseProfitLabel.getStyleClass().add("trade-label");
	HBox allCloseProfitHBox = new HBox();
	allCloseProfitHBox.getChildren().add(allCloseProfitLabel);
	allCloseProfitHBox.getChildren().add(allCloseProfitText);
	rightVbox.getChildren().add(allCloseProfitHBox);

	Label allContractValueLabel = new Label("合约价值:");
	allContractValueLabel.setMinWidth(labelWidth);
	allContractValueLabel.setAlignment(Pos.CENTER_RIGHT);
	allContractValueLabel.getStyleClass().add("trade-label");
	HBox allContractValueHBox = new HBox();
	allContractValueHBox.getChildren().add(allContractValueLabel);
	allContractValueHBox.getChildren().add(allContractValueText);
	rightVbox.getChildren().add(allContractValueHBox);

	Label allDepositAndWithdrawLabel = new Label("出入金:");
	allDepositAndWithdrawLabel.setMinWidth(labelWidth);
	allDepositAndWithdrawLabel.setAlignment(Pos.CENTER_RIGHT);
	allDepositAndWithdrawLabel.getStyleClass().add("trade-label");
	HBox allDepositAndWithdrawHBox = new HBox();
	allDepositAndWithdrawHBox.getChildren().add(allDepositAndWithdrawLabel);
	allDepositAndWithdrawHBox.getChildren().add(allDepositAndWithdrawText);
	rightVbox.getChildren().add(allDepositAndWithdrawHBox);

	hBox.getChildren().add(rightVbox);
	HBox.setHgrow(rightVbox, Priority.ALWAYS);

}
 
Example 18
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void createStateLabels() {
    Group overlay = map.getOverlayGroup();
    for(String state: Region.ALL_STATES) {
        Node stateNode = map.lookup("#"+state);
        if (stateNode != null) {
            Label label = new Label("+10");
            label.getStyleClass().add("heatmap-label");
            label.setTextAlignment(TextAlignment.CENTER);
            label.setAlignment(Pos.CENTER);
            label.setManaged(false);
            label.setOpacity(0);
            label.setVisible(false);
            Bounds stateBounds = stateNode.getBoundsInParent();
            if ("DE".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-25, stateBounds.getMinY(), 
                        stateBounds.getWidth()+50, stateBounds.getHeight());
            } else if ("VT".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()-25, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("NH".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+30, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-20, stateBounds.getMinY()-18, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("RI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth()+40, stateBounds.getHeight());
            } else if ("ID".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+60, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+60, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("FL".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+95, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("LA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-50, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            }
            stateLabelMap.put(state, label);
            overlay.getChildren().add(label);
        }
    }
}
 
Example 19
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void createStateLabels() {
    Group overlay = map.getOverlayGroup();
    for(String state: Region.ALL_STATES) {
        Node stateNode = map.lookup("#"+state);
        if (stateNode != null) {
            Label label = new Label("+10");
            label.getStyleClass().add("heatmap-label");
            label.setTextAlignment(TextAlignment.CENTER);
            label.setAlignment(Pos.CENTER);
            label.setManaged(false);
            label.setOpacity(0);
            label.setVisible(false);
            Bounds stateBounds = stateNode.getBoundsInParent();
            if ("DE".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-25, stateBounds.getMinY(), 
                        stateBounds.getWidth()+50, stateBounds.getHeight());
            } else if ("VT".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()-25, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("NH".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+30, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-20, stateBounds.getMinY()-18, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("RI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth()+40, stateBounds.getHeight());
            } else if ("ID".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+60, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+60, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("FL".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+95, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("LA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-50, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            }
            stateLabelMap.put(state, label);
            overlay.getChildren().add(label);
        }
    }
}
 
Example 20
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);
}