Skip to content

Commit

Permalink
javadoc and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjacobsen committed Apr 29, 2020
1 parent 9b0da1b commit 473364a
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 6 deletions.
37 changes: 31 additions & 6 deletions java/src/jmri/jmrit/display/layoutEditor/TrackSegment.java
Expand Up @@ -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.
* <p>
* If the argument is
* <ul>
* <li>HIDECONALL then set HIDECONALL
* <li>SHOWCON reset HIDECONALL is set, other wise set SHOWCON
* <li>HIDECON or otherwise set HIDECON
* </ul>
* Then always redraw the LayoutEditor panel and set it dirty.
*/
public void hideConstructionLines(int hide) {
if (hide == HIDECONALL) {
showConstructionLine |= HIDECONALL;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
137 changes: 137 additions & 0 deletions java/test/jmri/jmrit/display/layoutEditor/TrackSegmentTest.java
Expand Up @@ -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());
Expand Down

0 comments on commit 473364a

Please sign in to comment.