Skip to content

Commit d5be09e

Browse files
Tom BrouwsTom Brouws
Tom Brouws
authored and
Tom Brouws
committed
Merge pull request #113 from ProgrammingLife3/fix/limitZoom
Added upper limit to zoom level
2 parents 6c09fe3 + a355c25 commit d5be09e

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/main/java/tudelft/ti2806/pl3/ScreenSize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public int getMinimumHeight() {
7777
* Calculate the sizes of the windows.
7878
*/
7979
public void calculate() {
80-
zoomBarHeight = calculate(ZoomBarView.ZOOMBAR_FACTOR, getHeight());
80+
zoomBarHeight = calculate(ZoomBarView.ZOOM_BAR_FACTOR, getHeight());
8181
sideBarWidth = calculate(SideBarView.SIDEBAR_FACTOR, getWidth());
8282
}
8383

src/main/java/tudelft/ti2806/pl3/visualization/ZoomedGraphModel.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class ZoomedGraphModel extends Observable implements Observer, LoadingObs
3737
* Minimum distance between nodes in pixels, can be overruled by {@link #MIN_NODE_COUNT}.
3838
*/
3939
private static final float MIN_NODE_DISTANCE = 60f;
40+
private static final float MIN_ZOOM_LEVEL = 1;
41+
private static final float MAX_ZOOM_LEVEL = 1000;
4042
private FilteredGraphModel filteredGraphModel;
4143

4244
private Wrapper collapsedNode;
@@ -67,8 +69,12 @@ public List<WrapperClone> getDataNodeWrapperList() {
6769
* the new zoom level
6870
*/
6971
public void setZoomLevel(float zoomLevel) {
70-
if (zoomLevel >= 1) {
71-
this.zoomLevel = zoomLevel;
72+
this.zoomLevel = zoomLevel;
73+
if (zoomLevel < MIN_ZOOM_LEVEL) {
74+
this.zoomLevel = MIN_ZOOM_LEVEL;
75+
}
76+
if (zoomLevel > MAX_ZOOM_LEVEL) {
77+
this.zoomLevel = MAX_ZOOM_LEVEL;
7278
}
7379
}
7480

src/main/java/tudelft/ti2806/pl3/zoombar/ZoomBarView.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
*/
2222
@SuppressWarnings("serial")
2323
public class ZoomBarView extends JPanel implements View, Observer {
24-
public static final double ZOOMBAR_FACTOR = 0.1;
24+
public static final double ZOOM_BAR_FACTOR = 0.1;
25+
private static final int INDICATOR_MIN_WIDTH = 5;
2526

2627
private int x = 0;
2728
private int width = -1;
@@ -80,7 +81,10 @@ private void drawInterest(Graphics g) {
8081
* graphics
8182
*/
8283
private void drawIndicator(Graphics g) {
83-
if (width > 0) {
84+
if (width != -1) {
85+
if (width < INDICATOR_MIN_WIDTH) {
86+
width = INDICATOR_MIN_WIDTH;
87+
}
8488
Graphics2D g2 = (Graphics2D) g;
8589
float thickness = 2;
8690
Stroke oldStroke = g2.getStroke();

src/test/java/tudelft/ti2806/pl3/ScreensizeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testHeight() {
3636
public void testCalculateZoombar() {
3737
screenSize.setHeight(testHeight);
3838
screenSize.calculate();
39-
int zoombarheight = (int) (ZoomBarView.ZOOMBAR_FACTOR * testHeight);
39+
int zoombarheight = (int) (ZoomBarView.ZOOM_BAR_FACTOR * testHeight);
4040
assertEquals(zoombarheight, screenSize.getZoomBarHeight());
4141

4242
}

src/test/java/tudelft/ti2806/pl3/visualisation/ZoomedGraphModelTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public void testZoom() {
3434
zoomedGraphModel.setZoomLevel(5);
3535
assertEquals(5, zoomedGraphModel.getZoomLevel(), 0);
3636
zoomedGraphModel.setZoomLevel(-1);
37-
assertEquals(5, zoomedGraphModel.getZoomLevel(), 0);
37+
assertEquals(1, zoomedGraphModel.getZoomLevel(), 0);
38+
zoomedGraphModel.setZoomLevel(1001);
39+
assertEquals(1000, zoomedGraphModel.getZoomLevel(), 0);
3840
}
3941
}

0 commit comments

Comments
 (0)