下面列出了javafx.scene.control.SeparatorMenuItem#javafx.stage.Modality 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void showSelectableTextModal(String title, String text) {
TextArea textArea = new BisqTextArea();
textArea.setText(text);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setPrefSize(800, 600);
Scene scene = new Scene(textArea);
Stage stage = new Stage();
if (null != title) {
stage.setTitle(title);
}
stage.setScene(scene);
stage.initModality(Modality.NONE);
stage.initStyle(StageStyle.UTILITY);
stage.show();
}
@Inject
public OpenWithDialog(StylesConfig styles, List<Module> modules) {
initModality(Modality.WINDOW_MODAL);
initStyle(StageStyle.UTILITY);
setResizable(false);
setTitle(DefaultI18nContext.getInstance().i18n("Open with"));
this.modules = modules.stream().sorted(comparing(m -> m.descriptor().getName())).collect(toList());
messageTitle.getStyleClass().add("-pdfsam-open-with-dialog-title");
BorderPane containerPane = new BorderPane();
containerPane.getStyleClass().addAll(Style.CONTAINER.css());
containerPane.getStyleClass().addAll("-pdfsam-open-with-dialog", "-pdfsam-open-with-container");
containerPane.setTop(messageTitle);
BorderPane.setAlignment(messageTitle, Pos.TOP_CENTER);
filesList.setPrefHeight(150);
containerPane.setCenter(filesList);
buttons.getStyleClass().addAll(Style.CONTAINER.css());
containerPane.setBottom(buttons);
BorderPane.setAlignment(buttons, Pos.CENTER);
Scene scene = new Scene(containerPane);
scene.getStylesheets().addAll(styles.styles());
scene.setOnKeyReleased(new HideOnEscapeHandler(this));
setScene(scene);
eventStudio().addAnnotatedListeners(this);
}
public static void openActivityMonitor(BatchRunner runner) {
try {
FXMLLoader loader = new FXMLLoader(CurlyApp.class.getResource("/fxml/RunnerReport.fxml"));
loader.setResources(ApplicationState.getInstance().getResourceBundle());
loader.load();
RunnerActivityController runnerActivityController = loader.getController();
Stage popup = new Stage();
popup.setScene(new Scene(loader.getRoot()));
popup.initModality(Modality.APPLICATION_MODAL);
popup.initOwner(applicationWindow);
runnerActivityController.attachRunner(runner);
popup.showAndWait();
} catch (IOException ex) {
Logger.getLogger(CurlyApp.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static BaseController openScene(Stage stage, String newFxml,
StageStyle stageStyle) {
try {
Stage newStage = new Stage(); // new stage should be opened instead of keeping old stage, to clean resources
newStage.initModality(Modality.NONE);
newStage.initStyle(StageStyle.DECORATED);
newStage.initOwner(null);
BaseController controller = initScene(newStage, newFxml, stageStyle);
if (stage != null) {
closeStage(stage);
}
return controller;
} catch (Exception e) {
logger.error(e.toString());
return null;
}
}
public static void _showMessageDialog(Window parent, String message, String title, AlertType type, boolean monospace) {
Alert alert = new Alert(type);
alert.initOwner(parent);
alert.setTitle(title);
alert.setHeaderText(title);
alert.setContentText(message);
alert.initModality(Modality.APPLICATION_MODAL);
alert.setResizable(true);
if (monospace) {
Text text = new Text(message);
alert.getDialogPane().setStyle("-fx-padding: 0 10px 0 10px;");
text.setStyle(" -fx-font-family: monospace;");
alert.getDialogPane().contentProperty().set(text);
}
alert.showAndWait();
}
public static void runAlert(BiConsumer<Stage, AlertWindowController> setup) {
try {
// JavaFX2 doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
// files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
// an odd sort of way.
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.APPLICATION_MODAL);
FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
Pane pane = loader.load();
AlertWindowController controller = loader.getController();
setup.accept(dialogStage, controller);
dialogStage.setScene(new Scene(pane));
dialogStage.showAndWait();
} catch (IOException e) {
// We crashed whilst trying to show the alert dialog (this should never happen). Give up!
throw new RuntimeException(e);
}
}
public void importChinaTowns() {
synchronized (this) {
if (task != null) {
return;
}
task = new SingletonTask<Void>() {
@Override
protected boolean handle() {
File file = FxmlControl.getInternalFile("/data/db/Geography_Code_china_towns_internal.csv",
"data", "Geography_Code_china_towns_internal.csv", false);
GeographyCode.importInternalCSV(loading, file, true);
return true;
}
@Override
protected void whenSucceeded() {
refreshAction();
}
};
loading = openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
}
private void initMenu() {
//BaseFrame frame=new BaseFrame();
information.initModality(Modality.APPLICATION_MODAL);
information.initOwner(menu);
information.getDialogPane().setHeaderText(null);
//information.initOwner(frame);
//textInput.initOwner(frame);
textInput.setTitle("输入分组");
textInput.setContentText("名称:");
textInput.getEditor().setText("");
addCategoryMenuItem.setText("新建分组");
findGroupMenuItem.setText("查找群");
updateCategoryNameMenuItem.setText("重命名分组");
addMenuItem.setText("创建一个群");
menu.getItems().add(addCategoryMenuItem);
menu.getItems().add(findGroupMenuItem);
menu.getItems().add(updateCategoryNameMenuItem);
menu.getItems().add(addMenuItem);
}
private void initMenu() {
information.initModality(Modality.APPLICATION_MODAL);
information.initOwner(menu);
information.getDialogPane().setHeaderText(null);
textInput.setTitle("输入分组");
textInput.setContentText("名称:");
textInput.getEditor().setText("");
addCategoryMenuItem.setText("新建分组");
findUserMenuItem.setText("查找用户");
updateCategoryNameMenuItem.setText("重命名分组");
menu.getItems().add(addCategoryMenuItem);
menu.getItems().add(findUserMenuItem);
menu.getItems().add(updateCategoryNameMenuItem);
}
/**
* Opens {@link PreferencesFx} in a dialog window.
*
* @param modal if true, will not allow the user to interact with any other window than
* the {@link PreferencesFxDialog}, as long as it is open.
*/
public void show(boolean modal) {
if (!modalityInitialized) {
// only set modality once to avoid exception:
// java.lang.IllegalStateException: Cannot set modality once stage has been set visible
Modality modality = modal ? Modality.APPLICATION_MODAL : Modality.NONE;
dialog.initModality(modality);
modalityInitialized = true;
}
if (modal) {
dialog.showAndWait();
} else {
dialog.show();
}
}
public static void runAlert (BiConsumer<Stage, AlertWindowController> setup) {
try {
// JavaFX2 doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
// files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
// an odd sort of way.
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.APPLICATION_MODAL);
FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
Pane pane = loader.load();
AlertWindowController controller = loader.getController();
setup.accept(dialogStage, controller);
dialogStage.setScene(new Scene(pane));
dialogStage.showAndWait();
} catch (IOException e) {
// We crashed whilst trying to show the alert dialog (this should never happen). Give up!
throw new RuntimeException(e);
}
}
private AvailabilityEditorController getAvailabilityController() throws Exception {
if (availabilityEditorController == null) {
FXMLLoader loader = FXMLLoaderFactory.availabilityEditorLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("availability.editor"));
dialogStage.initModality(Modality.APPLICATION_MODAL);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
availabilityEditorController = loader.getController();
availabilityEditorController.setDialogStage(dialogStage);
}
return availabilityEditorController;
}
/**
* Construct and return a transaction details dialog window.
*/
public static Stage build(final ResourceBundle resources, final WalletTransaction transaction)
throws IOException {
final Stage stage = new Stage();
final FXMLLoader loader = new FXMLLoader(TransactionDetailsDialog.class.getResource("/txDetailsDialog.fxml"), resources);
final Scene scene = new Scene(loader.load());
scene.getStylesheets().add(CATE.DEFAULT_STYLESHEET);
stage.setScene(scene);
final TransactionDetailsDialog controller = loader.getController();
controller.setTransaction(transaction);
controller.stage = stage;
stage.setTitle(resources.getString("txDetails.title"));
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
stage.getIcons().add(new Image("/org/libdohj/cate/cate.png"));
return stage;
}
public ProgressDialog(Translation title, Stage primaryStage) {
initStyle(StageStyle.TRANSPARENT);
setResizable(false);
initModality(Modality.APPLICATION_MODAL);
initOwner(primaryStage);
this.title.textProperty().bind(title.getProperty());
this.title.getStyleClass().add("progress-title");
label.getStyleClass().add("progress-info");
box.getStyleClass().add("progress-dialog");
box.getChildren().addAll(this.title, progressBar, label);
progressBar.prefWidthProperty().bind(box.widthProperty());
this.title.prefWidthProperty().bind(box.widthProperty());
label.prefWidthProperty().bind(box.widthProperty());
Scene scene = new Scene(box);
scene.setFill(Color.TRANSPARENT);
scene.getStylesheets().addAll(primaryStage.getScene().getStylesheets());
setScene(scene);
}
HttpSource showHttpServerEditor() throws Exception {
FXMLLoader loader = FXMLLoaderFactory.httpServerLoader();
AnchorPane page = (AnchorPane) loader.getRoot();
// Create the dialog Stage.
Stage dialogStage = new Stage(StageStyle.DECORATED);
dialogStage.setTitle(DesignerLocalizer.instance().getLangString("http.servers.title"));
dialogStage.initModality(Modality.WINDOW_MODAL);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// get the controller
HttpServerController httpServerController = loader.getController();
httpServerController.setDialogStage(dialogStage);
httpServerController.initializeServer();
// Show the dialog and wait until the user closes it
httpServerController.getDialogStage().showAndWait();
return httpServerController.getSource();
}
public Arma3ToolsDirNotSetPopup() {
super(ArmaDialogCreator.getPrimaryStage(), new VBox(5), null);
ResourceBundle bundle = Lang.ApplicationBundle();
setTitle(bundle.getString("Popups.generic_popup_title"));
myStage.initModality(Modality.APPLICATION_MODAL);
myStage.setResizable(false);
Button btnLocate = new Button(bundle.getString("ValueEditors.ImageValueEditor.set_a3_tools_btn"));
btnLocate.setOnAction(new EventHandler<>() {
@Override
public void handle(ActionEvent event) {
new ChangeDirectoriesDialog().showAndWait();
close();
}
});
myRootElement.setPadding(new Insets(10));
myRootElement.getChildren().add(new Label(bundle.getString("ValueEditors.ImageValueEditor.a3_tools_dir_not_set")));
myRootElement.getChildren().add(btnLocate);
myRootElement.getChildren().addAll(new Separator(Orientation.HORIZONTAL), getBoundResponseFooter(true, true, false));
}
@Override
protected void setSecondArea(String hexFormat) {
if (isSettingValues || displayArea == null
|| !contentSplitPane.getItems().contains(displayArea)) {
return;
}
isSettingValues = true;
LoadingController loadingController = openHandlingStage(Modality.WINDOW_MODAL);
if (!hexFormat.isEmpty()) {
String[] lines = hexFormat.split("\n");
StringBuilder text = new StringBuilder();
String lineText;
for (String line : lines) {
lineText = new String(ByteTools.hexFormatToBytes(line), sourceInformation.getCharset());
lineText = lineText.replaceAll("\n", " ").replaceAll("\r", " ") + "\n";
text.append(lineText);
}
displayArea.setText(text.toString());
} else {
displayArea.clear();
}
if (loadingController != null) {
loadingController.closeStage();
}
isSettingValues = false;
}
/** Builds the new stage, done in the constructor. */
private Stage createStage(Stage mainStage) {
return new StageBuilder().withOwner(mainStage)
.withModality(Modality.WINDOW_MODAL)
.withStyle(StageStyle.DECORATED)
.withFxml(DesignerUtil.getFxml("xpath-export-wizard"), root, this)
.withTitle("Export XPath expression to XML rule")
.newStage();
}
@FXML
public void rotateLeft() {
synchronized (this) {
if (task != null) {
return;
}
task = new SingletonTask<Void>() {
private Image newImage;
@Override
protected boolean handle() {
newImage = FxmlImageManufacture.rotateImage(imageView.getImage(), 360 - rotateAngle);
if (task == null || isCancelled()) {
return false;
}
return newImage != null;
}
@Override
protected void whenSucceeded() {
parent.updateImage(ImageOperation.Transform, "rotateLeft", (360 - rotateAngle) + "",
newImage, cost);
}
};
parent.openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
}
public static void showDialog(Window owner, String title, Message message) {
alert = new Alert(AlertType.NONE);
alert.initOwner(owner);
alert.setTitle(title);
ObservableMap<String, String> messages = message.getMessages();
StringBuilder msg = new StringBuilder();
messages.forEach((key, value) -> msg.append(String.format("%s\t: %s%n", key, value)));
alert.getDialogPane().setMinHeight(messages.size() * 30d);
alert.setContentText(msg.toString());
// Run with small delay on each change
messages.addListener((Change<? extends String, ? extends String> change) -> Platform.runLater(() -> {
StringBuilder msgChange = new StringBuilder();
messages.forEach((key, value) -> msgChange.append(String.format("%s\t: %s%n", key, value)));
alert.setContentText(msgChange.toString());
if (messages.values().stream().allMatch(val -> val.startsWith(Message.processed))) {
stopDialog();
message.clearMessages();
}
}));
alert.initModality(Modality.APPLICATION_MODAL);
alert.getDialogPane().getStylesheets()
.add(LoadDialog.class.getResource("/css/application.css").toExternalForm());
// Calculate the center position of the parent Stage
double centerXPosition = owner.getX() + owner.getWidth() / 2d;
double centerYPosition = owner.getY() + owner.getHeight() / 2d;
alert.setOnShowing(e -> {
alert.setX(centerXPosition - alert.getDialogPane().getWidth() / 2d);
alert.setY(centerYPosition - alert.getDialogPane().getHeight() / 2d);
});
alert.show();
}
public static JFXAlert createDialog(JFXDialogLayout content) {
JFXAlert dialog = new JFXAlert(primaryStage);
dialog.setContent(content);
dialog.setOverlayClose(false);
dialog.initModality(Modality.APPLICATION_MODAL);
return dialog;
}
public void rotate(final int rotateAngle) {
if (imageView.getImage() == null) {
return;
}
currentAngle = rotateAngle;
synchronized (this) {
if (task != null) {
return;
}
task = new SingletonTask<Void>() {
private Image newImage;
@Override
protected boolean handle() {
newImage = FxmlImageManufacture.rotateImage(imageView.getImage(), rotateAngle);
return newImage != null;
}
@Override
protected void whenSucceeded() {
imageView.setImage(newImage);
checkSelect();
setImageChanged(true);
refinePane();
}
};
openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
}
protected void html2markdown(String contents) {
if (contents == null || contents.isEmpty()) {
markdownArea.setText("");
return;
}
synchronized (this) {
if (task != null) {
return;
}
task = new SingletonTask<Void>() {
private String md;
@Override
protected boolean handle() {
try {
MutableDataSet options = new MutableDataSet();
md = FlexmarkHtmlConverter.builder(options).build().convert(contents);
return md != null;
} catch (Exception e) {
error = e.toString();
return false;
}
}
@Override
protected void whenSucceeded() {
markdownArea.setText(md);
}
};
openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
}
public ExportWindow(List<File> files){
this.files = files;
VBox root = new VBox();
Scene scene = new Scene(root);
window.initOwner(Main.window);
window.initModality(Modality.WINDOW_MODAL);
window.getIcons().add(new Image(getClass().getResource("/logo.png")+""));
window.setWidth(650);
window.setMinWidth(500);
window.setMaxWidth(800);
window.setTitle("PDF4Teachers - " + TR.tr("Exporter") + " (" + files.size() + " " + TR.tr("documents)"));
window.setScene(scene);
window.setOnCloseRequest(e -> window.close());
StyleManager.putStyle(root, Style.DEFAULT);
if(files.size() == 1){
setupSimplePanel(root);
}else{
setupComplexPanel(root);
}
window.show();
}
private void setupStage(Window owner) {
final Scene scene = new Scene(this);
scene.getStylesheets().add(getClass().getResource(ApplicationConstants.GLOBAL_CSS_FILE_NAME).toExternalForm());
scene.setRoot(this);
stage.setScene(scene);
stage.setTitle("Settings");
stage.setResizable(false);
stage.centerOnScreen();
stage.initOwner(owner);
stage.initModality(Modality.APPLICATION_MODAL);
}
protected void loadCities() {
if (citySelector == null) {
return;
}
citySelector.getItems().clear();
String country = countrySelector.getValue();
String province = provinceSelector.getValue();
if (country == null || country.trim().isBlank()) {
return;
}
synchronized (this) {
BaseTask addressesTask = new BaseTask<Void>() {
private List<String> cities;
@Override
protected boolean handle() {
// cities = TableGeographyCode.cities(country, province);
return true;
}
@Override
protected void whenSucceeded() {
String v = citySelector.getValue();
isSettingValues = true;
citySelector.getItems().addAll(cities);
if (v != null) {
citySelector.setValue(v);
}
isSettingValues = false;
}
};
openHandlingStage(addressesTask, Modality.WINDOW_MODAL);
Thread thread = new Thread(addressesTask);
thread.setDaemon(true);
thread.start();
}
}
@FXML
private void loadELAProcessor(ActionEvent event) throws Exception {
ELABatchImageProcessor processor = new ELABatchImageProcessor();
Stage stage = new Stage();
stage.initOwner(rootPane.getScene().getWindow());
stage.initModality(Modality.WINDOW_MODAL);
processor.start(stage);
}
@FXML
public void loadSystemClipboard() {
synchronized (this) {
if (task != null) {
return;
}
final Image clip = SystemTools.fetchImageInClipboard(false);
if (clip == null
|| (lastSystemClip != null
&& FxmlImageManufacture.sameImage(lastSystemClip, clip))) {
parent.popInformation(message("NoImageInClipboard"));
return;
}
lastSystemClip = clip;
task = new SingletonTask<Void>() {
private ImageClipboard clip;
@Override
protected boolean handle() {
String name = ImageClipboard.add(lastSystemClip, false);
clip = ImageClipboard.thumbnail(name);
return clip != null;
}
@Override
protected void whenSucceeded() {
thumbnails.add(0, clip);
}
};
parent.openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
}
}
/** 显示值输入窗口.
* @param isNum 是否选择整数类型, true为整数, false为字符串
*/
public boolean showValuePanel(boolean isNum) {
// 创建 FXMLLoader 对象
FXMLLoader loader = new FXMLLoader();
// 加载文件
loader.setLocation(this.getClass().getResource("/views/ListAddLayout.fxml"));
AnchorPane pane = null;
try {
pane = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
// 创建对话框
Stage dialogStage = new Stage();
dialogStage.setTitle("添加值");
dialogStage.initModality(Modality.WINDOW_MODAL);
Scene scene = new Scene(pane);
dialogStage.setScene(scene);
controller = loader.getController();
controller.setDialogStage(dialogStage);
if (isNum) {
controller.setTipText("输入0便立即删除\n-1 则永久存活 \n-2 则不存在");
controller.setFlag("number");
}
// 显示对话框, 并等待, 直到用户关闭
dialogStage.showAndWait();
return controller.isOkChecked();
}
public GameDialog() {
Button btnSubmit = new Button("Submit");
btnSubmit.setOnAction(event -> {
fieldAnswer.setEditable(false);
textActualAnswer.setVisible(true);
correct = textActualAnswer.getText().equals(fieldAnswer.getText().trim());
});
VBox vbox = new VBox(10, textQuestion, fieldAnswer, textActualAnswer, btnSubmit);
vbox.setAlignment(Pos.CENTER);
Scene scene = new Scene(vbox);
setScene(scene);
initModality(Modality.APPLICATION_MODAL);
}