Skip to content

Commit 3344369

Browse files
committed
Improved interaction of selection & graying out of cells (sf #862)
1 parent 816f2d2 commit 3344369

File tree

9 files changed

+50
-33
lines changed

9 files changed

+50
-33
lines changed

src/main/java/nl/utwente/groove/gui/display/GraphEditorTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public void propertyChange(PropertyChangeEvent evt) {
401401
this.refreshing = true;
402402
getNonNullJModel().syncGraph();
403403
getJGraph().setEditable(mode != PREVIEW_MODE);
404-
getJGraph().refreshAllCells();
404+
getJGraph().refreshAllCells(true);
405405
getJGraph().refresh();
406406
this.refreshing = false;
407407
}

src/main/java/nl/utwente/groove/gui/display/LTSDisplay.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void stateChanged(ChangeEvent e) {
252252
if (getJModel().reloadGraph()) {
253253
getJGraph().refreshFiltering();
254254
getJGraph().refreshActive();
255-
getJGraph().refreshAllCells();
255+
getJGraph().refreshAllCells(true);
256256
getJGraph().doLayout(false);
257257
getJGraph().scrollToActive();
258258
}
@@ -526,7 +526,7 @@ public void doFilterLTS() {
526526
if (getJGraph().setFilter(getFilter())) {
527527
boolean layout = getJGraph().refreshFiltering();
528528
layout |= getJGraph().refreshActive();
529-
getJGraph().refreshAllCells();
529+
getJGraph().refreshAllCells(false);
530530
if (layout) {
531531
getJGraph().doLayout(false);
532532
}

src/main/java/nl/utwente/groove/gui/display/StateDisplay.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ public void update(SimulatorModel source, SimulatorModel oldModel, Set<Change> c
363363
}
364364
// all cells repainted, even though everything but the
365365
// edge colour seems to be OK even without doing this
366-
getJGraph().refreshAllCells();
366+
// Grayed-out selected elements should remain selected
367+
getJGraph().refreshAllCells(false);
367368
}
368369
updateStatus();
369370
activateListening();

src/main/java/nl/utwente/groove/gui/jgraph/JGraph.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public String getToolTipText(MouseEvent evt) {
338338
}
339339

340340
/**
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.
342342
* If the specified cell is hidden (according to the underlying model),
343343
* returns false; otherwise, passes on the query to super.
344344
* @see JCell#isGrayedOut()
@@ -437,8 +437,10 @@ public Rectangle2D getGraphBounds() {
437437
return getCellBounds(getRoots());
438438
}
439439

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) {
442444
if (!jCellSet.isEmpty()) {
443445
JGraphLayoutCache cache = getGraphLayoutCache();
444446
Collection<JCell<G>> visibleCells = new HashSet<>(jCellSet.size());
@@ -468,10 +470,12 @@ public void refreshCells(Collection<? extends JCell<G>> jCellSet) {
468470
}
469471
}
470472
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+
}
475479
// make sure refreshed cells are not selected
476480
boolean selectsInsertedCells = cache.isSelectsLocalInsertedCells();
477481
cache.setSelectsLocalInsertedCells(false);
@@ -487,11 +491,14 @@ public void refreshCells(Collection<? extends JCell<G>> jCellSet) {
487491
}
488492
}
489493

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) {
492499
var model = getModel();
493500
if (model != null) {
494-
refreshCells(model.getRoots());
501+
refreshCells(model.getRoots(), unselectGrayedOut);
495502
}
496503
}
497504

@@ -529,13 +536,15 @@ public void changeGrayedOut(Set<JCell<G>> jCells, boolean grayedOut) {
529536
}
530537
}
531538
}
532-
model.toBackSilent(changedJCells);
533-
refreshCells(changedJCells);
539+
if (grayedOut) {
540+
model.toBackSilent(changedJCells);
541+
}
542+
refreshCells(changedJCells, false);
534543
}
535544

536545
/**
537546
* 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
539548
* resulting graph view update, if they wish.
540549
*/
541550
public boolean isModelRefreshing() {
@@ -1523,7 +1532,6 @@ class MyGraphSelectionListener implements GraphSelectionListener {
15231532
@SuppressWarnings("unchecked")
15241533
@Override
15251534
public void valueChanged(GraphSelectionEvent e) {
1526-
Object[] cells = e.getCells();
15271535
Object[] selectedCells = getSelectionCells();
15281536
if (selectedCells.length > 0) {
15291537
getSelectionModel().removeGraphSelectionListener(this);
@@ -1552,6 +1560,7 @@ public void valueChanged(GraphSelectionEvent e) {
15521560
getSelectionModel().addGraphSelectionListener(this);
15531561
}
15541562
Object selectedCell = null;
1563+
Object[] cells = e.getCells();
15551564
var viewBounds = getViewPortBounds();
15561565
for (int i = 0; i < cells.length; i++) {
15571566
Object c = cells[i];
@@ -1594,7 +1603,7 @@ protected void doRefresh() {
15941603
var model = getModel();
15951604
assert model != null;
15961605
model.refreshVisuals();
1597-
refreshAllCells();
1606+
refreshAllCells(true);
15981607
}
15991608
}
16001609

src/main/java/nl/utwente/groove/gui/jgraph/JGraphUI.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import java.util.ArrayList;
4646
import java.util.Collection;
4747
import java.util.Collections;
48+
import java.util.LinkedList;
49+
import java.util.List;
4850

4951
import javax.swing.JComponent;
5052
import javax.swing.JViewport;
@@ -448,16 +450,20 @@ private void completeSelect(MouseEvent evt) {
448450
* the selection changes.
449451
*/
450452
private void selectCellsForEvent(Collection<JCell<G>> cells, MouseEvent evt) {
451-
if (cells.isEmpty()) {
453+
List<JCell<G>> nonGrayCells = new LinkedList<>();
454+
cells.stream().filter(c -> !c.isGrayedOut()).forEach(nonGrayCells::add);
455+
if (nonGrayCells.isEmpty()) {
452456
getJGraph().clearSelection();
453457
} else if (isToggleSelectionEvent(evt)) {
454-
for (JCell<G> jCell : cells) {
455-
toggleSelectionCellForEvent(jCell, evt);
458+
for (JCell<G> jCell : nonGrayCells) {
459+
if (!jCell.isGrayedOut()) {
460+
toggleSelectionCellForEvent(jCell, evt);
461+
}
456462
}
457463
} else if (isAddToSelectionEvent(evt)) {
458-
getJGraph().addSelectionCells(cells.toArray());
464+
getJGraph().addSelectionCells(nonGrayCells.toArray());
459465
} else {
460-
getJGraph().setSelectionCells(cells.toArray());
466+
getJGraph().setSelectionCells(nonGrayCells.toArray());
461467
}
462468
}
463469

src/main/java/nl/utwente/groove/gui/jgraph/LTSJGraph.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void reloadJModel() {
133133
if (getFilter() != Filter.NONE) {
134134
refreshFiltering();
135135
}
136-
refreshAllCells();
136+
refreshAllCells(true);
137137
refreshActive();
138138
doLayout(true);
139139
scrollToActive();
@@ -385,7 +385,7 @@ public boolean setActive(GraphState activeState, GraphTransition activeTrans) {
385385
setSelectionCells(activeCells.toArray());
386386
}
387387
if (!changedCells.isEmpty()) {
388-
refreshCells(changedCells);
388+
refreshCells(changedCells, false);
389389
}
390390
return result;
391391
}
@@ -442,7 +442,7 @@ void reactivate() {
442442
}
443443
if (!activeCells.isEmpty()) {
444444
setSelectionCells(activeCells.toArray());
445-
refreshCells(activeCells);
445+
refreshCells(activeCells, false);
446446
}
447447
}
448448

@@ -507,8 +507,9 @@ public boolean isResult(GraphTransition trans) {
507507
return result != null && result.contains(trans);
508508
}
509509

510-
/** Filters the LTS.
511-
* @return {@code true} if any cells were added (necessitating a relayout). */
510+
/** Filters the LTS according to the current value of {@link #getFilter()}.
511+
* @return {@code true} if any cells were added (necessitating a relayout).
512+
*/
512513
public boolean refreshFiltering() {
513514
boolean result = false;
514515
GTSFragment fragment;

src/main/java/nl/utwente/groove/gui/jgraph/LTSJModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void statusUpdate(GTS lts, GraphState explored, int change) {
103103
if (isExploring()) {
104104
this.changedCells.add(jCell);
105105
} else {
106-
getJGraph().refreshCells(Collections.singleton(jCell));
106+
getJGraph().refreshCells(Collections.singleton(jCell), false);
107107
}
108108
}
109109
}
@@ -310,7 +310,7 @@ public void setExploring(boolean exploring) {
310310
addElements(this.addedNodes, this.addedEdges, false);
311311
}
312312
if (!this.changedCells.isEmpty()) {
313-
getJGraph().refreshCells(this.changedCells);
313+
getJGraph().refreshCells(this.changedCells, true);
314314
}
315315
}
316316
}

src/main/java/nl/utwente/groove/gui/tree/LabelTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void installListeners() {
103103

104104
getFilter().addObserver(evt -> {
105105
LabelTree.this.repaint();
106-
getJGraph().refreshCells((Set<JCell<G>>) evt.getNewValue());
106+
getJGraph().refreshCells((Set<JCell<G>>) evt.getNewValue(), false);
107107
});
108108
addMouseListener(new MyMouseListener());
109109
}

src/main/java/nl/utwente/groove/gui/tree/RuleLevelTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public boolean isSelected() {
304304
public void setSelected(boolean selected) {
305305
this.selected = selected;
306306
Set<AspectJCell> changes = updateVisibleCells(Collections.singleton(this));
307-
getJGraph().refreshCells(changes);
307+
getJGraph().refreshCells(changes, false);
308308
}
309309

310310
@Override

0 commit comments

Comments
 (0)