From 473364adcfb651d06b6cdc179d2794e18e92b1f7 Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Tue, 28 Apr 2020 21:27:47 -0700 Subject: [PATCH] javadoc and tests --- .../display/layoutEditor/TrackSegment.java | 37 ++++- .../layoutEditor/TrackSegmentTest.java | 137 ++++++++++++++++++ 2 files changed, 168 insertions(+), 6 deletions(-) diff --git a/java/src/jmri/jmrit/display/layoutEditor/TrackSegment.java b/java/src/jmri/jmrit/display/layoutEditor/TrackSegment.java index a25ed847fe9..5e1ee5c84ab 100644 --- a/java/src/jmri/jmrit/display/layoutEditor/TrackSegment.java +++ b/java/src/jmri/jmrit/display/layoutEditor/TrackSegment.java @@ -1944,17 +1944,30 @@ public boolean isActive() { } public static final int SHOWCON = 0x01; - public static final int HIDECON = 0x02; //flag set on a segment basis. - public static final int HIDECONALL = 0x04; //Used by layout editor for hiding all + public static final int HIDECON = 0x02; // flag set on a segment basis. + public static final int HIDECONALL = 0x04; // Used by layout editor for hiding all public int showConstructionLine = SHOWCON; + /** + * @return true if HIDECON is not set and HIDECONALL is not set + */ public boolean isShowConstructionLines() { return (((showConstructionLine & HIDECON) != HIDECON) && ((showConstructionLine & HIDECONALL) != HIDECONALL)); } - //Methods used by Layout Editor + /** + * Method used by LayoutEditor. + *

+ * If the argument is + *

+ * Then always redraw the LayoutEditor panel and set it dirty. + */ public void hideConstructionLines(int hide) { if (hide == HIDECONALL) { showConstructionLine |= HIDECONALL; @@ -1971,6 +1984,9 @@ public void hideConstructionLines(int hide) { layoutEditor.setDirty(); } + /** + * @returns true if SHOWCON is not set + */ public boolean hideConstructionLines() { return ((showConstructionLine & SHOWCON) != SHOWCON); } @@ -3374,13 +3390,22 @@ else if (key.equals("tunnel")) { } //if (decorathions != null) } //setDirections - // - //arrow decoration accessors - // + /** + * Arrow decoration accessor. + * The 0 (none) and 1 through 5 arrow decorations are keyed to + * files like program:resources/icons/decorations/ArrowStyle1.png + * et al. + */ public int getArrowStyle() { return arrowStyle; } + /** + * Set the arrow decoration. + * The 0 (none) and 1 through 5 arrow decorations are keyed to + * files like program:resources/icons/decorations/ArrowStyle1.png + * et al. + */ public void setArrowStyle(int newVal) { if (arrowStyle != newVal) { if (newVal > 0) { diff --git a/java/test/jmri/jmrit/display/layoutEditor/TrackSegmentTest.java b/java/test/jmri/jmrit/display/layoutEditor/TrackSegmentTest.java index 71c890c0907..d6ef5d45756 100644 --- a/java/test/jmri/jmrit/display/layoutEditor/TrackSegmentTest.java +++ b/java/test/jmri/jmrit/display/layoutEditor/TrackSegmentTest.java @@ -34,6 +34,143 @@ public void testCtor() { } } + @Test + public void testConstructionLinesRead () { + trackSegment.showConstructionLine = 0; + Assert.assertTrue("From 0", trackSegment.isShowConstructionLines()); + Assert.assertTrue("From 0", trackSegment.hideConstructionLines()); + + trackSegment.showConstructionLine = trackSegment.HIDECONALL; + Assert.assertFalse("HIDECONALL", trackSegment.isShowConstructionLines()); + Assert.assertTrue("HIDECONALL", trackSegment.hideConstructionLines()); + + trackSegment.showConstructionLine = trackSegment.HIDECON; + Assert.assertFalse("HIDECON", trackSegment.isShowConstructionLines()); + Assert.assertTrue("HIDECON", trackSegment.hideConstructionLines()); + + trackSegment.showConstructionLine = trackSegment.SHOWCON; + Assert.assertTrue("SHOWCON", trackSegment.isShowConstructionLines()); + Assert.assertFalse("SHOWCON", trackSegment.hideConstructionLines()); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON | trackSegment.HIDECONALL; + Assert.assertFalse("all", trackSegment.isShowConstructionLines()); + Assert.assertFalse("all", trackSegment.hideConstructionLines()); + + } + + @Test + public void hideConstructionLinesOfInt() { + trackSegment.showConstructionLine = 0; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON); + + trackSegment.showConstructionLine = 0; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON ); + + trackSegment.showConstructionLine = 0; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.SHOWCON; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON); + + trackSegment.showConstructionLine = trackSegment.SHOWCON; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON); + + trackSegment.showConstructionLine = trackSegment.SHOWCON; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON | trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.HIDECON; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON); + + trackSegment.showConstructionLine = trackSegment.HIDECON; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON); + + trackSegment.showConstructionLine = trackSegment.HIDECON; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON |trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, 0); + + trackSegment.showConstructionLine = trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON ); + + trackSegment.showConstructionLine = trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.HIDECON |trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON); + + trackSegment.showConstructionLine = trackSegment.HIDECON |trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON ); + + trackSegment.showConstructionLine = trackSegment.HIDECON |trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON | trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON ); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON |trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON | trackSegment.HIDECON |trackSegment.HIDECONALL); + + // ---- + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON |trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.SHOWCON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON | trackSegment.HIDECON ); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON |trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECON); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.HIDECON); + + trackSegment.showConstructionLine = trackSegment.SHOWCON | trackSegment.HIDECON |trackSegment.HIDECONALL; + trackSegment.hideConstructionLines(trackSegment.HIDECONALL); + Assert.assertEquals(trackSegment.showConstructionLine, trackSegment.SHOWCON | trackSegment.HIDECON |trackSegment.HIDECONALL); + } + @Test public void testReplaceTrackConnection() { Assume.assumeFalse(GraphicsEnvironment.isHeadless());