2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
21 import java.util.List;
23 import jalview.datamodel.*;
25 public class IdCanvas extends Panel
27 protected AlignViewport av;
29 protected boolean showScores = true;
31 protected int maxIdLength = -1;
33 protected String maxIdStr = null;
41 boolean fastPaint = false;
43 List<SequenceI> searchResults;
45 public IdCanvas(AlignViewport av)
49 PaintRefresher.Register(this, av.getSequenceSetId());
52 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
55 int charHeight = av.getCharHeight();
57 if (searchResults != null && searchResults.contains(s))
59 gg.setColor(Color.black);
60 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
62 gg.setColor(Color.white);
64 else if (av.getSelectionGroup() != null
65 && av.getSelectionGroup().getSequences(null).contains(s))
67 gg.setColor(Color.lightGray);
68 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
70 gg.setColor(Color.white);
74 gg.setColor(av.getSequenceColour(s));
75 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
77 gg.setColor(Color.black);
80 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
81 ((i - starty) * charHeight) + ypos + charHeight
84 if (av.hasHiddenRows() && av.showHiddenMarkers)
86 drawMarker(i, starty, ypos);
91 public void fastPaint(int vertical)
99 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical
102 int ss = av.startSeq, es = av.endSeq, transY = 0;
103 if (vertical > 0) // scroll down
106 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
112 transY = imgHeight - vertical * av.charHeight;
115 else if (vertical < 0)
124 gg.translate(0, transY);
128 gg.translate(0, -transY);
134 public void update(Graphics g)
139 public void paint(Graphics g)
141 if (getSize().height < 0 || getSize().width < 0)
148 g.drawImage(image, 0, 0, this);
152 imgHeight = getSize().height;
153 imgHeight -= imgHeight % av.charHeight;
160 if (image == null || imgHeight != image.getHeight(this))
162 image = createImage(getSize().width, imgHeight);
163 gg = image.getGraphics();
164 gg.setFont(av.getFont());
167 // Fill in the background
168 gg.setColor(Color.white);
169 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
170 .getFont().getSize());
173 gg.fillRect(0, 0, getSize().width, getSize().height);
174 drawIds(av.startSeq, av.endSeq);
175 g.drawImage(image, 0, 0, this);
178 void drawIds(int starty, int endy)
180 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
181 .getFont().getSize());
185 Color currentColor = Color.white;
186 Color currentTextColor = Color.black;
188 if (av.getWrapAlignment())
190 int maxwidth = av.getAlignment().getWidth();
191 int alheight = av.getAlignment().getHeight();
193 if (av.hasHiddenColumns())
195 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
198 int annotationHeight = 0;
199 AnnotationLabels labels = null;
201 if (av.showAnnotation)
203 AnnotationPanel ap = new AnnotationPanel(av);
204 annotationHeight = ap.adjustPanelHeight();
205 labels = new AnnotationLabels(av);
208 int hgap = av.charHeight;
209 if (av.scaleAboveWrapped)
211 hgap += av.charHeight;
214 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
216 int rowSize = av.getEndRes() - av.getStartRes();
218 // Draw the rest of the panels
219 for (int ypos = hgap, row = av.startRes; (ypos <= getSize().height)
220 && (row < maxwidth); ypos += cHeight, row += rowSize)
222 for (int i = starty; i < alheight; i++)
225 SequenceI s = av.getAlignment().getSequenceAt(i);
227 if (av.hasHiddenRows())
231 drawIdString(gg, s, i, 0, ypos);
236 gg.translate(0, ypos + (alheight * av.charHeight));
237 labels.drawComponent(gg, getSize().width);
238 gg.translate(0, -ypos - (alheight * av.charHeight));
245 // Now draw the id strings
247 for (int i = starty; i < endy; i++)
250 seq = av.getAlignment().getSequenceAt(i);
256 // boolean isrep=false;
257 if (av.hasHiddenRows())
263 // Selected sequence colours
264 if ((searchResults != null) && searchResults.contains(seq))
266 currentColor = Color.black;
267 currentTextColor = Color.white;
269 else if ((av.getSelectionGroup() != null)
270 && av.getSelectionGroup().getSequences(null).contains(seq))
272 currentColor = Color.lightGray;
273 currentTextColor = Color.black;
277 currentColor = av.getSequenceColour(seq);
278 currentTextColor = Color.black;
281 gg.setColor(currentColor);
282 // TODO: isrep could be used to highlight the representative in a
284 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
286 gg.setColor(currentTextColor);
288 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
289 (((i - starty) * av.charHeight) + av.charHeight)
290 - (av.charHeight / 5));
292 if (av.hasHiddenRows() && av.showHiddenMarkers)
294 drawMarker(i, starty, 0);
300 public void setHighlighted(List<SequenceI> list)
302 searchResults = list;
306 void drawMarker(int i, int starty, int yoffset)
308 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
309 // Use this method here instead of calling hiddenSeq adjust
311 int hSize = hseqs.length;
314 int lastIndex = i - 1;
315 int nextIndex = i + 1;
317 for (int j = 0; j < hSize; j++)
319 if (hseqs[j] != null)
321 if (j - 1 < hiddenIndex)
325 if (j - 1 < lastIndex)
329 if (j - 1 < nextIndex)
336 boolean below = (hiddenIndex > lastIndex + 1);
337 boolean above = (nextIndex > hiddenIndex + 1);
339 gg.setColor(Color.blue);
342 gg.fillPolygon(new int[]
343 { getSize().width - av.charHeight, getSize().width - av.charHeight,
344 getSize().width }, new int[]
345 { (i - starty) * av.charHeight + yoffset,
346 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
347 (i - starty) * av.charHeight + yoffset }, 3);
351 gg.fillPolygon(new int[]
352 { getSize().width - av.charHeight, getSize().width - av.charHeight,
353 getSize().width }, new int[]
354 { (i - starty + 1) * av.charHeight + yoffset,
355 (i - starty + 1) * av.charHeight + yoffset - av.charHeight / 4,
356 (i - starty + 1) * av.charHeight + yoffset }, 3);
361 boolean setHiddenFont(SequenceI seq)
363 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
366 if (av.getHiddenRepSequences() != null
367 && av.getHiddenRepSequences().containsKey(seq))