Skip to content

Commit c1a13ac

Browse files
authored
Merge pull request #128 from NucodeLabs/development
Zoom In/Out buttons. Little improvements
2 parents baddc08 + b7ffd26 commit c1a13ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+196
-215
lines changed

src/main/java/ru/nucodelabs/gem/app/GemApplication.kt

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import javafx.stage.Window
1010
import javafx.stage.WindowEvent
1111
import javafx.stage.WindowEvent.WINDOW_CLOSE_REQUEST
1212
import ru.nucodelabs.gem.config.AppModule
13-
import ru.nucodelabs.gem.config.ArgNames
13+
import ru.nucodelabs.gem.config.Name
1414
import ru.nucodelabs.gem.config.slf4j
1515
import ru.nucodelabs.gem.view.AlertsFactory
1616
import ru.nucodelabs.gem.view.controller.main.MainViewController
@@ -56,16 +56,17 @@ class GemApplication : GuiceApplication(AppModule()) {
5656
@Throws(Exception::class)
5757
override fun start(primaryStage: Stage) {
5858
Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler(alertsFactory))
59+
5960
val params: List<String> = parameters.raw + macOSHandledFiles
60-
if (
61-
params.any {
62-
it.endsWith(".EXP", ignoreCase = true) || it.endsWith(".json", ignoreCase = true)
63-
}
64-
) {
65-
processParams(params)
66-
} else {
61+
log.info("Parameters are $params")
62+
if (!handleFileParameters(params)) {
6763
log.info("Starting MainView without parameters")
68-
guiceInjector.getInstance(Key.get(Stage::class.java, Names.named(ArgNames.View.MAIN_VIEW))).show()
64+
guiceInjector.getInstance(
65+
Key.get(
66+
Stage::class.java,
67+
Names.named(Name.View.MAIN_VIEW)
68+
)
69+
).show()
6970
}
7071
}
7172

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

77-
private fun processParams(params: List<String>): Boolean {
78-
log.info("Parameters are $params")
79-
val expFiles = mutableListOf<File>()
80-
for (param in params) {
81-
if (param.endsWith(".EXP", ignoreCase = true)) {
82-
expFiles += File(param)
83-
} else if (param.endsWith(".json", ignoreCase = true)) {
84-
loadMainViewWithJsonFile(File(param))
85-
return true
86-
}
87-
}
88-
if (expFiles.isNotEmpty()) {
89-
loadMainViewWithEXPFiles(expFiles)
90-
return true
91-
}
92-
return false
78+
/**
79+
* true if files handled, false if no files to open detected
80+
*/
81+
private fun handleFileParameters(params: List<String>): Boolean {
82+
83+
val expFiles = params.filter { it.endsWith(".EXP", ignoreCase = true) }
84+
val jsonFiles = params.filter { it.endsWith(".json", ignoreCase = true) }
85+
86+
loadMainViewWithEXPFiles(expFiles.map { File(it) })
87+
jsonFiles.forEach { jsonFile -> loadMainViewWithJsonFile(File(jsonFile)) }
88+
89+
return expFiles.isNotEmpty() or jsonFiles.isNotEmpty()
9390
}
9491

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

10198
private fun loadMainViewWithEXPFiles(expFiles: List<File>) =
10299
fxmlLoaderAfterShow().getController<MainViewController>().run {
103-
expFiles.forEach {
104-
log.info("Import EXP, file: ${it.absolutePath}")
100+
expFiles.filter { it.exists() }.forEach {
101+
log.info("Starting - Import EXP file: ${it.name}")
105102
importEXP(it)
106103
}
107104
}
108105

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

111108
private fun mainViewFxmlLoader() =
112-
guiceInjector.getInstance(Key.get(FXMLLoader::class.java, Names.named(ArgNames.View.MAIN_VIEW)))
109+
guiceInjector.getInstance(Key.get(FXMLLoader::class.java, Names.named(Name.View.MAIN_VIEW)))
113110
}

src/main/java/ru/nucodelabs/gem/app/StartGemApplication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
66

7+
import java.util.Locale;
8+
79
/**
810
* Main, запускает приложение JavaFX
911
*/
@@ -12,6 +14,7 @@ public class StartGemApplication {
1214
private static final Logger log = LoggerFactory.getLogger(StartGemApplication.class);
1315

1416
public static void main(String[] args) {
17+
Locale.setDefault(Locale.Category.DISPLAY, Locale.of("ru")); // TODO: en locale support
1518
try {
1619
Application.launch(GemApplication.class, args);
1720
} catch (Exception e) {

src/main/java/ru/nucodelabs/gem/config/AppModule.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,35 @@ protected void configure() {
6363

6464
@Provides
6565
@Singleton
66-
private ResourceBundle uiProperties() {
67-
// TODO support en locale
68-
return ResourceBundle.getBundle("ui", Locale.of("ru"));
66+
private Locale currentLocale() {
67+
return Locale.getDefault(Locale.Category.DISPLAY);
6968
}
7069

7170
@Provides
72-
@Named(ArgNames.CSS)
7371
@Singleton
74-
private String provideStylesheet() {
75-
return "ru/nucodelabs/gem/view/common.css";
72+
private ResourceBundle uiProperties() {
73+
return ResourceBundle.getBundle("ui", currentLocale());
7674
}
7775

7876
@Provides
79-
@Named(ArgNames.View.MAIN_VIEW)
77+
@Named(Name.View.MAIN_VIEW)
8078
private URL provideMainViewFXML() {
8179
return MainViewController.class.getResource("MainSplitLayoutView.fxml");
8280
}
8381

8482
@Provides
85-
@Named(ArgNames.View.ANISOTROPY_MAIN_VIEW)
83+
@Named(Name.View.ANISOTROPY_MAIN_VIEW)
8684
URL anisotropyMainView() {
8785
return AnisotropyMainViewController.class.getResource("AnisotropyMainView.fxml");
8886
}
8987

9088
@Provides
91-
@Named(ArgNames.View.ANISOTROPY_MAIN_VIEW)
89+
@Named(Name.View.ANISOTROPY_MAIN_VIEW)
9290
private Stage anisotropyMainViewWindow(
9391
ResourceBundle uiProperties,
9492
Injector injector,
95-
@Named(ArgNames.View.ANISOTROPY_MAIN_VIEW) URL url,
96-
@Named(ArgNames.View.MAIN_VIEW) Stage mainStage
93+
@Named(Name.View.ANISOTROPY_MAIN_VIEW) URL url,
94+
@Named(Name.View.MAIN_VIEW) Stage mainStage
9795
) throws IOException {
9896
FXMLLoader fxmlLoader = new FXMLLoader(url, uiProperties);
9997
fxmlLoader.setControllerFactory(injector.createChildInjector(new AnisotropyProjectModule())::getInstance);
@@ -105,22 +103,26 @@ private Stage anisotropyMainViewWindow(
105103
return stage;
106104
}
107105

108-
109106
@Provides
110-
@Named(ArgNames.View.MAIN_VIEW)
111-
private FXMLLoader provideFXMLLoader(ResourceBundle uiProperties, Injector injector, @Named(ArgNames.View.MAIN_VIEW) URL url) {
107+
@Named(Name.View.MAIN_VIEW)
108+
private FXMLLoader provideFXMLLoader(
109+
ResourceBundle uiProperties,
110+
Injector injector,
111+
@Named(Name.View.MAIN_VIEW) URL url
112+
) {
112113
FXMLLoader fxmlLoader = new FXMLLoader(url, uiProperties);
113114
fxmlLoader.setControllerFactory(injector.createChildInjector(new MainViewModule())::getInstance);
114115
return fxmlLoader;
115116
}
116117

117118
@Provides
118-
@Named(ArgNames.View.MAIN_VIEW)
119-
private Stage create(@Named(ArgNames.View.MAIN_VIEW) FXMLLoader loader) throws IOException {
119+
@Named(Name.View.MAIN_VIEW)
120+
private Stage create(@Named(Name.View.MAIN_VIEW) FXMLLoader loader) throws IOException {
120121
return loader.load();
121122
}
122123

123124
@Provides
125+
@Singleton
124126
private Validator provideValidator() {
125127
try (var factory = Validation.buildDefaultValidatorFactory()) {
126128
return factory.getValidator();
@@ -146,7 +148,7 @@ private Preferences preferences() {
146148
}
147149

148150
@Provides
149-
@Named(ArgNames.PRECISE)
151+
@Named(Name.PRECISE_FORMAT)
150152
DecimalFormat preciseFormat() {
151153
DecimalFormat decimalFormat = new DecimalFormat();
152154
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
@@ -190,7 +192,7 @@ public Double fromString(String string) {
190192
try {
191193
return decimalFormat.parse(string).doubleValue();
192194
} catch (ParseException e) {
193-
throw new IllegalArgumentException(e);
195+
return Double.NaN;
194196
}
195197
}
196198
};
@@ -213,7 +215,7 @@ public Number fromString(String string) {
213215

214216
@Provides
215217
@Singleton
216-
@Named(ArgNames.DEFAULT_CLR)
218+
@Named(Name.DEFAULT_CLR)
217219
ClrInfo clrInfo() throws IOException {
218220
// Firstly lookup next to executable
219221
var externalFile = Paths.get("colormap/default.clr").toFile();
@@ -224,13 +226,15 @@ ClrInfo clrInfo() throws IOException {
224226
"Resource colormap/default.clr is null"
225227
);
226228
try (defaultResourceStream) {
229+
log.info("Loading default .clr file from resources");
227230
return new ClrInfo(
228231
"Default",
229232
new String(defaultResourceStream.readAllBytes(), StandardCharsets.UTF_8)
230233
);
231234
}
232235
}
233236
try (var externalFileStream = new FileInputStream(externalFile)) {
237+
log.info("Loading external .clr file");
234238
return new ClrInfo(
235239
externalFile.getAbsolutePath(),
236240
new String(externalFileStream.readAllBytes(), StandardCharsets.UTF_8)
@@ -240,28 +244,29 @@ ClrInfo clrInfo() throws IOException {
240244

241245
@Provides
242246
@Singleton
243-
@Named(ArgNames.CLR_SOURCE)
244-
String clrSource(@Named(ArgNames.DEFAULT_CLR) ClrInfo clrInfo) {
247+
@Named(Name.CLR_SOURCE)
248+
String clrSource(@Named(Name.DEFAULT_CLR) ClrInfo clrInfo) {
245249
return clrInfo.source();
246250
}
247251

248252
@Provides
249-
@Named(ArgNames.DEFAULT_CLR)
250-
ClrParser clrParser(@Named(ArgNames.DEFAULT_CLR) ClrInfo clrInfo) {
253+
@Named(Name.DEFAULT_CLR)
254+
@Singleton
255+
ClrParser clrParser(@Named(Name.DEFAULT_CLR) ClrInfo clrInfo) {
251256
return new ClrParser(clrInfo.content());
252257
}
253258

254259
@Provides
255260
@Singleton
256-
ColorMapper colorMapper(@Named(ArgNames.DEFAULT_CLR) ClrParser clrParser) {
261+
ColorMapper colorMapper(@Named(Name.DEFAULT_CLR) ClrParser clrParser) {
257262
List<ColorNode> valueColorList = clrParser.getColorNodes();
258263
return new ColorPalette(valueColorList, 0, 1500, 15);
259264
}
260265

261266
@Provides
262267
@Singleton
263-
@Named(ArgNames.DIFF)
264-
ColorMapper diffColorMapper(@Named(ArgNames.DEFAULT_CLR) ClrParser clrParser) {
268+
@Named(Name.DIFF)
269+
ColorMapper diffColorMapper(@Named(Name.DEFAULT_CLR) ClrParser clrParser) {
265270
List<ColorNode> valueColorList = clrParser.getColorNodes();
266271
return new ColorPalette(valueColorList, 0, 2, 15);
267272
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.nucodelabs.gem.config
2+
3+
object AppProps {
4+
const val APP_NAME = "gem"
5+
const val FULL_APP_NAME = "ru.nucodelabs.$APP_NAME"
6+
7+
const val DEFAULT_LOG_LEVEL = "INFO"
8+
const val DEFAULT_LOG_STDOUT = false
9+
10+
val logLevel: String = System.getProperty("app.gem.log.level", DEFAULT_LOG_LEVEL)
11+
val logStdout: Boolean = System.getProperty("app.gem.log.stdout", DEFAULT_LOG_STDOUT.toString()).toBoolean()
12+
}

src/main/java/ru/nucodelabs/gem/config/ChartsModule.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,10 @@
22

33
import com.google.inject.AbstractModule;
44
import com.google.inject.Provides;
5-
import com.google.inject.name.Named;
6-
import javafx.beans.property.ObjectProperty;
7-
import javafx.beans.property.SimpleObjectProperty;
8-
import javafx.collections.FXCollections;
9-
import javafx.collections.ObservableList;
10-
import javafx.scene.chart.XYChart;
115
import ru.nucodelabs.geo.forward.ForwardSolver;
126
import ru.nucodelabs.geo.ves.calc.graph.MisfitsFunction;
137

14-
import java.util.ArrayList;
15-
16-
import static ru.nucodelabs.gem.view.controller.charts.VesCurvesController.TOTAL_COUNT;
17-
188
public class ChartsModule extends AbstractModule {
19-
@Provides
20-
private ObjectProperty<ObservableList<XYChart.Series<Number, Number>>> emptyChartData() {
21-
return new SimpleObjectProperty<>(
22-
FXCollections.observableArrayList(new ArrayList<>()));
23-
}
24-
25-
@Provides
26-
@Named("VESCurves")
27-
private ObjectProperty<ObservableList<XYChart.Series<Number, Number>>> provideVESCurvesData() {
28-
ObjectProperty<ObservableList<XYChart.Series<Number, Number>>> dataProperty =
29-
new SimpleObjectProperty<>(FXCollections.observableArrayList());
30-
for (int i = 0; i < TOTAL_COUNT; i++) {
31-
dataProperty.get().add(new XYChart.Series<>());
32-
}
33-
return dataProperty;
34-
}
359

3610
@Provides
3711
MisfitsFunction misfitValuesFactory(ForwardSolver forwardSolver) {

src/main/java/ru/nucodelabs/gem/config/DialogsModule.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
import javafx.scene.control.Dialog;
88

99
public class DialogsModule extends AbstractModule {
10+
1011
@Provides
11-
@Named(ArgNames.SAVE)
12-
Dialog<ButtonType> provideSaveDialog(@Named(ArgNames.CSS) String stylesheet) {
12+
@Named(Name.SAVE)
13+
Dialog<ButtonType> provideSaveDialog() {
1314
Dialog<ButtonType> saveDialog = new Dialog<>();
1415
saveDialog.setTitle("Сохранение");
1516
saveDialog.setContentText("Сохранить изменения?");
1617
saveDialog.getDialogPane().getButtonTypes()
1718
.addAll(ButtonType.YES,
1819
ButtonType.NO,
1920
ButtonType.CANCEL);
20-
saveDialog.getDialogPane().getStylesheets().add(stylesheet);
21+
saveDialog.getDialogPane().getStylesheets().add(Style.COMMON_STYLESHEET);
2122
return saveDialog;
2223
}
2324
}

src/main/java/ru/nucodelabs/gem/config/FileChoosersModule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class FileChoosersModule extends AbstractModule {
1818

1919
@Provides
2020
@Singleton
21-
@Named(ArgNames.File.EXP)
21+
@Named(Name.File.EXP)
2222
private FileChooser provideEXPFileChooser(ResourceBundle ui, Preferences preferences) {
2323
FileChooser chooser = new FileChooser();
2424
chooser.getExtensionFilters().addAll(
@@ -34,7 +34,7 @@ private FileChooser provideEXPFileChooser(ResourceBundle ui, Preferences prefere
3434

3535
@Provides
3636
@Singleton
37-
@Named(ArgNames.File.JSON)
37+
@Named(Name.File.JSON)
3838
private FileChooser provideJSONFileChooser(ResourceBundle ui, Preferences preferences) {
3939
FileChooser chooser = new FileChooser();
4040
chooser.getExtensionFilters().addAll(
@@ -53,7 +53,7 @@ private FileChooser provideJSONFileChooser(ResourceBundle ui, Preferences prefer
5353

5454
@Provides
5555
@Singleton
56-
@Named(ArgNames.File.MOD)
56+
@Named(Name.File.MOD)
5757
private FileChooser provideMODFileChooser(ResourceBundle ui, Preferences preferences) {
5858
FileChooser chooser = new FileChooser();
5959
chooser.getExtensionFilters().addAll(
@@ -69,7 +69,7 @@ private FileChooser provideMODFileChooser(ResourceBundle ui, Preferences prefere
6969

7070
@Provides
7171
@Singleton
72-
@Named(ArgNames.File.PNG)
72+
@Named(Name.File.PNG)
7373
private FileChooser pngFileChooser(Preferences preferences) {
7474
FileChooser chooser = new FileChooser();
7575
chooser.getExtensionFilters().addAll(

0 commit comments

Comments
 (0)