X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2FScaleRenderer.java;h=dc3272ff84decd7d8a0a499230a2850cbe870d58;hb=b7cb4c78d9d787e918c9d88f917a41642dd90a7a;hp=d91ea745113dcf7d57a5315b09af5123d2dc0b3f;hpb=721eacfd0eb9bfb415c60448b8ec8f24774b196b;p=jalview.git diff --git a/src/jalview/renderer/ScaleRenderer.java b/src/jalview/renderer/ScaleRenderer.java index d91ea74..dc3272f 100644 --- a/src/jalview/renderer/ScaleRenderer.java +++ b/src/jalview/renderer/ScaleRenderer.java @@ -21,9 +21,11 @@ package jalview.renderer; import jalview.api.AlignViewportI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** @@ -35,34 +37,72 @@ import java.util.List; 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) + { + major = isMajor; + column = col; + text = txt; + } + } + + /** * 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. + * @param av + * @param startx + * left-most column in visible view + * @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) */ - public static List calculateMarks(AlignViewportI av, - int startx, int endx) + public List calculateMarks(AlignViewportI av, int startx, + int endx) { - new ArrayList(); - int scalestartx = (startx / 10) * 10; SequenceI refSeq = av.getAlignment().getSeqrep(); - int refSp = 0, refEp = -1, refStart = 0, refEnd = -1, refStartI = 0, refEndI = -1; + int refSp = 0; + int refStartI = 0; + int refEndI = -1; + + HiddenColumns hc = av.getAlignment().getHiddenColumns(); + if (refSeq != null) { - // find bounds and set origin appopriately - // locate first visible position for this sequence - int[] refbounds = av.getColumnSelection() - .locateVisibleBoundsOfSequence(refSeq); + // find bounds and set origin appropriately + // locate first residue in sequence which is not hidden + Iterator it = hc.iterator(); + int index = refSeq.firstResidueOutsideIterator(it); + refSp = hc.absoluteToVisibleColumn(index); + + refStartI = refSeq.findIndex(refSeq.getStart()) - 1; + + int seqlength = refSeq.getLength(); + // get sequence position past the end of the sequence + int pastEndPos = refSeq.findPosition(seqlength + 1); + refEndI = refSeq.findIndex(pastEndPos - 1) - 1; - refSp = refbounds[0]; - refEp = refbounds[1]; - refStart = refbounds[2]; - refEnd = refbounds[3]; - refStartI = refbounds[4]; - refEndI = refbounds[5]; scalestartx = refSp + ((scalestartx - refSp) / 10) * 10; } @@ -70,23 +110,22 @@ public class ScaleRenderer { scalestartx += 5; } - List marks = new ArrayList(); + List marks = new ArrayList<>(); String string; - int maxX = 0, refN, iadj; + 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) { - Object[] amark = new Object[3]; if (((i - refSp) % 10) == 0) { if (refSeq == null) { - iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1) + 1; + iadj = hc.visibleToAbsoluteColumn(i - 1) + 1; string = String.valueOf(iadj); } else { - iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1); + iadj = hc.visibleToAbsoluteColumn(i - 1); refN = refSeq.findPosition(iadj); // TODO show bounds if position is a gap // - ie L--R -> "1L|2R" for @@ -104,18 +143,12 @@ public class ScaleRenderer string = 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, string)); } 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; }