Java Code Examples for javafx.scene.control.Button#setUserData()

The following examples show how to use javafx.scene.control.Button#setUserData() . 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: MetaDeckView.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
public void displayDecks(List<Deck> decks) {
	contentPane.getChildren().clear();
	for (Deck deck : decks) {
		if (deck.isMetaDeck()) {
			continue;
		}
		ImageView graphic = new ImageView(IconFactory.getClassIcon(deck.getHeroClass()));
		graphic.setFitWidth(48);
		graphic.setFitHeight(48);
		Button deckButton = new Button(deck.getName(), graphic);
		deckButton.setMaxWidth(160);
		deckButton.setMinWidth(160);
		deckButton.setMaxHeight(120);
		deckButton.setMinHeight(120);
		deckButton.setWrapText(true);
		deckButton.setContentDisplay(ContentDisplay.LEFT);
		deckButton.setOnAction(event -> NotificationProxy.sendNotification(GameNotification.ADD_DECK_TO_META_DECK, deck));
		deckButton.setUserData(deck);
		contentPane.getChildren().add(deckButton);
	}
}
 
Example 2
Source File: EpidemicReportsSettingsController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
protected void makeLocationsColors() {
    try {
        colorRects.clear();
        locationColorsBox.getChildren().clear();
        List<GeographyCode> locations = chartController.chartLocations;
        if (locations == null || locationColors == null) {
            return;
        }
        Collections.sort(locations, (GeographyCode p1, GeographyCode p2)
                -> p1.getFullName().compareTo(p2.getFullName()));
        for (int i = 0; i < locations.size(); i++) {
            GeographyCode location = locations.get(i);
            String name = location.getFullName();
            String color = locationColors.get(name);
            Label label = new Label(name);
            Rectangle rect = new Rectangle();
            rect.setWidth(15);
            rect.setHeight(15);
            Color c = Color.web(color);
            rect.setFill(c);
            FxmlControl.setTooltip(rect, new Tooltip(FxmlColor.colorNameDisplay(c)));
            rect.setUserData(name);
            colorRects.add(rect);

            Button button = new Button();
            ImageView image = new ImageView(ControlStyle.getIcon("iconPalette.png"));
            image.setFitWidth(AppVariables.iconSize);
            image.setFitHeight(AppVariables.iconSize);
            button.setGraphic(image);
            button.setOnAction((ActionEvent event) -> {
                showPalette(button, message("Settings") + " - " + name);
            });
            button.setUserData(i);
            VBox.setMargin(button, new Insets(0, 0, 0, 15));
            FxmlControl.setTooltip(button, message("Palette"));

            HBox line = new HBox();
            line.setAlignment(Pos.CENTER_LEFT);
            line.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
            line.setSpacing(5);
            VBox.setVgrow(line, Priority.ALWAYS);
            HBox.setHgrow(line, Priority.ALWAYS);
            line.getChildren().addAll(label, rect, button);

            locationColorsBox.getChildren().add(line);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 3
Source File: CommandManagerFX.java    From megan-ce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * creates a button for the command
 *
 * @param command
 * @return button
 */
private javafx.scene.control.ButtonBase getButtonFX(final ICommand command) {
    if (command == null) {
        javafx.scene.control.Button nullButton = new javafx.scene.control.Button("Null");
        nullButton.setDisable(true);
        return nullButton;
    }
    if (command instanceof ICheckBoxCommand) {
        final ICheckBoxCommand checkBoxCommand = (ICheckBoxCommand) command;

        final CheckBox cbox = new CheckBox(command.getName());
        cbox.setOnAction(event -> {
            checkBoxCommand.setSelected(cbox.isSelected());
            if (command.getAutoRepeatInterval() > 0)
                command.actionPerformedAutoRepeat(ACTION_EVENT_FROM_FX);
            else
                command.actionPerformed(ACTION_EVENT_FROM_FX);
        });
        if (command.getDescription() != null) {
            cbox.setUserData(command.getDescription());
            Tooltip.install(cbox, new Tooltip(command.getDescription()));
        }
        if (command.getIcon() != null) {
            cbox.setGraphic(asImageViewFX(command.getIcon()));
        }
        cbox.setSelected(checkBoxCommand.isSelected());
        button2CommandFX.put(cbox, checkBoxCommand);
        return cbox;
    } else {
        final Button button = new Button(command.getName());
        button.setOnAction(event -> {
            if (command.getAutoRepeatInterval() > 0)
                command.actionPerformedAutoRepeat(ACTION_EVENT_FROM_FX);
            else
                command.actionPerformed(ACTION_EVENT_FROM_FX);
        });
        if (command.getDescription() != null) {
            button.setUserData(command.getDescription());
            Tooltip.install(button, new Tooltip(command.getDescription()));
        }
        if (command.getIcon() != null) {
            button.setGraphic(asImageViewFX(command.getIcon()));
        }
        button2CommandFX.put(button, command);
        return button;
    }
}
 
Example 4
Source File: ListController.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@FXML
public void initialize() {

    String[][] buttonDefs = {
            {"Edit", "Editting"},
            {"Run", "Running"},
            {"Send", "Sending"}
    };

    String[][] data = {
            {"A", "ID: A001"},
            {"B", "ID: B001"},
            {"C", "ID: C001"},
            {"D", "ID: D001"},
            {"E", "ID: E001"}
    };

    //
    // Renders
    //
    // A | Edit A button | Run A button | Send A button
    // B | Edit B button | Run B button | Send B button
    // ...
    //

    for( String[] rec : data ) {

        HBox hbox = new HBox();
        hbox.setSpacing(20.0d);

        Label label= new Label( rec[0] );
        hbox.getChildren().add(label);

        for( String[] buttonDef : buttonDefs ) {
            Button btn = new Button(buttonDef[0]);
            btn.getProperties().put(PROP_COMMAND_MESSAGE, buttonDef[1]);
            btn.setUserData(rec[1]);
            btn.setOnAction(commandHandler);
            hbox.getChildren().add(btn);
        }

        lvButtons.getItems().add( hbox );
    }
}