下面列出了怎么用javafx.scene.control.SplitMenuButton的API类实例代码及写法,或者点击链接到github查看源代码。
public RequestComponentFxml(RequestComponent controller) {
setId("requestComponent");
HboxExt reqEdit = add(hbox("generalRequestEdit"));
controller.mainEditingArea = reqEdit.add(hbox("mainEditingArea"), true);
controller.submitBtn = reqEdit.add(new SplitMenuButton());
JavaFxUtils.publishEscToParent(controller.submitBtn);
controller.submitBtn.setId("submitBtn");
controller.submitBtn.setText("submit");
controller.submitBtn.setOnAction(e -> controller.onSubmit());
controller.saveBtn = reqEdit.add(new SplitMenuButton());
controller.saveBtn.setId("saveBtn");
controller.saveBtn.setText("save");
controller.saveBtn.setOnAction(e -> controller.onSave());
controller.saveBtn.getStyleClass().add("secondary");
MenuItem saveAs = new MenuItem("save as...");
saveAs.setOnAction(e -> controller.onSaveAs());
controller.saveBtn.getItems().add(saveAs);
MenuItem export = new MenuItem("export...");
export.setOnAction(e -> controller.onExport());
controller.saveBtn.getItems().add(export);
JFXTabPane tabPane = add(new JFXTabPane(), true);
tabPane.setId("tabs");
tabPane.setDisableAnimation(true);
controller.tabs = tabPane;
tabPane.setPrefHeight(300);
}
@Test
@Category(NoHeadless.class)
public void clearAllSettings() {
Listener<ClearModuleEvent> listener = mock(Listener.class);
ArgumentCaptor<ClearModuleEvent> captor = ArgumentCaptor.forClass(ClearModuleEvent.class);
eventStudio().add(ClearModuleEvent.class, listener, MODULE);
SplitMenuButton btn = lookup("#clear-button").queryAs(SplitMenuButton.class);
for (Node child : btn.getChildrenUnmodifiable()) {
if (child.getStyleClass().contains("arrow-button")) {
clickOn(child).clickOn(".menu-item");
}
}
verify(listener).onEvent(captor.capture());
assertTrue(captor.getValue().clearEverything);
}
/**
* @return A node with screenshot buttons which can be inserted into the toolbar
*/
public HBox getScreenshotInteractorBar() {
final HBox buttonBar = new HBox();
final Separator separator = new Separator();
separator.setOrientation(Orientation.VERTICAL);
SplitMenuButton button = new SplitMenuButton();
button.setGraphic(new HBox(0.1, new Glyph(FONT_AWESOME, FontAwesome.Glyph.CAMERA).size(FONT_SIZE),
new Glyph(FONT_AWESOME, FontAwesome.Glyph.CLIPBOARD).size(FONT_SIZE - 8.0)));
button.setOnAction(evt -> {
if (toFile) {
screenshotToFile(true);
} else {
screenshotToClipboard();
}
});
MenuItem toClipMenu = new MenuItem("Screenshot to clipboard",
new Glyph(FONT_AWESOME, FontAwesome.Glyph.CLIPBOARD));
toClipMenu.setOnAction(evt -> {
toFile = false;
button.setGraphic(new HBox(0.1, new Glyph(FONT_AWESOME, FontAwesome.Glyph.CAMERA).size(FONT_SIZE),
new Glyph(FONT_AWESOME, FontAwesome.Glyph.CLIPBOARD).size(FONT_SIZE - 8.8)));
button.setTooltip(new Tooltip("Copy screenshot of plot to Clipboard"));
screenshotToClipboard();
});
MenuItem toFileMenu = new MenuItem("Screenshot to file", new Glyph(FONT_AWESOME, FontAwesome.Glyph.FILE));
toFileMenu.setOnAction(evt -> {
toFile = true;
button.setGraphic(new HBox(0.1, new Glyph(FONT_AWESOME, FontAwesome.Glyph.CAMERA).size(FONT_SIZE),
new Glyph(FONT_AWESOME, FontAwesome.Glyph.FILE).size(FONT_SIZE - 8.0)));
button.setTooltip(new Tooltip("Save plot as image"));
screenshotToFile(true);
});
MenuItem settingsMenu = new MenuItem("Screenshot settings", new Glyph(FONT_AWESOME, FontAwesome.Glyph.WRENCH));
settingsMenu.setOnAction(evt -> {
ScreenshotDialog alert = new ScreenshotDialog();
alert.showAndWait() //
.filter(response -> response == ButtonType.OK) //
.ifPresent(response -> {
directory.set(alert.getDirectory());
pattern.set(alert.getPattern());
});
});
button.getItems().addAll(toClipMenu, toFileMenu, new SeparatorMenuItem(), settingsMenu);
buttonBar.getChildren().addAll(separator, button);
return buttonBar;
}
private SplitMenuButton createNewButton() {
SplitMenuButton newButton = new SplitMenuButton(newTestcaseAction.getMenuItem(), etAction.getMenuItem());
newButton.setGraphic(newTestcaseAction.getButton().getGraphic());
newButton.setOnAction(newTestcaseAction.getButton().getOnAction());
return newButton;
}