2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
24 import jalview.datamodel.*;
\r
26 public class IdCanvas
\r
29 protected AlignViewport av;
\r
31 protected boolean showScores = true;
\r
33 protected int maxIdLength = -1;
\r
34 protected String maxIdStr = null;
\r
38 boolean fastPaint = false;
\r
40 java.util.Vector searchResults;
\r
42 public IdCanvas(AlignViewport av)
\r
46 PaintRefresher.Register(this, av.getSequenceSetId());
\r
49 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
\r
52 int charHeight = av.getCharHeight();
\r
54 if (searchResults != null && searchResults.contains(s))
\r
56 gg.setColor(Color.black);
\r
57 gg.fillRect(0, ( (i - starty) * charHeight) + ypos,
\r
58 getSize().width, charHeight);
\r
59 gg.setColor(Color.white);
\r
61 else if (av.getSelectionGroup() != null &&
\r
62 av.getSelectionGroup().getSequences(null).contains(s))
\r
64 gg.setColor(Color.lightGray);
\r
65 gg.fillRect(0, ( (i - starty) * charHeight) + ypos,
\r
66 getSize().width, charHeight);
\r
67 gg.setColor(Color.white);
\r
71 gg.setColor(av.getSequenceColour(s));
\r
72 gg.fillRect(0, ( (i - starty) * charHeight) + ypos,
\r
73 getSize().width, charHeight);
\r
74 gg.setColor(Color.black);
\r
77 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
\r
78 ( (i - starty) * charHeight) + ypos +
\r
79 charHeight - (charHeight / 5));
\r
81 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
83 drawMarker(i, starty, ypos);
\r
88 public void fastPaint(int vertical)
\r
96 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
\r
98 int ss = av.startSeq, es = av.endSeq, transY = 0;
\r
99 if (vertical > 0) // scroll down
\r
101 ss = es - vertical;
\r
102 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
\r
108 transY = imgHeight - vertical * av.charHeight;
\r
111 else if (vertical < 0)
\r
113 es = ss - vertical;
\r
114 if (es > av.endSeq)
\r
120 gg.translate(0, transY);
\r
124 gg.translate(0, -transY);
\r
130 public void update(Graphics g)
\r
135 public void paint(Graphics g)
\r
137 if (getSize().height < 0 || getSize().width < 0)
\r
144 g.drawImage(image, 0, 0, this);
\r
148 imgHeight = getSize().height;
\r
149 imgHeight -= imgHeight % av.charHeight;
\r
156 if (image == null || imgHeight != image.getHeight(this))
\r
158 image = createImage(getSize().width, imgHeight);
\r
159 gg = image.getGraphics();
\r
160 gg.setFont(av.getFont());
\r
163 //Fill in the background
\r
164 gg.setColor(Color.white);
\r
165 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
166 av.getFont().getSize());
\r
167 gg.setFont(italic);
\r
169 gg.fillRect(0, 0, getSize().width, getSize().height);
\r
170 drawIds(av.startSeq, av.endSeq);
\r
171 g.drawImage(image, 0, 0, this);
\r
174 void drawIds(int starty, int endy)
\r
176 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
177 av.getFont().getSize());
\r
179 gg.setFont(italic);
\r
181 Color currentColor = Color.white;
\r
182 Color currentTextColor = Color.black;
\r
184 if (av.getWrapAlignment())
\r
186 int maxwidth = av.alignment.getWidth();
\r
187 int alheight = av.alignment.getHeight();
\r
189 if (av.hasHiddenColumns)
\r
191 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
194 int annotationHeight = 0;
\r
195 AnnotationLabels labels = null;
\r
197 if (av.showAnnotation)
\r
199 AnnotationPanel ap = new AnnotationPanel(av);
\r
200 annotationHeight = ap.adjustPanelHeight();
\r
201 labels = new AnnotationLabels(av);
\r
204 int hgap = av.charHeight;
\r
205 if (av.scaleAboveWrapped)
\r
207 hgap += av.charHeight;
\r
210 int cHeight = alheight * av.charHeight
\r
212 + annotationHeight;
\r
214 int rowSize = av.getEndRes() - av.getStartRes();
\r
216 // Draw the rest of the panels
\r
217 for (int ypos = hgap, row = av.startRes;
\r
218 (ypos <= getSize().height) && (row < maxwidth);
\r
219 ypos += cHeight, row += rowSize)
\r
221 for (int i = starty; i < alheight; i++)
\r
223 if (av.hasHiddenRows)
\r
229 gg.setFont(italic);
\r
232 SequenceI s = av.alignment.getSequenceAt(i);
\r
233 drawIdString(gg, s, i, 0, ypos);
\r
236 if (labels != null)
\r
238 gg.translate(0, ypos + (alheight * av.charHeight));
\r
239 labels.drawComponent(gg, getSize().width);
\r
240 gg.translate(0, -ypos - (alheight * av.charHeight));
\r
247 //Now draw the id strings
\r
249 //Now draw the id strings
\r
251 for (int i = starty; i < endy; i++)
\r
253 if (av.hasHiddenRows)
\r
258 seq = av.alignment.getSequenceAt(i);
\r
264 // Selected sequence colours
\r
265 if ( (searchResults != null) &&
\r
266 searchResults.contains(seq))
\r
268 currentColor = Color.black;
\r
269 currentTextColor = Color.white;
\r
271 else if ( (av.getSelectionGroup() != null) &&
\r
272 av.getSelectionGroup().getSequences(null).contains(seq))
\r
274 currentColor = Color.lightGray;
\r
275 currentTextColor = Color.black;
\r
279 currentColor = av.getSequenceColour(seq);
\r
280 currentTextColor = Color.black;
\r
283 gg.setColor(currentColor);
\r
285 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
\r
288 gg.setColor(currentTextColor);
\r
290 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()),
\r
292 ( ( (i - starty) * av.charHeight) + av.charHeight) -
\r
293 (av.charHeight / 5));
\r
295 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
297 drawMarker(i, starty, 0);
\r
303 public void setHighlighted(java.util.Vector found)
\r
305 searchResults = found;
\r
309 void drawMarker(int i, int starty, int yoffset)
\r
311 SequenceI[] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
\r
312 //Use this method here instead of calling hiddenSeq adjust
\r
314 int hSize = hseqs.length;
\r
316 int hiddenIndex = i;
\r
317 int lastIndex = i - 1;
\r
318 int nextIndex = i + 1;
\r
320 boolean below = (hiddenIndex > lastIndex + 1);
\r
321 boolean above = (nextIndex > hiddenIndex + 1);
\r
323 for (int j = 0; j < hSize; j++)
\r
325 if (hseqs[j] != null)
\r
327 if (j - 1 < hiddenIndex)
\r
331 if (j - 1 < lastIndex)
\r
335 if (j - 1 < nextIndex)
\r
342 gg.setColor(Color.blue);
\r
345 gg.fillPolygon(new int[]
\r
346 {getSize().width - av.charHeight,
\r
347 getSize().width - av.charHeight,
\r
351 (i - starty) * av.charHeight + yoffset,
\r
352 (i - starty) * av.charHeight + yoffset + av.charHeight / 4,
\r
353 (i - starty) * av.charHeight + yoffset
\r
358 gg.fillPolygon(new int[]
\r
359 {getSize().width - av.charHeight,
\r
360 getSize().width - av.charHeight,
\r
364 (i - starty + 1) * av.charHeight + yoffset,
\r
365 (i - starty + 1) * av.charHeight + yoffset -
\r
367 (i - starty + 1) * av.charHeight + yoffset
\r
373 void setHiddenFont(int i)
\r
375 /* System.out.println(i+" "+av.alignment.getHeight());
\r
376 if (av.alignment.getSequenceAt(i).getHiddenSequences() != null)
\r
377 gg.setFont(new Font(av.getFont().getName(), Font.BOLD,
\r
378 av.getFont().getSize()));
\r
380 gg.setFont(new Font(av.getFont().getName(), Font.ITALIC,
\r
381 av.getFont().getSize()));*/
\r