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.appletgui;
23 import jalview.datamodel.SequenceI;
24 import jalview.viewmodel.ViewportRanges;
26 import java.awt.Color;
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.Panel;
31 import java.util.List;
33 public class IdCanvas extends Panel
35 protected AlignViewport av;
37 protected boolean showScores = true;
39 protected int maxIdLength = -1;
41 protected String maxIdStr = null;
49 boolean fastPaint = false;
51 List<SequenceI> searchResults;
53 public IdCanvas(AlignViewport av)
57 PaintRefresher.Register(this, av.getSequenceSetId());
60 public void drawIdString(Graphics gg, boolean hiddenRows, SequenceI s,
61 int i, int starty, int ypos)
63 int charHeight = av.getCharHeight();
65 if (searchResults != null && searchResults.contains(s))
67 gg.setColor(Color.black);
68 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
70 gg.setColor(Color.white);
72 else if (av.getSelectionGroup() != null
73 && av.getSelectionGroup().getSequences(null).contains(s))
75 gg.setColor(Color.lightGray);
76 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
78 gg.setColor(Color.white);
82 gg.setColor(av.getSequenceColour(s));
83 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
85 gg.setColor(Color.black);
88 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
89 ((i - starty) * charHeight) + ypos + charHeight
94 drawMarker(i, starty, ypos);
99 public void fastPaint(int vertical)
107 ViewportRanges ranges = av.getRanges();
109 gg.copyArea(0, 0, getSize().width, imgHeight, 0,
110 -vertical * av.getCharHeight());
112 int ss = ranges.getStartSeq(), es = ranges.getEndSeq(), transY = 0;
113 if (vertical > 0) // scroll down
116 if (ss < ranges.getStartSeq()) // ie scrolling too fast, more than a page
120 ss = ranges.getStartSeq();
124 transY = imgHeight - ((vertical + 1) * av.getCharHeight());
127 else if (vertical < 0)
130 if (es > ranges.getEndSeq())
132 es = ranges.getEndSeq();
136 gg.translate(0, transY);
140 gg.translate(0, -transY);
147 public void update(Graphics g)
153 public void paint(Graphics g)
155 if (getSize().height < 0 || getSize().width < 0)
162 g.drawImage(image, 0, 0, this);
166 imgHeight = getSize().height;
167 imgHeight -= imgHeight % av.getCharHeight();
174 if (image == null || imgHeight != image.getHeight(this))
176 image = createImage(getSize().width, imgHeight);
177 gg = image.getGraphics();
178 gg.setFont(av.getFont());
181 // Fill in the background
182 gg.setColor(Color.white);
183 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
184 .getFont().getSize());
187 gg.fillRect(0, 0, getSize().width, getSize().height);
188 drawIds(av.getRanges().getStartSeq(), av.getRanges().getEndSeq());
189 g.drawImage(image, 0, 0, this);
193 * local copy of av.getCharHeight set at top of drawIds
195 private int avcharHeight;
197 void drawIds(int starty, int endy)
199 // hardwired italic IDs in applet currently
200 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
201 .getFont().getSize());
202 // temp variable for speed
203 avcharHeight = av.getCharHeight();
207 Color currentColor = Color.white;
208 Color currentTextColor = Color.black;
210 final boolean doHiddenCheck = av.isDisplayReferenceSeq()
211 || av.hasHiddenRows(), hiddenRows = av.hasHiddenRows()
212 && av.getShowHiddenMarkers();
214 if (av.getWrapAlignment())
216 int maxwidth = av.getAlignment().getWidth();
217 int alheight = av.getAlignment().getHeight();
219 if (av.hasHiddenColumns())
221 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
224 int annotationHeight = 0;
225 AnnotationLabels labels = null;
227 if (av.isShowAnnotation())
229 AnnotationPanel ap = new AnnotationPanel(av);
230 annotationHeight = ap.adjustPanelHeight();
231 labels = new AnnotationLabels(av);
233 int hgap = avcharHeight;
234 if (av.getScaleAboveWrapped())
236 hgap += avcharHeight;
239 int cHeight = alheight * avcharHeight + hgap + annotationHeight;
241 int rowSize = av.getRanges().getEndRes()
242 - av.getRanges().getStartRes();
243 // Draw the rest of the panels
244 for (int ypos = hgap, row = av.getRanges().getStartRes(); (ypos <= getSize().height)
245 && (row < maxwidth); ypos += cHeight, row += rowSize)
247 for (int i = starty; i < alheight; i++)
250 SequenceI s = av.getAlignment().getSequenceAt(i);
256 drawIdString(gg, hiddenRows, s, i, 0, ypos);
261 gg.translate(0, ypos + (alheight * avcharHeight));
262 labels.drawComponent(gg, getSize().width);
263 gg.translate(0, -ypos - (alheight * avcharHeight));
270 // Now draw the id strings
272 for (int i = starty; i <= endy; i++)
275 seq = av.getAlignment().getSequenceAt(i);
281 // boolean isrep=false;
288 // Selected sequence colours
289 if ((searchResults != null) && searchResults.contains(seq))
291 currentColor = Color.black;
292 currentTextColor = Color.white;
294 else if ((av.getSelectionGroup() != null)
295 && av.getSelectionGroup().getSequences(null).contains(seq))
297 currentColor = Color.lightGray;
298 currentTextColor = Color.black;
302 currentColor = av.getSequenceColour(seq);
303 currentTextColor = Color.black;
306 gg.setColor(currentColor);
307 // TODO: isrep could be used to highlight the representative in a
309 gg.fillRect(0, (i - starty) * avcharHeight, getSize().width,
311 gg.setColor(currentTextColor);
313 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
314 (((i - starty) * avcharHeight) + avcharHeight)
315 - (avcharHeight / 5));
319 drawMarker(i, starty, 0);
325 public void setHighlighted(List<SequenceI> list)
327 searchResults = list;
331 void drawMarker(int i, int starty, int yoffset)
333 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
334 // Use this method here instead of calling hiddenSeq adjust
336 int hSize = hseqs.length;
339 int lastIndex = i - 1;
340 int nextIndex = i + 1;
342 for (int j = 0; j < hSize; j++)
344 if (hseqs[j] != null)
346 if (j - 1 < hiddenIndex)
350 if (j - 1 < lastIndex)
354 if (j - 1 < nextIndex)
361 boolean below = (hiddenIndex > lastIndex + 1);
362 boolean above = (nextIndex > hiddenIndex + 1);
364 gg.setColor(Color.blue);
367 gg.fillPolygon(new int[] { getSize().width - avcharHeight,
368 getSize().width - avcharHeight, getSize().width }, new int[] {
369 (i - starty) * avcharHeight + yoffset,
370 (i - starty) * avcharHeight + yoffset + avcharHeight / 4,
371 (i - starty) * avcharHeight + yoffset }, 3);
375 gg.fillPolygon(new int[] { getSize().width - avcharHeight,
376 getSize().width - avcharHeight, getSize().width }, new int[] {
377 (i - starty + 1) * avcharHeight + yoffset,
378 (i - starty + 1) * avcharHeight + yoffset - avcharHeight / 4,
379 (i - starty + 1) * avcharHeight + yoffset }, 3);
384 boolean setHiddenFont(SequenceI seq)
386 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
389 if (av.isReferenceSeq(seq) || av.isHiddenRepSequence(seq))