2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.datamodel.SequenceI;
\r
25 import java.awt.Color;
\r
26 import java.awt.Font;
\r
27 import java.awt.Graphics;
\r
28 import java.awt.Image;
\r
29 import javax.swing.JPanel;
\r
30 import java.util.List;
\r
32 public class IdCanvas extends JPanel
\r
34 protected AlignViewport av;
\r
36 protected boolean showScores = true;
\r
38 protected int maxIdLength = -1;
\r
40 protected String maxIdStr = null;
\r
48 boolean fastPaint = false;
\r
50 List<SequenceI> searchResults;
\r
52 public IdCanvas(AlignViewport av)
\r
56 PaintRefresher.Register(this, av.getSequenceSetId());
\r
59 public void drawIdString(Graphics gg, boolean hiddenRows, SequenceI s,
\r
63 int charHeight = av.getCharHeight();
\r
65 if (searchResults != null && searchResults.contains(s))
\r
67 gg.setColor(Color.black);
\r
68 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
\r
70 gg.setColor(Color.white);
\r
72 else if (av.getSelectionGroup() != null
\r
73 && av.getSelectionGroup().getSequences(null).contains(s))
\r
75 gg.setColor(Color.lightGray);
\r
76 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
\r
78 gg.setColor(Color.white);
\r
82 gg.setColor(av.getSequenceColour(s));
\r
83 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
\r
85 gg.setColor(Color.black);
\r
88 gg.drawString(s.getDisplayId(av.getShowJVSuffix()), 0,
\r
89 ((i - starty) * charHeight) + ypos + charHeight
\r
90 - (charHeight / 5));
\r
94 drawMarker(i, starty, ypos);
\r
99 public void fastPaint(int vertical)
\r
107 gg.copyArea(0, 0, getSize().width, imgHeight, 0,
\r
108 -vertical * av.getCharHeight());
\r
110 int ss = av.startSeq, es = av.endSeq, transY = 0;
\r
111 if (vertical > 0) // scroll down
\r
113 ss = es - vertical;
\r
114 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
\r
120 transY = imgHeight - vertical * av.getCharHeight();
\r
123 else if (vertical < 0)
\r
125 es = ss - vertical;
\r
126 if (es > av.endSeq)
\r
132 gg.translate(0, transY);
\r
136 gg.translate(0, -transY);
\r
142 public void update(Graphics g)
\r
147 public void paint(Graphics g)
\r
149 if (getSize().height < 0 || getSize().width < 0)
\r
156 g.drawImage(image, 0, 0, this);
\r
160 imgHeight = getSize().height;
\r
161 imgHeight -= imgHeight % av.getCharHeight();
\r
168 if (image == null || imgHeight != image.getHeight(this))
\r
170 image = createImage(getSize().width, imgHeight);
\r
171 gg = image.getGraphics();
\r
172 gg.setFont(av.getFont());
\r
175 // Fill in the background
\r
176 gg.setColor(Color.white);
\r
177 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
\r
178 .getFont().getSize());
\r
179 gg.setFont(italic);
\r
181 gg.fillRect(0, 0, getSize().width, getSize().height);
\r
182 drawIds(av.startSeq, av.endSeq);
\r
183 g.drawImage(image, 0, 0, this);
\r
187 * local copy of av.getCharHeight set at top of drawIds
\r
189 private int avcharHeight;
\r
190 void drawIds(int starty, int endy)
\r
192 // hardwired italic IDs in applet currently
\r
193 Font italic = new Font(av.getFont().getName(), Font.ITALIC, av
\r
194 .getFont().getSize());
\r
195 // temp variable for speed
\r
196 avcharHeight = av.getCharHeight();
\r
198 gg.setFont(italic);
\r
200 Color currentColor = Color.white;
\r
201 Color currentTextColor = Color.black;
\r
203 final boolean doHiddenCheck = av.isDisplayReferenceSeq()
\r
204 || av.hasHiddenRows(), hiddenRows = av.hasHiddenRows()
\r
205 && av.getShowHiddenMarkers();
\r
207 if (av.getWrapAlignment())
\r
209 int maxwidth = av.getAlignment().getWidth();
\r
210 int alheight = av.getAlignment().getHeight();
\r
212 if (av.hasHiddenColumns())
\r
214 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
\r
217 int annotationHeight = 0;
\r
218 AnnotationLabels labels = null;
\r
220 if (av.isShowAnnotation())
\r
222 AnnotationPanel ap = new AnnotationPanel(av);
\r
223 annotationHeight = ap.adjustPanelHeight();
\r
224 labels = new AnnotationLabels(av);
\r
226 int hgap = avcharHeight;
\r
227 if (av.getScaleAboveWrapped())
\r
229 hgap += avcharHeight;
\r
232 int cHeight = alheight * avcharHeight + hgap + annotationHeight;
\r
234 int rowSize = av.getEndRes() - av.getStartRes();
\r
235 // Draw the rest of the panels
\r
236 for (int ypos = hgap, row = av.startRes; (ypos <= getSize().height)
\r
237 && (row < maxwidth); ypos += cHeight, row += rowSize)
\r
239 for (int i = starty; i < alheight; i++)
\r
242 SequenceI s = av.getAlignment().getSequenceAt(i);
\r
243 gg.setFont(italic);
\r
248 drawIdString(gg, hiddenRows, s, i, 0, ypos);
\r
251 if (labels != null)
\r
253 gg.translate(0, ypos + (alheight * avcharHeight));
\r
254 labels.drawComponent(gg, getSize().width);
\r
255 gg.translate(0, -ypos - (alheight * avcharHeight));
\r
262 // Now draw the id strings
\r
264 for (int i = starty; i < endy; i++)
\r
267 seq = av.getAlignment().getSequenceAt(i);
\r
272 gg.setFont(italic);
\r
273 // boolean isrep=false;
\r
277 setHiddenFont(seq);
\r
280 // Selected sequence colours
\r
281 if ((searchResults != null) && searchResults.contains(seq))
\r
283 currentColor = Color.black;
\r
284 currentTextColor = Color.white;
\r
286 else if ((av.getSelectionGroup() != null)
\r
287 && av.getSelectionGroup().getSequences(null).contains(seq))
\r
289 currentColor = Color.lightGray;
\r
290 currentTextColor = Color.black;
\r
294 currentColor = av.getSequenceColour(seq);
\r
295 currentTextColor = Color.black;
\r
298 gg.setColor(currentColor);
\r
299 // TODO: isrep could be used to highlight the representative in a
\r
301 gg.fillRect(0, (i - starty) * avcharHeight, getSize().width,
\r
303 gg.setColor(currentTextColor);
\r
305 gg.drawString(seq.getDisplayId(av.getShowJVSuffix()), 0,
\r
306 (((i - starty) * avcharHeight) + avcharHeight)
\r
307 - (avcharHeight / 5));
\r
311 drawMarker(i, starty, 0);
\r
317 public void setHighlighted(List<SequenceI> list)
\r
319 searchResults = list;
\r
323 void drawMarker(int i, int starty, int yoffset)
\r
325 SequenceI[] hseqs = av.getAlignment().getHiddenSequences().hiddenSequences;
\r
326 // Use this method here instead of calling hiddenSeq adjust
\r
328 int hSize = hseqs.length;
\r
330 int hiddenIndex = i;
\r
331 int lastIndex = i - 1;
\r
332 int nextIndex = i + 1;
\r
334 for (int j = 0; j < hSize; j++)
\r
336 if (hseqs[j] != null)
\r
338 if (j - 1 < hiddenIndex)
\r
342 if (j - 1 < lastIndex)
\r
346 if (j - 1 < nextIndex)
\r
353 boolean below = (hiddenIndex > lastIndex + 1);
\r
354 boolean above = (nextIndex > hiddenIndex + 1);
\r
356 gg.setColor(Color.blue);
\r
359 gg.fillPolygon(new int[]
\r
360 { getSize().width - avcharHeight, getSize().width - avcharHeight,
\r
361 getSize().width }, new int[]
\r
362 { (i - starty) * avcharHeight + yoffset,
\r
363 (i - starty) * avcharHeight + yoffset + avcharHeight / 4,
\r
364 (i - starty) * avcharHeight + yoffset }, 3);
\r
368 gg.fillPolygon(new int[]
\r
369 { getSize().width - avcharHeight, getSize().width - avcharHeight,
\r
370 getSize().width }, new int[]
\r
371 { (i - starty + 1) * avcharHeight + yoffset,
\r
372 (i - starty + 1) * avcharHeight + yoffset - avcharHeight / 4,
\r
373 (i - starty + 1) * avcharHeight + yoffset }, 3);
\r
378 boolean setHiddenFont(SequenceI seq)
\r
380 Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
\r
383 if (av.isHiddenRepSequence(seq))
\r