2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
24 import java.awt.image.*;
\r
26 import javax.swing.*;
\r
33 * @version $Revision$
\r
35 public class IdCanvas extends JPanel
\r
37 protected AlignViewport av;
\r
38 protected boolean showScores = true;
\r
39 protected int maxIdLength = -1;
\r
40 protected String maxIdStr = null;
\r
41 BufferedImage image;
\r
44 boolean fastPaint = false;
\r
45 java.util.Vector searchResults;
\r
48 * Creates a new IdCanvas object.
\r
50 * @param av DOCUMENT ME!
\r
52 public IdCanvas(AlignViewport av)
\r
54 setLayout(new BorderLayout());
\r
56 PaintRefresher.Register(this, av.getSequenceSetId());
\r
62 * @param gg DOCUMENT ME!
\r
63 * @param s DOCUMENT ME!
\r
64 * @param i DOCUMENT ME!
\r
65 * @param starty DOCUMENT ME!
\r
66 * @param ypos DOCUMENT ME!
\r
68 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, int ypos)
\r
70 int charHeight = av.charHeight;
\r
72 if ((searchResults != null) && searchResults.contains(s))
\r
74 gg.setColor(Color.black);
\r
75 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
77 gg.setColor(Color.white);
\r
79 else if ((av.getSelectionGroup() != null) &&
\r
80 av.getSelectionGroup().getSequences(false).contains(s))
\r
82 gg.setColor(Color.lightGray);
\r
83 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
85 gg.setColor(Color.white);
\r
89 gg.setColor(s.getColor());
\r
90 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
92 gg.setColor(Color.black);
\r
96 gg.drawString( s.getDisplayId(av.getShowJVSuffix()),
\r
97 0, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
\r
99 if (av.hasHiddenRows && av.showHiddenMarkers)
\r
100 drawMarker(i, starty, ypos);
\r
108 * @param vertical DOCUMENT ME!
\r
110 public void fastPaint(int vertical)
\r
119 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
\r
121 int ss = av.startSeq;
\r
122 int es = av.endSeq;
\r
125 if (vertical > 0) // scroll down
\r
127 ss = es - vertical;
\r
129 if (ss < av.startSeq)
\r
130 { // ie scrolling too fast, more than a page at a time
\r
135 transY = imgHeight - (vertical * av.charHeight);
\r
138 else if (vertical < 0)
\r
140 es = ss - vertical;
\r
142 if (es > av.endSeq)
\r
148 gg.translate(0, transY);
\r
152 gg.translate(0, -transY);
\r
161 * @param g DOCUMENT ME!
\r
163 public void paintComponent(Graphics g)
\r
165 g.setColor(Color.white);
\r
166 g.fillRect(0, 0, getWidth(), getHeight());
\r
171 g.drawImage(image, 0, 0, this);
\r
176 int oldHeight = imgHeight;
\r
178 imgHeight = getHeight();
\r
179 imgHeight -= (imgHeight % av.charHeight);
\r
186 if(oldHeight!=imgHeight || image.getWidth(this)!=getWidth())
\r
188 image = new BufferedImage(getWidth(), imgHeight,
\r
189 BufferedImage.TYPE_INT_RGB);
\r
192 gg = (Graphics2D) image.getGraphics();
\r
193 //Fill in the background
\r
194 gg.setColor(Color.white);
\r
195 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
197 drawIds(av.getStartSeq(), av.endSeq);
\r
199 g.drawImage(image, 0, 0, this);
\r
205 * @param starty DOCUMENT ME!
\r
206 * @param endy DOCUMENT ME!
\r
208 void drawIds(int starty, int endy)
\r
210 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
211 av.getFont().getSize());
\r
213 gg.setFont(italic);
\r
216 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
217 RenderingHints.VALUE_ANTIALIAS_ON);
\r
219 Color currentColor = Color.white;
\r
220 Color currentTextColor = Color.black;
\r
222 if (av.getWrapAlignment())
\r
224 int maxwidth = av.alignment.getWidth();
\r
225 int alheight = av.alignment.getHeight();
\r
227 if (av.hasHiddenColumns)
\r
228 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
230 int annotationHeight = 0;
\r
231 AnnotationLabels labels = null;
\r
233 if(av.showAnnotation)
\r
235 AnnotationPanel ap = new AnnotationPanel(av);
\r
236 annotationHeight = ap.adjustPanelHeight();
\r
237 labels = new AnnotationLabels(av);
\r
240 int hgap = av.charHeight;
\r
241 if (av.scaleAboveWrapped)
\r
242 hgap += av.charHeight;
\r
244 int cHeight = alheight * av.charHeight
\r
246 + annotationHeight;
\r
248 int rowSize = av.getEndRes() - av.getStartRes();
\r
251 // Draw the rest of the panels
\r
252 for (int ypos = hgap, row = av.startRes;
\r
253 (ypos <= getHeight()) && (row < maxwidth);
\r
254 ypos += cHeight, row += rowSize)
\r
256 for (int i = starty; i < alheight; i++)
\r
258 if (av.hasHiddenRows)
\r
263 gg.setFont(italic);
\r
265 SequenceI s = av.alignment.getSequenceAt(i);
\r
266 drawIdString(gg, s, i, 0, ypos);
\r
271 gg.translate(0, ypos+(alheight * av.charHeight));
\r
272 labels.drawComponent(gg, getWidth());
\r
273 gg.translate(0, -ypos-(alheight * av.charHeight));
\r
281 //Now draw the id strings
\r
283 SequenceI sequence;
\r
284 //Now draw the id strings
\r
285 for (int i = starty; i < endy; i++)
\r
287 sequence = av.alignment.getSequenceAt(i);
\r
289 if (av.hasHiddenRows)
\r
294 // Selected sequence colours
\r
295 if ( (searchResults != null) &&
\r
296 searchResults.contains(sequence))
\r
298 currentColor = Color.black;
\r
299 currentTextColor = Color.white;
\r
301 else if ( (av.getSelectionGroup() != null) &&
\r
302 av.getSelectionGroup().getSequences(false).contains(
\r
305 currentColor = Color.lightGray;
\r
306 currentTextColor = Color.black;
\r
310 currentColor = sequence.getColor();
\r
311 currentTextColor = Color.black;
\r
314 gg.setColor(currentColor);
\r
316 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
\r
319 gg.setColor(currentTextColor);
\r
321 String string = sequence.getDisplayId( av.getShowJVSuffix());
\r
323 gg.drawString(string, 0,
\r
324 (((i - starty) * av.charHeight) + av.charHeight) -
\r
325 (av.charHeight / 5));
\r
327 if(av.hasHiddenRows && av.showHiddenMarkers)
\r
328 drawMarker(i, starty, 0);
\r
335 void drawMarker(int i, int starty, int yoffset)
\r
338 SequenceI [] hseqs = av.alignment.getHiddenSequences().hiddenSequences;
\r
339 //Use this method here instead of calling hiddenSeq adjust
\r
341 int hSize = hseqs.length;
\r
343 int hiddenIndex = i;
\r
344 int lastIndex = i - 1;
\r
345 int nextIndex = i + 1;
\r
347 for(int j=0; j<hSize; j++)
\r
349 if (hseqs[j] != null)
\r
351 if(j-1<hiddenIndex)
\r
360 boolean below = (hiddenIndex > lastIndex + 1);
\r
361 boolean above = (nextIndex > hiddenIndex+1);
\r
364 gg.setColor(Color.blue);
\r
367 gg.fillPolygon(new int[]
\r
368 {getWidth()- av.charHeight,
\r
369 getWidth()- av.charHeight,
\r
373 (i - starty) * av.charHeight +yoffset,
\r
374 (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
\r
375 (i - starty) * av.charHeight+yoffset
\r
380 gg.fillPolygon(new int[]
\r
381 {getWidth()- av.charHeight,
\r
382 getWidth()- av.charHeight,
\r
386 (i - starty+1) * av.charHeight +yoffset,
\r
387 (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
\r
388 (i - starty+1) * av.charHeight +yoffset
\r
394 void setHiddenFont(int i)
\r
396 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
397 av.getFont().getSize());
\r
398 Font bold = new Font(av.getFont().getName(), Font.BOLD,
\r
399 av.getFont().getSize());
\r
402 if (av.alignment.getSequenceAt(i)!=null
\r
403 && av.alignment.getSequenceAt(i).getHiddenSequences() != null)
\r
406 gg.setFont(italic);
\r
412 * @param found DOCUMENT ME!
\r
414 public void setHighlighted(java.util.Vector found)
\r
416 searchResults = found;
\r