2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3 * Copyright (C) 2015 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.appletgui;
23 import jalview.datamodel.SequenceI;
25 import java.awt.Color;
27 import java.awt.Graphics;
28 import java.awt.Image;
29 import java.awt.Panel;
30 import java.util.List;
32 public class IdCanvas extends Panel
34 protected AlignViewport av;
36 protected boolean showScores = true;
38 protected int maxIdLength = -1;
40 protected String maxIdStr = null;
48 boolean fastPaint = false;
50 List<SequenceI> searchResults;
52 public IdCanvas(AlignViewport av)
56 PaintRefresher.Register(this, av.getSequenceSetId());
59 public void drawIdString(Graphics gg, boolean hiddenRows, SequenceI s,
60 int i, int starty, int ypos)
62 int charHeight = av.getCharHeight();
64 if (searchResults != null && searchResults.contains(s))
66 gg.setColor(Color.black);
67 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
69 gg.setColor(Color.white);
71 else if (av.getSelectionGroup() != null
72 && av.getSelectionGroup().getSequences(null).contains(s))
74 gg.setColor(Color.lightGray);
75 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
77 gg.setColor(Color.white);
81 gg.setColor(av.getSequenceColour(s));
82 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
84 gg.setColor(Color.black);
87 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
88 ((i - starty) * charHeight) + ypos + charHeight
93 drawMarker(i, starty, ypos);
98 public void fastPaint(int vertical)
106 gg.copyArea(0, 0, getSize().width, imgHeight, 0,
107 -vertical * av.getCharHeight());
109 int ss = av.startSeq, es = av.endSeq, transY = 0;
110 if (vertical > 0) // scroll down
113 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
119 transY = imgHeight - vertical * av.getCharHeight();
122 else if (vertical < 0)
131 gg.translate(0, transY);
135 gg.translate(0, -transY);
141 public void update(Graphics g)
146 public void paint(Graphics g)
148 if (getSize().height < 0 || getSize().width < 0)
155 g.drawImage(image, 0, 0, this);
159 imgHeight = getSize().height;
160 imgHeight -= imgHeight % av.getCharHeight();
167 if (image == null || imgHeight != image.getHeight(this))
169 image = createImage(getSize().width, imgHeight);
170 gg = image.getGraphics();
171 gg.setFont(av.getFont());
174 // Fill in the background
175 gg.setColor(Color.white);
176 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
177 .getFont().getSize());
180 gg.fillRect(0, 0, getSize().width, getSize().height);
181 drawIds(av.startSeq, av.endSeq);
182 g.drawImage(image, 0, 0, this);
186 * local copy of av.getCharHeight set at top of drawIds
188 private int avcharHeight;
190 void drawIds(int starty, int endy)
192 // hardwired italic IDs in applet currently
193 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
194 .getFont().getSize());
195 // temp variable for speed
196 avcharHeight = av.getCharHeight();
200 Color currentColor = Color.white;
201 Color currentTextColor = Color.black;
203 final boolean doHiddenCheck = av.isDisplayReferenceSeq()
204 || av.hasHiddenRows(), hiddenRows = av.hasHiddenRows()
205 && av.getShowHiddenMarkers();
207 if (av.getWrapAlignment())
209 int maxwidth = av.getAlignment().getWidth();
210 int alheight = av.getAlignment().getHeight();
212 if (av.hasHiddenColumns())
214 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
217 int annotationHeight = 0;
218 AnnotationLabels labels = null;
220 if (av.isShowAnnotation())
222 AnnotationPanel ap = new AnnotationPanel(av);
223 annotationHeight = ap.adjustPanelHeight();
224 labels = new AnnotationLabels(av);
226 int hgap = avcharHeight;
227 if (av.getScaleAboveWrapped())
229 hgap += avcharHeight;
232 int cHeight = alheight * avcharHeight + hgap + annotationHeight;
234 int rowSize = av.getEndRes() - av.getStartRes();
235 // Draw the rest of the panels
236 for (int ypos = hgap, row = av.startRes; (ypos <= getSize().height)
237 && (row < maxwidth); ypos += cHeight, row += rowSize)
239 for (int i = starty; i < alheight; i++)
242 SequenceI s = av.getAlignment().getSequenceAt(i);
248 drawIdString(gg, hiddenRows, s, i, 0, ypos);
253 gg.translate(0, ypos + (alheight * avcharHeight));
254 labels.drawComponent(gg, getSize().width);
255 gg.translate(0, -ypos - (alheight * avcharHeight));
262 // Now draw the id strings
264 for (int i = starty; i < endy; i++)
267 seq = av.getAlignment().getSequenceAt(i);
273 // boolean isrep=false;
280 // Selected sequence colours
281 if ((searchResults != null) && searchResults.contains(seq))
283 currentColor = Color.black;
284 currentTextColor = Color.white;
286 else if ((av.getSelectionGroup() != null)
287 && av.getSelectionGroup().getSequences(null).contains(seq))
289 currentColor = Color.lightGray;
290 currentTextColor = Color.black;
294 currentColor = av.getSequenceColour(seq);
295 currentTextColor = Color.black;
298 gg.setColor(currentColor);
299 // TODO: isrep could be used to highlight the representative in a
301 gg.fillRect(0, (i - starty) * avcharHeight, getSize().width,
303 gg.setColor(currentTextColor);
305 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
306 (((i - starty) * avcharHeight) + avcharHeight)
307 - (avcharHeight / 5));
311 drawMarker(i, starty, 0);
317 public void setHighlighted(List<SequenceI> list)
319 searchResults = list;
323 void drawMarker(int i, int starty, int yoffset)
325 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
326 // Use this method here instead of calling hiddenSeq adjust
328 int hSize = hseqs.length;
331 int lastIndex = i - 1;
332 int nextIndex = i + 1;
334 for (int j = 0; j < hSize; j++)
336 if (hseqs[j] != null)
338 if (j - 1 < hiddenIndex)
342 if (j - 1 < lastIndex)
346 if (j - 1 < nextIndex)
353 boolean below = (hiddenIndex > lastIndex + 1);
354 boolean above = (nextIndex > hiddenIndex + 1);
356 gg.setColor(Color.blue);
359 gg.fillPolygon(new int[] { getSize().width - avcharHeight,
360 getSize().width - avcharHeight, getSize().width }, new int[] {
361 (i - starty) * avcharHeight + yoffset,
362 (i - starty) * avcharHeight + yoffset + avcharHeight / 4,
363 (i - starty) * avcharHeight + yoffset }, 3);
367 gg.fillPolygon(new int[] { getSize().width - avcharHeight,
368 getSize().width - avcharHeight, getSize().width }, new int[] {
369 (i - starty + 1) * avcharHeight + yoffset,
370 (i - starty + 1) * avcharHeight + yoffset - avcharHeight / 4,
371 (i - starty + 1) * avcharHeight + yoffset }, 3);
376 boolean setHiddenFont(SequenceI seq)
378 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
381 if (av.isHiddenRepSequence(seq))