Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions src/main/java/ru/nucodelabs/gem/app/GemApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javafx.stage.Window
import javafx.stage.WindowEvent
import javafx.stage.WindowEvent.WINDOW_CLOSE_REQUEST
import ru.nucodelabs.gem.config.AppModule
import ru.nucodelabs.gem.config.ArgNames
import ru.nucodelabs.gem.config.Name
import ru.nucodelabs.gem.config.slf4j
import ru.nucodelabs.gem.view.AlertsFactory
import ru.nucodelabs.gem.view.controller.main.MainViewController
Expand Down Expand Up @@ -56,16 +56,17 @@ class GemApplication : GuiceApplication(AppModule()) {
@Throws(Exception::class)
override fun start(primaryStage: Stage) {
Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler(alertsFactory))

val params: List<String> = parameters.raw + macOSHandledFiles
if (
params.any {
it.endsWith(".EXP", ignoreCase = true) || it.endsWith(".json", ignoreCase = true)
}
) {
processParams(params)
} else {
log.info("Parameters are $params")
if (!handleFileParameters(params)) {
log.info("Starting MainView without parameters")
guiceInjector.getInstance(Key.get(Stage::class.java, Names.named(ArgNames.View.MAIN_VIEW))).show()
guiceInjector.getInstance(
Key.get(
Stage::class.java,
Names.named(Name.View.MAIN_VIEW)
)
).show()
}
}

Expand All @@ -74,40 +75,36 @@ class GemApplication : GuiceApplication(AppModule()) {
log.info("Exiting")
}

private fun processParams(params: List<String>): Boolean {
log.info("Parameters are $params")
val expFiles = mutableListOf<File>()
for (param in params) {
if (param.endsWith(".EXP", ignoreCase = true)) {
expFiles += File(param)
} else if (param.endsWith(".json", ignoreCase = true)) {
loadMainViewWithJsonFile(File(param))
return true
}
}
if (expFiles.isNotEmpty()) {
loadMainViewWithEXPFiles(expFiles)
return true
}
return false
/**
* true if files handled, false if no files to open detected
*/
private fun handleFileParameters(params: List<String>): Boolean {

val expFiles = params.filter { it.endsWith(".EXP", ignoreCase = true) }
val jsonFiles = params.filter { it.endsWith(".json", ignoreCase = true) }

loadMainViewWithEXPFiles(expFiles.map { File(it) })
jsonFiles.forEach { jsonFile -> loadMainViewWithJsonFile(File(jsonFile)) }

return expFiles.isNotEmpty() or jsonFiles.isNotEmpty()
}

private fun loadMainViewWithJsonFile(jsonFile: File) =
fxmlLoaderAfterShow().getController<MainViewController>().run {
log.info("Open JSON Section, file: ${jsonFile.absolutePath}")
log.info("Starting - Open JSON Section, file: ${jsonFile.name}")
openJsonSection(jsonFile)
}

private fun loadMainViewWithEXPFiles(expFiles: List<File>) =
fxmlLoaderAfterShow().getController<MainViewController>().run {
expFiles.forEach {
log.info("Import EXP, file: ${it.absolutePath}")
expFiles.filter { it.exists() }.forEach {
log.info("Starting - Import EXP file: ${it.name}")
importEXP(it)
}
}

private fun fxmlLoaderAfterShow(): FXMLLoader = mainViewFxmlLoader().also { it.load<Stage>().show() }

private fun mainViewFxmlLoader() =
guiceInjector.getInstance(Key.get(FXMLLoader::class.java, Names.named(ArgNames.View.MAIN_VIEW)))
guiceInjector.getInstance(Key.get(FXMLLoader::class.java, Names.named(Name.View.MAIN_VIEW)))
}
3 changes: 3 additions & 0 deletions src/main/java/ru/nucodelabs/gem/app/StartGemApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Locale;

/**
* Main, запускает приложение JavaFX
*/
Expand All @@ -12,6 +14,7 @@ public class StartGemApplication {
private static final Logger log = LoggerFactory.getLogger(StartGemApplication.class);

public static void main(String[] args) {
Locale.setDefault(Locale.Category.DISPLAY, Locale.of("ru")); // TODO: en locale support
try {
Application.launch(GemApplication.class, args);
} catch (Exception e) {
Expand Down
57 changes: 31 additions & 26 deletions src/main/java/ru/nucodelabs/gem/config/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,35 @@ protected void configure() {

@Provides
@Singleton
private ResourceBundle uiProperties() {
// TODO support en locale
return ResourceBundle.getBundle("ui", Locale.of("ru"));
private Locale currentLocale() {
return Locale.getDefault(Locale.Category.DISPLAY);
}

@Provides
@Named(ArgNames.CSS)
@Singleton
private String provideStylesheet() {
return "ru/nucodelabs/gem/view/common.css";
private ResourceBundle uiProperties() {
return ResourceBundle.getBundle("ui", currentLocale());
}

@Provides
@Named(ArgNames.View.MAIN_VIEW)
@Named(Name.View.MAIN_VIEW)
private URL provideMainViewFXML() {
return MainViewController.class.getResource("MainSplitLayoutView.fxml");
}

@Provides
@Named(ArgNames.View.ANISOTROPY_MAIN_VIEW)
@Named(Name.View.ANISOTROPY_MAIN_VIEW)
URL anisotropyMainView() {
return AnisotropyMainViewController.class.getResource("AnisotropyMainView.fxml");
}

@Provides
@Named(ArgNames.View.ANISOTROPY_MAIN_VIEW)
@Named(Name.View.ANISOTROPY_MAIN_VIEW)
private Stage anisotropyMainViewWindow(
ResourceBundle uiProperties,
Injector injector,
@Named(ArgNames.View.ANISOTROPY_MAIN_VIEW) URL url,
@Named(ArgNames.View.MAIN_VIEW) Stage mainStage
@Named(Name.View.ANISOTROPY_MAIN_VIEW) URL url,
@Named(Name.View.MAIN_VIEW) Stage mainStage
) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(url, uiProperties);
fxmlLoader.setControllerFactory(injector.createChildInjector(new AnisotropyProjectModule())::getInstance);
Expand All @@ -105,22 +103,26 @@ private Stage anisotropyMainViewWindow(
return stage;
}


@Provides
@Named(ArgNames.View.MAIN_VIEW)
private FXMLLoader provideFXMLLoader(ResourceBundle uiProperties, Injector injector, @Named(ArgNames.View.MAIN_VIEW) URL url) {
@Named(Name.View.MAIN_VIEW)
private FXMLLoader provideFXMLLoader(
ResourceBundle uiProperties,
Injector injector,
@Named(Name.View.MAIN_VIEW) URL url
) {
FXMLLoader fxmlLoader = new FXMLLoader(url, uiProperties);
fxmlLoader.setControllerFactory(injector.createChildInjector(new MainViewModule())::getInstance);
return fxmlLoader;
}

@Provides
@Named(ArgNames.View.MAIN_VIEW)
private Stage create(@Named(ArgNames.View.MAIN_VIEW) FXMLLoader loader) throws IOException {
@Named(Name.View.MAIN_VIEW)
private Stage create(@Named(Name.View.MAIN_VIEW) FXMLLoader loader) throws IOException {
return loader.load();
}

@Provides
@Singleton
private Validator provideValidator() {
try (var factory = Validation.buildDefaultValidatorFactory()) {
return factory.getValidator();
Expand All @@ -146,7 +148,7 @@ private Preferences preferences() {
}

@Provides
@Named(ArgNames.PRECISE)
@Named(Name.PRECISE_FORMAT)
DecimalFormat preciseFormat() {
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
Expand Down Expand Up @@ -190,7 +192,7 @@ public Double fromString(String string) {
try {
return decimalFormat.parse(string).doubleValue();
} catch (ParseException e) {
throw new IllegalArgumentException(e);
return Double.NaN;
}
}
};
Expand All @@ -213,7 +215,7 @@ public Number fromString(String string) {

@Provides
@Singleton
@Named(ArgNames.DEFAULT_CLR)
@Named(Name.DEFAULT_CLR)
ClrInfo clrInfo() throws IOException {
// Firstly lookup next to executable
var externalFile = Paths.get("colormap/default.clr").toFile();
Expand All @@ -224,13 +226,15 @@ ClrInfo clrInfo() throws IOException {
"Resource colormap/default.clr is null"
);
try (defaultResourceStream) {
log.info("Loading default .clr file from resources");
return new ClrInfo(
"Default",
new String(defaultResourceStream.readAllBytes(), StandardCharsets.UTF_8)
);
}
}
try (var externalFileStream = new FileInputStream(externalFile)) {
log.info("Loading external .clr file");
return new ClrInfo(
externalFile.getAbsolutePath(),
new String(externalFileStream.readAllBytes(), StandardCharsets.UTF_8)
Expand All @@ -240,28 +244,29 @@ ClrInfo clrInfo() throws IOException {

@Provides
@Singleton
@Named(ArgNames.CLR_SOURCE)
String clrSource(@Named(ArgNames.DEFAULT_CLR) ClrInfo clrInfo) {
@Named(Name.CLR_SOURCE)
String clrSource(@Named(Name.DEFAULT_CLR) ClrInfo clrInfo) {
return clrInfo.source();
}

@Provides
@Named(ArgNames.DEFAULT_CLR)
ClrParser clrParser(@Named(ArgNames.DEFAULT_CLR) ClrInfo clrInfo) {
@Named(Name.DEFAULT_CLR)
@Singleton
ClrParser clrParser(@Named(Name.DEFAULT_CLR) ClrInfo clrInfo) {
return new ClrParser(clrInfo.content());
}

@Provides
@Singleton
ColorMapper colorMapper(@Named(ArgNames.DEFAULT_CLR) ClrParser clrParser) {
ColorMapper colorMapper(@Named(Name.DEFAULT_CLR) ClrParser clrParser) {
List<ColorNode> valueColorList = clrParser.getColorNodes();
return new ColorPalette(valueColorList, 0, 1500, 15);
}

@Provides
@Singleton
@Named(ArgNames.DIFF)
ColorMapper diffColorMapper(@Named(ArgNames.DEFAULT_CLR) ClrParser clrParser) {
@Named(Name.DIFF)
ColorMapper diffColorMapper(@Named(Name.DEFAULT_CLR) ClrParser clrParser) {
List<ColorNode> valueColorList = clrParser.getColorNodes();
return new ColorPalette(valueColorList, 0, 2, 15);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ru/nucodelabs/gem/config/AppProps.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.nucodelabs.gem.config

object AppProps {
const val APP_NAME = "gem"
const val FULL_APP_NAME = "ru.nucodelabs.$APP_NAME"

const val DEFAULT_LOG_LEVEL = "INFO"
const val DEFAULT_LOG_STDOUT = false

val logLevel: String = System.getProperty("app.gem.log.level", DEFAULT_LOG_LEVEL)
val logStdout: Boolean = System.getProperty("app.gem.log.stdout", DEFAULT_LOG_STDOUT.toString()).toBoolean()
}
26 changes: 0 additions & 26 deletions src/main/java/ru/nucodelabs/gem/config/ChartsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,10 @@

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Named;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.XYChart;
import ru.nucodelabs.geo.forward.ForwardSolver;
import ru.nucodelabs.geo.ves.calc.graph.MisfitsFunction;

import java.util.ArrayList;

import static ru.nucodelabs.gem.view.controller.charts.VesCurvesController.TOTAL_COUNT;

public class ChartsModule extends AbstractModule {
@Provides
private ObjectProperty<ObservableList<XYChart.Series<Number, Number>>> emptyChartData() {
return new SimpleObjectProperty<>(
FXCollections.observableArrayList(new ArrayList<>()));
}

@Provides
@Named("VESCurves")
private ObjectProperty<ObservableList<XYChart.Series<Number, Number>>> provideVESCurvesData() {
ObjectProperty<ObservableList<XYChart.Series<Number, Number>>> dataProperty =
new SimpleObjectProperty<>(FXCollections.observableArrayList());
for (int i = 0; i < TOTAL_COUNT; i++) {
dataProperty.get().add(new XYChart.Series<>());
}
return dataProperty;
}

@Provides
MisfitsFunction misfitValuesFactory(ForwardSolver forwardSolver) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/ru/nucodelabs/gem/config/DialogsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import javafx.scene.control.Dialog;

public class DialogsModule extends AbstractModule {

@Provides
@Named(ArgNames.SAVE)
Dialog<ButtonType> provideSaveDialog(@Named(ArgNames.CSS) String stylesheet) {
@Named(Name.SAVE)
Dialog<ButtonType> provideSaveDialog() {
Dialog<ButtonType> saveDialog = new Dialog<>();
saveDialog.setTitle("Сохранение");
saveDialog.setContentText("Сохранить изменения?");
saveDialog.getDialogPane().getButtonTypes()
.addAll(ButtonType.YES,
ButtonType.NO,
ButtonType.CANCEL);
saveDialog.getDialogPane().getStylesheets().add(stylesheet);
saveDialog.getDialogPane().getStylesheets().add(Style.COMMON_STYLESHEET);
return saveDialog;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FileChoosersModule extends AbstractModule {

@Provides
@Singleton
@Named(ArgNames.File.EXP)
@Named(Name.File.EXP)
private FileChooser provideEXPFileChooser(ResourceBundle ui, Preferences preferences) {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
Expand All @@ -34,7 +34,7 @@ private FileChooser provideEXPFileChooser(ResourceBundle ui, Preferences prefere

@Provides
@Singleton
@Named(ArgNames.File.JSON)
@Named(Name.File.JSON)
private FileChooser provideJSONFileChooser(ResourceBundle ui, Preferences preferences) {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
Expand All @@ -53,7 +53,7 @@ private FileChooser provideJSONFileChooser(ResourceBundle ui, Preferences prefer

@Provides
@Singleton
@Named(ArgNames.File.MOD)
@Named(Name.File.MOD)
private FileChooser provideMODFileChooser(ResourceBundle ui, Preferences preferences) {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
Expand All @@ -69,7 +69,7 @@ private FileChooser provideMODFileChooser(ResourceBundle ui, Preferences prefere

@Provides
@Singleton
@Named(ArgNames.File.PNG)
@Named(Name.File.PNG)
private FileChooser pngFileChooser(Preferences preferences) {
FileChooser chooser = new FileChooser();
chooser.getExtensionFilters().addAll(
Expand Down
Loading
Loading