2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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.alignment);
\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 imgHeight = getHeight();
\r
177 imgHeight -= (imgHeight % av.charHeight);
\r
184 image = new BufferedImage(getWidth(), imgHeight,
\r
185 BufferedImage.TYPE_INT_RGB);
\r
186 gg = (Graphics2D) image.getGraphics();
\r
188 //Fill in the background
\r
189 gg.setColor(Color.white);
\r
190 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
193 drawIds(av.getStartSeq(), av.endSeq);
\r
195 g.drawImage(image, 0, 0, this);
\r
201 * @param starty DOCUMENT ME!
\r
202 * @param endy DOCUMENT ME!
\r
204 void drawIds(int starty, int endy)
\r
206 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
207 av.getFont().getSize());
\r
209 gg.setFont(italic);
\r
212 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
213 RenderingHints.VALUE_ANTIALIAS_ON);
\r
215 Color currentColor = Color.white;
\r
216 Color currentTextColor = Color.black;
\r
218 if (av.getWrapAlignment())
\r
220 int maxwidth = av.alignment.getWidth();
\r
221 int alheight = av.alignment.getHeight();
\r
223 if (av.hasHiddenColumns)
\r
224 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
226 int annotationHeight = 0;
\r
227 AnnotationLabels labels = null;
\r
229 if(av.showAnnotation)
\r
231 AnnotationPanel ap = new AnnotationPanel(av);
\r
232 annotationHeight = ap.adjustPanelHeight();
\r
233 labels = new AnnotationLabels(av);
\r
236 int hgap = av.charHeight;
\r
237 if (av.scaleAboveWrapped)
\r
238 hgap += av.charHeight;
\r
240 int cHeight = alheight * av.charHeight
\r
242 + annotationHeight;
\r
244 int rowSize = av.getEndRes() - av.getStartRes();
\r
247 // Draw the rest of the panels
\r
248 for (int ypos = hgap, row = av.startRes;
\r
249 (ypos <= getHeight()) && (row < maxwidth);
\r
250 ypos += cHeight, row += rowSize)
\r
252 for (int i = starty; i < alheight; i++)
\r
254 if (av.hasHiddenRows)
\r
259 gg.setFont(italic);
\r
261 SequenceI s = av.alignment.getSequenceAt(i);
\r
262 drawIdString(gg, s, i, 0, ypos);
\r
267 gg.translate(0, ypos+(alheight * av.charHeight));
\r
268 labels.drawComponent(gg, getWidth());
\r
269 gg.translate(0, -ypos-(alheight * av.charHeight));
\r
277 //Now draw the id strings
\r
279 //Now draw the id strings
\r
280 for (int i = starty; i < endy; i++)
\r
282 if (av.hasHiddenRows)
\r
287 // Selected sequence colours
\r
288 if ( (searchResults != null) &&
\r
289 searchResults.contains(av.alignment.getSequenceAt(i)))
\r
291 currentColor = Color.black;
\r
292 currentTextColor = Color.white;
\r
294 else if ( (av.getSelectionGroup() != null) &&
\r
295 av.getSelectionGroup().getSequences(false).contains(
\r
296 av.alignment.getSequenceAt(i)))
\r
298 currentColor = Color.lightGray;
\r
299 currentTextColor = Color.black;
\r
303 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
304 currentTextColor = Color.black;
\r
307 gg.setColor(currentColor);
\r
309 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
\r
312 gg.setColor(currentTextColor);
\r
314 String string = av.alignment.getSequenceAt(i).getDisplayId( av.getShowJVSuffix());
\r
316 gg.drawString(string, 0,
\r
317 (((i - starty) * av.charHeight) + av.charHeight) -
\r
318 (av.charHeight / 5));
\r
320 if(av.hasHiddenRows && av.showHiddenMarkers)
\r
321 drawMarker(i, starty, 0);
\r
328 void drawMarker(int i, int starty, int yoffset)
\r
330 int hiddenIndex = av.adjustForHiddenSeqs(i);
\r
331 int lastIndex = av.adjustForHiddenSeqs(i - 1);
\r
332 int nextIndex = av.adjustForHiddenSeqs(i + 1);
\r
334 boolean below = (hiddenIndex > lastIndex + 1);
\r
335 boolean above = (nextIndex>hiddenIndex+1);
\r
337 gg.setColor(Color.blue);
\r
340 gg.fillPolygon(new int[]
\r
341 {getWidth()- av.charHeight,
\r
342 getWidth()- av.charHeight,
\r
346 (i - starty) * av.charHeight +yoffset,
\r
347 (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
\r
348 (i - starty) * av.charHeight+yoffset
\r
353 gg.fillPolygon(new int[]
\r
354 {getWidth()- av.charHeight,
\r
355 getWidth()- av.charHeight,
\r
359 (i - starty+1) * av.charHeight +yoffset,
\r
360 (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
\r
361 (i - starty+1) * av.charHeight +yoffset
\r
367 void setHiddenFont(int i)
\r
369 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
370 av.getFont().getSize());
\r
371 Font bold = new Font(av.getFont().getName(), Font.BOLD,
\r
372 av.getFont().getSize());
\r
374 if (av.alignment.getSequenceAt(i).getHiddenSequences() != null)
\r
377 gg.setFont(italic);
\r
383 * @param found DOCUMENT ME!
\r
385 public void setHighlighted(java.util.Vector found)
\r
387 searchResults = found;
\r