Skip to content

Commit 25970fa

Browse files
committed
Refactoring: Processing file unit and rounding digits configured value is NULL
1 parent ca59b6c commit 25970fa

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

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

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public class SettingMenuController implements Initializable {
8989

9090
@FXML
9191
JFXComboBox<String> monitoringPresetComboBox; // 모니터링여부 설정 Preset ComboBox
92-
92+
9393
@FXML
9494
JFXComboBox<FileSize> fileSizeCB;
9595

9696
@FXML
9797
JFXComboBox<Integer> roundingDigitsCB;
98-
98+
9999
@FXML
100100
JFXComboBox<UsageUIType> usageUICB;
101101

@@ -121,36 +121,46 @@ public void initialize(URL location, ResourceBundle resources) {
121121
loadSelectedConfigFile(lastUsePropertiesFile);
122122

123123
// [설정] - [모니터링 여부 설정] - Preset 변경 Event
124-
monitoringPresetComboBox.getSelectionModel().selectedItemProperty()
125-
.addListener((options, oldValue, newValue) -> {
126-
loadMonitoringConfigFile(monitoringPresetMap.get(newValue));
127-
});
124+
monitoringPresetComboBox.valueProperty().addListener((options, oldValue, newValue) -> {
125+
loadMonitoringConfigFile(monitoringPresetMap.get(newValue));
126+
});
128127
} else {
129128
setVisible(noConnInfoConfigAP, true);
130129
setVisible(noMonitoringConfigAP, true);
131130
}
131+
132+
/* 실행 설정 탭 - 조회결과 단위 설정 콤보박스 */
133+
// 조회결과 단위 설정 콤보박스 아이템 설정
134+
fileSizeCB.getItems().addAll(FileSize.values());
132135

133-
this.fileSizeCB.getItems().addAll(FileSize.values());
134-
FileSize fileSize = FileSize.valueOf(propRepo.getCommonResource("unit.filesize"));
135-
this.fileSizeCB.getSelectionModel().select(fileSize);
136-
137-
fileSizeCB.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
136+
// 아이템 변경 리스너
137+
fileSizeCB.valueProperty().addListener((options, oldValue, newValue) -> {
138138
Map<String, Object> map = new HashMap<>();
139139
map.put("unit.filesize", newValue);
140140
propRepo.saveCommonConfig(map);
141141
});
142-
143-
this.roundingDigitsCB.getItems().addAll(List.of(1, 2, 3, 4, 5));
144-
int roundingDigits = propRepo.getIntegerCommonResource("unit.rounding");
145-
this.roundingDigitsCB.getSelectionModel().select(Integer.valueOf(roundingDigits));
146-
147-
roundingDigitsCB.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
142+
143+
// 초기값 - 설정된 값 없다면 기본값 GB
144+
FileSize fileSize = FileSize.of(propRepo.getCommonResource("unit.filesize"));
145+
fileSizeCB.getSelectionModel().select(fileSize == null ? FileSize.GB : fileSize);
146+
147+
/* 실행 설정 탭 - 반올림 자릿수 설정 콤보박스 */
148+
// 반올림 자릿수 설정 콤보박스 아이템 설정
149+
roundingDigitsCB.getItems().addAll(List.of(1, 2, 3, 4, 5));
150+
151+
// 아이템 변경 리스너
152+
roundingDigitsCB.valueProperty().addListener((options, oldValue, newValue) -> {
148153
Map<String, Object> map = new HashMap<>();
149154
map.put("unit.rounding", newValue);
150155
propRepo.saveCommonConfig(map);
151156
});
152157

153-
// Set usage UI type comboBox items and Set setting value;
158+
// 초기값 - 설정된 값 없다면 기본값 2
159+
String roundingDigits = propRepo.getCommonResource("unit.rounding");
160+
roundingDigitsCB.getSelectionModel().select(roundingDigits == null ? 2 : Integer.valueOf(roundingDigits));
161+
162+
163+
// Set usage UI type comboBox items and Set setting value;
154164
String usageUICode = propRepo.getCommonResource("usage-ui-type");
155165
usageUICB.setConverter(new StringConverter<UsageUIType>() {
156166
@Override
@@ -167,7 +177,7 @@ public UsageUIType fromString(String string) {
167177
this.usageUICB.getSelectionModel().select(UsageUIType.find(usageUICode));
168178
usageUICB.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
169179
Map<String, Object> map = new HashMap<>();
170-
map.put("usage-ui-type", newValue.getCode());
180+
map.put("usage-ui-type", newValue.getCode());
171181
propRepo.saveCommonConfig(map);
172182
});
173183
}
@@ -341,15 +351,15 @@ public void saveConnInfoSettings(ActionEvent e) {
341351

342352
ConnectionInfoVBox<JdbcConnectionInfo> dbConnVBox = (ConnectionInfoVBox<JdbcConnectionInfo>) connInfoVBox
343353
.lookup("#dbConnVBox");
344-
354+
345355
boolean isDBSaveSucceed = dbConnVBox.saveConnInfoSettings(configFilePath);
346356
if (!isDBSaveSucceed) {
347357
return;
348358
}
349359

350360
ConnectionInfoVBox<JschConnectionInfo> serverConnVBox = (ConnectionInfoVBox<JschConnectionInfo>) connInfoVBox
351361
.lookup("#serverConnVBox");
352-
362+
353363
boolean isServerSaveSucceed = serverConnVBox.saveConnInfoSettings(configFilePath);
354364
if (!isServerSaveSucceed) {
355365
return;
@@ -394,6 +404,7 @@ public void saveMonitoringSettings(ActionEvent e) {
394404
*/
395405
private void createMonitoringElements(VBox rootVBox, String[] monitoringElements, String[] elementContents) {
396406
for (String mName : monitoringElements) {
407+
// String headerToggleId = mName.replaceAll("\\s", "") + "TotalToggleBtn";
397408
String headerToggleId = mName.replaceAll("\\s", "") + "TotalToggleBtn";
398409

399410
// Header
@@ -410,8 +421,9 @@ private void createMonitoringElements(VBox rootVBox, String[] monitoringElements
410421
headerLabel.setAlignment(Pos.CENTER_LEFT);
411422
headerLabel.setPrefWidth(200);
412423
headerLabel.setPrefHeight(40);
413-
headerLabel.setStyle(
414-
"-fx-font-family: NanumGothic; -fx-text-fill: BLACK; -fx-font-weight: bold; -fx-font-size: 14px;");
424+
headerLabel.getStylesheets().add(System.getProperty("resourceBaseDir") + "/css/javaFx.css");
425+
headerLabel.getStyleClass().add("basic-font");
426+
headerLabel.setStyle("-fx-font-size: 13px");
415427

416428
JFXToggleButton headerToggleBtn = new JFXToggleButton();
417429
headerToggleBtn.setId(headerToggleId);
@@ -436,6 +448,7 @@ private void createMonitoringElements(VBox rootVBox, String[] monitoringElements
436448

437449
for (String s : elementContents) {
438450
String contentToggleId = mName.replaceAll("\\s", "") + s + "ToggleBtn";
451+
439452
HBox contentHBox = new HBox();
440453
Label contentLabel = new Label();
441454
contentLabel.setText(s);
@@ -444,7 +457,8 @@ private void createMonitoringElements(VBox rootVBox, String[] monitoringElements
444457
contentLabel.setMinWidth(80);
445458
contentLabel.setMaxWidth(80);
446459
contentLabel.setPrefHeight(40);
447-
contentLabel.setStyle("-fx-font-family: NanumGothic; -fx-text-fill: BLACK; -fx-font-size: 12px;");
460+
contentLabel.getStylesheets().add(System.getProperty("resourceBaseDir") + "/css/javaFx.css");
461+
contentLabel.getStyleClass().add("basic-font");
448462

449463
JFXToggleButton contentToggleBtn = new JFXToggleButton();
450464
contentToggleBtn.setId(contentToggleId);

src/main/java/root/utils/UnitUtils.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package root.utils;
22

3+
import java.util.Collections;
4+
import java.util.Map;
5+
import java.util.stream.Collectors;
6+
import java.util.stream.Stream;
7+
38
import lombok.Getter;
49

510
public class UnitUtils {
@@ -11,10 +16,21 @@ public enum FileSize {
1116
private String unit;
1217
private int order;
1318

19+
private static final Map<String, String> FILESIZE_MAP = Collections
20+
.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(FileSize::getUnit, FileSize::name)));
21+
1422
FileSize(String unit, int order) {
1523
this.unit = unit;
1624
this.order = order;
1725
}
26+
27+
public static FileSize of(final String unit) {
28+
try {
29+
return FileSize.valueOf(FILESIZE_MAP.get(unit));
30+
} catch (NullPointerException e) {
31+
return null;
32+
}
33+
}
1834
}
1935

2036
/**
@@ -40,6 +56,6 @@ public static double convertFileUnit(FileSize beforeUnit, FileSize afterUnit, do
4056
*/
4157
public static double convertFileUnit(FileSize beforeUnit, FileSize afterUnit, double value, int round) {
4258
double convertValue = UnitUtils.convertFileUnit(beforeUnit, afterUnit, value);
43-
return Double.valueOf(String.format("%."+round+"f", convertValue));
59+
return Double.valueOf(String.format("%." + round + "f", convertValue));
4460
}
4561
}

0 commit comments

Comments
 (0)