Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
#15 [Properties] Move own properties files in package i18n.
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoghuman committed Mar 7, 2017
1 parent 801f152 commit 69eaba3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 124 deletions.
31 changes: 15 additions & 16 deletions src/main/java/com/github/naoghuman/abclist/StartApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import com.airhacks.afterburner.injection.Injector;
import com.github.naoghuman.abclist.view.application.ApplicationView;
import com.github.naoghuman.abclist.configuration.IApplicationConfiguration;
import com.github.naoghuman.abclist.configuration.IPropertiesConfiguration;
import com.github.naoghuman.abclist.i18n.Properties;
import com.github.naoghuman.lib.database.api.DatabaseFacade;
import com.github.naoghuman.lib.logger.api.LoggerFacade;
import com.github.naoghuman.lib.preferences.api.PreferencesFacade;
Expand All @@ -38,7 +38,7 @@
*
* @author Naoghuman
*/
public class StartApplication extends Application implements IApplicationConfiguration {
public class StartApplication extends Application implements IPropertiesConfiguration {

public static void main(String[] args) {
launch(args);
Expand All @@ -49,24 +49,26 @@ public void init() throws Exception {
super.init();

PropertiesFacade.getDefault().register(KEY__APPLICATION__RESOURCE_BUNDLE);
PropertiesFacade.getDefault().register(IPropertiesConfiguration.KEY__CONVERTER__RESOURCE_BUNDLE);
PropertiesFacade.getDefault().register(KEY__CONVERTER__RESOURCE_BUNDLE);

final char borderSign = this.getProperty(KEY__APPLICATION__BORDER_SIGN).charAt(0);
final String message = this.getProperty(KEY__APPLICATION__MESSAGE_START);
final String title = this.getProperty(KEY__APPLICATION__TITLE) + this.getProperty(KEY__APPLICATION__VERSION);
final char borderSign = Properties.getPropertyForApplication(KEY__APPLICATION__BORDER_SIGN).charAt(0);
final String message = Properties.getPropertyForApplication(KEY__APPLICATION__MESSAGE_START);
final String title = Properties.getPropertyForApplication(KEY__APPLICATION__TITLE)
+ Properties.getPropertyForApplication(KEY__APPLICATION__VERSION);
LoggerFacade.getDefault().message(borderSign, 80, String.format(message, title));

final Boolean dropPreferencesFileAtStart = Boolean.FALSE;
PreferencesFacade.getDefault().init(dropPreferencesFileAtStart);

DatabaseFacade.getDefault().register(this.getProperty(KEY__APPLICATION__DATABASE));
DatabaseFacade.getDefault().register(Properties.getPropertyForApplication(KEY__APPLICATION__DATABASE));
}

@Override
public void start(Stage primaryStage) throws Exception {
final ApplicationView applicationView = new ApplicationView();
final Scene scene = new Scene(applicationView.getView(), 1280, 720);
primaryStage.setTitle(this.getProperty(KEY__APPLICATION__TITLE) + this.getProperty(KEY__APPLICATION__VERSION));
primaryStage.setTitle(Properties.getPropertyForApplication(KEY__APPLICATION__TITLE)
+ Properties.getPropertyForApplication(KEY__APPLICATION__VERSION));
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest((WindowEvent we) -> {
we.consume();
Expand All @@ -83,10 +85,6 @@ public void stop() throws Exception {
Injector.forgetAll();
}

private String getProperty(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__APPLICATION__RESOURCE_BUNDLE, propertyKey);
}

private void onCloseRequest() {
// afterburner.fx
Injector.forgetAll();
Expand All @@ -95,13 +93,14 @@ private void onCloseRequest() {
DatabaseFacade.getDefault().shutdown();

// Message
final char borderSign = this.getProperty(KEY__APPLICATION__BORDER_SIGN).charAt(0);
final String message = this.getProperty(KEY__APPLICATION__MESSAGE_STOP);
final String title = this.getProperty(KEY__APPLICATION__TITLE) + this.getProperty(KEY__APPLICATION__VERSION);
final char borderSign = Properties.getPropertyForApplication(KEY__APPLICATION__BORDER_SIGN).charAt(0);
final String message = Properties.getPropertyForApplication(KEY__APPLICATION__MESSAGE_STOP);
final String title = Properties.getPropertyForApplication(KEY__APPLICATION__TITLE)
+ Properties.getPropertyForApplication(KEY__APPLICATION__VERSION);
LoggerFacade.getDefault().message(borderSign, 80, String.format(message, title));

// Timer
final PauseTransition pt = new PauseTransition(DURATION__125);
final PauseTransition pt = new PauseTransition(LITTLE_DELAY__DURATION_125);
pt.setOnFinished((ActionEvent event) -> {
Platform.exit();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.airhacks.afterburner.injection.Injector;
import com.github.naoghuman.abclist.configuration.IPropertiesConfiguration;
import com.github.naoghuman.abclist.i18n.Properties;
import com.github.naoghuman.abclist.testdata.TestdataFacade;
import com.github.naoghuman.lib.database.api.DatabaseFacade;
import com.github.naoghuman.lib.logger.api.LoggerFacade;
Expand All @@ -41,9 +42,9 @@ public class TestdataApplication extends Application implements IPropertiesConfi
public void init() throws Exception {
PropertiesFacade.getDefault().register(KEY__TESTDATA__RESOURCE_BUNDLE);

final char borderSign = this.getProperty(KEY__TESTDATA_APPLICATION__BORDER_SIGN).charAt(0);
final String message = this.getProperty(KEY__TESTDATA_APPLICATION__MESSAGE_START);
final String title = this.getProperty(KEY__TESTDATA_APPLICATION__TITLE);
final char borderSign = Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__BORDER_SIGN).charAt(0);
final String message = Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__MESSAGE_START);
final String title = Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__TITLE);
LoggerFacade.getDefault().message(borderSign, 80, message + title);

final Boolean dropPreferencesFileAtStart = Boolean.FALSE;
Expand All @@ -53,7 +54,8 @@ public void init() throws Exception {
@Override
public void start(Stage primaryStage) throws Exception {
final Scene scene = new Scene(TestdataFacade.getDefault().getView(), 1280.0d, 720.0d);
primaryStage.setTitle(this.getProperty(KEY__TESTDATA_APPLICATION__TITLE) + this.getProperty(KEY__TESTDATA_APPLICATION__VERSION));
primaryStage.setTitle(Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__TITLE)
+ Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__VERSION));
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest((WindowEvent we) -> {
we.consume();
Expand All @@ -64,14 +66,10 @@ public void start(Stage primaryStage) throws Exception {
primaryStage.show();
}

private String getProperty(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__TESTDATA__RESOURCE_BUNDLE, propertyKey);
}

private void onCloseRequest() {
final char borderSign = this.getProperty(KEY__TESTDATA_APPLICATION__BORDER_SIGN).charAt(0);
final String message = this.getProperty(KEY__TESTDATA_APPLICATION__MESSAGE_STOP);
final String title = this.getProperty(KEY__TESTDATA_APPLICATION__TITLE);
final char borderSign = Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__BORDER_SIGN).charAt(0);
final String message = Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__MESSAGE_STOP);
final String title = Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__TITLE);
LoggerFacade.getDefault().message(borderSign, 80, message + title);

try {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,29 @@ public interface IPropertiesConfiguration {

public static final int NO_ENTITY = 0;

public static final int TAB_INDEX__TERMS = 1;
public static final int TAB_INDEX__TOPICS = 0;

public static final String STRING_DEFAULT_REGEX = "%s"; // NOI18N

public static final String INFO__FOUNDED_TERMS = "converter.info.founded.terms"; // NOI18N
public static final String INFO__FOUNDED_TOPICS = "application.info.founded.topics"; // NOI18N
public static final String INFO__FOUNDED_TOPIC_ELEMENTS = "application.info.founded.topicelements"; // NOI18N

public static final Duration LITTLE_DELAY__DURATION_125 = Duration.millis(125.0d);

public static final String KEY__APPLICATION__RESOURCE_BUNDLE = "/com/github/naoghuman/abclist/i18n/application.properties"; // NOI18N
public static final String KEY__CONVERTER__RESOURCE_BUNDLE = "/com/github/naoghuman/abclist/i18n/converter.properties"; // NOI18N
public static final String KEY__TESTDATA__RESOURCE_BUNDLE = "/com/github/naoghuman/abclist/i18n/testdataapplication.properties"; // NOI18N

public static final String KEY__APPLICATION__BORDER_SIGN = "application.border.sign"; // NOI18N
public static final String KEY__APPLICATION__BUILD_DATETIME = "application.build.datetime"; // NOI18N
public static final String KEY__APPLICATION__DATABASE = "application.database"; // NOI18N
public static final String KEY__APPLICATION__MESSAGE_START = "application.message.start"; // NOI18N
public static final String KEY__APPLICATION__MESSAGE_STOP = "application.message.stop"; // NOI18N
public static final String KEY__APPLICATION__TITLE = "application.title"; // NOI18N
public static final String KEY__APPLICATION__VERSION = "application.version"; // NOI18N

public static final String KEY__TESTDATA_APPLICATION__BORDER_SIGN = "application.testdata.border.sign"; // NOI18N
public static final String KEY__TESTDATA_APPLICATION__DATABASE = "application.database"; // NOI18N
public static final String KEY__TESTDATA_APPLICATION__MESSAGE_START = "application.testdata.message.start"; // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@
*/
public final class Properties implements IPropertiesConfiguration {

public static String getPropertyForApplication(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__APPLICATION__RESOURCE_BUNDLE, propertyKey);
}

public static String getPropertyForConverter(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__CONVERTER__RESOURCE_BUNDLE, propertyKey);
}

public static String getPropertyForTestdataApplication(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__TESTDATA__RESOURCE_BUNDLE, propertyKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.naoghuman.abclist.configuration.IPreferencesConfiguration;
import com.github.naoghuman.abclist.configuration.IPropertiesConfiguration;
import static com.github.naoghuman.abclist.configuration.IPropertiesConfiguration.KEY__TESTDATA_APPLICATION__DATABASE;
import com.github.naoghuman.abclist.i18n.Properties;
import com.github.naoghuman.abclist.model.Exercise;
import com.github.naoghuman.abclist.model.ExerciseTerm;
import com.github.naoghuman.abclist.model.Term;
Expand All @@ -42,7 +43,6 @@
import com.github.naoghuman.lib.database.api.DatabaseFacade;
import com.github.naoghuman.lib.logger.api.LoggerFacade;
import com.github.naoghuman.lib.preferences.api.PreferencesFacade;
import com.github.naoghuman.lib.properties.api.PropertiesFacade;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -319,10 +319,6 @@ private CheckBoxListCellModel getCheckBoxListCellModel(final String key) {
return model;
}

private String getProperty(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__TESTDATA__RESOURCE_BUNDLE, propertyKey);
}

public void onActionCreateTestdata() {
LoggerFacade.getDefault().debug(this.getClass(), "On action create Testdata"); // NOI18N

Expand All @@ -339,7 +335,7 @@ public void onActionCreateTestdata() {
ptDropDatabase.setDuration(Duration.millis(50.0d));
ptDropDatabase.setOnFinished((ActionEvent event) -> {
LoggerFacade.getDefault().debug(this.getClass(), "Drop database"); // NOI18N
DatabaseFacade.getDefault().drop(this.getProperty(KEY__TESTDATA_APPLICATION__DATABASE));
DatabaseFacade.getDefault().drop(Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__DATABASE));
});
sequentialTransition.getChildren().add(ptDropDatabase);
}
Expand All @@ -348,7 +344,7 @@ public void onActionCreateTestdata() {
ptRegisterDatabase.setDuration(Duration.millis(150.0d));
ptRegisterDatabase.setOnFinished((ActionEvent event) -> {
LoggerFacade.getDefault().debug(this.getClass(), "Register database"); // NOI18N
DatabaseFacade.getDefault().register(this.getProperty(KEY__TESTDATA_APPLICATION__DATABASE));
DatabaseFacade.getDefault().register(Properties.getPropertyForTestdataApplication(KEY__TESTDATA_APPLICATION__DATABASE));
});
sequentialTransition.getChildren().add(ptRegisterDatabase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.github.naoghuman.abclist.view.application;

import com.github.naoghuman.abclist.configuration.IActionConfiguration;
import com.github.naoghuman.abclist.configuration.IApplicationConfiguration;
import com.github.naoghuman.abclist.configuration.IDefaultConfiguration;
import com.github.naoghuman.abclist.configuration.IPropertiesConfiguration;
import com.github.naoghuman.abclist.i18n.Properties;
import com.github.naoghuman.abclist.json.Project;
import com.github.naoghuman.abclist.json.SimpleJsonReader;
import com.github.naoghuman.abclist.view.exercise.ExercisePresenter;
Expand Down Expand Up @@ -48,7 +48,6 @@
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -75,7 +74,7 @@
* @author Naoghuman
*/
public class ApplicationPresenter implements Initializable, IActionConfiguration,
IApplicationConfiguration, IDefaultConfiguration, IRegisterActions
IDefaultConfiguration, IPropertiesConfiguration, IRegisterActions
{
@FXML private Button bNavigationCreateNewExercise;
@FXML private Button bNavigationCreateNewTerm;
Expand Down Expand Up @@ -198,7 +197,7 @@ private void initializeNavigationTabTopics() {
LoggerFacade.getDefault().info(this.getClass(), "Initialize [Navigation] tab [Topic]s"); // NOI18N

// Info label for Topics
lInfoFoundedTopics.setText(this.getProperty(INFO__FOUNDED_TOPICS).replaceFirst(INFO__DEFAULT_REGEX, INFO__NO_ENTITIES_FOUND));
lInfoFoundedTopics.setText(Properties.getPropertyForApplication(INFO__FOUNDED_TOPICS).replaceFirst(STRING_DEFAULT_REGEX, String.valueOf(NO_ENTITY)));

// ListView lvNavigationTopics
final Callback callbackTopics = (Callback<ListView<Topic>, ListCell<Topic>>) (ListView<Topic> listView) -> new ListCell<Topic>() {
Expand Down Expand Up @@ -255,7 +254,7 @@ protected void updateItem(Topic topic, boolean empty) {
});

// Info label for TopicElements
lInfoFoundedElements.setText(this.getProperty(INFO__FOUNDED_TOPIC_ELEMENTS).replaceFirst(INFO__DEFAULT_REGEX, INFO__NO_ENTITIES_FOUND));
lInfoFoundedElements.setText(Properties.getPropertyForApplication(INFO__FOUNDED_TOPIC_ELEMENTS).replaceFirst(STRING_DEFAULT_REGEX, String.valueOf(NO_ENTITY)));

// ListView lvNavigationElements
final Callback callbackNavigationEntitys = (Callback<ListView<NavigationEntity>, ListCell<NavigationEntity>>) (ListView<NavigationEntity> listView) -> new ListCell<NavigationEntity>() {
Expand Down Expand Up @@ -301,10 +300,6 @@ private void initializeWelcomeView() {
vbWorkingArea.getChildren().add(parent);
}

private String getProperty(String propertyKey) {
return PropertiesFacade.getDefault().getProperty(KEY__APPLICATION__RESOURCE_BUNDLE, propertyKey);
}

public void onActionCreateNewExercise() {
LoggerFacade.getDefault().debug(this.getClass(), "On action create new [Exercise]"); // NOI18N

Expand Down Expand Up @@ -502,7 +497,7 @@ private void onActionRefreshNavigationTabTopics(ObservableList<Topic> topics) {
lvNavigationTopics.getItems().clear();
lvNavigationTopics.getItems().addAll(topics);

lInfoFoundedTopics.setText(this.getProperty(INFO__FOUNDED_TOPICS).replaceFirst(INFO__DEFAULT_REGEX, String.valueOf(topics.size())));
lInfoFoundedTopics.setText(Properties.getPropertyForApplication(INFO__FOUNDED_TOPICS).replaceFirst(STRING_DEFAULT_REGEX, String.valueOf(topics.size())));
}

private void onActionShowAllExercisesWithTopicId(Topic topic) {
Expand All @@ -518,7 +513,7 @@ private void onActionShowAllExercisesWithTopicId(Topic topic) {
lvNavigationElements.getItems().clear();
lvNavigationElements.getItems().addAll(navigationEntities);

lInfoFoundedElements.setText(this.getProperty(INFO__FOUNDED_TOPIC_ELEMENTS).replaceFirst(INFO__DEFAULT_REGEX, String.valueOf(navigationEntities.size())));
lInfoFoundedElements.setText(Properties.getPropertyForApplication(INFO__FOUNDED_TOPIC_ELEMENTS).replaceFirst(STRING_DEFAULT_REGEX, String.valueOf(navigationEntities.size())));
}

public void onActionShowAllTermsFromSelectedTopic() {
Expand Down
Loading

0 comments on commit 69eaba3

Please sign in to comment.