Skip to content

Commit 4dce08f

Browse files
authored
Merge pull request #104 from CodeDead/feature/qol
Added Chinese, Code quality upgrades, improved audio loop gap effect, reduced default UI width and height
2 parents 4e3d245 + cf3c98f commit 4dce08f

File tree

7 files changed

+175
-40
lines changed

7 files changed

+175
-40
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.codedead.opal.controller;
2+
3+
import static com.codedead.opal.utils.SharedVariables.DEFAULT_LOCALE;
4+
5+
public final class LanguageController {
6+
7+
/**
8+
* Initialize a new LanguageController
9+
*/
10+
private LanguageController() {
11+
// Default constructor
12+
}
13+
14+
/**
15+
* Get the language index from the locale
16+
*
17+
* @param locale The locale
18+
* @return The language index
19+
*/
20+
public static int getLanguageIndexFromLocale(final String locale) {
21+
return switch (locale.toLowerCase()) {
22+
case "de-de" -> 1;
23+
case "es-es" -> 2;
24+
case "fr-fr" -> 3;
25+
case "jp-jp" -> 4;
26+
case "nl-nl" -> 5;
27+
case "ru-ru" -> 6;
28+
case "tr-tr" -> 7;
29+
case "zh-cn" -> 8;
30+
default -> 0;
31+
};
32+
}
33+
34+
/**
35+
* Get the locale from the language index
36+
*
37+
* @param index The language index
38+
* @return The locale
39+
*/
40+
public static String getLocaleFromLanguageIndex(final int index) {
41+
return switch (index) {
42+
case 1 -> "de-DE";
43+
case 2 -> "es-ES";
44+
case 3 -> "fr-FR";
45+
case 4 -> "jp-JP";
46+
case 5 -> "nl-NL";
47+
case 6 -> "ru-RU";
48+
case 7 -> "tr-TR";
49+
case 8 -> "zh-CN";
50+
default -> DEFAULT_LOCALE;
51+
};
52+
}
53+
}

src/main/java/com/codedead/opal/controller/MainWindowController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ public void run() {
256256
*/
257257
@FXML
258258
private void initialize() {
259-
mniTimerEnabled.setOnAction(e ->
260-
{
259+
mniTimerEnabled.setOnAction(e -> {
261260
if (mniTimerEnabled.isSelected()) {
262261
final Properties properties = settingsController.getProperties();
263262
final long timerDelay = Long.parseLong(properties.getProperty("timerDelay", "3600000"));

src/main/java/com/codedead/opal/controller/SettingsWindowController.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import atlantafx.base.theme.*;
44
import com.codedead.opal.domain.NumberTextField;
5+
import com.codedead.opal.domain.OSType;
6+
import com.codedead.opal.domain.OsCheck;
57
import com.codedead.opal.utils.FxUtils;
68
import com.codedead.opal.utils.SharedVariables;
79
import javafx.application.Application;
@@ -21,6 +23,7 @@
2123

2224
import java.io.IOException;
2325
import java.util.Locale;
26+
import java.util.Objects;
2427
import java.util.ResourceBundle;
2528
import java.util.concurrent.TimeUnit;
2629

@@ -76,6 +79,10 @@ private void initialize() {
7679
cboTheme.getSelectionModel()
7780
.selectedItemProperty()
7881
.addListener((options, oldValue, newValue) -> ThemeController.setTheme(cboTheme.getValue()));
82+
83+
if (Objects.requireNonNull(OsCheck.getOperatingSystemType()) == OSType.OTHER) {
84+
chbTimerComputerShutdown.setDisable(true);
85+
}
7986
}
8087

8188
/**
@@ -137,16 +144,7 @@ private void loadSettings() {
137144
timerDelay = 1;
138145
}
139146

140-
switch (settingsController.getProperties().getProperty("locale", DEFAULT_LOCALE).toLowerCase()) {
141-
case "de-de" -> cboLanguage.getSelectionModel().select(1);
142-
case "es-es" -> cboLanguage.getSelectionModel().select(2);
143-
case "fr-fr" -> cboLanguage.getSelectionModel().select(3);
144-
case "jp-jp" -> cboLanguage.getSelectionModel().select(4);
145-
case "nl-nl" -> cboLanguage.getSelectionModel().select(5);
146-
case "ru-ru" -> cboLanguage.getSelectionModel().select(6);
147-
case "tr-tr" -> cboLanguage.getSelectionModel().select(7);
148-
default -> cboLanguage.getSelectionModel().select(0);
149-
}
147+
cboLanguage.getSelectionModel().select(LanguageController.getLanguageIndexFromLocale(settingsController.getProperties().getProperty("locale", DEFAULT_LOCALE)));
150148

151149
switch (settingsController.getProperties().getProperty("loglevel", "INFO").toUpperCase()) {
152150
case "OFF" -> cboLogLevel.getSelectionModel().select(0);
@@ -232,16 +230,7 @@ private void saveSettingsAction() {
232230

233231
showAlertIfLanguageMismatch(settingsController.getProperties().getProperty("locale", DEFAULT_LOCALE));
234232

235-
switch (cboLanguage.getSelectionModel().getSelectedIndex()) {
236-
case 1 -> settingsController.getProperties().setProperty("locale", "de-DE");
237-
case 2 -> settingsController.getProperties().setProperty("locale", "es-es");
238-
case 3 -> settingsController.getProperties().setProperty("locale", "fr-FR");
239-
case 4 -> settingsController.getProperties().setProperty("locale", "jp-JP");
240-
case 5 -> settingsController.getProperties().setProperty("locale", "nl-NL");
241-
case 6 -> settingsController.getProperties().setProperty("locale", "ru-RU");
242-
case 7 -> settingsController.getProperties().setProperty("locale", "tr-TR");
243-
default -> settingsController.getProperties().setProperty("locale", DEFAULT_LOCALE);
244-
}
233+
settingsController.getProperties().setProperty("locale", LanguageController.getLocaleFromLanguageIndex(cboLanguage.getSelectionModel().getSelectedIndex()));
245234

246235
settingsController.getProperties().setProperty("theme", cboTheme.getSelectionModel().getSelectedItem());
247236
settingsController.getProperties().setProperty("loglevel", cboLogLevel.getValue());
@@ -295,16 +284,7 @@ private void saveSettingsAction() {
295284
* @param languageToMatch The language that needs to be matched to the combobox
296285
*/
297286
private void showAlertIfLanguageMismatch(final String languageToMatch) {
298-
final String newLanguage = switch (cboLanguage.getSelectionModel().getSelectedIndex()) {
299-
case 1 -> "de-DE";
300-
case 2 -> "es-es";
301-
case 3 -> "fr-FR";
302-
case 4 -> "jp-JP";
303-
case 5 -> "nl-NL";
304-
case 6 -> "ru-RU";
305-
case 7 -> "tr-TR";
306-
default -> DEFAULT_LOCALE;
307-
};
287+
final String newLanguage = LanguageController.getLocaleFromLanguageIndex(cboLanguage.getSelectionModel().getSelectedIndex());
308288

309289
if (!languageToMatch.equals(newLanguage)) {
310290
FxUtils.showInformationAlert(translationBundle.getString("RestartRequired"), getClass().getResourceAsStream(SharedVariables.ICON_URL));

src/main/java/com/codedead/opal/domain/SoundPane.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ private void initializeMediaPlayer(final String value) throws URISyntaxException
9292
disposeMediaPlayer();
9393

9494
mediaPlayer = new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource(value)).toURI().toString()));
95+
mediaPlayer.currentTimeProperty().addListener((observableValue, oldDuration, newDuration) -> {
96+
// Quality of life improvement to reduce audio lag when restarting the media
97+
if (mediaPlayer != null && newDuration.toSeconds() >= mediaPlayer.getMedia().getDuration().toSeconds() - 0.5) {
98+
mediaPlayer.seek(Duration.ZERO);
99+
}
100+
});
95101
mediaPlayer.setOnEndOfMedia(() -> {
96102
if (mediaPlayer != null) {
97103
mediaPlayer.seek(Duration.ZERO);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
About=关于
2+
AboutText=Opal 由 DeadLine 创建\n\n音频:ZapSplat.com\n图像:Remix Icon\n主题:AtlantaFX\n版本:1.1.0\n\n版权所有 © 2023 CodeDead
3+
AboutWindowError=无法打开“关于”窗口!
4+
AboutWindowTitle=Opal - 关于
5+
AutoUpdate=自动检查更新
6+
Birds=鸟类
7+
Chatter=喋喋不休
8+
CheckForUpdates=检查更新
9+
Close=关闭
10+
ConfirmReset=您确定要重置所有设置吗?
11+
Donate=捐
12+
Exit=出口
13+
File=_文件
14+
FileExecutionError=无法打开文件!
15+
Fireplace=壁炉
16+
General=一般的
17+
Help=帮助
18+
HelpFileError=无法打开帮助文件!
19+
HelpMenu=_帮助
20+
Homepage=主页
21+
Language=语言
22+
License=执照
23+
LicenseFileError=无法打开许可证文件!
24+
LogLevel=日志级别
25+
MainWindowTitle=Opal
26+
Nature=自然
27+
NewUpdateAvailable=版本 {v} 现已推出。 您想下载此更新吗?
28+
NoUpdateAvailable=没有可用更新!
29+
Office=办公室
30+
OpenSoundPreset=打开声音预设
31+
OpenSoundPresetError=无法打开声音预设!
32+
Phone=电话
33+
Rain=雨
34+
Reset=重置
35+
ResetSettingsError=无法重置所有设置!
36+
RestartRequired=需要重新启动才能更改语言!
37+
Save=节省
38+
SaveSettingsError=无法保存设置!
39+
SaveSoundPreset=保存声音设置
40+
SaveSoundPresetError=无法保存声音设置!
41+
Settings=设置
42+
SettingsWindowError=无法打开设置窗口!
43+
SettingsWindowTitle=Opal - 设置
44+
Thunder=雷
45+
Tools=_工具
46+
Traffic=交通
47+
Typing=打字
48+
UpdateError=无法检查更新!
49+
WebsiteError=无法打开网站!
50+
Wind=风
51+
River=河
52+
Clock=钟
53+
Static=静止的
54+
Other=其他
55+
Timer=计时器
56+
Enabled=启用
57+
Delay=延迟
58+
Seconds=第二次
59+
Minutes=分钟
60+
Hours=小时
61+
TimerDelayTooSmall=定时器延迟不能小于1!
62+
Fantasy=幻想
63+
Fan=扇子
64+
TimerApplicationShutdown=退出应用程序
65+
Cave=洞穴
66+
Frogs=青蛙
67+
Zen=禅
68+
Coffee=咖啡
69+
Zoo=动物园
70+
Audiences=观众
71+
NetworkingEvent=社交活动
72+
TribalFestival=部落节日
73+
RugbyFootball=橄榄球
74+
Sleepy=困
75+
DrumTribalFestival=鼓部落节
76+
Gong=锣
77+
MediaButtons=媒体按钮
78+
DragDrop=拖放文件
79+
Theme=主题
80+
Space=空间
81+
Restaurant=餐厅
82+
Cancel=取消
83+
Display=展示
84+
TrayIcon=任务栏图标
85+
TrayIconError=无法创建托盘图标!
86+
Ocean=海洋
87+
Train=火车
88+
WhiteNoise=白噪声
89+
RadioFrequencyStatic=射频静电
90+
PinkNoise=粉红噪声
91+
BrownNoise=布朗噪声
92+
TimerComputerShutdown=关闭电脑
93+
AudioBalance=音频平衡
94+
Advanced=先进的
95+
Seagulls=海鸥
96+
Belltower=钟楼

src/main/resources/windows/MainWindow.fxml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<?import javafx.scene.image.Image?>
2323

2424
<GridPane
25-
prefHeight="370"
26-
prefWidth="560"
25+
prefHeight="350"
26+
prefWidth="550"
2727
xmlns:fx="http://javafx.com/fxml/1"
2828
fx:controller="com.codedead.opal.controller.MainWindowController"
2929
onDragOver="#onDragOver"
@@ -86,7 +86,7 @@
8686
<Image url="@../images/timer.png"/>
8787
</ImageView>
8888
</graphic>
89-
<CheckMenuItem fx:id="mniTimerEnabled" text="%Enabled"/>
89+
<CheckMenuItem fx:id="mniTimerEnabled" text="%Enabled" accelerator="Shortcut+T"/>
9090
</Menu>
9191
</Menu>
9292
<Menu text="%HelpMenu">
@@ -166,7 +166,7 @@
166166

167167
<Label GridPane.rowIndex="0" GridPane.columnIndex="1" text="%Nature">
168168
<font>
169-
<Font name="System Bold" size="16"/>
169+
<Font name="System Bold" size="15"/>
170170
</font>
171171
<GridPane.margin>
172172
<Insets left="5" right="5" top="10"/>
@@ -235,7 +235,7 @@
235235

236236
<Label GridPane.rowIndex="3" GridPane.columnIndex="1" text="%Office">
237237
<font>
238-
<Font name="System Bold" size="16"/>
238+
<Font name="System Bold" size="15"/>
239239
</font>
240240
<GridPane.margin>
241241
<Insets left="5" right="5" top="10"/>
@@ -288,7 +288,7 @@
288288

289289
<Label GridPane.rowIndex="6" GridPane.columnIndex="1" text="%Audiences">
290290
<font>
291-
<Font name="System Bold" size="16"/>
291+
<Font name="System Bold" size="15"/>
292292
</font>
293293
<GridPane.margin>
294294
<Insets left="5" right="5" top="10"/>
@@ -333,7 +333,7 @@
333333

334334
<Label GridPane.rowIndex="9" GridPane.columnIndex="1" text="%RadioFrequencyStatic">
335335
<font>
336-
<Font name="System Bold" size="16"/>
336+
<Font name="System Bold" size="15"/>
337337
</font>
338338
<GridPane.margin>
339339
<Insets left="5" right="5" top="10"/>
@@ -377,7 +377,7 @@
377377

378378
<Label GridPane.rowIndex="12" GridPane.columnIndex="1" text="%Other">
379379
<font>
380-
<Font name="System Bold" size="16"/>
380+
<Font name="System Bold" size="15"/>
381381
</font>
382382
<GridPane.margin>
383383
<Insets left="5" right="5" top="10"/>

src/main/resources/windows/SettingsWindow.fxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<String fx:value="Nederlands"/>
9595
<String fx:value="Русский"/>
9696
<String fx:value="Türkçe"/>
97+
<String fx:value="中国人"/>
9798
</FXCollections>
9899
</items>
99100
</ComboBox>

0 commit comments

Comments
 (0)