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.analysis.*;
\r
23 import jalview.datamodel.*;
\r
26 import java.awt.image.*;
\r
28 import javax.swing.*;
\r
35 * @version $Revision$
\r
37 public class IdCanvas extends JPanel
\r
39 protected AlignViewport av;
\r
40 protected boolean showScores = true;
\r
41 protected int maxIdLength = -1;
\r
42 protected String maxIdStr = null;
\r
43 BufferedImage image;
\r
46 boolean fastPaint = false;
\r
47 java.util.Vector searchResults;
\r
50 * Creates a new IdCanvas object.
\r
52 * @param av DOCUMENT ME!
\r
54 public IdCanvas(AlignViewport av)
\r
56 setLayout(new BorderLayout());
\r
58 PaintRefresher.Register(this, av.alignment);
\r
64 * @param gg DOCUMENT ME!
\r
65 * @param s DOCUMENT ME!
\r
66 * @param i DOCUMENT ME!
\r
67 * @param starty DOCUMENT ME!
\r
68 * @param ypos DOCUMENT ME!
\r
70 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
\r
73 int charHeight = av.charHeight;
\r
75 if ((searchResults != null) && searchResults.contains(s))
\r
77 gg.setColor(Color.black);
\r
78 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
80 gg.setColor(Color.white);
\r
82 else if ((av.getSelectionGroup() != null) &&
\r
83 av.getSelectionGroup().sequences.contains(s))
\r
85 gg.setColor(Color.lightGray);
\r
86 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
88 gg.setColor(Color.white);
\r
92 gg.setColor(s.getColor());
\r
93 gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
\r
95 gg.setColor(Color.black);
\r
98 String string = s.getName();
\r
100 if (av.getShowFullId())
\r
102 string = s.getDisplayId();
\r
105 gg.drawString(string, 0,
\r
106 (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));
\r
112 * @param vertical DOCUMENT ME!
\r
114 public void fastPaint(int vertical)
\r
123 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
\r
125 int ss = av.startSeq;
\r
126 int es = av.endSeq;
\r
129 if (vertical > 0) // scroll down
\r
131 ss = es - vertical;
\r
133 if (ss < av.startSeq)
\r
134 { // ie scrolling too fast, more than a page at a time
\r
139 transY = imgHeight - (vertical * av.charHeight);
\r
142 else if (vertical < 0)
\r
144 es = ss - vertical;
\r
146 if (es > av.endSeq)
\r
152 gg.translate(0, transY);
\r
156 gg.translate(0, -transY);
\r
165 * @param g DOCUMENT ME!
\r
167 public void paintComponent(Graphics g)
\r
169 g.setColor(Color.white);
\r
170 g.fillRect(0, 0, getWidth(), getHeight());
\r
175 g.drawImage(image, 0, 0, this);
\r
180 imgHeight = getHeight();
\r
181 imgHeight -= (imgHeight % av.charHeight);
\r
188 image = new BufferedImage(getWidth(), imgHeight,
\r
189 BufferedImage.TYPE_INT_RGB);
\r
190 gg = (Graphics2D) image.getGraphics();
\r
192 //Fill in the background
\r
193 gg.setColor(Color.white);
\r
194 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
195 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
196 RenderingHints.VALUE_ANTIALIAS_ON);
\r
198 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
199 av.getFont().getSize());
\r
200 gg.setFont(italic);
\r
202 drawIds(av.getStartSeq(), av.endSeq);
\r
204 g.drawImage(image, 0, 0, this);
\r
210 * @param starty DOCUMENT ME!
\r
211 * @param endy DOCUMENT ME!
\r
213 void drawIds(int starty, int endy)
\r
215 Color currentColor = Color.white;
\r
216 Color currentTextColor = Color.black;
\r
218 if (av.getWrapAlignment())
\r
220 int rowSize = av.getEndRes() - av.getStartRes();
\r
222 // Draw the rest of the panels
\r
223 for (int ypos = 2 * av.charHeight, row = av.startRes;
\r
224 (ypos <= getHeight()) && (row < av.alignment.getWidth());
\r
225 ypos += av.chunkHeight, row += rowSize)
\r
227 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
229 SequenceI s = av.alignment.getSequenceAt(i);
\r
230 drawIdString(gg, s, i, 0, ypos);
\r
236 //Now draw the id strings
\r
237 for (int i = starty; i < endy; i++)
\r
239 // Selected sequence colours
\r
240 if ((searchResults != null) &&
\r
241 searchResults.contains(av.alignment.getSequenceAt(i)))
\r
243 gg.setColor(Color.black);
\r
244 currentColor = Color.black;
\r
245 currentTextColor = Color.white;
\r
247 else if ((av.getSelectionGroup() != null) &&
\r
248 av.getSelectionGroup().sequences.contains(
\r
249 av.alignment.getSequenceAt(i)))
\r
251 currentColor = Color.lightGray;
\r
252 currentTextColor = Color.black;
\r
256 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
257 currentTextColor = Color.black;
\r
260 gg.setColor(currentColor);
\r
262 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),
\r
265 gg.setColor(currentTextColor);
\r
267 String string = av.alignment.getSequenceAt(i).getName();
\r
269 if (av.getShowFullId())
\r
271 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
274 gg.drawString(string, 0,
\r
275 (((i - starty) * av.charHeight) + av.charHeight) -
\r
276 (av.charHeight / 5));
\r
280 gg.setColor(Color.white);
\r
281 gg.fillRect(getWidth() - 4, 0, 4, getHeight());
\r
288 * @param found DOCUMENT ME!
\r
290 public void setHighlighted(java.util.Vector found)
\r
292 searchResults = found;
\r