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
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.alignment);
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(false).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(s.getColor());
72 gg.fillRect(0, ((i - starty) * charHeight) + ypos,
73 getSize().width, charHeight);
74 gg.setColor(Color.black);
78 gg.drawString( s.getDisplayId(av.getShowJVSuffix()), 0,
79 ((i - starty) * charHeight) + ypos +
80 charHeight - (charHeight / 5));
82 if (av.hasHiddenRows && av.showHiddenMarkers)
83 drawMarker(i, starty, ypos);
87 public void fastPaint(int vertical)
95 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
97 int ss = av.startSeq, es = av.endSeq, transY = 0;
98 if (vertical > 0) // scroll down
101 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
107 transY = imgHeight - vertical * av.charHeight;
110 else if (vertical < 0)
119 gg.translate(0, transY);
123 gg.translate(0, -transY);
129 public void update(Graphics g)
134 public void paint(Graphics g)
136 if (getSize().height < 0 || getSize().width < 0)
143 g.drawImage(image, 0, 0, this);
147 imgHeight = getSize().height;
148 imgHeight -= imgHeight % av.charHeight;
155 if (image == null || imgHeight != image.getHeight(this))
157 image = createImage(getSize().width, imgHeight);
158 gg = image.getGraphics();
159 gg.setFont(av.getFont());
162 //Fill in the background
163 gg.setColor(Color.white);
164 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
165 av.getFont().getSize());
168 gg.fillRect(0, 0, getSize().width, getSize().height);
169 drawIds(av.startSeq, av.endSeq);
170 g.drawImage(image, 0, 0, this);
173 void drawIds(int starty, int endy)
175 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
176 av.getFont().getSize());
180 Color currentColor = Color.white;
181 Color currentTextColor = Color.black;
183 if (av.getWrapAlignment())
185 int maxwidth = av.alignment.getWidth();
186 int alheight = av.alignment.getHeight();
188 if (av.hasHiddenColumns)
189 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
191 int annotationHeight = 0;
192 AnnotationLabels labels = null;
194 if (av.showAnnotation)
196 AnnotationPanel ap = new AnnotationPanel(av);
197 annotationHeight = ap.adjustPanelHeight();
198 labels = new AnnotationLabels(av);
201 int hgap = av.charHeight;
202 if (av.scaleAboveWrapped)
203 hgap += av.charHeight;
205 int cHeight = alheight * av.charHeight
209 int rowSize = av.getEndRes() - av.getStartRes();
211 // Draw the rest of the panels
212 for (int ypos = hgap, row = av.startRes;
213 (ypos <= getSize().height) && (row < maxwidth);
214 ypos += cHeight, row += rowSize)
216 for (int i = starty; i < alheight; i++)
218 if (av.hasHiddenRows)
225 SequenceI s = av.alignment.getSequenceAt(i);
226 drawIdString(gg, s, i, 0, ypos);
231 gg.translate(0, ypos + (alheight * av.charHeight));
232 labels.drawComponent(gg, getSize().width);
233 gg.translate(0, -ypos - (alheight * av.charHeight));
240 //Now draw the id strings
242 //Now draw the id strings
243 for (int i = starty; i < endy; i++)
245 if (av.hasHiddenRows)
250 // Selected sequence colours
251 if ( (searchResults != null) &&
252 searchResults.contains(av.alignment.getSequenceAt(i)))
254 currentColor = Color.black;
255 currentTextColor = Color.white;
257 else if ( (av.getSelectionGroup() != null) &&
258 av.getSelectionGroup().getSequences(false).contains(
259 av.alignment.getSequenceAt(i)))
261 currentColor = Color.lightGray;
262 currentTextColor = Color.black;
266 currentColor = av.alignment.getSequenceAt(i).getColor();
267 currentTextColor = Color.black;
270 gg.setColor(currentColor);
272 gg.fillRect(0, (i - starty) * av.charHeight, getSize().width,
275 gg.setColor(currentTextColor);
277 String string = av.alignment.getSequenceAt(i).getDisplayId(av.
280 gg.drawString(string, 0,
281 ( ( (i - starty) * av.charHeight) + av.charHeight) -
282 (av.charHeight / 5));
284 if (av.hasHiddenRows && av.showHiddenMarkers)
285 drawMarker(i, starty, 0);
290 public void setHighlighted(java.util.Vector found)
292 searchResults = found;
296 void drawMarker(int i, int starty, int yoffset)
298 int hiddenIndex = av.adjustForHiddenSeqs(i);
299 int lastIndex = av.adjustForHiddenSeqs(i - 1);
300 int nextIndex = av.adjustForHiddenSeqs(i + 1);
302 boolean below = (hiddenIndex > lastIndex + 1);
303 boolean above = (nextIndex>hiddenIndex+1);
305 gg.setColor(Color.blue);
308 gg.fillPolygon(new int[]
309 {getSize().width- av.charHeight,
310 getSize().width- av.charHeight,
314 (i - starty) * av.charHeight +yoffset,
315 (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,
316 (i - starty) * av.charHeight+yoffset
321 gg.fillPolygon(new int[]
322 {getSize().width- av.charHeight,
323 getSize().width - av.charHeight,
327 (i - starty+1) * av.charHeight +yoffset,
328 (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,
329 (i - starty+1) * av.charHeight +yoffset
335 void setHiddenFont(int i)
337 /* System.out.println(i+" "+av.alignment.getHeight());
338 if (av.alignment.getSequenceAt(i).getHiddenSequences() != null)
339 gg.setFont(new Font(av.getFont().getName(), Font.BOLD,
340 av.getFont().getSize()));
342 gg.setFont(new Font(av.getFont().getName(), Font.ITALIC,
343 av.getFont().getSize()));*/