2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 package jalview.appletgui;
24 import jalview.datamodel.*;
29 protected AlignViewport av;
31 protected boolean showScores = true;
33 protected int maxIdLength = -1;
34 protected String maxIdStr = null;
38 boolean fastPaint = false;
40 java.util.Vector searchResults;
42 public IdCanvas(AlignViewport av)
46 PaintRefresher.Register(this, av.getSequenceSetId());
49 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
52 int charHeight = av.getCharHeight();
54 if (searchResults != null && searchResults.contains(s))
56 gg.setColor(Color.black);
57 gg.fillRect(0, ( (i - starty) * charHeight) + ypos,
58 getSize().width, charHeight);
59 gg.setColor(Color.white);
61 else if (av.getSelectionGroup() != null &&
62 av.getSelectionGroup().getSequences(null).contains(s))
64 gg.setColor(Color.lightGray);
65 gg.fillRect(0, ( (i - starty) * charHeight) + ypos,
66 getSize().width, charHeight);
67 gg.setColor(Color.white);
71 gg.setColor(av.getSequenceColour(s));
72 gg.fillRect(0, ( (i - starty) * charHeight) + ypos,
73 getSize().width, charHeight);
74 gg.setColor(Color.black);
77 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
78 ( (i - starty) * charHeight) + ypos +
79 charHeight - (charHeight / 5));
81 if (av.hasHiddenRows && av.showHiddenMarkers)
83 drawMarker(i, starty, ypos);
88 public void fastPaint(int vertical)
96 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
98 int ss = av.startSeq, es = av.endSeq, transY = 0;
99 if (vertical > 0) // scroll down
102 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
108 transY = imgHeight - vertical * av.charHeight;
111 else if (vertical < 0)
120 gg.translate(0, transY);
124 gg.translate(0, -transY);
130 public void update(Graphics g)
135 public void paint(Graphics g)
137 if (getSize().height < 0 || getSize().width < 0)
144 g.drawImage(image, 0, 0, this);
148 imgHeight = getSize().height;
149 imgHeight -= imgHeight % av.charHeight;
156 if (image == null || imgHeight != image.getHeight(this))
158 image = createImage(getSize().width, imgHeight);
159 gg = image.getGraphics();
160 gg.setFont(av.getFont());
163 //Fill in the background
164 gg.setColor(Color.white);
165 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
166 av.getFont().getSize());
169 gg.fillRect(0, 0, getSize().width, getSize().height);
170 drawIds(av.startSeq, av.endSeq);
171 g.drawImage(image, 0, 0, this);
174 void drawIds(int starty, int endy)
176 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
177 av.getFont().getSize());
181 Color currentColor = Color.white;
182 Color currentTextColor = Color.black;
184 if (av.getWrapAlignment())
186 int maxwidth = av.alignment.getWidth();
187 int alheight = av.alignment.getHeight();
189 if (av.hasHiddenColumns)
191 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
194 int annotationHeight = 0;
195 AnnotationLabels labels = null;
197 if (av.showAnnotation)
199 AnnotationPanel ap = new AnnotationPanel(av);
200 annotationHeight = ap.adjustPanelHeight();
201 labels = new AnnotationLabels(av);
204 int hgap = av.charHeight;
205 if (av.scaleAboveWrapped)
207 hgap += av.charHeight;
210 int cHeight = alheight * av.charHeight
214 int rowSize = av.getEndRes() - av.getStartRes();
216 // Draw the rest of the panels
217 for (int ypos = hgap, row = av.startRes;
218 (ypos <= getSize().height) && (row < maxwidth);
219 ypos += cHeight, row += rowSize)
221 for (int i = starty; i < alheight; i++)
224 SequenceI s = av.alignment.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.alignment.getSequenceAt(i);
255 //boolean isrep=false;
256 if (av.hasHiddenRows)
262 // Selected sequence colours
263 if ( (searchResults != null) &&
264 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 different way
283 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
285 gg.setColor(currentTextColor);
287 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()),
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(java.util.Vector found)
302 searchResults = found;
306 void drawMarker(int i, int starty, int yoffset)
308 SequenceI[] hseqs = av.alignment.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;
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,
345 getSize().width - av.charHeight,
349 (i - starty) * av.charHeight + yoffset,
350 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
351 (i - starty) * av.charHeight + yoffset
356 gg.fillPolygon(new int[]
357 {getSize().width - av.charHeight,
358 getSize().width - av.charHeight,
362 (i - starty + 1) * av.charHeight + yoffset,
363 (i - starty + 1) * av.charHeight + yoffset -
365 (i - starty + 1) * av.charHeight + yoffset
370 boolean setHiddenFont(SequenceI seq)
372 Font bold = new Font(av.getFont().getName(), Font.BOLD
374 av.getFont().getSize());
376 if (av.hiddenRepSequences != null &&
377 av.hiddenRepSequences.containsKey(seq))