/
ScenicViewGui.java
1154 lines (991 loc) · 47.5 KB
/
ScenicViewGui.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
/*
* Scenic View,
* Copyright (C) 2012 Jonathan Giles, Ander Ruiz, Amy Fowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.scenicview.view;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import org.fxconnector.AppController;
import org.fxconnector.Configuration;
import org.fxconnector.ConnectorUtils;
import org.fxconnector.StageController;
import org.fxconnector.StageControllerImpl;
import org.fxconnector.StageID;
import org.fxconnector.event.AnimationsCountEvent;
import org.fxconnector.event.DetailsEvent;
import org.fxconnector.event.EvLogEvent;
import org.fxconnector.event.FXConnectorEvent;
import org.fxconnector.event.FXConnectorEvent.SVEventType;
import org.fxconnector.event.FXConnectorEventDispatcher;
import org.fxconnector.event.MousePosEvent;
import org.fxconnector.event.NodeAddRemoveEvent;
import org.fxconnector.event.NodeCountEvent;
import org.fxconnector.event.NodeSelectedEvent;
import org.fxconnector.event.SceneDetailsEvent;
import org.fxconnector.event.ShortcutEvent;
import org.fxconnector.event.WindowDetailsEvent;
import org.fxconnector.node.SVNode;
import org.scenicview.model.Persistence;
import org.scenicview.model.update.AppsRepository;
import org.scenicview.model.update.UpdateStrategy;
import org.scenicview.utils.ExceptionLogger;
import org.scenicview.utils.Logger;
import org.scenicview.view.control.FilterTextField;
import org.scenicview.view.dialog.AboutBox;
import org.scenicview.view.dialog.HelpBox;
import org.scenicview.view.tabs.AnimationsTab;
import org.scenicview.view.tabs.CSSFXTab;
import org.scenicview.view.tabs.DetailsTab;
import org.scenicview.view.tabs.EventLogTab;
import org.scenicview.view.tabs.JavaDocTab;
import org.scenicview.view.tabs.ThreeDOMTab;
/**
* The base UI
*/
public class ScenicViewGui {
private static final String HELP_URL = "http://fxexperience.com/scenic-view/help";
public static final String STYLESHEETS = ScenicViewGui.class.getResource("scenicview.css").toExternalForm();
public static final Image APP_ICON = DisplayUtils.getUIImage("mglass.png");
public static final String VERSION = "8.0.0";
private final Thread shutdownHook = new Thread() {
@Override public void run() {
// We can't use close() because we are not in FXThread
saveProperties();
}
};
// Scenic View UI
private final Stage scenicViewStage;
private BorderPane rootBorderPane;
private SplitPane splitPane;
// menu bar area
private MenuBar menuBar;
private CheckMenuItem showFilteredNodesInTree;
private CheckMenuItem showNodesIdInTree;
private CheckMenuItem autoRefreshStyleSheets;
private CheckMenuItem componentSelectOnClick;
private CheckMenuItem showInvisibleNodes;
private CheckMenuItem showSearchBar;
// filter area
// private TitledPane filtersPane;
private FilterTextField propertyFilterField;
private List<NodeFilter> activeNodeFilters;
// tree area
private Node treeViewScanningPlaceholder;
private ScenegraphTreeView treeView;
// search bar area
private GridPane searchBar;
// status bar area
private StatusBar statusBar;
private VBox bottomVBox;
public final Configuration configuration = new Configuration();
private final List<FXConnectorEvent> eventQueue = new LinkedList<>();
private UpdateStrategy updateStrategy;
private long lastMousePosition;
private final FXConnectorEventDispatcher stageModelListener = new FXConnectorEventDispatcher() {
@Override public void dispatchEvent(final FXConnectorEvent appEvent) {
if (isValid(appEvent)) {
// doDispatchEvent(appEvent);
switch (appEvent.getType()) {
case ROOT_UPDATED:
doDispatchEvent(appEvent);
break;
case MOUSE_POSITION:
if (System.currentTimeMillis() - lastMousePosition > 500) {
lastMousePosition = System.currentTimeMillis();
// No need to synchronize here
eventQueue.add(appEvent);
}
break;
default:
// No need to synchronize here
eventQueue.add(appEvent);
break;
}
} else {
Logger.print("Unused event " + appEvent);
}
}
private boolean isValid(final FXConnectorEvent appEvent) {
for (int i = 0; i < appRepository.getApps().size(); i++) {
if (appRepository.getApps().get(i).getID() == appEvent.getStageID().getAppID()) {
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).getID().getStageID() == appEvent.getStageID().getStageID()) {
return true;
}
}
break;
}
}
return false;
}
};
// private final List<AppController> apps = new ArrayList<AppController>();
private final AppsRepository appRepository;
public StageController activeStage;
private SVNode selectedNode;
private TabPane tabPane;
private DetailsTab detailsTab;
private EventLogTab eventsTab;
private AnimationsTab animationsTab;
private JavaDocTab javadocTab;
private ThreeDOMTab threeDOMTab;
private CSSFXTab cssfxTab;
public ScenicViewGui(final UpdateStrategy updateStrategy, final Stage scenicViewStage) {
this.scenicViewStage = scenicViewStage;
Persistence.loadProperties();
Runtime.getRuntime().addShutdownHook(shutdownHook);
buildUI();
// checkNewVersion(false);
this.appRepository = new AppsRepository(this);
this.updateStrategy = updateStrategy;
this.updateStrategy.start(appRepository);
// we update Scenic View on a separate thread, based on events coming
// in from FX Connector. The events arrive into the eventQueue, and
// are processed here
Timeline eventDispatcher = new Timeline(new KeyFrame(Duration.millis(60), event -> {
// No need to synchronize
while (!eventQueue.isEmpty()) {
try {
doDispatchEvent(eventQueue.remove(0));
} catch (final Exception e) {
ExceptionLogger.submitException(e);
}
}
}));
eventDispatcher.setCycleCount(Animation.INDEFINITE);
eventDispatcher.play();
}
private void buildUI() {
rootBorderPane = new BorderPane();
rootBorderPane.setId(StageController.FX_CONNECTOR_BASE_ID + "scenic-view");
// search bar
buildFiltersBox();
// menubar
buildMenuBar();
// main splitpane
splitPane = new SplitPane();
splitPane.setId("main-splitpane");
// treeview
treeView = new ScenegraphTreeView(activeNodeFilters, this);
treeViewScanningPlaceholder = new VBox(10) {
{
ProgressIndicator progress = new ProgressIndicator();
Label label = new Label("Scanning for JavaFX applications");
label.getStyleClass().add("scanning-label");
getChildren().addAll(progress, label);
setAlignment(Pos.CENTER);
treeView.expandedItemCountProperty().addListener(o -> {
setVisible(treeView.getExpandedItemCount() == 0);
});
}
};
StackPane treeViewStackPane = new StackPane(treeView, treeViewScanningPlaceholder);
treeViewStackPane.setStyle(" -fx-padding: 0");
treeView.setMaxHeight(Double.MAX_VALUE);
// right side
detailsTab = new DetailsTab(this, new Consumer<String>() {
@Override public void accept(String property) {
ScenicViewGui.this.loadAPI(property);
}
});
animationsTab = new AnimationsTab(this);
tabPane = new TabPane();
tabPane.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> updateMenuBar(oldValue, newValue));
javadocTab = new JavaDocTab(this);
eventsTab = new EventLogTab(this);
eventsTab.activeProperty().addListener((ov, oldValue, newValue) -> {
configuration.setEventLogEnabled(newValue);
configurationUpdated();
});
// 3Dom
threeDOMTab = new ThreeDOMTab(this);
// CSSFX
cssfxTab = new CSSFXTab(this);
tabPane.getTabs().addAll(detailsTab, eventsTab, /*animationsTab,*/ javadocTab, threeDOMTab, cssfxTab);
// /3Dom
Persistence.loadProperty("splitPaneDividerPosition", splitPane, 0.3);
// putting it all together
splitPane.getItems().addAll(treeViewStackPane, tabPane);
rootBorderPane.setCenter(splitPane);
// status bar
statusBar = new StatusBar();
bottomVBox = new VBox(searchBar, statusBar);
rootBorderPane.setBottom(bottomVBox);
Persistence.loadProperty("stageWidth", scenicViewStage, 800);
Persistence.loadProperty("stageHeight", scenicViewStage, 800);
}
private void buildFiltersBox() {
propertyFilterField = createFilterField("Type property names or values here", null);
propertyFilterField.setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override public void handle(final KeyEvent arg0) {
filterProperties(propertyFilterField.getText());
}
});
propertyFilterField.setDisable(true);
final FilterTextField idFilterField = createFilterField("Type Node ID's here");
idFilterField.setOnButtonClick(() -> {
idFilterField.setText("");
update();
});
final FilterTextField classNameFilterField = createFilterField("Type class names here");
classNameFilterField.setOnButtonClick(() -> {
classNameFilterField.setText("");
update();
});
searchBar = new GridPane();
searchBar.setVgap(5);
searchBar.setHgap(5);
searchBar.setSnapToPixel(true);
searchBar.setPadding(new Insets(0, 5, 5, 0));
searchBar.getStyleClass().add("search-bar");
GridPane.setHgrow(idFilterField, Priority.ALWAYS);
GridPane.setHgrow(classNameFilterField, Priority.ALWAYS);
GridPane.setHgrow(propertyFilterField, Priority.ALWAYS);
int column = 1;
Label nodeIdFilterLabel = new Label("Node ID Filter:");
Label classNameFilterLabel = new Label("Class Name Filter:");
Label propertyFilterLabel = new Label("Property Filter:");
searchBar.add(nodeIdFilterLabel, column++, 1);
searchBar.add(idFilterField, column++, 1);
searchBar.add(classNameFilterLabel, column++, 1);
searchBar.add(classNameFilterField, column++, 1);
searchBar.add(propertyFilterLabel, column++, 1);
searchBar.add(propertyFilterField, column++, 1);
// create filters for nodes
activeNodeFilters = new ArrayList<>();
/**
* Create a filter for our own nodes
*/
activeNodeFilters.add(new NodeFilter() {
@Override public boolean allowChildrenOnRejection() {
return false;
}
@Override public boolean accept(final SVNode node) {
// do not create tree nodes for our bounds rectangles
return ConnectorUtils.isNormalNode(node);
}
@Override public boolean ignoreShowFilteredNodesInTree() {
return true;
}
@Override public boolean expandAllNodes() {
return false;
}
});
activeNodeFilters.add(new NodeFilter() {
@Override public boolean allowChildrenOnRejection() {
return false;
}
@Override public boolean accept(final SVNode node) {
return showInvisibleNodes.isSelected() || node.isVisible();
}
@Override public boolean ignoreShowFilteredNodesInTree() {
return false;
}
@Override public boolean expandAllNodes() {
return false;
}
});
activeNodeFilters.add(new NodeFilter() {
@Override public boolean allowChildrenOnRejection() {
return true;
}
@Override public boolean accept(final SVNode node) {
if (idFilterField.getText().equals(""))
return true;
return node.getId() != null && node.getId().toLowerCase().indexOf(idFilterField.getText().toLowerCase()) != -1;
}
@Override public boolean ignoreShowFilteredNodesInTree() {
return false;
}
@Override public boolean expandAllNodes() {
return !idFilterField.getText().equals("");
}
});
activeNodeFilters.add(new NodeFilter() {
@Override public boolean allowChildrenOnRejection() {
return true;
}
@Override public boolean accept(final SVNode node) {
if (classNameFilterField.getText().equals(""))
return true;
// Allow reduces or complete className
return node.getNodeClass().toLowerCase().indexOf(classNameFilterField.getText().toLowerCase()) != -1;
}
@Override public boolean ignoreShowFilteredNodesInTree() {
return false;
}
@Override public boolean expandAllNodes() {
return !classNameFilterField.getText().equals("");
}
});
}
private void buildMenuBar() {
menuBar = new MenuBar();
menuBar.setUseSystemMenuBar(true);
// menuBar.setId("main-menubar");
// ---- File Menu
// final MenuItem classpathItem = new MenuItem("Configure Classpath");
// classpathItem.setOnAction(new EventHandler<ActionEvent>() {
// @Override public void handle(final ActionEvent arg0) {
// final Properties properties = PropertiesUtils.getProperties();
//
// final String toolsPath = properties.getProperty(ScenicViewBooter.JDK_PATH_KEY);
// final File jdkPathFile = new ClassPathDialog(toolsPath).show(scenicViewStage);
//
// if (jdkPathFile != null) {
// properties.setProperty(ScenicViewBooter.JDK_PATH_KEY, jdkPathFile.getAbsolutePath());
// PropertiesUtils.saveProperties();
// }
// }
// });
final MenuItem exitItem = new MenuItem("E_xit Scenic View");
exitItem.setAccelerator(KeyCombination.keyCombination("CTRL+Q"));
exitItem.setOnAction(event -> {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
close();
// TODO Why closing the Stage does not dispatch
// WINDOW_CLOSE_REQUEST??
scenicViewStage.close();
});
final Menu fileMenu = new Menu("File");
// if (updateStrategy.needsClassPathConfiguration()) {
// fileMenu.getItems().addAll(classpathItem, new SeparatorMenuItem());
// }
fileMenu.getItems().add(exitItem);
// ---- Options Menu
final CheckMenuItem showBoundsCheckbox = buildCheckMenuItem("Show Bounds Overlays", "Show the bound overlays on selected",
"Do not show bound overlays on selected", "showBounds", Boolean.TRUE);
showBoundsCheckbox.setId("show-bounds-checkbox");
// showBoundsCheckbox.setTooltip(new
// Tooltip("Display a yellow highlight for boundsInParent and green outline for layoutBounds."));
configuration.setShowBounds(showBoundsCheckbox.isSelected());
showBoundsCheckbox.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setShowBounds(newValue);
configurationUpdated();
});
final CheckMenuItem collapseControls = buildCheckMenuItem("Collapse controls In Tree", "Controls will be collapsed", "Controls will be expanded",
"collapseControls", Boolean.TRUE);
collapseControls.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setCollapseControls(newValue);
configurationUpdated();
});
configuration.setCollapseControls(collapseControls.isSelected());
final CheckMenuItem collapseContentControls = buildCheckMenuItem("Collapse container controls In Tree", "Container controls will be collapsed",
"Container controls will be expanded", "collapseContainerControls", Boolean.FALSE);
collapseContentControls.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setCollapseContentControls(newValue);
configurationUpdated();
});
collapseContentControls.disableProperty().bind(collapseControls.selectedProperty().not());
configuration.setCollapseContentControls(collapseContentControls.isSelected());
final CheckMenuItem showBaselineCheckbox = buildCheckMenuItem("Show Baseline Overlay", "Display a red line at the current node's baseline offset",
"Do not show baseline overlay", "showBaseline", Boolean.FALSE);
showBaselineCheckbox.setId("show-baseline-overlay");
configuration.setShowBaseline(showBaselineCheckbox.isSelected());
showBaselineCheckbox.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setShowBaseline(newValue);
configurationUpdated();
});
final CheckMenuItem automaticScenegraphStructureRefreshing = buildCheckMenuItem("Auto-Refresh Scenegraph",
"Scenegraph structure will be automatically updated on change", "Scenegraph structure will NOT be automatically updated on change",
"automaticScenegraphStructureRefreshing", Boolean.TRUE);
automaticScenegraphStructureRefreshing.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setAutoRefreshSceneGraph(automaticScenegraphStructureRefreshing.isSelected());
configurationUpdated();
});
configuration.setAutoRefreshSceneGraph(automaticScenegraphStructureRefreshing.isSelected());
// --- show search bar
showSearchBar = buildCheckMenuItem("Show Search Bar", "Shows a search bar to allow you to filter the displayed information",
"Shows a search bar to allow you to filter the displayed information", "showSearchBar", Boolean.TRUE);
searchBar.visibleProperty().bind(showSearchBar.selectedProperty());
searchBar.managedProperty().bind(showSearchBar.selectedProperty());
// --- show invisible nodes
showInvisibleNodes = buildCheckMenuItem("Show Invisible Nodes In Tree", "Invisible nodes will be faded in the scenegraph tree",
"Invisible nodes will not be shown in the scenegraph tree", "showInvisibleNodes", Boolean.FALSE);
final ChangeListener<Boolean> visilityListener = (o, oldValue, newValue) -> {
configuration.setVisibilityFilteringActive(!showInvisibleNodes.isSelected() && !showFilteredNodesInTree.isSelected());
configurationUpdated();
};
showInvisibleNodes.selectedProperty().addListener(visilityListener);
// --- show node IDs in tree
showNodesIdInTree = buildCheckMenuItem("Show Node IDs", "Node IDs will be shown on the scenegraph tree",
"Node IDs will not be shown the Scenegraph tree", "showNodesIdInTree", Boolean.FALSE);
showNodesIdInTree.selectedProperty().addListener(o -> update());
// --- show filtered nodes in tree
showFilteredNodesInTree = buildCheckMenuItem("Show Filtered Nodes In Tree", "Filtered nodes will be faded in the tree",
"Filtered nodes will not be shown in tree (unless they are parents of non-filtered nodes)", "showFilteredNodesInTree", Boolean.TRUE);
showFilteredNodesInTree.selectedProperty().addListener(visilityListener);
configuration.setVisibilityFilteringActive(!showInvisibleNodes.isSelected() && !showFilteredNodesInTree.isSelected());
/**
* Filter invisible nodes only makes sense if showFilteredNodesInTree is not selected
*/
showInvisibleNodes.disableProperty().bind(showFilteredNodesInTree.selectedProperty());
componentSelectOnClick = buildCheckMenuItem("Component highlight/select on click", "Click on the scene to select a component", "", null, null);
componentSelectOnClick.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> selectOnClick(newValue));
final CheckMenuItem ignoreMouseTransparentNodes = buildCheckMenuItem("Ignore MouseTransparent Nodes", "Transparent nodes will not be selectable",
"Transparent nodes can be selected", "ignoreMouseTransparentNodes", Boolean.TRUE);
ignoreMouseTransparentNodes.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setIgnoreMouseTransparent(newValue);
configurationUpdated();
});
configuration.setIgnoreMouseTransparent(ignoreMouseTransparentNodes.isSelected());
final CheckMenuItem registerShortcuts = buildCheckMenuItem("Register shortcuts", "SV Keyboard shortcuts will be registered on your app",
"SV Keyboard shortcuts will be removed on your app", "registerShortcuts", Boolean.TRUE);
registerShortcuts.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setRegisterShortcuts(newValue);
configurationUpdated();
});
configuration.setRegisterShortcuts(registerShortcuts.isSelected());
autoRefreshStyleSheets = buildCheckMenuItem("Auto-Refresh StyleSheets",
"A background thread will check modifications on the css files to reload them if needed", "StyleSheets autorefreshing disabled",
"autoRefreshStyleSheets", Boolean.FALSE);
autoRefreshStyleSheets.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
configuration.setAutoRefreshStyles(newValue);
configurationUpdated();
});
configuration.setAutoRefreshStyles(autoRefreshStyleSheets.isSelected());
final Menu scenegraphMenu = new Menu("Scenegraph");
scenegraphMenu.getItems().addAll(automaticScenegraphStructureRefreshing, autoRefreshStyleSheets, registerShortcuts, new SeparatorMenuItem(),
componentSelectOnClick, ignoreMouseTransparentNodes);
final Menu displayOptionsMenu = new Menu("Display Options");
// final Menu ruler = new Menu("Ruler");
// final CheckMenuItem showRuler = buildCheckMenuItem("Show Ruler", "Show ruler in the scene for alignment purposes", "", null, null);
// showRuler.selectedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
// configuration.setShowRuler(newValue.booleanValue());
// configurationUpdated();
// });
//
// final RulerConfigurationMenuItem rulerConfig = new RulerConfigurationMenuItem();
// rulerConfig.colorProperty().addListener(new ChangeListener<Color>() {
//
// @Override public void changed(final ObservableValue<? extends Color> arg0, final Color arg1, final Color newValue) {
// final int red = (int) (newValue.getRed() * 255);
// final int green = (int) (newValue.getGreen() * 255);
// final int blue = (int) (newValue.getBlue() * 255);
// configuration.setRulerColor(toHexByte(red) + toHexByte(green) + toHexByte(blue));
// configurationUpdated();
// }
//
// private String toHexByte(final int value) {
// return (value < 16) ? "0" + Integer.toString(value, 16) : Integer.toString(value, 16);
// }
// });
// rulerConfig.rulerSeparationProperty().addListener((ChangeListener<Number>) (o, oldValue, newValue) -> {
// configuration.setRulerSeparation(newValue.intValue());
// configurationUpdated();
// });
// configuration.setRulerSeparation(rulerConfig.rulerSeparationProperty().get());
// ruler.getItems().addAll(showRuler, rulerConfig);
displayOptionsMenu.getItems().addAll(showBoundsCheckbox,
showBaselineCheckbox,
// showRuler,
showSearchBar,
showFilteredNodesInTree,
showInvisibleNodes,
showNodesIdInTree,
collapseControls,
collapseContentControls);
final Menu aboutMenu = new Menu("Help");
final MenuItem help = new MenuItem("Help Contents");
help.setOnAction(event -> HelpBox.make("Help Contents", HELP_URL, scenicViewStage));
// final MenuItem newVersion = new MenuItem("Check For New Version");
// newVersion.setOnAction(new EventHandler<ActionEvent>() {
// @Override public void handle(final ActionEvent arg0) {
// checkNewVersion(true);
// }
// });
final MenuItem about = new MenuItem("About");
about.setOnAction(event -> AboutBox.make("About", scenicViewStage));
aboutMenu.getItems().addAll(help/*, newVersion*/, about);
menuBar.getMenus().addAll(fileMenu, displayOptionsMenu, scenegraphMenu, aboutMenu);
rootBorderPane.setTop(menuBar);
}
private void updateMenuBar(final Tab oldValue, final Tab newValue) {
if (oldValue != null && oldValue instanceof ContextMenuContainer) {
Menu menu = ((ContextMenuContainer) oldValue).getMenu();
menuBar.getMenus().remove(menu);
}
if (newValue != null && newValue instanceof ContextMenuContainer) {
Menu newMenu = ((ContextMenuContainer) newValue).getMenu();
if (newMenu != null) {
menuBar.getMenus().add(menuBar.getMenus().size() - 1, newMenu);
}
}
}
protected void selectOnClick(final boolean newValue) {
if (configuration.isComponentSelectOnClick() != newValue) {
configuration.setComponentSelectOnClick(newValue);
configurationUpdated();
}
}
// private void checkNewVersion(final boolean forced) {
// final SimpleDateFormat format = new SimpleDateFormat("ddMMyyyy");
// final String value = Persistence.loadProperty("lastVersionCheck", null);
// try {
// if (forced || value == null || ((System.currentTimeMillis() - format.parse(value).getTime()) > 86400000)) {
// Platform.runLater(new Runnable() {
// @Override public void run() {
// final String newVersion = VersionChecker.checkVersion(VERSION);
// String versionNum = null;
// if (newVersion != null) {
// // For now the version is on the first line
// versionNum = newVersion;
// if (newVersion.indexOf('\n') != -1) {
// versionNum = newVersion.substring(0, newVersion.indexOf('\n'));
// }
// // Now check whether our version is newer
// if (versionNum.compareTo(ScenicView.VERSION) < 0) {
// versionNum = null;
// }
// }
//
// if (versionNum != null) {
// new InfoBox("Version check", "New version found:" + versionNum + " (Yours is:" + ScenicView.VERSION + ")", newVersion, 400, 200);
// } else if (forced) {
// new InfoBox("Version check", "You already have the latest version of Scenic View.", null, 400, 150);
// }
//
// Persistence.saveProperty("lastVersionCheck", format.format(new Date()));
// }
// });
//
// }
// } catch (final Exception e) {
// ExceptionLogger.submitException(e);
// }
// }
public void removeApp(final AppController appController) {
treeView.removeApp(appController);
}
public void removeStage(final StageController stageController) {
treeView.removeStage(stageController);
}
public void setActiveStage(final StageController activeStage) {
this.activeStage = activeStage;
cssfxTab.setActiveStage(activeStage.getID());
}
public FXConnectorEventDispatcher getStageModelListener() {
return stageModelListener;
}
public void configurationUpdated() {
for (int i = 0; i < appRepository.getApps().size(); i++) {
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).isOpened()) {
stages.get(j).configurationUpdated(configuration);
}
}
}
}
public void animationsEnabled(final boolean enabled) {
for (int i = 0; i < appRepository.getApps().size(); i++) {
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).isOpened()) {
stages.get(j).animationsEnabled(enabled);
}
}
}
}
public void updateAnimations() {
animationsTab.clear();
for (int i = 0; i < appRepository.getApps().size(); i++) {
/**
* Only first stage
*/
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).isOpened()) {
stages.get(j).updateAnimations();
break;
}
}
}
}
public void pauseAnimation(final StageID id, final int animationID) {
for (int i = 0; i < appRepository.getApps().size(); i++) {
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).getID().equals(id)) {
stages.get(j).pauseAnimation(animationID);
}
}
}
updateAnimations();
}
private void loadAPI(final String property) {
if (tabPane.getTabs().contains(javadocTab)) {
if (property != null) {
goToTab(JavaDocTab.TAB_NAME);
}
if (javadocTab.isSelected()) {
javadocTab.loadAPI(property);
}
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public String findProperty(final String className, final String property) {
Class node = null;
try {
node = Class.forName(className);
node.getDeclaredMethod(property + "Property");
return className;
} catch (final Exception e) {
return findProperty(node.getSuperclass().getName(), property);
}
}
public void update() {
for (int i = 0; i < appRepository.getApps().size(); i++) {
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).isOpened()) {
stages.get(j).update();
}
}
}
}
StageController getStageController(final StageID id) {
for (int i = 0; i < appRepository.getApps().size(); i++) {
final List<StageController> stages = appRepository.getApps().get(i).getStages();
for (int j = 0; j < stages.size(); j++) {
if (stages.get(j).getID().equals(id)) {
return stages.get(j);
}
}
}
return appRepository.getApps().get(0).getStages().get(0);
// return null;
}
protected void filterProperties(final String text) {
detailsTab.filterProperties(text);
}
public void setSelectedNode(final StageController controller, final SVNode value) {
if (value != selectedNode) {
if (controller != null && activeStage != controller) {
/**
* Remove selected from previous active
*/
activeStage.setSelectedNode(null);
activeStage = controller;
}
storeSelectedNode(value);
eventsTab.setSelectedNode(value);
loadAPI(null);
propertyFilterField.setText("");
propertyFilterField.setDisable(value == null);
filterProperties(propertyFilterField.getText());
threeDOMTab.setSelectedNode(value); // 3D addition
cssfxTab.setActiveStage((controller==null)?null:controller.getID());
}
}
public SVNode getSelectedNode() {
return selectedNode;
}
public void removeNode() {
activeStage.removeSelectedNode();
}
private void storeSelectedNode(final SVNode value) {
selectedNode = value;
if (selectedNode != null && detailsTab.isSelected())
setStatusText("Click on the labels to modify its values. The panel could have different capabilities. When changed the values will be highlighted",
8000);
activeStage.setSelectedNode(value);
}
public CheckMenuItem buildCheckMenuItem(final String text, final String toolTipSelected, final String toolTipNotSelected, final String property,
final Boolean value) {
final CheckMenuItem menuItem = new CheckMenuItem(text);
if (property != null) {
Persistence.loadProperty(property, menuItem, value);
} else if (value != null) {
menuItem.setSelected(value);
}
menuItem.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override public void changed(final ObservableValue<? extends Boolean> arg0, final Boolean arg1, final Boolean newValue) {
setStatusText(newValue ? toolTipSelected : toolTipNotSelected, 4000);
}
});
return menuItem;
}
private FilterTextField createFilterField(final String prompt) {
return createFilterField(prompt, event -> update());
}
private FilterTextField createFilterField(final String prompt, final EventHandler<KeyEvent> keyHandler) {
final FilterTextField filterField = new FilterTextField();
filterField.setPromptText(prompt);
if (keyHandler != null) {
filterField.setOnKeyReleased(keyHandler);
}
filterField.focusedProperty().addListener((ChangeListener<Boolean>) (o, oldValue, newValue) -> {
if (newValue) {
setStatusText("Type any text for filtering");
} else {
clearStatusText();
}
});
return filterField;
}
private void closeApps() {
for (final Iterator<AppController> iterator = appRepository.getApps().iterator(); iterator.hasNext();) {
final AppController stage = iterator.next();
stage.close();
}
}
public void close() {
closeApps();
saveProperties();
updateStrategy.finish();
}
private void saveProperties() {
Persistence.saveProperties();
}
public void setStatusText(final String text) {
statusBar.setStatusText(text);
}
public void setStatusText(final String text, final long timeout) {
statusBar.setStatusText(text, timeout);
}
public void clearStatusText() {
statusBar.clearStatusText();
}
public boolean hasStatusText() {
return statusBar.hasStatus();
}
// @Override protected double computePrefWidth(final double height) {
// return 600;
// }
//
// @Override protected double computePrefHeight(final double width) {
// return 600;
// }
//
// @Override protected void layoutChildren() {
// layoutInArea(borderPane, getPadding().getLeft(), getPadding().getTop(), getWidth() - getPadding().getLeft() - getPadding().getRight(), getHeight()
// - getPadding().getTop() - getPadding().getBottom(), 0, HPos.LEFT, VPos.TOP);
// }
public final BorderPane getBorderPane() {
return rootBorderPane;
}
// /**
// * For autoTesting purposes
// */
// @Override public ObservableList<Node> getChildren() {
// return super.getChildren();
// }
public static void show(final ScenicViewGui scenicview, final Stage stage) {
final Scene scene = new Scene(scenicview.rootBorderPane);
scene.getStylesheets().addAll(STYLESHEETS);
stage.setScene(scene);
stage.getIcons().add(APP_ICON);
if (scenicview.activeStage != null && scenicview.activeStage instanceof StageControllerImpl)
((StageControllerImpl) scenicview.activeStage).placeStage(stage);
stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> {
Runtime.getRuntime().removeShutdownHook(scenicview.shutdownHook);
scenicview.close();
});
stage.show();
}
public void openStage(final StageController controller) {
controller.setEventDispatcher(stageModelListener);
controller.configurationUpdated(configuration);
}
public void forceUpdate() {
update();
}
public void goToTab(String tabName) {
Tab switchToTab = null;