2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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;
24 import java.util.List;
26 import jalview.datamodel.*;
28 public class IdCanvas extends Panel
30 protected AlignViewport av;
32 protected boolean showScores = true;
34 protected int maxIdLength = -1;
36 protected String maxIdStr = null;
44 boolean fastPaint = false;
46 List<SequenceI> searchResults;
48 public IdCanvas(AlignViewport av)
52 PaintRefresher.Register(this, av.getSequenceSetId());
55 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
58 int charHeight = av.getCharHeight();
60 if (searchResults != null && searchResults.contains(s))
62 gg.setColor(Color.black);
63 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
65 gg.setColor(Color.white);
67 else if (av.getSelectionGroup() != null
68 && av.getSelectionGroup().getSequences(null).contains(s))
70 gg.setColor(Color.lightGray);
71 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
73 gg.setColor(Color.white);
77 gg.setColor(av.getSequenceColour(s));
78 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
80 gg.setColor(Color.black);
83 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
84 ((i - starty) * charHeight) + ypos + charHeight
87 if (av.hasHiddenRows() && av.showHiddenMarkers)
89 drawMarker(i, starty, ypos);
94 public void fastPaint(int vertical)
102 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical
105 int ss = av.startSeq, es = av.endSeq, transY = 0;
106 if (vertical > 0) // scroll down
109 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
115 transY = imgHeight - vertical * av.charHeight;
118 else if (vertical < 0)
127 gg.translate(0, transY);
131 gg.translate(0, -transY);
137 public void update(Graphics g)
142 public void paint(Graphics g)
144 if (getSize().height < 0 || getSize().width < 0)
151 g.drawImage(image, 0, 0, this);
155 imgHeight = getSize().height;
156 imgHeight -= imgHeight % av.charHeight;
163 if (image == null || imgHeight != image.getHeight(this))
165 image = createImage(getSize().width, imgHeight);
166 gg = image.getGraphics();
167 gg.setFont(av.getFont());
170 // Fill in the background
171 gg.setColor(Color.white);
172 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
173 .getFont().getSize());
176 gg.fillRect(0, 0, getSize().width, getSize().height);
177 drawIds(av.startSeq, av.endSeq);
178 g.drawImage(image, 0, 0, this);
181 void drawIds(int starty, int endy)
183 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
184 .getFont().getSize());
188 Color currentColor = Color.white;
189 Color currentTextColor = Color.black;
191 if (av.getWrapAlignment())
193 int maxwidth = av.getAlignment().getWidth();
194 int alheight = av.getAlignment().getHeight();
196 if (av.hasHiddenColumns())
198 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
201 int annotationHeight = 0;
202 AnnotationLabels labels = null;
204 if (av.showAnnotation)
206 AnnotationPanel ap = new AnnotationPanel(av);
207 annotationHeight = ap.adjustPanelHeight();
208 labels = new AnnotationLabels(av);
211 int hgap = av.charHeight;
212 if (av.scaleAboveWrapped)
214 hgap += av.charHeight;
217 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
219 int rowSize = av.getEndRes() - av.getStartRes();
221 // Draw the rest of the panels
222 for (int ypos = hgap, row = av.startRes; (ypos <= getSize().height)
223 && (row < maxwidth); ypos += cHeight, row += rowSize)
225 for (int i = starty; i < alheight; i++)
228 SequenceI s = av.getAlignment().getSequenceAt(i);
230 if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
234 drawIdString(gg, s, i, 0, ypos);
239 gg.translate(0, ypos + (alheight * av.charHeight));
240 labels.drawComponent(gg, getSize().width);
241 gg.translate(0, -ypos - (alheight * av.charHeight));
248 // Now draw the id strings
250 for (int i = starty; i < endy; i++)
253 seq = av.getAlignment().getSequenceAt(i);
259 // boolean isrep=false;
260 if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
266 // Selected sequence colours
267 if ((searchResults != null) && searchResults.contains(seq))
269 currentColor = Color.black;
270 currentTextColor = Color.white;
272 else if ((av.getSelectionGroup() != null)
273 && av.getSelectionGroup().getSequences(null).contains(seq))
275 currentColor = Color.lightGray;
276 currentTextColor = Color.black;
280 currentColor = av.getSequenceColour(seq);
281 currentTextColor = Color.black;
284 gg.setColor(currentColor);
285 // TODO: isrep could be used to highlight the representative in a
287 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
289 gg.setColor(currentTextColor);
291 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
292 (((i - starty) * av.charHeight) + av.charHeight)
293 - (av.charHeight / 5));
295 if (av.hasHiddenRows() && av.showHiddenMarkers)
297 drawMarker(i, starty, 0);
303 public void setHighlighted(List<SequenceI> list)
305 searchResults = list;
309 void drawMarker(int i, int starty, int yoffset)
311 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
312 // Use this method here instead of calling hiddenSeq adjust
314 int hSize = hseqs.length;
317 int lastIndex = i - 1;
318 int nextIndex = i + 1;
320 for (int j = 0; j < hSize; j++)
322 if (hseqs[j] != null)
324 if (j - 1 < hiddenIndex)
328 if (j - 1 < lastIndex)
332 if (j - 1 < nextIndex)
339 boolean below = (hiddenIndex > lastIndex + 1);
340 boolean above = (nextIndex > hiddenIndex + 1);
342 gg.setColor(Color.blue);
345 gg.fillPolygon(new int[]
346 { getSize().width - av.charHeight, getSize().width - av.charHeight,
347 getSize().width }, new int[]
348 { (i - starty) * av.charHeight + yoffset,
349 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
350 (i - starty) * av.charHeight + yoffset }, 3);
354 gg.fillPolygon(new int[]
355 { getSize().width - av.charHeight, getSize().width - av.charHeight,
356 getSize().width }, new int[]
357 { (i - starty + 1) * av.charHeight + yoffset,
358 (i - starty + 1) * av.charHeight + yoffset - av.charHeight / 4,
359 (i - starty + 1) * av.charHeight + yoffset }, 3);
364 boolean setHiddenFont(SequenceI seq)
366 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
369 if (av.isHiddenRepSequence(seq))