*/
public class ScaleRenderer
{
+ /**
+ * Represents one major or minor scale mark
+ */
public final class ScaleMark
{
+ /**
+ * true for a major scale mark, false for minor
+ */
public final boolean major;
+ /**
+ * visible column position (0..) e.g. 19
+ */
public final int column;
+ /**
+ * text (if any) to show e.g. "20"
+ */
public final String text;
ScaleMark(boolean isMajor, int col, String txt)
column = col;
text = txt;
}
+
+ /**
+ * String representation for inspection when debugging only
+ */
+ @Override
+ public String toString()
+ {
+ return String.format("%s:%d:%s", major ? "major" : "minor", column,
+ text);
+ }
}
/**
- * calculate positions markers on the alignment ruler
+ * Calculates position markers on the alignment ruler
*
* @param av
* @param startx
- * left-most column in visible view
+ * left-most column in visible view (0..)
* @param endx
- * - right-most column in visible view
- * @return List of ScaleMark holding boolean: true/false for major/minor mark,
- * marker position in alignment column coords, a String to be rendered
- * at the position (or null)
+ * - right-most column in visible view (0..)
+ * @return
*/
public List<ScaleMark> calculateMarks(AlignViewportI av, int startx,
int endx)
scalestartx += 5;
}
List<ScaleMark> marks = new ArrayList<ScaleMark>();
- String string;
- int refN, iadj;
// todo: add a 'reference origin column' to set column number relative to
- for (int i = scalestartx; i < endx; i += 5)
+ for (int i = scalestartx; i <= endx; i += 5)
{
if (((i - refSp) % 10) == 0)
{
+ String text;
if (refSeq == null)
{
- iadj = av.getAlignment().getHiddenColumns()
+ int iadj = av.getAlignment().getHiddenColumns()
.adjustForHiddenColumns(i - 1) + 1;
- string = String.valueOf(iadj);
+ text = String.valueOf(iadj);
}
else
{
- iadj = av.getAlignment().getHiddenColumns()
+ int iadj = av.getAlignment().getHiddenColumns()
.adjustForHiddenColumns(i - 1);
- refN = refSeq.findPosition(iadj);
+ int refN = refSeq.findPosition(iadj);
// TODO show bounds if position is a gap
// - ie L--R -> "1L|2R" for
// marker
if (iadj < refStartI)
{
- string = String.valueOf(iadj - refStartI);
+ text = String.valueOf(iadj - refStartI);
}
else if (iadj > refEndI)
{
- string = "+" + String.valueOf(iadj - refEndI);
+ text = "+" + String.valueOf(iadj - refEndI);
}
else
{
- string = String.valueOf(refN) + refSeq.getCharAt(iadj);
+ text = String.valueOf(refN) + refSeq.getCharAt(iadj);
}
}
- marks.add(new ScaleMark(true, i - startx - 1, string));
+ marks.add(new ScaleMark(true, i - startx - 1, text));
}
else
{
AlignViewport av = af.getViewport();
/*
- * scale has minor ticks at 5 and 15, major at 10 and 20
+ * scale has minor ticks at 5, 15, 25, major at 10 and 20
* (these are base 1, ScaleMark holds base 0 values)
*/
List<ScaleMark> marks = new ScaleRenderer().calculateMarks(av, 0, 25);
- assertEquals(marks.size(), 4);
+ assertEquals(marks.size(), 5);
assertFalse(marks.get(0).major);
assertEquals(marks.get(0).column, 4);
assertEquals(marks.get(3).column, 19);
assertEquals(marks.get(3).text, "20");
+ assertFalse(marks.get(4).major);
+ assertEquals(marks.get(4).column, 24);
+ assertNull(marks.get(4).text);
+
/*
* now hide columns 9-11 and 18-20 (base 1)
* scale marks are now in the same columns as before, but
av.hideColumns(8, 10);
av.hideColumns(17, 19);
marks = new ScaleRenderer().calculateMarks(av, 0, 25);
- assertEquals(marks.size(), 4);
+ assertEquals(marks.size(), 5);
assertFalse(marks.get(0).major);
assertEquals(marks.get(0).column, 4);
assertNull(marks.get(0).text);
assertTrue(marks.get(3).major);
assertEquals(marks.get(3).column, 19);
assertEquals(marks.get(3).text, "26"); // +6 hidden columns
+ assertFalse(marks.get(4).major);
+ assertEquals(marks.get(4).column, 24);
+ assertNull(marks.get(4).text);
}
}