下面列出了javafx.scene.control.Alert#initOwner ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initComponent() {
this.setTitle("选择头像");
this.setResizable(false);
this.setTitlePaneStyle(2);
this.setWidth(430);
this.setHeight(580);
this.setCenter(p);
alert = new Alert(AlertType.CONFIRMATION, "");
alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(this);
alert.getDialogPane().setContentText("确定选择");
alert.getDialogPane().setHeaderText(null);
p.setPrefWrapLength(400);
}
private void helpAbout() {
String version = null;
Package pkg = this.getClass().getPackage();
if (pkg != null)
version = pkg.getImplementationVersion();
if (version == null)
version = "(dev)";
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(Messages.get("MainWindow.about.title"));
alert.setHeaderText(Messages.get("MainWindow.about.headerText"));
alert.setContentText(Messages.get("MainWindow.about.contentText", version));
alert.setGraphic(new ImageView(new Image("org/markdownwriterfx/markdownwriterfx32.png")));
alert.initOwner(getScene().getWindow());
alert.getDialogPane().setPrefWidth(420);
alert.showAndWait();
}
/**
* 集計の追加
*/
@FXML
void addUnitAction(ActionEvent event) {
UnitDialog dialog = new UnitDialog();
Alert alert = new Alert(Alert.AlertType.NONE);
alert.getDialogPane().getStylesheets().add("logbook/gui/application.css");
InternalFXMLLoader.setGlobal(alert.getDialogPane());
alert.initOwner(this.getWindow());
alert.setTitle("集計の追加");
alert.setDialogPane(dialog);
alert.showAndWait().filter(ButtonType.APPLY::equals).ifPresent(b -> {
IUnit unit = dialog.getUnit();
if (unit != null) {
this.logMap.put(unit, BattleLogs.readSimpleLog(unit));
this.addTree(unit);
this.userUnit.add(unit);
}
});
}
/**
* If a user confirms that they want to close their modified graph, this method
* will remove it from the current list of tabs.
*
* @param pDiagramTab The current Tab that one wishes to close.
*/
public void close(DiagramTab pDiagramTab)
{
if(pDiagramTab.hasUnsavedChanges())
{
Alert alert = new Alert(AlertType.CONFIRMATION, RESOURCES.getString("dialog.close.ok"), ButtonType.YES, ButtonType.NO);
alert.initOwner(aMainStage);
alert.setTitle(RESOURCES.getString("dialog.close.title"));
alert.setHeaderText(RESOURCES.getString("dialog.close.title"));
alert.showAndWait();
if (alert.getResult() == ButtonType.YES)
{
removeGraphFrameFromTabbedPane(pDiagramTab);
}
}
else
{
removeGraphFrameFromTabbedPane(pDiagramTab);
}
}
@FXML
private void onOk(final ActionEvent actionEvent)
{
// possibly replace with ControlsFX validation framework
if (getEnteredName().isEmpty())
{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(Constants.APPLICATION_NAME);
// todo: i18n
alert.setContentText("Please enter a name for this method.");
alert.initOwner(newPurchaseDialog.getWindow());
alert.showAndWait();
return;
}
model.setCancelled(false);
Platform.runLater(() -> {
Window window = newPurchaseDialog.getWindow();
window.hide();
});
}
public boolean exitDialog(Stage stage) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.initOwner(stage);
alert.setTitle("Confirmation for Exit");//("Confirmation Dialog");
alert.setHeaderText("Leaving mars-sim ?");
//alert.initModality(Modality.APPLICATION_MODAL);
alert.setContentText("Note: Yes to exit mars-sim");
ButtonType buttonTypeYes = new ButtonType("Yes");
ButtonType buttonTypeNo = new ButtonType("No");
alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonTypeYes){
if (mainMenu.getMultiplayerMode() != null)
if (mainMenu.getMultiplayerMode().getChoiceDialog() != null)
mainMenu.getMultiplayerMode().getChoiceDialog().close();
alert.close();
Platform.exit();
System.exit(0);
return true;
} else {
alert.close();
return false;
}
}
private Alert get() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Info!");
alert.setHeaderText(headerText);
alert.setContentText(message);
alert.initOwner(mainStage);
return alert;
}
private Alert get() {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Warning!");
alert.setHeaderText(headerText);
alert.setContentText(message);
alert.initOwner(mainStage);
return alert;
}
public void deleteRedisKeyAction() {
ObservableList list = mc.redisValueTable.getSelectionModel().getSelectedItems();
if (list.isEmpty()) {
Toast.makeText("请选择要删除的记录").show(mc.pane.getScene().getWindow());
return;
}
StringBuilder key = new StringBuilder();
int i = 0;
for (Object object : list) {
Map mp = (Map) object;
key.append(mp.get("key"));
if (i != list.size() - 1) {
key.append(",");
}
i++;
}
Alert a = new Alert(Alert.AlertType.CONFIRMATION);
a.setTitle("确认删除");
a.setContentText("确认要删除[" + key + "]这些键值吗?");
a.initOwner(mc.pane.getScene().getWindow());
Optional<ButtonType> o = a.showAndWait();
if (o.get().getButtonData().equals(ButtonBar.ButtonData.OK_DONE)) {
String[] keys = key.toString().split(",");
String name = (String) mc.redisDatabaseList.getSelectionModel().getSelectedItem();
RedisUtil.deleteKeys(name, keys);
Toast.makeText("删除成功", Duration.seconds(1)).show(mc.pane.getScene().getWindow());
mc.paginationForValue.getPageFactory().call(0);
}
}
/**
* Exits the program if no graphs have been modified or if the user agrees to
* abandon modified graphs.
*/
public void exit()
{
final int modcount = getNumberOfUsavedDiagrams();
if (modcount > 0)
{
Alert alert = new Alert(AlertType.CONFIRMATION,
MessageFormat.format(RESOURCES.getString("dialog.exit.ok"), new Object[] { Integer.valueOf(modcount) }),
ButtonType.YES,
ButtonType.NO);
alert.initOwner(aMainStage);
alert.setTitle(RESOURCES.getString("dialog.exit.title"));
alert.setHeaderText(RESOURCES.getString("dialog.exit.title"));
alert.showAndWait();
if (alert.getResult() == ButtonType.YES)
{
Preferences.userNodeForPackage(UMLEditor.class).put("recent", aRecentFiles.serialize());
System.exit(0);
}
}
else
{
Preferences.userNodeForPackage(UMLEditor.class).put("recent", aRecentFiles.serialize());
System.exit(0);
}
}
@FXML
protected void deleteAction() {
final Path gameDir = packageManager.resolveInstallDir(selectedPackage);
final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setContentText(BundleUtils.getMessage("confirmDeleteGame_withoutData", gameDir));
alert.setTitle(BundleUtils.getLabel("message_deleteGame_title"));
alert.initOwner(stage);
alert.showAndWait()
.filter(response -> response == ButtonType.OK)
.ifPresent(response -> {
logger.info("Removing game: {}-{}", selectedPackage.getId(), selectedPackage.getVersion());
// triggering a game deletion implies the player doesn't want to play this game anymore
// hence, we unset `lastPlayedGameJob` and `lastPlayedGameVersion` settings independent of deletion success
launcherSettings.setLastPlayedGameJob("");
launcherSettings.setLastPlayedGameVersion("");
deleteButton.setDisable(true);
final DeleteTask deleteTask = new DeleteTask(packageManager, selectedVersion);
deleteTask.onDone(() -> {
packageManager.syncDatabase();
if (!selectedPackage.isInstalled()) {
startAndDownloadButton.setGraphic(downloadImage);
} else {
deleteButton.setDisable(false);
}
});
executor.submit(deleteTask);
});
}
public static Optional<ButtonType> _showConfirmDialog(Window parent, String message, String title, AlertType type,
ButtonType... buttonTypes) {
Alert alert = new Alert(type, message, buttonTypes);
alert.initOwner(parent);
alert.setTitle(title);
alert.initModality(Modality.APPLICATION_MODAL);
return alert.showAndWait();
}
public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.initOwner(owner);
alert.show();
}
public static Alert getAlert(String header, String content, AlertType alertType, Modality modality, Window window
, StageStyle style) {
Alert alert = new Alert(alertType);
alert.setTitle(QiniuValueConsts.MAIN_TITLE);
alert.setHeaderText(header);
alert.setContentText(content);
alert.initModality(modality);
alert.initOwner(window);
alert.initStyle(style);
return alert;
}
private Alert get() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("An error has occurred!");
alert.setHeaderText(headerText);
alert.setContentText(message);
alert.initOwner(mainStage);
return alert;
}
private void initComponent() {
this.setWidth(390);
this.setHeight(518);
this.setResizable(false);
this.setTitlePaneStyle(2);
this.setRadius(5);
this.setCenter(rootPane);
this.setTitle("更换头像");
imageFileChooser = new FileChooser();
imageFileChooser.getExtensionFilters().add(new ExtensionFilter("图片文件", "*.png", "*.jpg", "*.bmp", "*.gif"));
imagePane.setCoverSize(350, 350);
openButton.setText("上传头像");
selectButton.setText("选择系统头像");
openButton.setPrefSize(130, 30);
selectButton.setPrefSize(130, 30);
buttonBox.setPadding(new Insets(12, 10, 12, 14));
buttonBox.setSpacing(10);
buttonBox.getChildren().add(openButton);
buttonBox.getChildren().add(selectButton);
pane.setTop(buttonBox);
pane.setCenter(imagePane);
titleLabel.setText("更换头像");
titleLabel.setFont(Font.font("微软雅黑", 14));
titleLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1)");
topBox.setStyle("-fx-background-color:#2cb1e0");
topBox.setPrefHeight(30);
topBox.setPadding(new Insets(5, 10, 5, 10));
topBox.setSpacing(10);
topBox.getChildren().add(titleLabel);
alert = new Alert(AlertType.CONFIRMATION, "");
alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(this);
alert.getDialogPane().setContentText("确定选择");
alert.getDialogPane().setHeaderText(null);
cancelButton.setText("取消");
cancelButton.setPrefWidth(80);
doneButton.setText("确定");
doneButton.setPrefWidth(80);
bottomBox.setStyle("-fx-background-color:#c9e1e9");
bottomBox.setAlignment(Pos.BASELINE_RIGHT);
bottomBox.setPadding(new Insets(5, 10, 5, 10));
bottomBox.setSpacing(10);
bottomBox.getChildren().add(doneButton);
bottomBox.getChildren().add(cancelButton);
rootPane.setTop(topBox);
rootPane.setCenter(pane);
rootPane.setBottom(bottomBox);
Image coverImage = ImageBox.getImageClassPath("/classics/images/cropper/CircleMask.png");
imagePane.setCoverImage(coverImage);
}
public void checkUpdateAction() {
try {
HttpRequestData.Request req = new HttpRequestData.Request();
req.setUrl(updateURL);
req.setMethod(RequestMethod.GET.toString());
req.setTimeout("10000");
req.setCharset(Charset.UTF8.getCode());
HttpResponse resp = HttpClientUtil.sendRequest(req);
String respBody = EntityUtils.toString(resp.getEntity(), req.getCharset());
JsonObject json = gson.fromJson(respBody, JsonObject.class);
String cur = Undecorator.LOC.getString("VersionCode");
if (Integer.parseInt(cur) < json.get("version").getAsInt()) {
Alert a = new Alert(Alert.AlertType.CONFIRMATION);
a.setTitle("版本更新");
a.setContentText("当前版本:" + cur + "\n最新版本:" + json.get("version") + "\n更新内容:\n" + json.get("message").getAsString());
a.initOwner(mc.pane.getScene().getWindow());
Optional<ButtonType> o = a.showAndWait();
if (o.get().getButtonData().equals(ButtonBar.ButtonData.OK_DONE)) {
String dir = System.getProperty("user.dir");
HttpClientUtil.downloadFile(json.get("url").getAsString(), dir + "/开发辅助.jar.update");
a.setContentText("下载完成,请重启程序。");
a.setAlertType(Alert.AlertType.INFORMATION);
a.showAndWait();
File f = new File(dir + "/update.jar");
StringBuilder sb = new StringBuilder();
System.getenv().entrySet().forEach((entry) -> {
String key = entry.getKey();
String value = entry.getValue();
sb.append(key).append("=").append(value).append("#");
});
Runtime.getRuntime().exec("java -jar update.jar", sb.toString().split("#"), f.getParentFile());
System.exit(0);
}
} else {
Toast.makeText("当前已是最新版本", Duration.seconds(1)).show(mc.pane.getScene().getWindow());
}
} catch (Exception ex) {
Toast.makeText("检查更新异常:" + ex.getLocalizedMessage()).show(mc.pane.getScene().getWindow());
LOGGER.error(ex.getLocalizedMessage(), ex);
}
}
private URI getFileResource(final URI original_resource)
{
try
{
// Strip query from resource, because macros etc.
// are only relevant to runtime, not to editor
final URI resource = new URI(original_resource.getScheme(), original_resource.getUserInfo(),
original_resource.getHost(), original_resource.getPort(),
original_resource.getPath(), null, null);
// Does the resource already point to a local file?
File file = ModelResourceUtil.getFile(resource);
if (file != null)
{
last_local_file = file;
return file.toURI();
}
// Does user want to download into local file?
final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
DialogHelper.positionDialog(alert, DockPane.getActiveDockPane(), -200, -100);
alert.initOwner(DockPane.getActiveDockPane().getScene().getWindow());
alert.setResizable(true);
alert.setTitle(Messages.DownloadTitle);
alert.setHeaderText(MessageFormat.format(Messages.DownloadPromptFMT,
resource.toString()));
// Setting "Yes", "No" buttons
alert.getButtonTypes().clear();
alert.getButtonTypes().add(ButtonType.YES);
alert.getButtonTypes().add(ButtonType.NO);
if (alert.showAndWait().orElse(ButtonType.NO) == ButtonType.NO)
return null;
// Prompt for local file
final File local_file = promptForFilename(Messages.DownloadTitle);
if (local_file == null)
return null;
// In background thread, ..
JobManager.schedule(Messages.DownloadTitle, monitor ->
{
monitor.beginTask("Download " + resource);
// .. download resource into local file ..
try
(
final InputStream read = ModelResourceUtil.openResourceStream(resource.toString());
)
{
Files.copy(read, local_file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
// .. and then, back on UI thread, open editor for the local file
Platform.runLater(() -> create(ResourceParser.getURI(local_file)));
});
// For now, return null, no editor is opened right away.
}
catch (Exception ex)
{
ExceptionDetailsErrorDialog.openError("Error", "Cannot load " + original_resource, ex);
}
return null;
}
@Override
public void mousePressed(CircuitManager manager, CircuitState state, double x, double y) {
if(!isInput()) {
return;
}
if(state != manager.getCircuit().getTopLevelState()) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.initOwner(manager.getSimulatorWindow().getStage());
alert.initModality(Modality.WINDOW_MODAL);
alert.setTitle("Switch to top-level state?");
alert.setHeaderText("Switch to top-level state?");
alert.setContentText("Cannot modify state of a subcircuit. Switch to top-level state?");
Optional<ButtonType> buttonType = alert.showAndWait();
if(buttonType.isPresent() && buttonType.get() == ButtonType.OK) {
state = manager.getCircuit().getTopLevelState();
manager.getCircuitBoard().setCurrentState(state);
} else {
return;
}
}
Pin pin = getComponent();
WireValue value = state.getLastPushed(pin.getPort(Pin.PORT));
if(pin.getBitSize() == 1) {
pin.setValue(state,
new WireValue(1, value.getBit(0) == State.ONE ? State.ZERO : State.ONE));
} else {
double bitWidth = getScreenWidth() / Math.min(8.0, pin.getBitSize());
double bitHeight = getScreenHeight() / ((pin.getBitSize() - 1) / 8 + 1.0);
int bitCol = (int)(x / bitWidth);
int bitRow = (int)(y / bitHeight);
int bit = pin.getBitSize() - 1 - (bitCol + bitRow * 8);
if(bit >= 0 && bit < pin.getBitSize()) {
WireValue newValue = new WireValue(value);
newValue.setBit(bit, value.getBit(bit) == State.ONE ? State.ZERO : State.ONE);
pin.setValue(state, newValue);
}
}
}
private void saveAs()
{
DiagramTab diagramTab = getSelectedDiagramTab();
Diagram diagram = diagramTab.getDiagram();
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(FileExtensions.all());
fileChooser.setSelectedExtensionFilter(FileExtensions.forDiagramType(diagram.getType()));
if(diagramTab.getFile().isPresent())
{
fileChooser.setInitialDirectory(diagramTab.getFile().get().getParentFile());
fileChooser.setInitialFileName(diagramTab.getFile().get().getName());
}
else
{
fileChooser.setInitialDirectory(getLastDir(KEY_LAST_SAVEAS_DIR));
fileChooser.setInitialFileName("");
}
try
{
File result = fileChooser.showSaveDialog(aMainStage);
if( result != null )
{
PersistenceService.save(diagram, result);
addRecentFile(result.getAbsolutePath());
diagramTab.setFile(result);
diagramTab.setText(diagramTab.getFile().get().getName());
diagramTab.diagramSaved();
File dir = result.getParentFile();
if( dir != null )
{
setLastDir(KEY_LAST_SAVEAS_DIR, dir);
}
}
}
catch (IOException exception)
{
Alert alert = new Alert(AlertType.ERROR, RESOURCES.getString("error.save_file"), ButtonType.OK);
alert.initOwner(aMainStage);
alert.showAndWait();
}
}