doc: 增加UIResourceBundle注释
This commit is contained in:
parent
6679d6e04d
commit
59c8b8f5ed
@ -10,11 +10,22 @@ import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UI资源绑定,用于加载语言文件。
|
||||||
|
*
|
||||||
|
* @author songdragon
|
||||||
|
*/
|
||||||
public class UIResourceBundle {
|
public class UIResourceBundle {
|
||||||
|
|
||||||
private static final UIResourceBundle INSTANCE = new UIResourceBundle();
|
private static final UIResourceBundle INSTANCE = new UIResourceBundle();
|
||||||
|
/**
|
||||||
|
* resource目录下的i18n/i18nXXX.properties
|
||||||
|
*/
|
||||||
private static final String BASENAME = "i18n/i18n";
|
private static final String BASENAME = "i18n/i18n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前语言
|
||||||
|
*/
|
||||||
private Locale currentLocale;
|
private Locale currentLocale;
|
||||||
|
|
||||||
public static final UIResourceBundle getInstance() {
|
public static final UIResourceBundle getInstance() {
|
||||||
@ -25,8 +36,15 @@ public class UIResourceBundle {
|
|||||||
this.resetLocal();
|
this.resetLocal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源文件的观察者绑定。
|
||||||
|
*/
|
||||||
private ObjectProperty<ResourceBundle> resources = new SimpleObjectProperty<>();
|
private ObjectProperty<ResourceBundle> resources = new SimpleObjectProperty<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前资源文件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public ObjectProperty<ResourceBundle> resourcesProperty() {
|
public ObjectProperty<ResourceBundle> resourcesProperty() {
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
@ -39,6 +57,9 @@ public class UIResourceBundle {
|
|||||||
resourcesProperty().set(resources);
|
resourcesProperty().set(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置当前local
|
||||||
|
*/
|
||||||
public final void resetLocal() {
|
public final void resetLocal() {
|
||||||
if (this.currentLocale == LocalizationConfig.getCurrentLocal()) {
|
if (this.currentLocale == LocalizationConfig.getCurrentLocal()) {
|
||||||
return;
|
return;
|
||||||
@ -49,6 +70,11 @@ public class UIResourceBundle {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取key对应的绑定属性内容
|
||||||
|
* @param key key
|
||||||
|
* @return key对应的内容
|
||||||
|
*/
|
||||||
public StringBinding getStringBinding(String key) {
|
public StringBinding getStringBinding(String key) {
|
||||||
return new StringBinding() {
|
return new StringBinding() {
|
||||||
{
|
{
|
||||||
@ -62,6 +88,11 @@ public class UIResourceBundle {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工具方法:绑定StringProperty和Key对应的内容
|
||||||
|
* @param stringProperty
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
public static void bindStringProperty(StringProperty stringProperty, String key) {
|
public static void bindStringProperty(StringProperty stringProperty, String key) {
|
||||||
if (stringProperty == null) {
|
if (stringProperty == null) {
|
||||||
return;
|
return;
|
||||||
@ -69,10 +100,19 @@ public class UIResourceBundle {
|
|||||||
stringProperty.bind(getInstance().getStringBinding(key));
|
stringProperty.bind(getInstance().getStringBinding(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前资源中的key值
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static String getContent(String key) {
|
public static String getContent(String key) {
|
||||||
return getInstance().getResources().getString(key);
|
return getInstance().getResources().getString(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册资源变更监听器
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
public void addListener(ChangeListener<? super ResourceBundle> listener) {
|
public void addListener(ChangeListener<? super ResourceBundle> listener) {
|
||||||
this.resources.addListener(listener);
|
this.resources.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user