Skip to content

Commit 2a69d4c

Browse files
committed
Refactoring: Create 'CustomTextInputDialog'
1 parent c417903 commit 2a69d4c

File tree

3 files changed

+61
-36
lines changed

3 files changed

+61
-36
lines changed

src/main/java/root/javafx/Controller/SettingMenuController.java

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import root.javafx.CustomView.ConnectionInfoVBox;
5454
import root.javafx.CustomView.DBConnInfoControl;
5555
import root.javafx.CustomView.ServerConnInfoControl;
56+
import root.javafx.CustomView.dialogUI.CustomTextInputDialog;
5657
import root.utils.AlertUtils;
5758
import root.utils.UnitUtils.FileSize;
5859

@@ -208,35 +209,23 @@ public UsageUIType fromString(String string) {
208209
* @param e
209210
*/
210211
public void showMonitoringPresetPopup(ActionEvent e) {
211-
// TextInputDialog 생성
212-
TextInputDialog presetInputDialog = new TextInputDialog();
213-
// ICON
214-
presetInputDialog.setGraphic(new FontAwesomeIconView(FontAwesomeIcon.PENCIL, "30"));
215-
// CSS
216-
presetInputDialog.getDialogPane().getStylesheets().add(
217-
getClass().getResource(System.getProperty("resourceBaseDir") + "/css/dialog.css").toExternalForm());
218-
presetInputDialog.getDialogPane().getStyleClass().add("textInputDialog");
219-
// Dialog ICON
220-
Stage stage = (Stage) presetInputDialog.getDialogPane().getScene().getWindow();
221-
stage.getIcons().add(new Image(
222-
this.getClass().getResource(System.getProperty("resourceBaseDir") + "/image/add_icon.png").toString()));
223-
// Button Custom
224-
ButtonType okButton = new ButtonType("입력", ButtonData.OK_DONE);
225-
presetInputDialog.getDialogPane().getButtonTypes().removeAll(ButtonType.OK, ButtonType.CANCEL);
226-
presetInputDialog.getDialogPane().getButtonTypes().addAll(okButton, ButtonType.CANCEL);
227-
// Content
228-
presetInputDialog.setTitle("Preset 생성");
229-
presetInputDialog.setHeaderText("새로운 Monitoring Preset 이름을 입력해주세요.");
230-
presetInputDialog.setContentText("Preset 이름: ");
231-
// Result
212+
213+
// Create input dialog
214+
String dialogTitle = "Preset 생성";
215+
String dialogHeaderText = "새로운 Monitoring Preset 이름을 입력해주세요.";
216+
String dialogContentText = "Preset 이름: ";
217+
CustomTextInputDialog presetInputDialog = new CustomTextInputDialog(dialogTitle, dialogHeaderText,
218+
dialogContentText);
219+
220+
// Process input result
232221
Optional<String> result = presetInputDialog.showAndWait();
233222
result.ifPresent(input -> {
234-
logger.debug("Monitoring Preset 생성 Input: " + input);
223+
// TODO validate input value
235224

225+
// TODO move this logic to propertyService
236226
// 1. Preset명 이용하여 설정파일 생성 (./config/monitoring/{접속정보설정파일명}/{preset명}.properties
237-
File connInfoFile = new File(fileChooserText.getText());
238-
String connInfoFileName = connInfoFile.getName().substring(0,
239-
connInfoFile.getName().indexOf(".properties"));
227+
String connInfoFilePath = fileChooserText.getText();
228+
String connInfoFileName = connInfoFilePath.substring(0, connInfoFilePath.indexOf(".properties"));
240229
String filePath = "./config/monitoring/" + connInfoFileName + "/" + input + ".properties";
241230
propRepo.createNewPropertiesFile(filePath, "Monitoring");
242231

@@ -249,11 +238,9 @@ public void showMonitoringPresetPopup(ActionEvent e) {
249238
reloadingMonitoringSetting(input);
250239

251240
// 4. 성공 Alert 띄우기
252-
Alert successAlert = new Alert(AlertType.INFORMATION);
253-
successAlert.setHeaderText("Preset 생성");
254-
successAlert.setContentText("모니터링여부 설정 Preset이 생성되었습니다.");
255-
successAlert.getDialogPane().setStyle("-fx-font-family: NanumGothic;");
256-
successAlert.show();
241+
String successTitle = "Preset 생성";
242+
String successContent = "모니터링여부 설정 Preset이 생성되었습니다.";
243+
AlertUtils.showAlert(AlertType.INFORMATION, successTitle, successContent);
257244
});
258245
}
259246

@@ -468,7 +455,7 @@ private void createMonitoringElements(VBox rootVBox, String[] monitoringElements
468455

469456
for (String s : elementContents) {
470457
String contentToggleId = mName.replaceAll("\\s", "") + s + "ToggleBtn";
471-
458+
472459
HBox contentHBox = new HBox();
473460
Label contentLabel = new Label();
474461
contentLabel.setText(s);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package root.javafx.CustomView.dialogUI;
2+
3+
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
4+
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
5+
import javafx.scene.control.ButtonBar.ButtonData;
6+
import javafx.scene.control.ButtonType;
7+
import javafx.scene.control.TextInputDialog;
8+
import javafx.scene.image.Image;
9+
import javafx.stage.Stage;
10+
11+
public class CustomTextInputDialog extends TextInputDialog {
12+
13+
public CustomTextInputDialog(String title, String headerText, String contentText) {
14+
// ICON
15+
setGraphic(new FontAwesomeIconView(FontAwesomeIcon.PENCIL, "30"));
16+
17+
// CSS
18+
getDialogPane().getStylesheets().add(System.getProperty("resourceBaseDir") + "/css/dialog.css");
19+
getDialogPane().getStyleClass().add("textInputDialog");
20+
21+
// Dialog ICON
22+
Stage stage = (Stage) getDialogPane().getScene().getWindow();
23+
Image image = new Image(
24+
getClass().getResource(System.getProperty("resourceBaseDir") + "/image/add_icon.png").toString());
25+
stage.getIcons().add(image);
26+
27+
// Button Custom
28+
ButtonType okButton = new ButtonType("ÀÔ·Â", ButtonData.OK_DONE);
29+
getDialogPane().getButtonTypes().removeAll(ButtonType.OK, ButtonType.CANCEL);
30+
getDialogPane().getButtonTypes().addAll(okButton, ButtonType.CANCEL);
31+
32+
// Content
33+
setTitle(title);
34+
setHeaderText(headerText);
35+
setContentText(contentText);
36+
}
37+
}

src/main/java/root/utils/AlertUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
public class AlertUtils {
77

88
public static void showAlert(AlertType alertType, String alertHeaderText, String alertContentText) {
9-
Alert failAlert = new Alert(alertType);
10-
failAlert.setHeaderText(alertHeaderText);
11-
failAlert.setContentText(alertContentText);
12-
failAlert.getDialogPane().setStyle("-fx-font-family: NanumGothic;");
13-
failAlert.show();
9+
Alert alert = new Alert(alertType);
10+
alert.setHeaderText(alertHeaderText);
11+
alert.setContentText(alertContentText);
12+
alert.getDialogPane().getStylesheets().add(System.getProperty("resourceBaseDir") + "/css/javaFx.css");
13+
alert.getDialogPane().getStyleClass().add("basic-font");
14+
alert.show();
1415
}
1516
}

0 commit comments

Comments
 (0)