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

The following examples show how to use javafx.scene.control.Button#setMaxWidth() . 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: EditAxis.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
private Pane getRangeChangeButtons(final Axis axis, final boolean isHorizontal) {
    final Button incMaxButton = new Button("", new Glyph(EditAxis.FONT_AWESOME, "expand"));
    incMaxButton.setMaxWidth(Double.MAX_VALUE);
    VBox.setVgrow(incMaxButton, Priority.NEVER);
    HBox.setHgrow(incMaxButton, Priority.NEVER);
    incMaxButton.setOnAction(evt -> {
        axis.setAutoRanging(false);
        changeAxisRange(axis, true);
    });

    final Button decMaxButton = new Button("", new Glyph(EditAxis.FONT_AWESOME, "compress"));
    decMaxButton.setMaxWidth(Double.MAX_VALUE);
    VBox.setVgrow(decMaxButton, Priority.NEVER);
    HBox.setHgrow(decMaxButton, Priority.NEVER);

    decMaxButton.setOnAction(evt -> {
        axis.setAutoRanging(false);
        changeAxisRange(axis, false);
    });
    final Pane boxMax = isHorizontal ? new VBox() : new HBox();
    boxMax.getChildren().addAll(incMaxButton, decMaxButton);

    return boxMax;
}
 
Example 2
Source File: EditAxis.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
private Pane getMinMaxButtons(final Axis axis, final boolean isHorizontal, final boolean isMin) {
    final Button incMaxButton = new Button("", new Glyph(EditAxis.FONT_AWESOME, "\uf077"));
    incMaxButton.setMaxWidth(Double.MAX_VALUE);
    VBox.setVgrow(incMaxButton, Priority.ALWAYS);
    HBox.setHgrow(incMaxButton, Priority.ALWAYS);
    incMaxButton.setOnAction(evt -> {
        axis.setAutoRanging(false);
        changeAxisRangeLimit(axis, isHorizontal ? isMin : !isMin, true);
    });

    final Button decMaxButton = new Button("", new Glyph(EditAxis.FONT_AWESOME, "\uf078"));
    decMaxButton.setMaxWidth(Double.MAX_VALUE);
    VBox.setVgrow(decMaxButton, Priority.ALWAYS);
    HBox.setHgrow(decMaxButton, Priority.ALWAYS);

    decMaxButton.setOnAction(evt -> {
        axis.setAutoRanging(false);
        changeAxisRangeLimit(axis, isHorizontal ? isMin : !isMin, false);
    });
    final Pane box = isHorizontal ? new VBox() : new HBox();
    box.getChildren().addAll(incMaxButton, decMaxButton);

    return box;
}
 
Example 3
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Tuple3<Label, Button, Button> addTopLabel2Buttons(GridPane gridPane,
                                                                int rowIndex,
                                                                String labelText,
                                                                String title1,
                                                                String title2,
                                                                double top) {
    HBox hBox = new HBox();
    hBox.setSpacing(10);

    Button button1 = new AutoTooltipButton(title1);
    button1.setDefaultButton(true);
    button1.getStyleClass().add("action-button");
    button1.setDefaultButton(true);
    button1.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button1, Priority.ALWAYS);

    Button button2 = new AutoTooltipButton(title2);
    button2.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button2, Priority.ALWAYS);

    hBox.getChildren().addAll(button1, button2);

    final Tuple2<Label, VBox> topLabelWithVBox = addTopLabelWithVBox(gridPane, rowIndex, labelText, hBox, top);

    return new Tuple3<>(topLabelWithVBox.first, button1, button2);
}
 
Example 4
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 5
Source File: MainNode.java    From helloiot with GNU General Public License v3.0 6 votes vote down vote up
public void setToolbarButton(EventHandler<ActionEvent> backevent, Node graphic, String text) {
    
    Label l = new Label();
    l.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    l.setAlignment(Pos.CENTER);
    l.setGraphic(graphic);
    l.setPrefSize(45.0, 40.0);             
    
    backbutton = new Button(text, l);     
    backbutton.setAlignment(Pos.BASELINE_LEFT);
    backbutton.setMaxWidth(Double.MAX_VALUE);
    backbutton.setFocusTraversable(false);
    backbutton.setMnemonicParsing(false);
    backbutton.getStyleClass().add("menubutton");
    backbutton.setOnAction(backevent);
    backbutton.setVisible(backevent != null);
}
 
Example 6
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Tuple3<Button, Button, Button> add3Buttons(GridPane gridPane,
                                                         int rowIndex,
                                                         String title1,
                                                         String title2,
                                                         String title3,
                                                         double top) {
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    Button button1 = new AutoTooltipButton(title1);

    button1.getStyleClass().add("action-button");
    button1.setDefaultButton(true);
    button1.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button1, Priority.ALWAYS);

    Button button2 = new AutoTooltipButton(title2);
    button2.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button2, Priority.ALWAYS);

    Button button3 = new AutoTooltipButton(title3);
    button3.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button3, Priority.ALWAYS);

    hBox.getChildren().addAll(button1, button2, button3);
    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 0);
    GridPane.setMargin(hBox, new Insets(top, 10, 0, 0));
    gridPane.getChildren().add(hBox);
    return new Tuple3<>(button1, button2, button3);
}
 
Example 7
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Tuple3<Button, Button, HBox> add2ButtonsWithBox(GridPane gridPane, int rowIndex, String title1,
                                                              String title2, double top, boolean hasPrimaryButton) {
    HBox hBox = new HBox();
    hBox.setSpacing(10);

    Button button1 = new AutoTooltipButton(title1);

    if (hasPrimaryButton) {
        button1.getStyleClass().add("action-button");
        button1.setDefaultButton(true);
    }

    button1.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button1, Priority.ALWAYS);

    Button button2 = new AutoTooltipButton(title2);
    button2.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button2, Priority.ALWAYS);

    hBox.getChildren().addAll(button1, button2);

    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 0);
    GridPane.setMargin(hBox, new Insets(top, 10, 0, 0));
    gridPane.getChildren().add(hBox);
    return new Tuple3<>(button1, button2, hBox);
}
 
Example 8
Source File: MarsNode.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Button createGreenhouseDialog(Farming farm) {
	String name = farm.getBuilding().getNickName();
	Button b = new Button(name);
	b.setMaxWidth(Double.MAX_VALUE);

     List<String> choices = new ArrayList<>();
     choices.add("Lettuce");
     choices.add("Green Peas");
     choices.add("Carrot");

     ChoiceDialog<String> dialog = new ChoiceDialog<>("List of Crops", choices);
     dialog.setTitle(name);
     dialog.setHeaderText("Plant a Crop");
     dialog.setContentText("Choose Your Crop:");
     dialog.initOwner(stage); // post the same icon from stage
     dialog.initStyle(StageStyle.UTILITY);
     //dialog.initModality(Modality.NONE);

	b.setPadding(new Insets(20));
	b.setId("settlement-node");
	b.getStylesheets().add("/fxui/css/settlementnode.css");
    b.setOnAction(e->{
        // The Java 8 way to get the response value (with lambda expression).
    	Optional<String> selected = dialog.showAndWait();
        selected.ifPresent(crop -> System.out.println("Crop added to the queue: " + crop));
    });

   //ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
   //ButtonType buttonTypeOk = new ButtonType("OK", ButtonData.OK_DONE);
   //dialog.getButtonTypes().setAll(buttonTypeCancel, buttonTypeOk);

    return b;
}
 
Example 9
Source File: JobViewer.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void updateItem(final Boolean ignored, final boolean empty)
{
    super.updateItem(ignored, empty);

    boolean running = ! empty;

    TableRow<JobInfo> row = null;
    if (running)
    {
        row = getTableRow();
        if (row == null)
            running = false;
    }

    if (running)
    {
        setAlignment(Pos.CENTER_RIGHT);
        final JobInfo info = row.getItem();
        final Button cancel = new Button(Messages.JobCancel, new ImageView(ABORT));
        cancel.setOnAction(event -> info.job.cancel());
        cancel.setMaxWidth(Double.MAX_VALUE);
        setGraphic(cancel);
    }
    else
        setGraphic(null);
}
 
Example 10
Source File: FilesList.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Node createButtons()
{
    final Button attach = new Button(Messages.AttachFile);
    final Button remove = new Button(Messages.RemoveSelected, ImageCache.getImageView(ImageCache.class, "/icons/delete.png"));

    attach.setTooltip(new Tooltip(Messages.AddImageLog));
    remove.setTooltip(new Tooltip(Messages.RemoveSelectedFiles));

    // Only enable 'remove' when file(s) selected
    remove.disableProperty().bind(Bindings.isEmpty(files.getSelectionModel().getSelectedItems()));

    attach.setOnAction(event ->
    {
        final FileChooser dialog = new FileChooser();
        dialog.setInitialDirectory(new File(System.getProperty("user.home")));
        final List<File> to_add = dialog.showOpenMultipleDialog(getScene().getWindow());
        if (null != to_add)
            files.getItems().addAll(to_add);
    });

    remove.setOnAction(event ->
    {
        final List<File> selected = new ArrayList<>(files.getSelectionModel().getSelectedItems());
        if (selected.size() > 0)
            files.getItems().removeAll(selected);
    });

    final HBox row = new HBox(10, attach, remove);
    // Have buttons equally split the available width
    attach.setMaxWidth(Double.MAX_VALUE);
    remove.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(attach, Priority.ALWAYS);
    HBox.setHgrow(remove, Priority.ALWAYS);

    return row;
}
 
Example 11
Source File: TemporalAmountPane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Button createButton(final String label, final TemporalAmount amount)
{
    final Button button = new Button(label);
    button.setMaxWidth(Double.MAX_VALUE);
    button.setOnAction(event ->
    {
        setTimespan(amount);
        notifyListeners();
    });
    return button;
}
 
Example 12
Source File: FormulaPane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Node createButton(final String text, final String tooltip, final EventHandler<ActionEvent> on_action)
{
    final Button button = new Button(text);
    button.setFocusTraversable(false);
    button.setMaxWidth(Double.MAX_VALUE);
    button.setTooltip(new Tooltip(tooltip));
    button.setOnAction(on_action);
    return button;
}
 
Example 13
Source File: CheckListView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void initVerticalButtonBar() {
    verticalButtonBar = new VBox();
    Button upButton = FXUIUtils.createButton("up", "Move selection up", true, "Up");
    upButton.setMaxWidth(Double.MAX_VALUE);
    upButton.setOnAction((e) -> {
        checkListFormNode.moveUpSelected();
        if (checkListFormNode.isDirty()) {
            fireContentChanged();
        }
    });

    Button deleteButton = FXUIUtils.createButton("remove", "Delete selection", true, "Remove");
    deleteButton.setOnAction((e) -> {
        checkListFormNode.deleteSelected();
        if (checkListFormNode.isDirty()) {
            fireContentChanged();
        }
    });

    Button downButton = FXUIUtils.createButton("down", "Move selection down", true, "Down");
    downButton.setOnAction((e) -> {
        checkListFormNode.moveDownSelected();
        if (checkListFormNode.isDirty()) {
            fireContentChanged();
        }
    });
    downButton.setMaxWidth(Double.MAX_VALUE);

    verticalButtonBar.getChildren().addAll(upButton, deleteButton, downButton);
}
 
Example 14
Source File: MainWindowController.java    From tcMenu with Apache License 2.0 5 votes vote down vote up
private void buildDialogButton(MenuButtonType btn1, HBox buttonArea) {
    if(btn1 != MenuButtonType.NONE) {
        Button btn = new Button(btn1.getButtonName());
        btn.setOnAction((e)-> remoteControl.sendDialogAction(btn1));
        btn.getStyleClass().add("flatButton");
        HBox.setHgrow(btn, Priority.ALWAYS);
        btn.setMaxWidth(Double.MAX_VALUE);
        buttonArea.getChildren().add(btn);
    }
}
 
Example 15
Source File: UpdatePane.java    From Recaf with MIT License 4 votes vote down vote up
private Button getButton() {
	Button button = new ActionButton(translate("update.download"), this::update);
	button.setMaxHeight(Double.MAX_VALUE);
	button.setMaxWidth(Double.MAX_VALUE);
	return button;
}
 
Example 16
Source File: MainNode.java    From helloiot with GNU General Public License v3.0 4 votes vote down vote up
public void construct(List<UnitPage> appunitpages) {
    
    appunitpage.subscribeStatus(messagePageHandler);
    appbeeper.subscribeStatus(beeper.getMessageHandler());
    appbuzzer.subscribeStatus(buzzer.getMessageHandler());
    systime.subscribeStatus(timeindicator.getMessageHandler());

    // Add configured unitpages.
    for (UnitPage up : appunitpages) {
        this.addUnitPage(up);
    }

    //Init unit nodes
    for (Unit u : app.getUnits()) {
        Node n = u.getNode();
        if (n != null) {
            UnitPage unitpage = buildUnitPage(UnitPage.getPage(n));
            unitpage.addUnitNode(n);
        }
    }

    // Build listpages based on unitpages
    List<UnitPage> sortedunitpages = new ArrayList<>();
    sortedunitpages.addAll(unitpages.values());
    Collections.sort(sortedunitpages);
    firstmenupage = null;
    for (UnitPage value : sortedunitpages) {
        value.buildNode();
        if (!value.isSystem() && !value.isEmpty() && (value.getName() == null || !value.getName().startsWith("."))) {
            Label l = new Label();
            l.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            l.setAlignment(Pos.CENTER);
            l.setGraphic(value.getGraphic());
            l.setPrefSize(45.0, 40.0);                
            Button buttonmenu = new Button(value.getText(), l);
            buttonmenu.getStyleClass().add("menubutton");
            buttonmenu.setAlignment(Pos.BASELINE_LEFT);
            buttonmenu.setMaxWidth(Double.MAX_VALUE);
            buttonmenu.setFocusTraversable(false);
            buttonmenu.setMnemonicParsing(false);
            buttonmenu.setOnAction(e -> {
                appunitpage.sendStatus(value.getName());              
            });
            menupages.getChildren().add(buttonmenu); // Last button is disconnect button
            if (firstmenupage == null) {
                firstmenupage = value.getName();
            }
        }
    }
    
    // Add backbutton
    if (backbutton != null && backbutton.isVisible()) {
        menupages.getChildren().add(new Separator(Orientation.HORIZONTAL));
        menupages.getChildren().add(backbutton);
    }
    
    gotoPage("start");

    // Remove menubutton if 0 or 1 visible page.
    menubutton.setVisible(!menupages.getChildren().isEmpty());
}
 
Example 17
Source File: ChangeAtmosphereEffectSample.java    From arcgis-runtime-samples-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {

  try {
    // create stack pane and JavaFX app scene
    StackPane stackPane = new StackPane();
    Scene fxScene = new Scene(stackPane);
    fxScene.getStylesheets().add(getClass().getResource("/change_atmosphere_effect/style.css").toExternalForm());

    // set title, size, and add JavaFX scene to stage
    stage.setTitle("Change Atmosphere Effect Sample");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.setScene(fxScene);
    stage.show();

    // create a scene and add a basemap to it
    ArcGISScene scene = new ArcGISScene();
    scene.setBasemap(Basemap.createImagery());

    // set the scene to a scene view
    sceneView = new SceneView();
    sceneView.setArcGISScene(scene);

    // add base surface for elevation data
    Surface surface = new Surface();
    ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(
            "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");
    surface.getElevationSources().add(elevationSource);
    scene.setBaseSurface(surface);

    // add a camera and initial camera position
    Camera camera = new Camera(64.416919, -14.483728, 100, 318, 105, 0);
    sceneView.setViewpointCamera(camera);

    // create a control panel
    VBox controlsVBox = new VBox(6);
    controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0, 0, 0, 0.3)"),
        CornerRadii.EMPTY, Insets.EMPTY)));
    controlsVBox.setPadding(new Insets(10.0));
    controlsVBox.setMaxSize(260, 110);
    controlsVBox.getStyleClass().add("panel-region");

    // create buttons to set each atmosphere effect
    Button noAtmosphereButton = new Button("No Atmosphere Effect");
    Button realisticAtmosphereButton = new Button ("Realistic Atmosphere Effect");
    Button horizonAtmosphereButton = new Button ("Horizon Only Atmosphere Effect");
    noAtmosphereButton.setMaxWidth(Double.MAX_VALUE);
    realisticAtmosphereButton.setMaxWidth(Double.MAX_VALUE);
    horizonAtmosphereButton.setMaxWidth(Double.MAX_VALUE);

    noAtmosphereButton.setOnAction(event -> sceneView.setAtmosphereEffect(AtmosphereEffect.NONE));
    realisticAtmosphereButton.setOnAction(event -> sceneView.setAtmosphereEffect(AtmosphereEffect.REALISTIC));
    horizonAtmosphereButton.setOnAction(event -> sceneView.setAtmosphereEffect(AtmosphereEffect.HORIZON_ONLY));

    // add buttons to the control panel
    controlsVBox.getChildren().addAll(noAtmosphereButton, realisticAtmosphereButton, horizonAtmosphereButton);

    // add scene view and control panel to the stack pane
    stackPane.getChildren().addAll(sceneView, controlsVBox);
    StackPane.setAlignment(controlsVBox, Pos.TOP_RIGHT);
    StackPane.setMargin(controlsVBox, new Insets(10, 0, 0, 10));
  } catch (Exception e) {
    // on any error, display the stack trace.
    e.printStackTrace();
  }
}
 
Example 18
Source File: NewsView.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
private AnchorPane createBisqDAOContent() {
    AnchorPane anchorPane = new AnchorPane();
    anchorPane.setMinWidth(373);

    GridPane bisqDAOPane = new GridPane();
    AnchorPane.setTopAnchor(bisqDAOPane, 0d);
    bisqDAOPane.setVgap(5);
    bisqDAOPane.setMaxWidth(373);

    int rowIndex = 0;
    TitledGroupBg theBisqDaoTitledGroup = addTitledGroupBg(bisqDAOPane, rowIndex, 3, Res.get("dao.news.bisqDAO.title"));
    theBisqDaoTitledGroup.getStyleClass().addAll("last", "dao-news-titled-group");
    Label daoTeaserContent = addMultilineLabel(bisqDAOPane, ++rowIndex, Res.get("dao.news.bisqDAO.description"));
    daoTeaserContent.getStyleClass().add("dao-news-teaser");
    Hyperlink hyperlink = addHyperlinkWithIcon(bisqDAOPane, ++rowIndex, Res.get("dao.news.bisqDAO.readMoreLink"), "https://bisq.network/docs/dao");
    hyperlink.getStyleClass().add("dao-news-link");

    GridPane pastContributorsPane = new GridPane();
    AnchorPane.setBottomAnchor(pastContributorsPane, 0d);

    pastContributorsPane.setVgap(5);
    pastContributorsPane.setMaxWidth(373);

    rowIndex = 0;
    TitledGroupBg contributorsTitledGroup = addTitledGroupBg(pastContributorsPane, rowIndex, 4, Res.get("dao.news.pastContribution.title"));
    contributorsTitledGroup.getStyleClass().addAll("last", "dao-news-titled-group");
    Label pastContributionDescription = addMultilineLabel(pastContributorsPane, ++rowIndex, Res.get("dao.news.pastContribution.description"));
    pastContributionDescription.getStyleClass().add("dao-news-content");
    Tuple3<Label, BsqAddressTextField, VBox> tuple = addLabelBsqAddressTextField(pastContributorsPane, ++rowIndex,
            Res.get("dao.news.pastContribution.yourAddress"),
            Layout.FIRST_ROW_DISTANCE);
    addressTextField = tuple.second;
    Button requestNowButton = addPrimaryActionButton(pastContributorsPane, ++rowIndex, Res.get("dao.news.pastContribution.requestNow"), 0);
    requestNowButton.setMaxWidth(Double.MAX_VALUE);
    GridPane.setHgrow(requestNowButton, Priority.ALWAYS);
    requestNowButton.setOnAction(e -> GUIUtil.openWebPage("https://bisq.network/docs/dao/genesis"));

    anchorPane.getChildren().addAll(bisqDAOPane, pastContributorsPane);

    return anchorPane;
}
 
Example 19
Source File: SortManager.java    From PDF4Teachers with Apache License 2.0 4 votes vote down vote up
public void setup(GridPane parent, String selectedButtonName, String... buttonsName){

        int row = 0;
        for(String buttonName : buttonsName){

            if(buttonName.equals("\n")){
                row++; continue;
            }

            Button button = new Button(buttonName);
            button.setGraphic(Builders.buildImage(getClass().getResource("/img/Sort/up.png")+"", 0, 0));
            button.setAlignment(Pos.CENTER_LEFT);
            button.setMaxWidth(Double.MAX_VALUE);
            GridPane.setHgrow(button, Priority.ALWAYS);
            BooleanProperty order = new SimpleBooleanProperty(true);
            buttons.put(button, order);
            parent.addRow(row, button);

            if(selectedButtonName.equals(buttonName)){
                selectedButton.set(button);
                button.setStyle("-fx-background-color: " + selectedColor + ";");
            }else button.setStyle("-fx-background-color: " + StyleManager.getHexAccentColor() + ";");

            // Image de l'ordre
            order.addListener(new ChangeListener<>() {
                @Override public void changed(ObservableValue<? extends Boolean> observableValue, Boolean lastOrder, Boolean newOrder) {
                    button.setGraphic(Builders.buildImage(getClass().getResource(newOrder ? "/img/Sort/up.png" : "/img/Sort/down.png") + "", 0, 0));
                }
            });

            // Change selectedButton lors du clic ET update l'ordre
            button.setOnAction(actionEvent -> {
                if(selectedButton.get() == button){
                    order.set(!order.get());
                    updateSort.call(button.getText(), order.get());
                }else selectedButton.set(button);
            });
        }
        if(selectedButton.get() == null){
            selectedButton.set(buttons.keySet().iterator().next());
            buttons.keySet().iterator().next().setStyle("-fx-background-color: " + selectedColor);
        }

        // Couleurs des boutons
        selectedButton.addListener((observableValue, lastSelected, newSelected) -> {
            lastSelected.setStyle("-fx-background-color: " + StyleManager.getHexAccentColor() + ";");
            newSelected.setStyle("-fx-background-color: " + selectedColor + ";");
            updateSort.call(newSelected.getText(), buttons.get(newSelected).get());
        });
    }
 
Example 20
Source File: ChartPerformanceBenchmark.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
private Button startTestButton(final String label, final int[] nSamplesTest, final long updatePeriod) {
    final Button startTimer = new Button(label);
    startTimer.setTooltip(new Tooltip("start test series iterating through each chart implementation"));
    startTimer.setMaxWidth(Double.MAX_VALUE);
    startTimer.setOnAction(evt -> {
        if (timer == null) {
            timer = new Thread() {
                @Override
                public void run() {
                    try {
                        for (int i = 0; i < nSamplesTest.length; i++) {
                            final int samples = nSamplesTest[i];
                            final int wait = i == 0 ? 2 * WAIT_PERIOD : WAIT_PERIOD;
                            LOGGER.atInfo().log("start test iteration for: " + samples + " samples");
                            if (samples > 10000) {
                                // pre-emptively abort test JavaFX Chart
                                // test case (too high memory/cpu
                                // consumptions crashes gc)
                                compute[0] = false;
                            }
                            final TestThread t1 = new TestThread(1, compute[0] ? samples : 1000, chart1,
                                    chartTestCase1, results1, updatePeriod, wait);
                            final TestThread t2 = new TestThread(2, compute[1] ? samples : 1000, chart2,
                                    chartTestCase2, results2, updatePeriod, wait);
                            final TestThread t3 = new TestThread(3, compute[2] ? samples : 1000, chart3,
                                    chartTestCase3, results3, updatePeriod, wait);

                            meter.resetAverages();
                            if (compute[0]) {
                                t1.start();
                                t1.join();
                            }
                            if (compute[1]) {
                                t2.start();
                                t2.join();
                            }
                            if (compute[2]) {
                                t3.start();
                                t3.join();
                            }

                            if (i <= 2) {
                                // ignore compute for first iteration
                                // (needed to optimise JIT compiler)
                                compute[0] = true;
                                compute[1] = true;
                                compute[2] = true;
                                results1.clearData();
                                results2.clearData();
                                results3.clearData();
                            }
                        }
                    } catch (final InterruptedException e) {
                        if (LOGGER.isErrorEnabled()) {
                            LOGGER.atError().setCause(e).log("InterruptedException");
                        }
                    }
                }
            };
            timer.start();
            LOGGER.atInfo().log("reset FPS averages");
            meter.resetAverages();
        } else {
            timer.interrupt();
            timer = null;
        }
    });
    return startTimer;
}