Skip to content

Commit

Permalink
Issue #466 Move getSelectedBounds to RenderingFacade
Browse files Browse the repository at this point in the history
First step in removing any computation involving rendering out of the
SelectionModel.
  • Loading branch information
prmr committed Jun 7, 2022
1 parent cf513dc commit 06875c1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/org/jetuml/gui/DiagramCanvasController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.jetuml.geom.Point;
import org.jetuml.geom.Rectangle;
import org.jetuml.viewers.Grid;
import org.jetuml.viewers.RenderingFacade;
import org.jetuml.viewers.nodes.NodeViewerRegistry;

import javafx.scene.input.MouseEvent;
Expand Down Expand Up @@ -167,7 +168,7 @@ public void paste()
}
Iterable<DiagramElement> newElements = Clipboard.instance().getElements();
if(!aSelectionModel.isEmpty() &&
viewerFor(aDiagramBuilder.getDiagram()).isOverlapping(aSelectionModel.getSelectionBounds(), newElements))
viewerFor(aDiagramBuilder.getDiagram()).isOverlapping(RenderingFacade.getBounds(aSelectionModel), newElements))
{
shiftElements(newElements, GRID_SIZE);
}
Expand Down
17 changes: 2 additions & 15 deletions src/org/jetuml/gui/SelectionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.jetuml.gui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -77,20 +78,6 @@ public void selectAll(DiagramData pDiagramData)
aObserver.selectionModelChanged();
}

/**
* @return A rectangle that represents the bounding
* box of the entire selection.
*/
public Rectangle getSelectionBounds()
{
Rectangle bounds = getLastSelectedBounds();
for(DiagramElement selected : aSelected )
{
bounds = bounds.add(DiagramViewer.getBounds(selected));
}
return bounds;
}

/*
* Returns a rectangle that represents the bounding box of the last selected element.
*/
Expand Down Expand Up @@ -378,7 +365,7 @@ public void set(DiagramElement pElement)
@Override
public Iterator<DiagramElement> iterator()
{
return aSelected.iterator();
return Collections.unmodifiableList(aSelected).iterator();
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/org/jetuml/viewers/RenderingFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
*******************************************************************************/
package org.jetuml.viewers;

import java.util.Iterator;

import org.jetuml.diagram.DiagramElement;
import org.jetuml.diagram.Edge;
import org.jetuml.diagram.Node;
import org.jetuml.geom.Rectangle;
import org.jetuml.viewers.edges.EdgeViewerRegistry;
import org.jetuml.viewers.nodes.NodeViewerRegistry;

Expand Down Expand Up @@ -56,4 +59,16 @@ public static Canvas createIcon(DiagramElement pElement)
}
}

public static Rectangle getBounds(Iterable<DiagramElement> pElements)
{
assert pElements != null;
assert pElements.iterator().hasNext();
Iterator<DiagramElement> elements = pElements.iterator();
Rectangle bounds = DiagramViewer.getBounds(elements.next());
while( elements.hasNext() )
{
bounds = bounds.add(DiagramViewer.getBounds(elements.next()));
}
return bounds;
}
}
3 changes: 2 additions & 1 deletion test/org/jetuml/gui/TestSelectionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.jetuml.geom.Line;
import org.jetuml.geom.Point;
import org.jetuml.geom.Rectangle;
import org.jetuml.viewers.RenderingFacade;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -104,7 +105,7 @@ private void assertEntireSelectionBounds(int pX, int pY, int pWidth, int pHeight

private void assertSelectionBounds(int pX, int pY, int pWidth, int pHeight)
{
assertEquals(new Rectangle(pX, pY, pWidth, pHeight), aModel.getSelectionBounds());
assertEquals(new Rectangle(pX, pY, pWidth, pHeight), RenderingFacade.getBounds(aModel));
}

@Test
Expand Down

0 comments on commit 06875c1

Please sign in to comment.