2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.renderer;
23 import jalview.api.AlignViewportI;
24 import jalview.datamodel.SequenceI;
26 import java.util.ArrayList;
27 import java.util.List;
30 * Calculate and display alignment rulers
35 public class ScaleRenderer
38 * Represents one major or minor scale mark
40 public final class ScaleMark
43 * true for a major scale mark, false for minor
45 public final boolean major;
48 * visible column position (0..) e.g. 19
50 public final int column;
53 * text (if any) to show e.g. "20"
55 public final String text;
57 ScaleMark(boolean isMajor, int col, String txt)
65 * String representation for inspection when debugging only
68 public String toString()
70 return String.format("%s:%d:%s", major ? "major" : "minor", column,
76 * Calculates position markers on the alignment ruler
80 * left-most column in visible view (0..)
82 * - right-most column in visible view (0..)
85 public List<ScaleMark> calculateMarks(AlignViewportI av, int startx,
88 int scalestartx = (startx / 10) * 10;
90 SequenceI refSeq = av.getAlignment().getSeqrep();
91 int refSp = 0, refStartI = 0, refEndI = -1;
94 // find bounds and set origin appopriately
95 // locate first visible position for this sequence
96 int[] refbounds = av.getAlignment().getHiddenColumns()
97 .locateVisibleBoundsOfSequence(refSeq);
100 refStartI = refbounds[4];
101 refEndI = refbounds[5];
102 scalestartx = refSp + ((scalestartx - refSp) / 10) * 10;
105 if (refSeq == null && scalestartx % 10 == 0)
109 List<ScaleMark> marks = new ArrayList<ScaleMark>();
110 // todo: add a 'reference origin column' to set column number relative to
111 for (int i = scalestartx; i <= endx; i += 5)
113 if (((i - refSp) % 10) == 0)
118 int iadj = av.getAlignment().getHiddenColumns()
119 .adjustForHiddenColumns(i - 1) + 1;
120 text = String.valueOf(iadj);
124 int iadj = av.getAlignment().getHiddenColumns()
125 .adjustForHiddenColumns(i - 1);
126 int refN = refSeq.findPosition(iadj);
127 // TODO show bounds if position is a gap
128 // - ie L--R -> "1L|2R" for
130 if (iadj < refStartI)
132 text = String.valueOf(iadj - refStartI);
134 else if (iadj > refEndI)
136 text = "+" + String.valueOf(iadj - refEndI);
140 text = String.valueOf(refN) + refSeq.getCharAt(iadj);
143 marks.add(new ScaleMark(true, i - startx - 1, text));
147 marks.add(new ScaleMark(false, i - startx - 1, null));