2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
24 import java.awt.image.*;
35 public class IdCanvas extends JPanel
37 protected AlignViewport av;
38 protected boolean showScores = true;
39 protected int maxIdLength = -1;
40 protected String maxIdStr = null;
44 boolean fastPaint = false;
45 java.util.Vector searchResults;
48 * Creates a new IdCanvas object.
50 * @param av DOCUMENT ME!
52 public IdCanvas(AlignViewport av)
54 setLayout(new BorderLayout());
56 PaintRefresher.Register(this, av.alignment);
62 * @param gg DOCUMENT ME!
63 * @param s DOCUMENT ME!
64 * @param i DOCUMENT ME!
65 * @param starty DOCUMENT ME!
66 * @param ypos DOCUMENT ME!
68 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, int ypos)
70 int charHeight = av.charHeight;
72 if ((searchResults != null) && searchResults.contains(s))
74 gg.setColor(Color.black);
75 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
77 gg.setColor(Color.white);
79 else if ((av.getSelectionGroup() != null) &&
80 av.getSelectionGroup().getSequences(false).contains(s))
82 gg.setColor(Color.lightGray);
83 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
85 gg.setColor(Color.white);
89 gg.setColor(s.getColor());
90 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
92 gg.setColor(Color.black);
96 gg.drawString( s.getDisplayId(av.getShowJVSuffix()),
97 0, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
99 if (av.hasHiddenRows && av.showHiddenMarkers)
100 drawMarker(i, starty, ypos);
108 * @param vertical DOCUMENT ME!
110 public void fastPaint(int vertical)
119 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
121 int ss = av.startSeq;
125 if (vertical > 0) // scroll down
129 if (ss < av.startSeq)
130 { // ie scrolling too fast, more than a page at a time
135 transY = imgHeight - (vertical * av.charHeight);
138 else if (vertical < 0)
148 gg.translate(0, transY);
152 gg.translate(0, -transY);
161 * @param g DOCUMENT ME!
163 public void paintComponent(Graphics g)
165 g.setColor(Color.white);
166 g.fillRect(0, 0, getWidth(), getHeight());
171 g.drawImage(image, 0, 0, this);
176 int oldHeight = imgHeight;
178 imgHeight = getHeight();
179 imgHeight -= (imgHeight % av.charHeight);
186 if(oldHeight!=imgHeight || image.getWidth(this)!=getWidth())
188 image = new BufferedImage(getWidth(), imgHeight,
189 BufferedImage.TYPE_INT_RGB);
192 gg = (Graphics2D) image.getGraphics();
193 //Fill in the background
194 gg.setColor(Color.white);
195 gg.fillRect(0, 0, getWidth(), imgHeight);
197 drawIds(av.getStartSeq(), av.endSeq);
199 g.drawImage(image, 0, 0, this);
205 * @param starty DOCUMENT ME!
206 * @param endy DOCUMENT ME!
208 void drawIds(int starty, int endy)
210 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
211 av.getFont().getSize());
216 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
217 RenderingHints.VALUE_ANTIALIAS_ON);
219 Color currentColor = Color.white;
220 Color currentTextColor = Color.black;
222 if (av.getWrapAlignment())
224 int maxwidth = av.alignment.getWidth();
225 int alheight = av.alignment.getHeight();
227 if (av.hasHiddenColumns)
228 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
230 int annotationHeight = 0;
231 AnnotationLabels labels = null;
233 if(av.showAnnotation)
235 AnnotationPanel ap = new AnnotationPanel(av);
236 annotationHeight = ap.adjustPanelHeight();
237 labels = new AnnotationLabels(av);
240 int hgap = av.charHeight;
241 if (av.scaleAboveWrapped)
242 hgap += av.charHeight;
244 int cHeight = alheight * av.charHeight
248 int rowSize = av.getEndRes() - av.getStartRes();
251 // Draw the rest of the panels
252 for (int ypos = hgap, row = av.startRes;
253 (ypos <= getHeight()) && (row < maxwidth);
254 ypos += cHeight, row += rowSize)
256 for (int i = starty; i < alheight; i++)
258 if (av.hasHiddenRows)
265 SequenceI s = av.alignment.getSequenceAt(i);
266 drawIdString(gg, s, i, 0, ypos);
271 gg.translate(0, ypos+(alheight * av.charHeight));
272 labels.drawComponent(gg, getWidth());
273 gg.translate(0, -ypos-(alheight * av.charHeight));
281 //Now draw the id strings
283 //Now draw the id strings
284 for (int i = starty; i < endy; i++)
286 if (av.hasHiddenRows)
291 // Selected sequence colours
292 if ( (searchResults != null) &&
293 searchResults.contains(av.alignment.getSequenceAt(i)))
295 currentColor = Color.black;
296 currentTextColor = Color.white;
298 else if ( (av.getSelectionGroup() != null) &&
299 av.getSelectionGroup().getSequences(false).contains(
300 av.alignment.getSequenceAt(i)))
302 currentColor = Color.lightGray;
303 currentTextColor = Color.black;
307 currentColor = av.alignment.getSequenceAt(i).getColor();
308 currentTextColor = Color.black;
311 gg.setColor(currentColor);
313 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
316 gg.setColor(currentTextColor);
318 String string = av.alignment.getSequenceAt(i).getDisplayId( av.getShowJVSuffix());
320 gg.drawString(string, 0,
321 (((i - starty) * av.charHeight) + av.charHeight) -
322 (av.charHeight / 5));
324 if(av.hasHiddenRows && av.showHiddenMarkers)
325 drawMarker(i, starty, 0);
332 void drawMarker(int i, int starty, int yoffset)
334 int hiddenIndex = av.adjustForHiddenSeqs(i);
335 int lastIndex = av.adjustForHiddenSeqs(i - 1);
336 int nextIndex = av.adjustForHiddenSeqs(i + 1);
338 boolean below = (hiddenIndex > lastIndex + 1);
339 boolean above = (nextIndex>hiddenIndex+1);
341 gg.setColor(Color.blue);
344 gg.fillPolygon(new int[]
345 {getWidth()- av.charHeight,
346 getWidth()- av.charHeight,
350 (i - starty) * av.charHeight +yoffset,
351 (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
352 (i - starty) * av.charHeight+yoffset
357 gg.fillPolygon(new int[]
358 {getWidth()- av.charHeight,
359 getWidth()- av.charHeight,
363 (i - starty+1) * av.charHeight +yoffset,
364 (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
365 (i - starty+1) * av.charHeight +yoffset
371 void setHiddenFont(int i)
373 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
374 av.getFont().getSize());
375 Font bold = new Font(av.getFont().getName(), Font.BOLD,
376 av.getFont().getSize());
378 if (av.alignment.getSequenceAt(i).getHiddenSequences() != null)
387 * @param found DOCUMENT ME!
389 public void setHighlighted(java.util.Vector found)
391 searchResults = found;