DialogUtils.java
7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package cn.csbr.app.gui.util;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.component.common.ActionCallBack;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.controlsfx.dialog.CommandLinksDialog;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/***
* 对话框工具类
*/
public class DialogUtils {
public static void showHeaderTextInformationAlert(String message ,Stage stage) {
Alert dlg = new Alert(Alert.AlertType.INFORMATION, message);
dlg.initOwner(stage);
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.setHeaderText("");
dlg.setTitle("提示信息");
dlg.setOnCloseRequest(e -> {
dlg.close();
});
dlg.initModality(Modality.APPLICATION_MODAL);
//dlg.initOwner(owner);
dlg.show();
return;
}
public static void showHeaderTextInformationAlert2(String message ,Stage stage,boolean falg) {
Alert dlg = new Alert(Alert.AlertType.INFORMATION, message);
dlg.initOwner(stage);
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.setHeaderText("");
dlg.setTitle("提示信息");
dlg.setOnCloseRequest(e -> {
dlg.close();
if(falg){
stage.close();
}
});
dlg.initModality(Modality.APPLICATION_MODAL);
//dlg.initOwner(owner);
dlg.show();
return;
}
public static void showAlert(String message, ActionCallBack callBack) {
Alert dlg = new Alert(Alert.AlertType.INFORMATION, message);
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.setHeaderText("");
dlg.setTitle("提示信息");
//dlg.initOwner(owner);
dlg.setOnCloseRequest(e -> {
dlg.close();
});
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.showAndWait().ifPresent(new Consumer<ButtonType>() {
@Override
public void accept(ButtonType buttonType) {
try {
callBack.callback(null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
return;
}
public static void showAlert(String message, ActionCallBack callBack, Stage stage) {
Alert dlg = new Alert(Alert.AlertType.INFORMATION, message);
dlg.initOwner(stage);
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.setHeaderText("");
dlg.setTitle("提示信息");
//dlg.initOwner(owner);
dlg.setOnCloseRequest(e -> {
dlg.close();
});
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.showAndWait().ifPresent(new Consumer<ButtonType>() {
@Override
public void accept(ButtonType buttonType) {
try {
callBack.callback(null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
return;
}
public static void showConfirm(String message, ActionCallBack callBack, Stage stage) {
Alert dlg = new Alert(Alert.AlertType.CONFIRMATION, message);
dlg.initOwner(stage);
dlg.initModality(Modality.APPLICATION_MODAL);
dlg.setHeaderText("");
dlg.setTitle("提示信息");
dlg.initModality(Modality.APPLICATION_MODAL);
//dlg.initOwner(owner);
dlg.setOnCloseRequest(e -> {
dlg.close();
});
dlg.showAndWait().ifPresent(new Consumer<ButtonType>() {
@Override
public void accept(ButtonType buttonType) {
if (buttonType.equals(ButtonType.OK)) {
try {
callBack.callback(null);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("----------------------buttonType:" + buttonType);
//
}
});
return;
}
public static void showCommand(String message, ActionCallBack callBack, List<String> titles, List values, Stage stage) {
List<CommandLinksDialog.CommandLinksButtonType> links = new ArrayList();
// List<CommandLinksDialog.CommandLinksButtonType> links = Arrays
// .asList(new CommandLinksDialog.CommandLinksButtonType(
// "Add a network that is in the range of this computer",
// "This shows you a list of networks that are currently available and lets you connect to one.", false),
// new CommandLinksDialog.CommandLinksButtonType(
// "Manually create a network profile",
// "This creates a new network profile or locates an existing one and saves it on your computer",
// true /*default*/),
// new CommandLinksDialog.CommandLinksButtonType("Create an ad hoc network",
// "This creates a temporary network for sharing files or and Internet connection", false));
int i = 0;
for (String title : titles) {
boolean isDefault = false;
if (i == 0) {
isDefault = true;
}
MyCommandLinksButtonType button = new MyCommandLinksButtonType(
title, isDefault);
button.setData(values.get(i));
links.add(button);
i++;
}
CommandLinksDialog dlg = new CommandLinksDialog(links);
dlg.initOwner(stage);
dlg.setOnCloseRequest(e -> {
dlg.close();
});
dlg.setTitle(message);
dlg.initModality(Modality.APPLICATION_MODAL);
// String optionalMasthead = "Manually connect to wireless network";
// dlg.getDialogPane().setContentText("How do you want to add a network?");
dlg.showAndWait().ifPresent(new Consumer<ButtonType>() {
@Override
public void accept(ButtonType buttonType) {
System.out.println("-------------------------buttonType:" + buttonType);
if (buttonType.getButtonData().equals(ButtonType.CLOSE.getButtonData())) {
return;
}
try {
callBack.callback(buttonType.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
class MyCommandLinksButtonType<T> extends CommandLinksDialog.CommandLinksButtonType {
private T data;
public MyCommandLinksButtonType(String text, boolean isDefault) {
super(text, isDefault);
}
public MyCommandLinksButtonType(String text, String longText, boolean isDefault) {
super(text, longText, isDefault);
}
public MyCommandLinksButtonType(String text, String longText, Node graphic, boolean isDefault) {
super(text, longText, graphic, isDefault);
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}