2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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;
22 import jalview.datamodel.*;
24 public class IdCanvas extends Panel
26 protected AlignViewport av;
28 protected boolean showScores = true;
30 protected int maxIdLength = -1;
32 protected String maxIdStr = null;
40 boolean fastPaint = false;
42 java.util.Vector searchResults;
44 public IdCanvas(AlignViewport av)
48 PaintRefresher.Register(this, av.getSequenceSetId());
51 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
54 int charHeight = av.getCharHeight();
56 if (searchResults != null && searchResults.contains(s))
58 gg.setColor(Color.black);
59 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
61 gg.setColor(Color.white);
63 else if (av.getSelectionGroup() != null
64 && av.getSelectionGroup().getSequences(null).contains(s))
66 gg.setColor(Color.lightGray);
67 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
69 gg.setColor(Color.white);
73 gg.setColor(av.getSequenceColour(s));
74 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
76 gg.setColor(Color.black);
79 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
80 ((i - starty) * charHeight) + ypos + charHeight
83 if (av.hasHiddenRows() && av.showHiddenMarkers)
85 drawMarker(i, starty, ypos);
90 public void fastPaint(int vertical)
98 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical
101 int ss = av.startSeq, es = av.endSeq, transY = 0;
102 if (vertical > 0) // scroll down
105 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
111 transY = imgHeight - vertical * av.charHeight;
114 else if (vertical < 0)
123 gg.translate(0, transY);
127 gg.translate(0, -transY);
133 public void update(Graphics g)
138 public void paint(Graphics g)
140 if (getSize().height < 0 || getSize().width < 0)
147 g.drawImage(image, 0, 0, this);
151 imgHeight = getSize().height;
152 imgHeight -= imgHeight % av.charHeight;
159 if (image == null || imgHeight != image.getHeight(this))
161 image = createImage(getSize().width, imgHeight);
162 gg = image.getGraphics();
163 gg.setFont(av.getFont());
166 // Fill in the background
167 gg.setColor(Color.white);
168 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
169 .getFont().getSize());
172 gg.fillRect(0, 0, getSize().width, getSize().height);
173 drawIds(av.startSeq, av.endSeq);
174 g.drawImage(image, 0, 0, this);
177 void drawIds(int starty, int endy)
179 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
180 .getFont().getSize());
184 Color currentColor = Color.white;
185 Color currentTextColor = Color.black;
187 if (av.getWrapAlignment())
189 int maxwidth = av.getAlignment().getWidth();
190 int alheight = av.getAlignment().getHeight();
192 if (av.hasHiddenColumns())
194 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
197 int annotationHeight = 0;
198 AnnotationLabels labels = null;
200 if (av.showAnnotation)
202 AnnotationPanel ap = new AnnotationPanel(av);
203 annotationHeight = ap.adjustPanelHeight();
204 labels = new AnnotationLabels(av);
207 int hgap = av.charHeight;
208 if (av.scaleAboveWrapped)
210 hgap += av.charHeight;
213 int cHeight = alheight * av.charHeight + hgap + annotationHeight;
215 int rowSize = av.getEndRes() - av.getStartRes();
217 // Draw the rest of the panels
218 for (int ypos = hgap, row = av.startRes; (ypos <= getSize().height)
219 && (row < maxwidth); ypos += cHeight, row += rowSize)
221 for (int i = starty; i < alheight; i++)
224 SequenceI s = av.getAlignment().getSequenceAt(i);
226 if (av.hasHiddenRows())
230 drawIdString(gg, s, i, 0, ypos);
235 gg.translate(0, ypos + (alheight * av.charHeight));
236 labels.drawComponent(gg, getSize().width);
237 gg.translate(0, -ypos - (alheight * av.charHeight));
244 // Now draw the id strings
246 for (int i = starty; i < endy; i++)
249 seq = av.getAlignment().getSequenceAt(i);
255 // boolean isrep=false;
256 if (av.hasHiddenRows())
262 // Selected sequence colours
263 if ((searchResults != null) && searchResults.contains(seq))
265 currentColor = Color.black;
266 currentTextColor = Color.white;
268 else if ((av.getSelectionGroup() != null)
269 && av.getSelectionGroup().getSequences(null).contains(seq))
271 currentColor = Color.lightGray;
272 currentTextColor = Color.black;
276 currentColor = av.getSequenceColour(seq);
277 currentTextColor = Color.black;
280 gg.setColor(currentColor);
281 // TODO: isrep could be used to highlight the representative in a
283 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
285 gg.setColor(currentTextColor);
287 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
288 (((i - starty) * av.charHeight) + av.charHeight)
289 - (av.charHeight / 5));
291 if (av.hasHiddenRows() && av.showHiddenMarkers)
293 drawMarker(i, starty, 0);
299 public void setHighlighted(java.util.Vector found)
301 searchResults = found;
305 void drawMarker(int i, int starty, int yoffset)
307 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
308 // Use this method here instead of calling hiddenSeq adjust
310 int hSize = hseqs.length;
313 int lastIndex = i - 1;
314 int nextIndex = i + 1;
316 for (int j = 0; j < hSize; j++)
318 if (hseqs[j] != null)
320 if (j - 1 < hiddenIndex)
324 if (j - 1 < lastIndex)
328 if (j - 1 < nextIndex)
335 boolean below = (hiddenIndex > lastIndex + 1);
336 boolean above = (nextIndex > hiddenIndex + 1);
338 gg.setColor(Color.blue);
341 gg.fillPolygon(new int[]
342 { getSize().width - av.charHeight, getSize().width - av.charHeight,
343 getSize().width }, new int[]
344 { (i - starty) * av.charHeight + yoffset,
345 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
346 (i - starty) * av.charHeight + yoffset }, 3);
350 gg.fillPolygon(new int[]
351 { getSize().width - av.charHeight, getSize().width - av.charHeight,
352 getSize().width }, new int[]
353 { (i - starty + 1) * av.charHeight + yoffset,
354 (i - starty + 1) * av.charHeight + yoffset - av.charHeight / 4,
355 (i - starty + 1) * av.charHeight + yoffset }, 3);
360 boolean setHiddenFont(SequenceI seq)
362 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
365 if (av.getHiddenRepSequences() != null
366 && av.getHiddenRepSequences().containsKey(seq))