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