/
GamaPreferences.java
1061 lines (900 loc) · 41.9 KB
/
GamaPreferences.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************************************
*
* GamaPreferences.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package msi.gama.common.preferences;
import static msi.gama.common.preferences.GamaPreferenceStore.getStore;
import static msi.gama.runtime.PlatformHelper.isLinux;
import static msi.gama.runtime.PlatformHelper.isMac;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.util.URI;
import org.geotools.referencing.CRS;
import msi.gama.common.interfaces.IKeyword;
import msi.gama.common.preferences.IPreferenceChangeListener.IPreferenceBeforeChangeListener;
import msi.gama.common.preferences.Pref.ValueProvider;
import msi.gama.common.util.FileUtils;
import msi.gama.outputs.layers.properties.ICameraDefinition;
import msi.gama.runtime.GAMA;
import msi.gama.util.GamaColor;
import msi.gama.util.GamaFont;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.file.GenericFile;
import msi.gama.util.file.IGamaFile;
import msi.gaml.compilation.GAML;
import msi.gaml.compilation.kernel.GamaMetaModel;
import msi.gaml.operators.Cast;
import msi.gaml.operators.Strings;
import msi.gaml.types.IType;
import one.util.streamex.StreamEx;
/**
* Class GamaPreferences.
*
* @author drogoul
* @since 26 août 2013
*
*/
@SuppressWarnings ({ "unchecked", "rawtypes" })
public class GamaPreferences {
/** The Constant GENERATOR_NAMES. */
public static final List<String> GENERATOR_NAMES =
Arrays.asList(IKeyword.CELLULAR, IKeyword.JAVA, IKeyword.MERSENNE);
/** The Constant BASIC_COLORS. */
public static final ValueProvider<GamaColor>[] BASIC_COLORS = new ValueProvider[] {
() -> new GamaColor(74, 97, 144), () -> new GamaColor(66, 119, 42), () -> new GamaColor(83, 95, 107),
() -> new GamaColor(195, 98, 43), () -> new GamaColor(150, 132, 106) };
/**
*
* Interface tab
*
*/
public static class Interface {
/** The Constant NAME. */
public static final String NAME = "Interface";
/**
* Startup
*/
public static final String STARTUP = "Startup";
/** The Constant CORE_SHOW_PAGE. */
public static final Pref<Boolean> CORE_SHOW_PAGE =
create("pref_show_welcome_page", "Display welcome page", true, IType.BOOL, false).in(NAME, STARTUP);
/** The Constant CORE_SHOW_MAXIMIZED. */
public static final Pref<Boolean> CORE_SHOW_MAXIMIZED =
create("pref_show_maximized", "Maximize GAMA window", true, IType.BOOL, false).in(NAME, STARTUP);
/** The Constant CORE_ASK_REBUILD. */
public static final Pref<Boolean> CORE_ASK_REBUILD =
create("pref_ask_rebuild", "Ask before rebuilding a corrupted workspace", true, IType.BOOL, false)
.in(NAME, STARTUP);
/** The Constant CORE_ASK_OUTDATED. */
public static final Pref<Boolean> CORE_ASK_OUTDATED = create("pref_ask_outdated",
"Ask before using a workspace created by another version", true, IType.BOOL, false).in(NAME, STARTUP);
/** The Constant CORE_ASK_REBUILD. */
public static final Pref<Boolean> CORE_STARTUP_MODEL =
create("pref_startup_model", "Open a model or an experiment at startup", false, IType.BOOL, false)
.in(NAME, STARTUP).activates("pref_default_model", "pref_default_experiment");
/** The Constant CORE_DEFAULT_MODEL. */
public static final Pref<? extends IGamaFile> CORE_DEFAULT_MODEL = create("pref_default_model",
"Choose the model to open at startup", () -> new GenericFile("Enter path", false), IType.FILE, false)
.in(NAME, STARTUP).restrictToWorkspace().withExtensions("gaml", "experiment")
.refreshes("pref_default_experiment").activates("pref_default_experiment");
/** The Constant CORE_DEFAULT_MODEL. */
public static final Pref<String> CORE_DEFAULT_EXPERIMENT =
create("pref_default_experiment", "Choose the experiment to run at startup", "", IType.STRING, false)
.in(NAME, STARTUP).among(() -> {
List result = new ArrayList();
if (CORE_STARTUP_MODEL.getValue()) {
IGamaFile file = CORE_DEFAULT_MODEL.getValue();
final URI uriModel = FileUtils.getURI(file.getOriginalPath(), null);
if (uriModel == null) return result;
result.addAll(GAML.getInfo(uriModel).getExperiments());
}
return result;
});
/**
* Menus
*/
public static final String MENUS = "Menus";
/** The Constant CORE_MENU_SIZE. */
public static final Pref<Integer> CORE_MENU_SIZE =
create("pref_menu_size", "Break down agents in menus every", 50, IType.INT, false).between(10, 1000)
.in(NAME, MENUS);
/**
* Console
*/
public static final String CONSOLE = "Console";
/** The Constant CORE_CONSOLE_SIZE. */
public static final Pref<Integer> CORE_CONSOLE_SIZE = create("pref_console_size",
"Max. number of characters to display (-1 = unlimited)", 20000, IType.INT, true).in(NAME, CONSOLE);
/** The Constant CORE_CONSOLE_BUFFER. */
public static final Pref<Integer> CORE_CONSOLE_BUFFER =
create("pref_console_buffer", "Max. number of characters to keep when paused (-1 = unlimited)", 20000,
IType.INT, true).in(NAME, CONSOLE);
/** The Constant CORE_CONSOLE_WRAP. */
public static final Pref<Boolean> CORE_CONSOLE_WRAP =
create("pref_console_wrap", "Wrap long lines (can slow down output)", false, IType.BOOL, true).in(NAME,
CONSOLE);
/**
* Appearance
*/
public static final String APPEARANCE = "Appearance";
/**
* Simulation Interface
*/
public static final String SIMULATIONS = "Simulations";
/** The Constant CORE_SIMULATION_NAME. */
public static final Pref<Boolean> CORE_SIMULATION_NAME = create("pref_append_simulation_name",
"Append the name of simulations to their outputs", false, IType.BOOL, true).in(NAME, SIMULATIONS);
/** The Constant SIMULATION_COLORS. */
public static final Pref<GamaColor>[] SIMULATION_COLORS = new Pref[5];
/** The keep navigator state. */
public static Pref<Boolean> KEEP_NAVIGATOR_STATE = create("pref_keep_navigator_state",
"Maintain the state of the navigator across sessions", true, IType.BOOL, false).in(NAME, STARTUP);
static {
for (var i = 0; i < 5; i++) {
SIMULATION_COLORS[i] = create("pref_simulation_color_" + i,
"Color of Simulation " + i + " in the UI (console, view tabs) ", BASIC_COLORS[i], IType.COLOR,
true).in(NAME, SIMULATIONS);
}
}
}
/**
*
* Modeling tab
*
*/
public static class Modeling {
/** The Constant NAME. */
public static final String NAME = "Editors";
/** The Constant TEXT. */
public static final String TEXT = "Edition";
/**
* Options
*/
public static final String OPTIONS = "Options";
// public static final Pref<Boolean> CORE_PERSPECTIVE = create("pref_switch_perspective",
// "Switch to modeling perspective when editing a model", false, IType.BOOL, false).in(NAME, OPTIONS);
/**
* Validation
*/
// public static final String VALIDATION = "Validation of Models";
public static final Pref<Boolean> WARNINGS_ENABLED =
create("pref_editor_enable_warnings", "Show warning markers in the editor", true, IType.BOOL, false)
.in(NAME, OPTIONS);
/** The Constant INFO_ENABLED. */
public static final Pref<Boolean> INFO_ENABLED =
create("pref_editor_enable_infos", "Show information markers in the editor", true, IType.BOOL, false)
.in(NAME, OPTIONS);
/** The Constant EDITOR_PERSPECTIVE_SAVE. */
public static final Pref<Boolean> EDITOR_PERSPECTIVE_SAVE =
create("pref_editor_perspective_save", "Save all editors when switching perspectives", true, IType.BOOL,
false).in(Modeling.NAME, Modeling.OPTIONS).activates("pref_editor_ask_save");
/** The Constant EDITOR_PERSPECTIVE_HIDE. */
public static final Pref<Boolean> EDITOR_PERSPECTIVE_HIDE = create("pref_editor_perspective_hide",
"Hide editors when switching to simulation perspectives (can be overriden in the 'layout' statement)",
true, IType.BOOL, false).in(Modeling.NAME, Modeling.OPTIONS);
/** The operators menu sort. */
public static Pref<String> OPERATORS_MENU_SORT = GamaPreferences
.create("pref_menu_operators_sort", "Sort operators menu by", "Category", IType.STRING, false)
.among("Name", "Category").in(Interface.NAME, Interface.MENUS);
/** The Constant CORE_CLOSE_QUOTE. */
public static final Pref<Boolean> CORE_CLOSE_QUOTE = GamaPreferences
.create("pref_editor_close_quote", "Automatically close single quotes — '..'", true, IType.BOOL, false)
.in(NAME, TEXT);
/** The Constant CORE_CLOSE_DOUBLE. */
public static final Pref<Boolean> CORE_CLOSE_DOUBLE = GamaPreferences.create("pref_editor_close_double",
"Automatically close double quotes — \"..\"", true, IType.BOOL, false).in(NAME, TEXT);
/** The Constant CORE_CLOSE_CURLY. */
public static final Pref<Boolean> CORE_CLOSE_CURLY = GamaPreferences
.create("pref_editor_close_curly", "Automatically close curly brackets — {..}", true, IType.BOOL, false)
.in(NAME, TEXT);
/** The Constant CORE_CLOSE_SQUARE. */
public static final Pref<Boolean> CORE_CLOSE_SQUARE = GamaPreferences.create("pref_editor_close_square",
"Automatically close square brackets — [..]", true, IType.BOOL, false).in(NAME, TEXT);
/** The Constant CORE_CLOSE_PARENTHESES. */
public static final Pref<Boolean> CORE_CLOSE_PARENTHESES =
GamaPreferences.create("pref_editor_close_parentheses", "Automatically close parentheses — (..)", true,
IType.BOOL, false).in(NAME, TEXT);
/** The Constant EDITOR_CLEAN_UP. */
public static final Pref<Boolean> EDITOR_CLEAN_UP =
GamaPreferences.create("pref_editor_save_format", "Apply formatting on save", false, IType.BOOL, false)
.in(NAME, GamaPreferences.Modeling.OPTIONS);
/** The Constant EDITOR_SAVE. */
public static final Pref<Boolean> EDITOR_SAVE =
GamaPreferences
.create("pref_editor_save_all", "Save all editors before lauching an experiment", true,
IType.BOOL, false)
.in(NAME, GamaPreferences.Modeling.OPTIONS).activates("pref_editor_ask_save");
/** The Constant EDITOR_DRAG_RESOURCES. */
public static final Pref<Boolean> EDITOR_DRAG_RESOURCES = GamaPreferences.create("pref_editor_drag_resources",
"Drag files and resources as references in GAML files", true, IType.BOOL, false).in(NAME, OPTIONS);
/** The Constant EDITOR_SAVE_ASK. */
public static final Pref<Boolean> EDITOR_SAVE_ASK =
GamaPreferences.create("pref_editor_ask_save", "Ask before saving each file", false, IType.BOOL, false)
.in(NAME, OPTIONS);
/** The Constant EDITBOX_ENABLED. */
public static final Pref<Boolean> EDITBOX_ENABLED = GamaPreferences
.create("pref_editor_editbox_on", "Turn on colorization of code sections", false, IType.BOOL, false)
.in(NAME, TEXT);
/** The Constant EDITOR_BASE_FONT. */
public static final Pref<GamaFont> EDITOR_BASE_FONT = GamaPreferences
.create("pref_editor_font", "Font of editors", (GamaFont) null, IType.FONT, false).in(NAME, TEXT);
/** The Constant EDITOR_BACKGROUND_COLOR. */
public static final Pref<GamaColor> EDITOR_BACKGROUND_COLOR =
GamaPreferences.create("pref_editor_background_color", "Background color of editors", (GamaColor) null,
IType.COLOR, false).in(NAME, TEXT);
/** The Constant EDITOR_MARK_OCCURRENCES. */
public static final Pref<Boolean> EDITOR_MARK_OCCURRENCES = GamaPreferences
.create("pref_editor_mark_occurrences", "Mark occurrences of symbols", true, IType.BOOL, false)
.in(NAME, TEXT);
// .activates("pref_tests_period");
// public static final Pref<String> TESTS_PERIOD = create("pref_tests_period", "Every", "Update", IType.STRING)
// .among(Arrays.asList("Day", "Week", "Month", "Update")).in(NAME, TESTS);
}
//
// public static class Experiments {
// public static final String NAME = "Experiments";
//
// // Unused for the moment
// }
/**
*
* Simulations tab
*
*/
public static class Simulations {
/** The Constant NAME. */
public static final String NAME = "Simulations";
}
/**
*
* Runtime tab
*
*/
public static class Runtime {
/** The Constant NAME. */
public static final String NAME = "Execution";
/**
* General
*/
/**
* Running experiments
*/
public static final String EXECUTION = "Experiments";
/** The Constant CORE_AUTO_RUN. */
public static final Pref<Boolean> CORE_AUTO_RUN = create("pref_experiment_auto_run",
"Auto-run experiments when they are launched", false, IType.BOOL, true).in(NAME, EXECUTION);
/** The Constant CORE_ASK_CLOSING. */
public static final Pref<Boolean> CORE_ASK_CLOSING =
create("pref_experiment_ask_closing", "Ask to close the previous experiment when launching a new one",
true, IType.BOOL, true).in(NAME, EXECUTION);
/** The Constant CORE_ASK_FULLSCREEN. */
public static final Pref<Boolean> CORE_ASK_FULLSCREEN =
create("pref_experiment_ask_fullscreen", "Ask before entering fullscreen mode", false, IType.BOOL, true)
.in(NAME, EXECUTION).hidden();
// public static final Pref<Double> CORE_DELAY_STEP = create("pref_experiment_default_step",
/** The Constant CORE_SYNC. */
// "Default step for the delay slider (in sec.)", 0.001, IType.FLOAT, true).in(NAME, EXECUTION).disabled();
public static final Pref<Boolean> CORE_SYNC =
create("pref_display_synchronized", "Synchronize outputs with the simulation", false, IType.BOOL, true)
.in(NAME, EXECUTION);
/** The Constant CORE_EXPAND_PARAMS. */
public static final Pref<Boolean> CORE_EXPAND_PARAMS =
create("pref_experiment_expand_params", "Auto expand Parameters Categories", false, IType.BOOL, true)
.in(NAME, EXECUTION);
/**
* Concurrency
*/
public static final String CONCURRENCY = "Parallelism";
/**
* Tests
*/
public static final String TESTS = "Tests";
/** The Constant TESTS_SORTED. */
public static final Pref<Boolean> TESTS_SORTED =
create("pref_tests_sorted", "Sorts the results of tests by severity", false, IType.BOOL, false)
.in(NAME, TESTS).withComment(", if true, aborted and failed tests are displayed first");
// public static final Pref<Boolean> RUN_TESTS =
// create("pref_run_tests", "Run tests after each update of the platform", false, IType.BOOL, false)
/** The Constant START_TESTS. */
// .in(NAME, TESTS).disabled().hidden();
public static final Pref<Boolean> START_TESTS =
create("pref_start_tests", "Run tests at each start of the platform", false, IType.BOOL, false).in(NAME,
TESTS);
/** The Constant USER_TESTS. */
public static final Pref<Boolean> USER_TESTS =
create("pref_user_tests", "Include user-defined tests in the tests suite", false, IType.BOOL, false)
.in(NAME, TESTS).withComment(", if true, will run user models with 'test' experiments");
/** The Constant FAILED_TESTS. */
public static final Pref<Boolean> FAILED_TESTS = create("pref_failed_tests",
"Only display (in the UI and in headless runs) failed and aborted tests", false, IType.BOOL, true)
.in(NAME, TESTS).withComment(", if true, only aborted and failed tests are displayed");
/** The Constant MEMORY. */
public static final String MEMORY = "Memory";
/** The Constant CORE_MEMORY_POLLING. */
public static final Pref<Boolean> CORE_MEMORY_POLLING =
create("pref_check_memory", "Monitor memory and emit a warning if it is low", true, IType.BOOL, true)
.in(NAME, MEMORY).activates("pref_memory_threshold", "pref_memory_frequency");
/** The Constant CORE_MEMORY_PERCENTAGE. */
public static final Pref<Integer> CORE_MEMORY_PERCENTAGE =
create("pref_memory_threshold", "Trigger warnings when the percentage of available memory is below", 20,
IType.INT, true).in(NAME, MEMORY);
/** The Constant CORE_MEMORY_FREQUENCY. */
public static final Pref<Integer> CORE_MEMORY_FREQUENCY = create("pref_memory_frequency",
"Interval (in seconds) at which memory should be monitored", 2, IType.INT, true).in(NAME, MEMORY);
/** The Constant CORE_MEMORY_ACTION. */
public static final Pref<Boolean> CORE_MEMORY_ACTION = create("pref_memory_action",
"If true, when running out of memory, GAMA will try to close the experiment, otherwise it exits", true,
IType.BOOL, true).in(NAME, MEMORY);
/**
* Errors & warnings
*/
public static final String ERRORS = "Runtime errors";
/** The Constant CORE_SHOW_ERRORS. */
public static final Pref<Boolean> CORE_SHOW_ERRORS =
create("pref_errors_display", "Show execution errors", true, IType.BOOL, true).in(NAME, ERRORS)
.activates("pref_errors_number", "pref_errors_recent_first", "pref_display_show_errors");
/** The Constant ERRORS_IN_DISPLAYS. */
public static final Pref<Boolean> ERRORS_IN_DISPLAYS = create("pref_display_show_errors",
"Show errors thrown in displays and outputs", false, IType.BOOL, true).in(NAME, ERRORS);
/** The Constant CORE_ERRORS_NUMBER. */
public static final Pref<Integer> CORE_ERRORS_NUMBER =
create("pref_errors_number", "Number of errors to display", 10, IType.INT, true).in(NAME, ERRORS)
.between(1, null);
/** The Constant CORE_RECENT. */
public static final Pref<Boolean> CORE_RECENT =
create("pref_errors_recent_first", "Display most recent first", true, IType.BOOL, true).in(NAME,
ERRORS);
/** The Constant CORE_REVEAL_AND_STOP. */
public static final Pref<Boolean> CORE_REVEAL_AND_STOP =
create("pref_errors_stop", "Stop simulation at first error", true, IType.BOOL, true).in(NAME, ERRORS);
/** The Constant CORE_WARNINGS. */
public static final Pref<Boolean> CORE_WARNINGS =
create("pref_errors_warnings_errors", "Treat warnings as errors", false, IType.BOOL, true).in(NAME,
ERRORS);
/** The Constant CORE_ERRORS_EDITOR_LINK. */
public static final Pref<Boolean> CORE_ERRORS_EDITOR_LINK = create("pref_errors_in_editor",
"Automatically open an editor and point at the faulty part of the model if an error or a warning is thrown",
true, IType.BOOL, true).in(NAME, ERRORS);
}
/**
* The Class Displays.
*/
public static class Displays {
/** The Constant NAME. */
public static final String NAME = "Displays";
/** The Constant PRESENTATION. */
public static final String PRESENTATION = "Presentation and Behavior of Graphical Display Views";
/**
* Presentation
*/
public static final List<String> LAYOUTS = Arrays.asList("None", "Stacked", "Split", "Horizontal", "Vertical");
/** The Constant CORE_DISPLAY_LAYOUT. */
public static final Pref<String> CORE_DISPLAY_LAYOUT =
create("pref_display_view_layout", "Default layout of display views", "Split", IType.STRING, true)
.among(LAYOUTS.toArray(new String[LAYOUTS.size()])).in(NAME, PRESENTATION);
// public static final Pref<Boolean> CORE_DISPLAY_ORDER = create("pref_display_same_order",
/** The Constant CORE_DISPLAY_BORDER. */
// "Stack displays in the order defined in the model", true, IType.BOOL, true).in(NAME, PRESENTATION);
public static final Pref<Boolean> CORE_DISPLAY_BORDER =
create("pref_display_show_border", "Display a border around display views", false, IType.BOOL, true)
.in(NAME, PRESENTATION);
/** The Constant CORE_DISPLAY_PERSPECTIVE. */
public static final Pref<Boolean> CORE_DISPLAY_PERSPECTIVE =
create("pref_display_continue_drawing", "Continue to draw displays when in Modeling perspective", false,
IType.BOOL, true).in(NAME, PRESENTATION);
/** The Constant DISPLAY_FAST_SNAPSHOT. */
public static final Pref<Boolean> DISPLAY_FAST_SNAPSHOT = create("pref_display_fast_snapshot",
"Enable fast snapshots (uncomplete when the display is obscured by others but much faster)", false,
IType.BOOL, true).in(NAME, PRESENTATION);
/** The Constant CORE_DISPLAY_TOOLBAR. */
public static final Pref<Boolean> CORE_DISPLAY_TOOLBAR =
create("pref_display_show_toolbar", "Show the display top toolbar", true, IType.BOOL, true).in(NAME,
PRESENTATION);
/** The Constant CORE_OVERLAY. */
public static final Pref<Boolean> CORE_OVERLAY =
create("pref_display_show_overlay", "Show the display bottom overlay", false, IType.BOOL, true).in(NAME,
PRESENTATION);
/**
* Charts
*/
public static final String CHARTS = "Charts Preferences";
/** The Constant CHART_FLAT. */
public static final Pref<Boolean> CHART_FLAT =
create("pref_display_flat_charts", "Display 'flat' histograms", true, IType.BOOL, true).in(NAME,
CHARTS);
/** The Constant CHART_MEMORIZE. */
public static final Pref<Boolean> CHART_MEMORIZE = create("pref_display_memorize_charts",
"Keep values in memory (to save them as CSV)", true, IType.BOOL, true).in(NAME, CHARTS);
/** The Constant CHART_GRIDLINES. */
public static final Pref<Boolean> CHART_GRIDLINES =
create("pref_chart_display_gridlines", "Display grid lines", true, IType.BOOL, true).in(NAME, CHARTS);
/**
* Drawing methods and defaults
*/
public static final String DRAWING = "Default Rendering Properties";
/** The Constant CORE_DISPLAY. */
public static final Pref<String> CORE_DISPLAY =
create("pref_display_default", "Default rendering method (Java2D for 2D, OpenGL for 3D)", "Java2D",
IType.STRING, true).among("Java2D", "OpenGL").in(NAME, DRAWING);
/** The Constant CORE_ANTIALIAS. */
public static final Pref<Boolean> CORE_ANTIALIAS =
create("pref_display_antialias", "Apply antialiasing", false, IType.BOOL, true).in(NAME, DRAWING);
/** The Constant CORE_BACKGROUND. */
public static final Pref<GamaColor> CORE_BACKGROUND =
create("pref_display_background_color", "Default background color ('background' facet of 'display')",
() -> GamaColor.getNamed("white"), IType.COLOR, true).in(NAME, DRAWING);
/** The Constant CORE_HIGHLIGHT. */
public static final Pref<GamaColor> CORE_HIGHLIGHT = create("pref_display_highlight_color",
"Default highlight color", () -> new GamaColor(0, 200, 200), IType.COLOR, true).in(NAME, DRAWING);
/** The Constant CORE_SHAPE. */
public static final Pref<String> CORE_SHAPE =
create("pref_display_default_shape", "Defaut shape of agents", "shape", IType.STRING, true)
.among("shape", "circle", "square", "triangle", "point", "cube", "sphere").in(NAME, DRAWING);
/** The Constant CORE_SIZE. */
public static final Pref<Double> CORE_SIZE =
create("pref_display_default_size", "Default size of agents", 1.0, IType.FLOAT, true)
.between(0.01, null).in(NAME, DRAWING);
/** The Constant CORE_COLOR. */
public static final Pref<GamaColor> CORE_COLOR = create("pref_display_default_color", "Default color of agents",
() -> GamaColor.getNamed("yellow"), IType.COLOR, true).in(NAME, DRAWING);
/**
* Options
*/
public static final String OPTIONS = "Advanced ";
/** The Constant DISPLAY_NO_ACCELERATION. */
public static final Pref<Boolean> DISPLAY_NO_ACCELERATION = create("pref_display_no_java2d_acceleration",
"Disable acceleration for Java2D (necessary on some configurations)", false, IType.BOOL, true)
.in(NAME, OPTIONS).hidden();
/**
* OPENGL
*/
public static final String RENDERING = "OpenGL Rendering Properties";
/** The Constant DISPLAY_ONLY_VISIBLE. */
public static final Pref<Boolean> DISPLAY_ONLY_VISIBLE = create("pref_display_visible_agents",
"Only display visible agents (faster, may create visual oddities)", false, IType.BOOL, true).in(NAME,
RENDERING);
/** The Constant CORE_DRAW_ENV. */
public static final Pref<Boolean> CORE_DRAW_ENV =
create("pref_display_show_referential", "Draw 3D axes", true, IType.BOOL, true).in(NAME, RENDERING);
/** The Constant DRAW_ROTATE_HELPER. */
public static final Pref<Boolean> DRAW_ROTATE_HELPER =
create("pref_display_show_rotation", "Draw rotation axes", true, IType.BOOL, true).in(NAME, RENDERING);
/** The Constant CORE_LINE_WIDTH. */
public static final Pref<Double> CORE_LINE_WIDTH = create("pref_display_line_width",
"Default line width (facet 'width' of 'draw')", 1.2d, IType.FLOAT, true).in(NAME, RENDERING);
/** The Constant ONLY_VISIBLE_FACES. */
public static final Pref<Boolean> ONLY_VISIBLE_FACES = create("pref_display_visible_faces",
"Draw only the 'external' faces of objects", false, IType.BOOL, true).in(NAME, RENDERING).hidden();
/** The Constant DISPLAY_SLICE_NUMBER. */
public static final Pref<Integer> DISPLAY_SLICE_NUMBER =
create("pref_display_slice_number", "Number of slices of circular geometries", 16, IType.INT, true)
.in(NAME, RENDERING);
/**
* Options
*/
public static final Pref<Double> OPENGL_ZOOM =
create("pref_display_zoom_factor", "Set the zoom factor (0 for slow, 1 fast)", 0.5, IType.FLOAT, true)
.in(NAME, RENDERING).between(0, 1);
public static final Pref<Double> OPENGL_KEYBOARD = create("pref_display_keyboard_factor",
"Set the sensitivity of the keyboard movements (0 for slow, 1 for fast)", 0.5, IType.FLOAT, true)
.in(NAME, RENDERING).between(0.01, 1);
public static final Pref<Double> OPENGL_MOUSE = create("pref_display_mouse_factor",
"set the sensitivity of the mouse/trackpad movements (0 for slow, 1 fast)", 0.5, IType.FLOAT, true)
.in(NAME, RENDERING).between(0.01, 1);
/** The Constant OPENGL_CAP_FPS. */
public static final Pref<Boolean> OPENGL_CAP_FPS =
create("pref_display_cap_fps", "Limit the number of frames per second", false, IType.BOOL, true)
.in(NAME, RENDERING).activates("pref_display_max_fps");
/** The Constant OPENGL_FPS. */
public static final Pref<Integer> OPENGL_FPS =
create("pref_display_max_fps", "Max. number of frames per second", 60, IType.INT, true).in(NAME,
RENDERING);
/** The Constant DISPLAY_POWER_OF_TWO. */
public static final Pref<Boolean> DISPLAY_POWER_OF_TWO = create("pref_display_power_of_2",
"Forces textures dimensions to a power of 2 (e.g. 16x16. Necessary on some configurations)", false,
IType.BOOL, true).in(NAME, RENDERING).hidden();
/** The Constant OPENGL_NUM_KEYS_CAM. */
public static final Pref<Boolean> OPENGL_NUM_KEYS_CAM = create("pref_display_numkeyscam",
"Use Numeric Keypad (2,4,6,8) for camera interaction", true, IType.BOOL, true).in(NAME, RENDERING);
/** The Constant OPENGL_DEFAULT_CAM. */
public static final Pref<String> OPENGL_DEFAULT_CAM =
create("pref_display_camera", "Default camera to use when none is specified", "From above",
IType.STRING, true).among(ICameraDefinition.PRESETS).in(NAME, RENDERING);
/** The Constant OPENGL_CLIPBOARD_CAM. */
public static final Pref<Boolean> OPENGL_CLIPBOARD_CAM = create("pref_display_clipboard_cam",
"Copy the camera definition to the clipboard when it is changed on the display", false, IType.BOOL,
true).in(NAME, RENDERING);
/** The Constant OPENGL_USE_IMAGE_CACHE. */
public static final Pref<Boolean> OPENGL_USE_IMAGE_CACHE = create("pref_display_use_cache",
"Use GAMA image cache when building textures in OpenGL (potentially faster when running several simulations, but uses more memory)",
true, IType.BOOL, true).in(NAME, RENDERING);
/** The Constant OPENGL_DEFAULT_LIGHT_INTENSITY. */
public static final Pref<Integer> OPENGL_DEFAULT_LIGHT_INTENSITY = create("pref_display_light_intensity",
"Set the default intensity of the ambient and default lights (from 0, completely dark, to 255, completely light)",
160, IType.INT, true).in(NAME, RENDERING).between(0, 255);
}
/**
* The Class External.
*/
public static class External {
/** The Constant NAME. */
public static final String NAME = "Data and Operators";
/**
* Http connections
*/
public static final String HTTP = "Http connections";
/** The Constant CORE_HTTP_CONNECT_TIMEOUT. */
public static final Pref<Integer> CORE_HTTP_CONNECT_TIMEOUT =
create("pref_http_connect_timeout", "Connection timeout (in ms)", 20000, IType.INT, true).in(NAME,
HTTP);
/** The Constant CORE_HTTP_READ_TIMEOUT. */
public static final Pref<Integer> CORE_HTTP_READ_TIMEOUT =
create("pref_http_read_timeout", "Read timeout (in ms)", 20000, IType.INT, true).in(NAME, HTTP);
/** The Constant CORE_HTTP_RETRY_NUMBER. */
public static final Pref<Integer> CORE_HTTP_RETRY_NUMBER = create("pref_http_retry_number",
"Number of times to retry if connection cannot be established", 3, IType.INT, true).in(NAME, HTTP);
/** The Constant CORE_HTTP_EMPTY_CACHE. */
public static final Pref<Boolean> CORE_HTTP_EMPTY_CACHE = create("pref_http_empty_cache",
"Empty the local cache of files downloaded from the web", true, IType.BOOL, true).in(NAME, HTTP);
/**
* Random numbers
*/
public static final String RNG = "Random number generation";
/** The Constant CORE_RNG. */
public static final Pref<String> CORE_RNG =
create("pref_rng_name", "Default random number generator", IKeyword.MERSENNE, IType.STRING, true)
.among(GENERATOR_NAMES).in(NAME, RNG);
/** The Constant CORE_SEED_DEFINED. */
public static final Pref<Boolean> CORE_SEED_DEFINED =
create("pref_rng_define_seed", "Define a default seed", false, IType.BOOL, true)
.activates("pref_rng_default_seed").in(NAME, RNG);
/** The Constant CORE_SEED. */
public static final Pref<Double> CORE_SEED =
create("pref_rng_default_seed", "Default seed value (0 is undefined)", 1d, IType.FLOAT, true).in(NAME,
RNG);
/** The Constant CORE_RND_EDITABLE. */
public static final Pref<Boolean> CORE_RND_EDITABLE =
create("pref_rng_in_parameters", "Include in the parameters", false, IType.BOOL, true).in(NAME, RNG);
/**
* Dates
*/
public static final String DATES = "Management of dates";
/**
* Optimizations
*/
public static final String OPTIMIZATIONS = "Optimizations";
/** The Constant CONSTANT_OPTIMIZATION. */
public static final Pref<Boolean> CONSTANT_OPTIMIZATION = create("pref_optimize_constant_expressions",
"Optimize constant expressions (experimental, performs a rebuild of models)", false, IType.BOOL, true)
.in(NAME, OPTIMIZATIONS).onChange(v -> {
try {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null);
} catch (CoreException e) {}
}).hidden();
/** The Constant AGENT_OPTIMIZATION. */
public static final Pref<Boolean> AGENT_OPTIMIZATION =
create("pref_optimize_agent_memory", "Optimize agents memory", true, IType.BOOL, true).in(NAME,
OPTIMIZATIONS);
/** The Constant AT_DISTANCE_OPTIMIZATION. */
public static final Pref<Boolean> AT_DISTANCE_OPTIMIZATION =
create("pref_optimize_at_distance", "Optimize the 'at_distance' operator", true, IType.BOOL, true)
.in(NAME, OPTIMIZATIONS);
/** The Constant PATH_COMPUTATION_OPTIMIZATION. */
public static final Pref<Boolean> PATH_COMPUTATION_OPTIMIZATION = create("pref_optimize_path_computation",
"Optimize the path computation operators and goto action (but with possible 'jump' issues)", false,
IType.BOOL, true).in(NAME, OPTIMIZATIONS);
/** The Constant QUADTREE_OPTIMIZATION. */
public static final Pref<Boolean> QUADTREE_OPTIMIZATION = create("pref_optimize_quadtree",
"Optimize spatial queries: add agents only when necessary in the quadtree (still experimental)", false,
IType.BOOL, true).in(NAME, OPTIMIZATIONS);
/** The Constant QUADTREE_SYNCHRONIZATION. */
public static final Pref<Boolean> QUADTREE_SYNCHRONIZATION = create("pref_synchronize_quadtree",
"Forces the spatial index to synchronize its operations. Useful for interactive models where the user may interfere.",
true, IType.BOOL, true).in(NAME, OPTIMIZATIONS);
/** The Constant USE_POOLING. */
public static final Pref<Boolean> USE_POOLING =
create("pref_use_pooling", "Use object pooling to reduce memory usage (still experimental)", false,
IType.BOOL, true).in(NAME, OPTIMIZATIONS).hidden();
/** The Constant TOLERANCE_POINTS. */
public static final Pref<Double> TOLERANCE_POINTS =
create("pref_point_tolerance", "Tolerance for the comparison of points", 0.0, IType.FLOAT, true)
.in(NAME, OPTIMIZATIONS);
/** The Constant SHAPEFILE_IN_MEMORY. */
public static final Pref<Boolean> SHAPEFILES_IN_MEMORY = create("pref_shapefiles_in_memory",
"In-memory shapefile mapping (optimizes access to shapefile data in exchange for increased memory usage)",
true, IType.BOOL, true).in(NAME, OPTIMIZATIONS);
/**
* Paths to libraries
*/
public static final String PATHS = "External libraries support";
/** The Constant LIB_SPATIALITE. */
public static final Pref<? extends IGamaFile> LIB_SPATIALITE =
create("pref_lib_spatialite", "Path to Spatialite library (http://www.gaia-gis.it/gaia-sins/)",
() -> new GenericFile("Enter path", false), IType.FILE, true).in(NAME, PATHS);
/** The Constant jriFile. */
public static final String jriFile = isMac() ? "libjri.jnilib" : isLinux() ? "libjri.so" : "jri.dll";
/** The Constant LIB_R. */
public static final Pref<? extends IGamaFile> LIB_R = create("pref_lib_r",
"Path to JRI library ($R_HOME/library/rJava/jri/" + jriFile + ") (http://www.r-project.org)",
() -> new GenericFile(getDefaultRPath(), false), IType.FILE, true).in(NAME, PATHS);
/**
* GeoTools
*/
public static final String GEOTOOLS =
"GIS Coordinate Reference Systems (http://spatialreference.org/ref/epsg/ for EPSG codes)";
/** The Constant LIB_TARGETED. */
public static final Pref<Boolean> LIB_TARGETED = create("pref_gis_auto_crs",
"Let GAMA find which CRS to use to project GIS data", true, IType.BOOL, true).in(NAME, GEOTOOLS);
/** The Constant LIB_PROJECTED. */
public static final Pref<Boolean> LIB_PROJECTED = create("pref_gis_same_crs",
"When no .prj file or CRS is supplied, consider GIS data to be already projected in this CRS", true,
IType.BOOL, true).deactivates("pref_gis_initial_crs").in(NAME, GEOTOOLS);
/** The Constant LIB_USE_DEFAULT. */
public static final Pref<Boolean> LIB_USE_DEFAULT =
create("pref_gis_save_crs", "When no CRS is provided, save the GIS data with the current CRS", true,
IType.BOOL, true).deactivates("pref_gis_output_crs").in(NAME, GEOTOOLS);
/** The Constant LIB_TARGET_CRS. */
public static final Pref<Integer> LIB_TARGET_CRS = create("pref_gis_default_crs",
"...or use the following EPSG code (the one that will also be used if no projection information is found)",
32648, IType.INT, true).in(NAME, GEOTOOLS)
.addChangeListener((IPreferenceBeforeChangeListener<Integer>) newValue -> {
final var codes = CRS.getSupportedCodes(newValue.toString());
if (codes.isEmpty()) return false;
return true;
});
/** The Constant LIB_INITIAL_CRS. */
public static final Pref<Integer> LIB_INITIAL_CRS =
create("pref_gis_initial_crs", "...or use the following CRS (EPSG code)", 4326, IType.INT, true)
.in(NAME, GEOTOOLS).addChangeListener((IPreferenceBeforeChangeListener<Integer>) newValue -> {
final var codes = CRS.getSupportedCodes(newValue.toString());
if (codes.isEmpty()) return false;
return true;
});
/** The Constant LIB_OUTPUT_CRS. */
public static final Pref<Integer> LIB_OUTPUT_CRS =
create("pref_gis_output_crs", "... or use this following CRS (EPSG code)", 4326, IType.INT, true)
.in(NAME, GEOTOOLS).addChangeListener((IPreferenceBeforeChangeListener<Integer>) newValue -> {
final var codes = CRS.getSupportedCodes(newValue.toString());
if (codes.isEmpty()) return false;
return true;
});
// RScript adress:
// "/Library/Frameworks/R.framework/Versions/3.4/Resources/bin/exec/x86_64/RScript"
// "usr/bin/RScript"
// "C:\\Program Files\\R\\R-2.15.1\\bin\\x64\\Rscript.exe"
/**
* Gets the default R path.
*
* @return the default R path
*/
// "C:\\Program Files\\R\\R-2.15.1\\bin\\Rscript.exe"
private static String getDefaultRPath() {
if (isMac()) return "/Library/Frameworks/R.framework/Resources/library/rJava/jri/libjri.jnilib";
if (isLinux()) return "/usr/local/lib/libjri.so";
return "C:\\Program Files\\R\\R-3.4.0\\library\\rJava\\jri\\jri.dll";
}
}
/** The prefs. */
private static Map<String, Pref<? extends Object>> prefs = new LinkedHashMap<>();
/**
* Gets the.
*
* @param <T>
* the generic type
* @param key
* the key
* @param clazz
* the clazz
* @return the pref
*/
public static <T> Pref<T> get(final String key, final Class<T> clazz) {
return (Pref<T>) prefs.get(key);
}
/**
* Gets the.
*
* @param key
* the key
* @return the pref
*/
public static Pref<?> get(final String key) {
return prefs.get(key);
}
/**
* Gets the all.
*
* @return the all
*/
public static Map<String, Pref<?>> getAll() { return prefs; }
/**
* Creates the.
*
* @param <T>
* the generic type
* @param key
* the key
* @param title
* the title
* @param value
* the value
* @param type
* the type
* @param inGaml
* the in gaml
* @return the pref
*/
public static <T> Pref<T> create(final String key, final String title, final T value, final int type,
final boolean inGaml) {
final var e = new Pref<T>(key, type, inGaml).named(title).in(Interface.NAME, "").init(value);
register(e);
return e;
}
/**
* Lazy create (tries not to compute immediately the value)
*
*/
public static <T> Pref<T> create(final String key, final String title, final ValueProvider<T> provider,
final int type, final boolean inGaml) {
final var e = new Pref<T>(key, type, inGaml).named(title).in(Interface.NAME, "").init(provider);
register(e);
return e;
}
/**
* Register.
*
* @param gp
* the gp
*/
private static void register(final Pref gp) {
final var key = gp.key;
if (key == null) return;
prefs.put(key, gp);
getStore().register(gp);
// Adds the preferences to the platform species if it is already created
final var spec = GamaMetaModel.INSTANCE.getPlatformSpeciesDescription();
if (spec != null && !spec.hasAttribute(key)) {
spec.addPref(key, gp);
// spec.validate();
}
}
/**
* Organize prefs.
*
* @return the map
*/
public static Map<String, Map<String, List<Pref>>> organizePrefs() {
final Map<String, Map<String, List<Pref>>> result = GamaMapFactory.create();
for (final Pref e : prefs.values()) {
if (e.isHidden()) { continue; }
final var tab = e.tab;
var groups = result.get(tab);
if (groups == null) {
groups = GamaMapFactory.create();
result.put(tab, groups);
}
final var group = e.group;
var in_group = groups.get(group);
if (in_group == null) {
in_group = new ArrayList<>();
groups.put(group, in_group);
}
in_group.add(e);
}
return result;
}
/**
* Sets the new preferences.
*
* @param modelValues
* the model values
*/
public static void setNewPreferences(final Map<String, Object> modelValues) {
for (final String name : modelValues.keySet()) {
final Pref e = prefs.get(name);
if (e == null) { continue; }
e.set(modelValues.get(name));
getStore().write(e);
}
}
/**
* Revert to default values.
*
* @param modelValues
* the model values
*/
public static void revertToDefaultValues(final Map<String, Object> modelValues) {
getStore().clear();
}
/**
* Apply preferences from.
*
* @param path
* the path
* @param modelValues
* the model values
*/
public static void applyPreferencesFrom(final String path, final Map<String, Object> modelValues) {
// DEBUG.OUT("Apply preferences from " + path);
getStore().loadFromProperties(path);
final List<Pref> entries = new ArrayList(prefs.values());
for (final Pref e : entries) {
register(e);
modelValues.put(e.key, e.getValue());
}
}
/**
* Save preferences to GAML.
*
* @param path
* the path
*/
public static void savePreferencesToGAML(final String path) {
try (var os = new FileWriter(path)) {
final var entries = StreamEx.ofValues(prefs).sortedBy(Pref::getName).toList();