32
32
import com .sun .hotspot .igv .hierarchicallayout .LinearLayoutManager ;
33
33
import com .sun .hotspot .igv .layout .LayoutGraph ;
34
34
import com .sun .hotspot .igv .selectioncoordinator .SelectionCoordinator ;
35
- import com .sun .hotspot .igv .util .ColorIcon ;
36
- import com .sun .hotspot .igv .util .DoubleClickAction ;
37
- import com .sun .hotspot .igv .util .PropertiesSheet ;
35
+ import com .sun .hotspot .igv .util .*;
38
36
import com .sun .hotspot .igv .view .actions .CustomSelectAction ;
39
37
import com .sun .hotspot .igv .view .actions .CustomizablePanAction ;
40
38
import com .sun .hotspot .igv .view .actions .MouseZoomAction ;
70
68
*
71
69
* @author Thomas Wuerthinger
72
70
*/
73
- public class DiagramScene extends ObjectScene implements DiagramViewer {
71
+ public class DiagramScene extends ObjectScene implements DiagramViewer , DoubleClickHandler {
74
72
75
73
private final CustomizablePanAction panAction ;
76
74
private final WidgetAction hoverAction ;
@@ -186,26 +184,26 @@ public ChangedEvent<DiagramViewer> getZoomChangedEvent() {
186
184
}
187
185
188
186
@ Override
189
- public void centerFigures (List <Figure > figures ) {
190
- Rectangle overall = null ;
187
+ public void centerFigures (Collection <Figure > figures ) {
191
188
getModel ().showFigures (figures );
192
- for (Figure f : figures ) {
193
- FigureWidget fw = getWidget (f );
194
- if (fw != null ) {
195
- Rectangle r = fw .getBounds ();
196
- Point p = fw .getLocation ();
197
- assert r != null ;
198
- Rectangle r2 = new Rectangle (p .x , p .y , r .width , r .height );
199
-
200
- if (overall == null ) {
201
- overall = r2 ;
202
- } else {
203
- overall = overall .union (r2 );
189
+ Rectangle overallRect = null ;
190
+ for (Figure figure : figures ) {
191
+ FigureWidget figureWidget = getWidget (figure );
192
+ if (figureWidget != null ) {
193
+ Rectangle bounds = figureWidget .getBounds ();
194
+ if (bounds != null ) {
195
+ Point location = figureWidget .getLocation ();
196
+ Rectangle figureRect = new Rectangle (location .x , location .y , bounds .width , bounds .height );
197
+ if (overallRect == null ) {
198
+ overallRect = figureRect ;
199
+ } else {
200
+ overallRect = overallRect .union (figureRect );
201
+ }
204
202
}
205
203
}
206
204
}
207
- if (overall != null ) {
208
- centerRectangle (overall );
205
+ if (overallRect != null ) {
206
+ centerRectangle (overallRect );
209
207
}
210
208
}
211
209
@@ -221,7 +219,15 @@ public void filteredChanged(SelectionCoordinator source) {
221
219
222
220
@ Override
223
221
public void filteredChanged (SelectionCoordinator source ) {
224
- gotoSelection (source .getSelectedObjects ());
222
+ Set <Integer > ids = source .getSelectedObjects ();
223
+ Set <Figure > figures = new HashSet <>();
224
+ for (Figure f : getModel ().getDiagram ().getFigures ()) {
225
+ if (ids .contains (f .getInputNode ().getId ())) {
226
+ figures .add (f );
227
+ }
228
+ }
229
+ centerFigures (figures );
230
+ setSelectedObjects (idSetToObjectSet (ids ));
225
231
validate ();
226
232
}
227
233
};
@@ -286,6 +292,9 @@ public DiagramScene(Action[] actions, Action[] actionsWithSelection, DiagramView
286
292
panAction = new CustomizablePanAction (MouseEvent .BUTTON1_DOWN_MASK );
287
293
getActions ().addAction (panAction );
288
294
295
+ // handle default double-click, when not handled by other DoubleClickHandler
296
+ getActions ().addAction (new DoubleClickAction (this ));
297
+
289
298
selectAction = new CustomSelectAction (new SelectProvider () {
290
299
public boolean isAimingAllowed (Widget widget , Point localLocation , boolean invertSelection ) {
291
300
return false ;
@@ -375,7 +384,12 @@ public void select(Widget widget, Point localLocation, boolean invertSelection)
375
384
}
376
385
}
377
386
378
- setSelectedObjects (selectedObjects );
387
+ Set <Object > symmetricDiff = new HashSet <>(getSelectedObjects ());
388
+ symmetricDiff .addAll (selectedObjects );
389
+ Set <Object > tmp = new HashSet <>(getSelectedObjects ());
390
+ tmp .retainAll (selectedObjects );
391
+ symmetricDiff .removeAll (tmp );
392
+ setSelectedObjects (symmetricDiff );
379
393
};
380
394
getActions ().addAction (ActionFactory .createRectangularSelectAction (rectangularSelectDecorator , selectLayer , rectangularSelectProvider ));
381
395
@@ -487,46 +501,42 @@ public boolean isAllVisible() {
487
501
return getModel ().getHiddenNodes ().isEmpty ();
488
502
}
489
503
490
- public Action createGotoAction (final Figure f ) {
491
- final DiagramScene diagramScene = this ;
492
- String name = f .getLines ()[0 ];
493
-
504
+ public Action createGotoAction (final Figure figure ) {
505
+ String name = figure .getLines ()[0 ];
494
506
name += " (" ;
495
-
496
- if (f .getCluster () != null ) {
497
- name += "B" + f .getCluster ().toString ();
507
+ if (figure .getCluster () != null ) {
508
+ name += "B" + figure .getCluster ().toString ();
498
509
}
499
- final boolean hidden = !getWidget (f , FigureWidget .class ).isVisible ();
500
- if (hidden ) {
501
- if (f .getCluster () != null ) {
510
+ boolean isHidden = !getWidget (figure , FigureWidget .class ).isVisible ();
511
+ if (isHidden ) {
512
+ if (figure .getCluster () != null ) {
502
513
name += ", " ;
503
514
}
504
515
name += "hidden" ;
505
516
}
506
517
name += ")" ;
507
- Action a = new AbstractAction (name , new ColorIcon (f .getColor ())) {
508
-
518
+ Action action = new AbstractAction (name , new ColorIcon (figure .getColor ())) {
509
519
@ Override
510
520
public void actionPerformed (ActionEvent e ) {
511
- diagramScene .gotoFigure (f );
521
+ setFigureSelection (Collections .singleton (figure ));
522
+ centerFigures (Collections .singleton (figure ));
512
523
}
513
524
};
514
525
515
- a .setEnabled (true );
516
- return a ;
526
+ action .setEnabled (true );
527
+ return action ;
517
528
}
518
529
519
- public Action createGotoAction (final Block b ) {
520
- final DiagramScene diagramScene = this ;
521
- String name = "B" + b .getInputBlock ().getName ();
522
- Action a = new AbstractAction (name ) {
530
+ public Action createGotoAction (final Block block ) {
531
+ String name = "B" + block .getInputBlock ().getName ();
532
+ Action action = new AbstractAction (name ) {
523
533
@ Override
524
534
public void actionPerformed (ActionEvent e ) {
525
- diagramScene . gotoBlock (b );
535
+ gotoBlock (block );
526
536
}
527
537
};
528
- a .setEnabled (true );
529
- return a ;
538
+ action .setEnabled (true );
539
+ return action ;
530
540
}
531
541
532
542
private void update () {
@@ -561,7 +571,7 @@ private void update() {
561
571
f .setWidth (maxWidth .get (f .getBlock ().getInputBlock ()));
562
572
}
563
573
564
- FigureWidget w = new FigureWidget (f , hoverAction , selectAction , this , mainLayer );
574
+ FigureWidget w = new FigureWidget (f , this , mainLayer );
565
575
w .getActions ().addAction (ActionFactory .createPopupMenuAction (w ));
566
576
w .getActions ().addAction (selectAction );
567
577
w .getActions ().addAction (hoverAction );
@@ -588,7 +598,8 @@ private void update() {
588
598
589
599
if (getModel ().getShowBlocks () || getModel ().getShowCFG ()) {
590
600
for (InputBlock bn : d .getInputBlocks ()) {
591
- BlockWidget w = new BlockWidget (this , d , bn );
601
+ BlockWidget w = new BlockWidget (this , bn );
602
+ w .getActions ().addAction (new DoubleClickAction (w ));
592
603
w .setVisible (false );
593
604
addObject (bn , w );
594
605
blockLayer .addChild (w );
@@ -891,6 +902,11 @@ public void setInteractionMode(InteractionMode mode) {
891
902
// and the selection action handles it instead
892
903
}
893
904
905
+ @ Override
906
+ public void handleDoubleClick (Widget w , WidgetAction .WidgetMouseEvent e ) {
907
+ setSelectedObjects (Collections .emptySet ());
908
+ }
909
+
894
910
private class ConnectionSet {
895
911
896
912
private Set <Connection > connections ;
@@ -932,38 +948,6 @@ private Set<Object> idSetToObjectSet(Set<Integer> ids) {
932
948
return result ;
933
949
}
934
950
935
- private void gotoSelection (Set <Integer > ids ) {
936
-
937
- Rectangle overall = null ;
938
- Set <Integer > hiddenNodes = new HashSet <>(getModel ().getHiddenNodes ());
939
- hiddenNodes .removeAll (ids );
940
- getModel ().setHiddenNodes (hiddenNodes );
941
-
942
- Set <Object > objects = idSetToObjectSet (ids );
943
- for (Object o : objects ) {
944
-
945
- Widget w = getWidget (o );
946
- if (w != null ) {
947
- Rectangle r = w .getBounds ();
948
- Point p = w .convertLocalToScene (new Point (0 , 0 ));
949
-
950
- assert r != null ;
951
- Rectangle r2 = new Rectangle (p .x , p .y , r .width , r .height );
952
-
953
- if (overall == null ) {
954
- overall = r2 ;
955
- } else {
956
- overall = overall .union (r2 );
957
- }
958
- }
959
- }
960
- if (overall != null ) {
961
- centerRectangle (overall );
962
- }
963
-
964
- setSelectedObjects (objects );
965
- }
966
-
967
951
private void centerRectangle (Rectangle r ) {
968
952
Rectangle rect = convertSceneToView (r );
969
953
Rectangle viewRect = scrollPane .getViewport ().getViewRect ();
@@ -986,7 +970,7 @@ private void centerRectangle(Rectangle r) {
986
970
}
987
971
988
972
@ Override
989
- public void setSelection ( Collection <Figure > list ) {
973
+ public void setFigureSelection ( Set <Figure > list ) {
990
974
super .setSelectedObjects (new HashSet <>(list ));
991
975
}
992
976
@@ -1004,10 +988,6 @@ public UndoRedo getUndoRedo() {
1004
988
return getUndoRedoManager ();
1005
989
}
1006
990
1007
- private boolean isVisible (Figure f ) {
1008
- return !getModel ().getHiddenNodes ().contains (f .getInputNode ().getId ());
1009
- }
1010
-
1011
991
@ Override
1012
992
public void componentHidden () {
1013
993
SelectionCoordinator .getInstance ().getHighlightedChangedEvent ().removeListener (highlightedCoordinatorListener );
@@ -1122,31 +1102,6 @@ private void updateHiddenNodes(Set<Integer> newHiddenNodes, boolean doRelayout)
1122
1102
validate ();
1123
1103
}
1124
1104
1125
- private void showFigure (Figure f ) {
1126
- HashSet <Integer > newHiddenNodes = new HashSet <>(getModel ().getHiddenNodes ());
1127
- newHiddenNodes .remove (f .getInputNode ().getId ());
1128
- getModel ().setHiddenNodes (newHiddenNodes );
1129
- }
1130
-
1131
- private void centerWidget (Widget w ) {
1132
- Rectangle r = w .getBounds ();
1133
- Point p = w .getLocation ();
1134
- assert r != null ;
1135
- centerRectangle (new Rectangle (p .x , p .y , r .width , r .height ));
1136
- }
1137
-
1138
- public void gotoFigure (final Figure f ) {
1139
- if (!isVisible (f )) {
1140
- showFigure (f );
1141
- }
1142
-
1143
- FigureWidget fw = getWidget (f );
1144
- if (fw != null ) {
1145
- centerWidget (fw );
1146
- setSelection (Collections .singletonList (f ));
1147
- }
1148
- }
1149
-
1150
1105
public JPopupMenu createPopupMenu () {
1151
1106
JPopupMenu menu = new JPopupMenu ();
1152
1107
0 commit comments