2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
22 import java.util.List;
24 import jalview.datamodel.*;
26 public class IdCanvas extends Panel
28 protected AlignViewport av;
30 protected boolean showScores = true;
32 protected int maxIdLength = -1;
34 protected String maxIdStr = null;
42 boolean fastPaint = false;
44 List<SequenceI> searchResults;
46 public IdCanvas(AlignViewport av)
50 PaintRefresher.Register(this, av.getSequenceSetId());
53 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
56 int charHeight = av.getCharHeight();
58 if (searchResults != null && searchResults.contains(s))
60 gg.setColor(Color.black);
61 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
63 gg.setColor(Color.white);
65 else if (av.getSelectionGroup() != null
66 && av.getSelectionGroup().getSequences(null).contains(s))
68 gg.setColor(Color.lightGray);
69 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
71 gg.setColor(Color.white);
75 gg.setColor(av.getSequenceColour(s));
76 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
78 gg.setColor(Color.black);
81 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
82 ((i - starty) * charHeight) + ypos + charHeight
85 if (av.hasHiddenRows() && av.showHiddenMarkers)
87 drawMarker(i, starty, ypos);
92 public void fastPaint(int vertical)
100 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical
103 int ss = av.startSeq, es = av.endSeq, transY = 0;
104 if (vertical > 0) // scroll down
107 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
113 transY = imgHeight - vertical * av.charHeight;
116 else if (vertical < 0)
125 gg.translate(0, transY);
129 gg.translate(0, -transY);
135 public void update(Graphics g)
140 public void paint(Graphics g)
142 if (getSize().height < 0 || getSize().width < 0)
149 g.drawImage(image, 0, 0, this);
153 imgHeight = getSize().height;
154 imgHeight -= imgHeight % av.charHeight;
161 if (image == null || imgHeight != image.getHeight(this))
163 image = createImage(getSize().width, imgHeight);
164 gg = image.getGraphics();
165 gg.setFont(av.getFont());
168 // Fill in the background
169 gg.setColor(Color.white);
170 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
171 .getFont().getSize());
174 gg.fillRect(0, 0, getSize().width, getSize().height);
175 drawIds(av.startSeq, av.endSeq);
176 g.drawImage(image, 0, 0, this);
179 void drawIds(int starty, int endy)
181 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
182 .getFont().getSize());
186 Color currentColor = Color.white;
187 Color currentTextColor = Color.black;
189 if (av.getWrapAlignment())
191 int maxwidth = av.getAlignment().getWidth();
192 int alheight = av.getAlignment().getHeight();
194 if (av.hasHiddenColumns())
196 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
199 int annotationHeight = 0;
200 AnnotationLabels labels = null;
202 if (av.showAnnotation)
204 AnnotationPanel ap = new AnnotationPanel(av);
205 annotationHeight = ap.adjustPanelHeight();
206 labels = new AnnotationLabels(av);
209 int hgap = av.charHeight;
210 if (av.scaleAboveWrapped)
212 hgap += av.charHeight;
215 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
217 int rowSize = av.getEndRes() - av.getStartRes();
219 // Draw the rest of the panels
220 for (int ypos = hgap, row = av.startRes; (ypos <= getSize().height)
221 && (row < maxwidth); ypos += cHeight, row += rowSize)
223 for (int i = starty; i < alheight; i++)
226 SequenceI s = av.getAlignment().getSequenceAt(i);
228 if (av.hasHiddenRows())
232 drawIdString(gg, s, i, 0, ypos);
237 gg.translate(0, ypos + (alheight * av.charHeight));
238 labels.drawComponent(gg, getSize().width);
239 gg.translate(0, -ypos - (alheight * av.charHeight));
246 // Now draw the id strings
248 for (int i = starty; i < endy; i++)
251 seq = av.getAlignment().getSequenceAt(i);
257 // boolean isrep=false;
258 if (av.hasHiddenRows())
264 // Selected sequence colours
265 if ((searchResults != null) && searchResults.contains(seq))
267 currentColor = Color.black;
268 currentTextColor = Color.white;
270 else if ((av.getSelectionGroup() != null)
271 && av.getSelectionGroup().getSequences(null).contains(seq))
273 currentColor = Color.lightGray;
274 currentTextColor = Color.black;
278 currentColor = av.getSequenceColour(seq);
279 currentTextColor = Color.black;
282 gg.setColor(currentColor);
283 // TODO: isrep could be used to highlight the representative in a
285 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
287 gg.setColor(currentTextColor);
289 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
290 (((i - starty) * av.charHeight) + av.charHeight)
291 - (av.charHeight / 5));
293 if (av.hasHiddenRows() && av.showHiddenMarkers)
295 drawMarker(i, starty, 0);
301 public void setHighlighted(List<SequenceI> list)
303 searchResults = list;
307 void drawMarker(int i, int starty, int yoffset)
309 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
310 // Use this method here instead of calling hiddenSeq adjust
312 int hSize = hseqs.length;
315 int lastIndex = i - 1;
316 int nextIndex = i + 1;
318 for (int j = 0; j < hSize; j++)
320 if (hseqs[j] != null)
322 if (j - 1 < hiddenIndex)
326 if (j - 1 < lastIndex)
330 if (j - 1 < nextIndex)
337 boolean below = (hiddenIndex > lastIndex + 1);
338 boolean above = (nextIndex > hiddenIndex + 1);
340 gg.setColor(Color.blue);
343 gg.fillPolygon(new int[]
344 { getSize().width - av.charHeight, getSize().width - av.charHeight,
345 getSize().width }, new int[]
346 { (i - starty) * av.charHeight + yoffset,
347 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
348 (i - starty) * av.charHeight + yoffset }, 3);
352 gg.fillPolygon(new int[]
353 { getSize().width - av.charHeight, getSize().width - av.charHeight,
354 getSize().width }, new int[]
355 { (i - starty + 1) * av.charHeight + yoffset,
356 (i - starty + 1) * av.charHeight + yoffset - av.charHeight / 4,
357 (i - starty + 1) * av.charHeight + yoffset }, 3);
362 boolean setHiddenFont(SequenceI seq)
364 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
367 if (av.getHiddenRepSequences() != null
368 && av.getHiddenRepSequences().containsKey(seq))