下面列出了怎么用javafx.scene.control.Alert.AlertType的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public Optional<ButtonType> delete(Optional<ButtonType> option) {
if (!option.isPresent() || option.get() != FXUIUtils.YES_ALL) {
option = FXUIUtils.showConfirmDialog(null, "Do you want to delete `" + group.getName() + "`?", "Confirm",
AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, FXUIUtils.YES_ALL, ButtonType.CANCEL);
}
if (option.isPresent() && (option.get() == ButtonType.YES || option.get() == FXUIUtils.YES_ALL)) {
try {
Group.delete(type, group);
Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.DELETE, this));
getParent().getChildren().remove(this);
} catch (Exception e) {
e.printStackTrace();
String message = String.format("Unable to delete: %s: %s%n", group.getName(), e);
FXUIUtils.showMessageDialog(null, message, "Unable to delete", AlertType.ERROR);
}
}
return option;
}
public static Group createGroup(GroupType type, Path path, String name) {
List<Group> groups = getGroups(type);
for (Group g : groups) {
if (g.getName().equals(name)) {
Optional<ButtonType> option = FXUIUtils.showConfirmDialog(null,
type.fileType() + " `" + g.getName() + "` name is already used.", "Duplicate " + type.fileType() + " Name",
AlertType.CONFIRMATION);
if (!option.isPresent() || option.get() == ButtonType.CANCEL) {
return null;
}
}
}
Group group = new Group(name);
try {
Files.write(path, (type.fileCommentHeader() + group.toJSONString()).getBytes());
return new Group(path.toFile());
} catch (IOException e) {
return null;
}
}
private void showError(final String message) {
Runnable dialog = new Runnable() {
@Override
public void run() {
Alert dlg = DialogUtils.createAlert(AlertType.ERROR);
dlg.setTitle("Error - Delete.");
dlg.setHeaderText("Could not delete file(s).");
dlg.setContentText(message);
dlg.showAndWait();
}
};
if (Platform.isFxApplicationThread()) {
dialog.run();
} else {
Platform.runLater(dialog);
}
}
public void removeTimingLocation(ActionEvent fxevent){
final TimingLocation tl = timingLocListView.getSelectionModel().getSelectedItem();
// If the location is referenced by a split,
// toss up a warning and leave it alone
final StringProperty splitsUsing = new SimpleStringProperty();
raceDAO.listRaces().forEach(r -> {
r.getSplits().forEach(s -> {
if (s.getTimingLocation().equals(tl)) splitsUsing.set(splitsUsing.getValueSafe() + r.getRaceName() + " " + s.getSplitName() + "\n");
});
});
if (splitsUsing.isEmpty().get()) {
timingDAO.removeTimingLocation(tl);;
timingLocAddButton.requestFocus();
//timingLocAddButton.setDefaultButton(true);
} else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Unable to Remove Timing Location");
alert.setHeaderText("Unable to remove the " + tl.getLocationName() + " timing location.");
alert.setContentText("The timing location is in use by the following splits:\n" + splitsUsing.getValueSafe());
alert.showAndWait();
}
}
public static void showAboutPopup(DesignerRoot root) {
Alert licenseAlert = new Alert(AlertType.INFORMATION);
licenseAlert.setWidth(500);
licenseAlert.setHeaderText("About");
ScrollPane scroll = new ScrollPane();
TextArea textArea = new TextArea();
String sb =
"PMD core version:\t\t\t" + PMDVersion.VERSION + "\n"
+ "Designer version:\t\t\t" + Designer.getCurrentVersion()
+ " (supports PMD core " + Designer.getPmdCoreMinVersion() + ")\n"
+ "Designer settings dir:\t\t"
+ root.getService(DesignerRoot.DISK_MANAGER).getSettingsDirectory() + "\n"
+ "Available languages:\t\t"
+ AuxLanguageRegistry.getSupportedLanguages().map(Language::getTerseName).collect(Collectors.toList())
+ "\n";
textArea.setText(sb);
scroll.setContent(textArea);
licenseAlert.getDialogPane().setContent(scroll);
licenseAlert.showAndWait();
}
@FXML
void movie(ActionEvent event) {
// キャプチャ中であれば止める
this.stopTimeLine();
// 連写モード解除
this.cyclic.setSelected(false);
if ((AppConfig.get().getFfmpegPath() == null || AppConfig.get().getFfmpegPath().isEmpty())
|| (AppConfig.get().getFfmpegArgs() == null || AppConfig.get().getFfmpegArgs().isEmpty())
|| (AppConfig.get().getFfmpegExt() == null || AppConfig.get().getFfmpegExt().isEmpty())) {
Tools.Conrtols.alert(AlertType.INFORMATION, "設定が必要です", "[設定]メニューの[キャプチャ]タブから"
+ "FFmpegパスおよび引数を設定してください。", this.getWindow());
this.movie.setSelected(false);
}
if (this.movie.isSelected()) {
// キャプチャボタンテキストの変更
this.setCatureButtonState(ButtonState.START);
// 直接保存に設定
this.direct.setSelected(true);
} else {
// キャプチャボタンテキストの変更
this.setCatureButtonState(ButtonState.CAPTURE);
}
}
@FXML private void handleDownloadArticleButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnSucceeded(t -> downloadContents("ARTICLE"));
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
downloadContents("ARTICLE");
}
}
@FXML private void handleSelectFileAction(){
if(! zdsUtils.isAuthenticated()){
Service<Void> loginTask = menuManager.handleLoginButtonAction(null);
loginTask.setOnSucceeded(t -> selectAndUploadImage());
loginTask.setOnCancelled(t -> {
menuManager.getHBottomBox().getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
selectAndUploadImage();
}
}
private static void showError(final String message) {
Runnable dialog = new Runnable() {
@Override
public void run() {
Alert dlg = DialogUtils.createAlert(AlertType.ERROR);
dlg.setTitle("Error Share Folder.");
dlg.setHeaderText("Could not share folder.");
dlg.setContentText(message);
dlg.showAndWait();
}
};
if (Platform.isFxApplicationThread()) {
dialog.run();
} else {
Platform.runLater(dialog);
}
}
public void clearAllOverrides(ActionEvent fxevent){
//TODO: Prompt and then remove all times associated with that timing location
// _or_ all timing locations
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Clear Overrides...");
alert.setHeaderText("Delete Overrides:");
alert.setContentText("Do you want to delete all overrides?");
//ButtonType allButtonType = new ButtonType("All");
ButtonType deleteButtonType = new ButtonType("Delete",ButtonData.YES);
ButtonType cancelButtonType = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(cancelButtonType, deleteButtonType );
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == deleteButtonType) {
// delete all
timingDAO.clearAllOverrides();
}
}
public static boolean confirmMoveDirectoryDialog(File newPath) {
boolean yes = false;
Alert dlg = DialogUtils.createAlert(AlertType.CONFIRMATION);
dlg.setTitle("Move Directory");
dlg.setHeaderText("Move the directory?");
dlg.setContentText(String.format("This will move the directory to a new location: %s.",
newPath.toString()));
dlg.getButtonTypes().clear();
dlg.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);
dlg.showAndWait();
yes = dlg.getResult() == ButtonType.YES;
return yes;
}
private void close()
{
DiagramTab diagramTab = getSelectedDiagramTab();
// we only want to check attempts to close a frame
if( diagramTab.hasUnsavedChanges() )
{
// ask user if it is ok to close
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(diagramTab);
}
return;
}
else
{
removeGraphFrameFromTabbedPane(diagramTab);
}
}
public static ButtonType showAlert(AlertType type, String title, String header, String errorMessage) {
// Show the error message.
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(errorMessage);
alert.setResizable(true);
// modal
Optional<ButtonType> result = alert.showAndWait();
ButtonType buttonType = null;
try {
buttonType = result.get();
} catch (NoSuchElementException e) {
}
return buttonType;
}
/**
* Indicates when a graphic is clicked by showing an Alert.
*/
private void createGraphicDialog() {
try {
// get the list of graphics returned by identify
IdentifyGraphicsOverlayResult result = identifyGraphics.get();
List<Graphic> graphics = result.getGraphics();
if (!graphics.isEmpty()) {
// show a alert dialog box if a graphic was returned
Alert dialog = new Alert(AlertType.INFORMATION);
dialog.initOwner(mapView.getScene().getWindow());
dialog.setHeaderText(null);
dialog.setTitle("Information Dialog Sample");
dialog.setContentText("Clicked on " + graphics.size() + " graphic");
dialog.showAndWait();
}
} catch (Exception e) {
// on any error, display the stack trace
e.printStackTrace();
}
}
@FXML private void handleDownloadButtonAction(ActionEvent event){
if(! MainApp.getZdsutils().isAuthenticated()){
Service<Void> loginTask = handleLoginButtonAction(event);
loginTask.setOnSucceeded(t -> downloadContents(null));
loginTask.setOnCancelled(t -> {
hBottomBox.getChildren().clear();
Alert alert = new CustomAlert(AlertType.ERROR);
alert.setTitle(Configuration.getBundle().getString("ui.dialog.auth.failed.title"));
alert.setHeaderText(Configuration.getBundle().getString("ui.dialog.auth.failed.header"));
alert.setContentText(Configuration.getBundle().getString("ui.dialog.auth.failed.text"));
alert.showAndWait();
});
loginTask.start();
}else{
downloadContents(null);
}
}
@Override
public Optional<ButtonType> delete(Optional<ButtonType> option) {
if (!option.isPresent() || option.get() != FXUIUtils.YES_ALL) {
option = FXUIUtils.showConfirmDialog(null, "Do you want to delete `" + path + "`?", "Confirm", AlertType.CONFIRMATION,
ButtonType.YES, ButtonType.NO, FXUIUtils.YES_ALL, ButtonType.CANCEL);
}
if (option.isPresent() && (option.get() == ButtonType.YES || option.get() == FXUIUtils.YES_ALL)) {
if (Files.exists(path)) {
try {
Files.delete(path);
Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.DELETE, this));
getParent().getChildren().remove(this);
} catch (IOException e) {
String message = String.format("Unable to delete: %s: %s%n", path, e);
FXUIUtils.showMessageDialog(null, message, "Unable to delete", AlertType.ERROR);
}
}
}
return option;
}
private void newFolder(Resource resource) {
Path filePath = resource.getFilePath();
if (filePath == null) {
return;
}
File file;
if (resource instanceof FolderResource) {
file = resource.getFilePath().toFile();
} else {
file = resource.getFilePath().getParent().toFile();
}
File newFile = FXUIUtils.showMarathonSaveFileChooser(new MarathonFileChooserInfo("Create new folder", file, true),
"Create a folder with the given name", FXUIUtils.getIcon("fldr_obj"));
if (newFile == null) {
return;
}
if (newFile.exists()) {
FXUIUtils.showMessageDialog(this.getScene().getWindow(), "Folder with name '" + newFile.getName() + "' already exists.",
"Folder exists", AlertType.INFORMATION);
} else {
newFile.mkdir();
}
refreshView();
}
@Override
public void neuralnetProcessCompleted(HashMap<String, Double> result) {
if (result == null) {
Platform.runLater(new Runnable() {
@Override
public void run() {
Calert.showAlert("Forced Rollback", "Image Detection Failed:\nCorrupted File", AlertType.ERROR);
rollBack(null);
return;
}
});
}
bulgingTransition.stop();
updateIndicatorText("Done");
System.out.println("Neural net result:-\n" + result);
loadResult(result);
}
private boolean checkInput()
{
if (traces.isEmpty())
{
new Alert(AlertType.INFORMATION, Messages.AddAnnotation_NoTraces).showAndWait();
return false;
}
final MultipleSelectionModel<Trace<XTYPE>> seletion = trace_list.getSelectionModel();
final Trace<XTYPE> item = seletion.isEmpty() ? traces.get(0) : seletion.getSelectedItem();
final String content = text.getText().trim();
if (content.isEmpty())
{
new Alert(AlertType.WARNING, Messages.AddAnnotation_NoContent).showAndWait();
return false;
}
plot.addAnnotation(item, content);
return true;
}
/**
* ノードの内容をPNGファイルとして出力します
*
* @param node ノード
* @param title タイトル及びファイル名
* @param own 親ウインドウ
*/
public static void storeSnapshot(Node node, String title, Window own) {
try {
FileChooser chooser = new FileChooser();
chooser.setTitle(title + "の保存");
chooser.setInitialFileName(title + ".png");
chooser.getExtensionFilters().addAll(
new ExtensionFilter("PNG Files", "*.png"));
File f = chooser.showSaveDialog(own);
if (f != null) {
SnapshotParameters sp = new SnapshotParameters();
sp.setFill(Color.WHITESMOKE);
WritableImage image = node.snapshot(sp, null);
try (OutputStream out = Files.newOutputStream(f.toPath())) {
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", out);
}
}
} catch (Exception e) {
alert(AlertType.WARNING, "画像ファイルに保存出来ませんでした", "指定された場所へ画像ファイルを書き込みできませんでした", e, own);
}
}
public static void closeProject() {
Alert alert = new Alert(AlertType.CONFIRMATION);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getIcons().add(mzMineIcon);
alert.setTitle("Confirmation");
alert.setHeaderText("Close project");
String s = "Are you sure you want to close the current project?";
alert.setContentText(s);
Optional<ButtonType> result = alert.showAndWait();
if ((result.isPresent()) && (result.get() == ButtonType.OK)) {
MZmineGUIProject newProject = new MZmineGUIProject();
activateProject(newProject);
setStatusBarMessage("");
}
}
@Override
public void handleInput(GroupInputInfo info) {
try {
File file = info.getFile();
if (file == null) {
return;
}
Group group = Group.createGroup(type, file.toPath(), info.getName());
if (group == null) {
return;
}
fileUpdated(file);
navigatorPanel.updated(DisplayWindow.this, new FileResource(file.getParentFile()));
suitesPanel.updated(DisplayWindow.this, new FileResource(file));
featuresPanel.updated(DisplayWindow.this, new FileResource(file));
storiesPanel.updated(DisplayWindow.this, new FileResource(file));
issuesPanel.updated(DisplayWindow.this, new FileResource(file));
Platform.runLater(() -> openFile(file));
} catch (Exception e) {
e.printStackTrace();
FXUIUtils.showConfirmDialog(DisplayWindow.this,
"Could not complete creation of " + type.fileType().toLowerCase() + " file.",
"Error in creating a " + type.fileType().toLowerCase() + " file", AlertType.ERROR);
}
}
@Override
public void handle(FixtureStageInfo fixtureInfo) {
newFile(getFixtureHeader(fixtureInfo.getProperties(), fixtureInfo.getSelectedLauncher()),
new File(System.getProperty(Constants.PROP_FIXTURE_DIR)));
currentEditor.setDirty(true);
File fixtureFile = new File(System.getProperty(Constants.PROP_FIXTURE_DIR),
fixtureInfo.getFixtureName() + scriptModel.getSuffix());
try {
currentEditor.setData("filename", fixtureFile.getName());
saveTo(fixtureFile);
currentEditor.setDirty(false);
updateView();
} catch (IOException e) {
FXUIUtils.showMessageDialog(DisplayWindow.this, "Unable to save the fixture: " + e.getMessage(), "Invalid File",
AlertType.ERROR);
return;
}
setDefaultFixture(fixtureInfo.getFixtureName());
}
private boolean closeEditor(IEditor e) {
if (e == null) {
return true;
}
if (e.isDirty()) {
Optional<ButtonType> result = FXUIUtils.showConfirmDialog(DisplayWindow.this,
"File \"" + e.getName() + "\" Modified. Do you want to save the changes ",
"File \"" + e.getName() + "\" Modified", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO,
ButtonType.CANCEL);
ButtonType shouldSaveFile = result.get();
if (shouldSaveFile == ButtonType.CANCEL) {
return false;
}
if (shouldSaveFile == ButtonType.YES) {
File file = save(e);
if (file == null) {
return false;
}
EditorDockable dockable = (EditorDockable) e.getData("dockable");
dockable.updateKey();
}
}
return true;
}
public boolean canAppend(File file) {
EditorDockable dockable = findEditorDockable(file);
if (dockable == null) {
return true;
}
if (!dockable.getEditor().isDirty()) {
return true;
}
Optional<ButtonType> result = FXUIUtils.showConfirmDialog(DisplayWindow.this,
"File " + file.getName() + " being edited. Do you want to save the file?", "Save Module", AlertType.CONFIRMATION,
ButtonType.YES, ButtonType.NO);
ButtonType option = result.get();
if (option == ButtonType.YES) {
save(dockable.getEditor());
return true;
}
return false;
}
/**
* Shows a message in an alert dialog.
*
* @param title title of alert
* @param message message to display
*/
private void displayMessage(String title, String message) {
Platform.runLater(() -> {
Alert dialog = new Alert(AlertType.INFORMATION);
dialog.initOwner(mapView.getScene().getWindow());
dialog.setHeaderText(title);
dialog.setContentText(message);
dialog.showAndWait();
});
}
/** Called when user tries to close the tab
*
* <p>Derived class may override.
*
* @return Should the tab close? Otherwise it stays open.
*/
protected boolean okToClose()
{
if (! isDirty())
return true;
final String text = MessageFormat.format(Messages.DockAlertMsg, getLabel());
final Alert prompt = new Alert(AlertType.NONE,
text,
ButtonType.NO, ButtonType.CANCEL, ButtonType.YES);
prompt.setTitle(Messages.DockAlertTitle);
prompt.getDialogPane().setMinSize(300, 100);
prompt.setResizable(true);
DialogHelper.positionDialog(prompt, getTabPane(), -200, -100);
final ButtonType result = prompt.showAndWait().orElse(ButtonType.CANCEL);
// Cancel the close request
if (result == ButtonType.CANCEL)
return false;
// Close without saving?
if (result == ButtonType.NO)
return true;
// Save in background job ...
JobManager.schedule(Messages.Save, monitor -> save(monitor));
// .. and leave the tab open, so user can then try to close again
return false;
}
private void saveCircuitsInternal() {
try {
saveCircuits();
} catch(Exception exc) {
exc.printStackTrace();
Alert alert = new Alert(AlertType.ERROR);
alert.initOwner(stage);
alert.initModality(Modality.WINDOW_MODAL);
alert.setTitle("Error");
alert.setHeaderText("Error saving circuit.");
alert.setContentText("Error when saving the circuit: " + exc.getMessage());
alert.showAndWait();
}
}
/**
* displays a modal popup and waits for answer
*
* @param message what to display as main message
* @param yesmessage what to display on button for yes
* @param nomessage what to display on button for no
* @return true if answer is yes, false if answer of the popup is false
*/
public boolean displayModalPopup(String message, String yesmessage, String nomessage) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Unsaved data warning");
alert.setContentText("There is unsaved data. Do you want to continue and lose data ?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK)
return true;
return false;
}
void load() {
Path path = this.path.get();
if (path == null || markdownEditorPane == null)
return;
lastModified = path.toFile().lastModified();
try {
String markdown = null;
boolean readOnly = false;
long fileSize = Files.size(path);
if (fileSize > MAX_FILE_SIZE) {
markdown = Messages.get("FileEditor.tooLarge", fileSize, MAX_FILE_SIZE);
readOnly = true;
} else {
// load file
markdown = load(path);
// check whether this is a binary file
if (markdown.indexOf(0) >= 0) {
markdown = Messages.get("FileEditor.binary", fileSize);
readOnly = true;
if (fileSize <= MAX_HEX_FILE_SIZE)
markdown += "\n\n\n" + toHex(Files.readAllBytes(path));
}
}
markdownEditorPane.setReadOnly(readOnly);
markdownEditorPane.setMarkdown(markdown);
markdownEditorPane.getUndoManager().mark();
} catch (IOException ex) {
Alert alert = mainWindow.createAlert(AlertType.ERROR,
Messages.get("FileEditor.loadFailed.title"),
Messages.get("FileEditor.loadFailed.message"), path, ex.getMessage());
alert.showAndWait();
}
}