public class ScaleRenderer
{
/**
- * calculate positions markers on the alignment ruler
- *
- * @return List { Object { .. } } Boolean: true/false for major/minor mark,
- * Integer: marker position in alignment column coords, String: null
- * or a String to be rendered at the position.
+ * Represents one major or minor scale mark
*/
- public static List<Object[]> calculateMarks(AlignViewportI av,
- int startx, int endx)
+ public final class ScaleMark
{
- new ArrayList<Object[]>();
+ /**
+ * 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)
+ {
+ major = isMajor;
+ 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);
+ }
+ }
+
+ /**
+ * Calculates position markers on the alignment ruler
+ *
+ * @param av
+ * @param startx
+ * left-most column in visible view (0..)
+ * @param endx
+ * - right-most column in visible view (0..)
+ * @return
+ */
+ public List<ScaleMark> calculateMarks(AlignViewportI av, int startx,
+ int endx)
+ {
int scalestartx = (startx / 10) * 10;
SequenceI refSeq = av.getAlignment().getSeqrep();
{
// find bounds and set origin appopriately
// locate first visible position for this sequence
- int[] refbounds = av.getColumnSelection()
+ int[] refbounds = av.getAlignment().getHiddenColumns()
.locateVisibleBoundsOfSequence(refSeq);
refSp = refbounds[0];
{
scalestartx += 5;
}
- List<Object[]> marks = new ArrayList<Object[]>();
- String string;
- int refN, iadj;
+ List<ScaleMark> marks = new ArrayList<ScaleMark>();
// 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)
{
- Object[] amark = new Object[3];
if (((i - refSp) % 10) == 0)
{
+ String text;
if (refSeq == null)
{
- iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1) + 1;
- string = String.valueOf(iadj);
+ int iadj = av.getAlignment().getHiddenColumns()
+ .adjustForHiddenColumns(i - 1) + 1;
+ text = String.valueOf(iadj);
}
else
{
- iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1);
- refN = refSeq.findPosition(iadj);
+ int iadj = av.getAlignment().getHiddenColumns()
+ .adjustForHiddenColumns(i - 1);
+ 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);
}
}
- amark[0] = Boolean.TRUE;
- amark[1] = Integer.valueOf(i - startx - 1);
- amark[2] = string;
-
+ marks.add(new ScaleMark(true, i - startx - 1, text));
}
else
{
- amark[0] = Boolean.FALSE;
- amark[1] = Integer.valueOf(i - startx - 1);
- amark[2] = null;
+ marks.add(new ScaleMark(false, i - startx - 1, null));
}
- marks.add(amark);
}
return marks;
}