@@ -338,7 +338,7 @@ public String getToolTipText(MouseEvent evt) {
338
338
}
339
339
340
340
/**
341
- * Overrides the super method to make sure hidden cells ae never editable.
341
+ * Overrides the super method to make sure hidden cells are never editable.
342
342
* If the specified cell is hidden (according to the underlying model),
343
343
* returns false; otherwise, passes on the query to super.
344
344
* @see JCell#isGrayedOut()
@@ -437,8 +437,10 @@ public Rectangle2D getGraphBounds() {
437
437
return getCellBounds (getRoots ());
438
438
}
439
439
440
- /** Refreshes the visibility and view of a given set of JCells. */
441
- public void refreshCells (Collection <? extends JCell <G >> jCellSet ) {
440
+ /** Refreshes the visibility and view of a given set of JCells.
441
+ * @param unselectGrayedOut if {@code true}, unselect all grayed-out cells.
442
+ */
443
+ public void refreshCells (Collection <? extends JCell <G >> jCellSet , boolean unselectGrayedOut ) {
442
444
if (!jCellSet .isEmpty ()) {
443
445
JGraphLayoutCache cache = getGraphLayoutCache ();
444
446
Collection <JCell <G >> visibleCells = new HashSet <>(jCellSet .size ());
@@ -468,10 +470,12 @@ public void refreshCells(Collection<? extends JCell<G>> jCellSet) {
468
470
}
469
471
}
470
472
JGraph .this .modelRefreshing = true ;
471
- // unselect all hidden and grayed-out cells
472
- var unselectedCells = new HashSet <>(hiddenCells );
473
- visibleCells .stream ().filter (JCell ::isGrayedOut ).forEach (unselectedCells ::add );
474
- getSelectionModel ().removeSelectionCells (unselectedCells .toArray ());
473
+ if (unselectGrayedOut ) {
474
+ // unselect all hidden and grayed-out cells
475
+ var unselectedCells = new HashSet <>(hiddenCells );
476
+ visibleCells .stream ().filter (JCell ::isGrayedOut ).forEach (unselectedCells ::add );
477
+ getSelectionModel ().removeSelectionCells (unselectedCells .toArray ());
478
+ }
475
479
// make sure refreshed cells are not selected
476
480
boolean selectsInsertedCells = cache .isSelectsLocalInsertedCells ();
477
481
cache .setSelectsLocalInsertedCells (false );
@@ -487,11 +491,14 @@ public void refreshCells(Collection<? extends JCell<G>> jCellSet) {
487
491
}
488
492
}
489
493
490
- /** Refreshes the visibility and view of all JCells in the model. */
491
- public void refreshAllCells () {
494
+ /**
495
+ * Refreshes the visibility and view of all JCells in the model.
496
+ * @param unselectGrayedOut if {@code true}, unselect all grayed-out cells.
497
+ */
498
+ public void refreshAllCells (boolean unselectGrayedOut ) {
492
499
var model = getModel ();
493
500
if (model != null ) {
494
- refreshCells (model .getRoots ());
501
+ refreshCells (model .getRoots (), unselectGrayedOut );
495
502
}
496
503
}
497
504
@@ -529,13 +536,15 @@ public void changeGrayedOut(Set<JCell<G>> jCells, boolean grayedOut) {
529
536
}
530
537
}
531
538
}
532
- model .toBackSilent (changedJCells );
533
- refreshCells (changedJCells );
539
+ if (grayedOut ) {
540
+ model .toBackSilent (changedJCells );
541
+ }
542
+ refreshCells (changedJCells , false );
534
543
}
535
544
536
545
/**
537
546
* Indicates if this {@link JGraph} is in the course of processing
538
- * a {@link #refreshCells(Collection)}. This allows listeners to ignore the
547
+ * a {@link #refreshCells(Collection, boolean )}. This allows listeners to ignore the
539
548
* resulting graph view update, if they wish.
540
549
*/
541
550
public boolean isModelRefreshing () {
@@ -1523,7 +1532,6 @@ class MyGraphSelectionListener implements GraphSelectionListener {
1523
1532
@ SuppressWarnings ("unchecked" )
1524
1533
@ Override
1525
1534
public void valueChanged (GraphSelectionEvent e ) {
1526
- Object [] cells = e .getCells ();
1527
1535
Object [] selectedCells = getSelectionCells ();
1528
1536
if (selectedCells .length > 0 ) {
1529
1537
getSelectionModel ().removeGraphSelectionListener (this );
@@ -1552,6 +1560,7 @@ public void valueChanged(GraphSelectionEvent e) {
1552
1560
getSelectionModel ().addGraphSelectionListener (this );
1553
1561
}
1554
1562
Object selectedCell = null ;
1563
+ Object [] cells = e .getCells ();
1555
1564
var viewBounds = getViewPortBounds ();
1556
1565
for (int i = 0 ; i < cells .length ; i ++) {
1557
1566
Object c = cells [i ];
@@ -1594,7 +1603,7 @@ protected void doRefresh() {
1594
1603
var model = getModel ();
1595
1604
assert model != null ;
1596
1605
model .refreshVisuals ();
1597
- refreshAllCells ();
1606
+ refreshAllCells (true );
1598
1607
}
1599
1608
}
1600
1609
0 commit comments