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
22 import java.awt.image.*;
\r
23 import javax.swing.*;
\r
25 import jalview.analysis.*;
\r
26 import jalview.datamodel.*;
\r
28 public class IdCanvas
\r
31 protected AlignViewport av;
\r
32 protected boolean showScores = true;
\r
33 protected int maxIdLength = -1;
\r
34 protected String maxIdStr = null;
\r
35 BufferedImage image;
\r
38 boolean fastPaint = false;
\r
39 java.util.Vector searchResults;
\r
41 public IdCanvas(AlignViewport av)
\r
43 setLayout(new BorderLayout());
\r
45 PaintRefresher.Register(this, av.alignment);
\r
48 public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,
\r
51 int charHeight = av.getCharHeight();
\r
53 if ( (searchResults != null) && searchResults.contains(s))
\r
55 gg.setColor(Color.black);
\r
57 AlignmentUtil.getPixelHeight(starty, i, charHeight) + ypos,
\r
58 getWidth(), charHeight);
\r
59 gg.setColor(Color.white);
\r
61 else if ( (av.getSelectionGroup() != null) &&
\r
62 av.getSelectionGroup().sequences.contains(s))
\r
64 gg.setColor(Color.lightGray);
\r
66 AlignmentUtil.getPixelHeight(starty, i, charHeight) + ypos,
\r
67 getWidth(), charHeight);
\r
68 gg.setColor(Color.white);
\r
72 gg.setColor(s.getColor());
\r
74 AlignmentUtil.getPixelHeight(starty, i, charHeight) + ypos,
\r
75 getWidth(), charHeight);
\r
76 gg.setColor(Color.black);
\r
79 String string = s.getName();
\r
81 if (av.getShowFullId())
\r
83 string = s.getDisplayId();
\r
86 gg.drawString(string, 0,
\r
87 (AlignmentUtil.getPixelHeight(starty, i, charHeight) + ypos +
\r
88 charHeight) - (charHeight / 5));
\r
91 public void fastPaint(int vertical)
\r
99 gg.copyArea(0, 0, getWidth(), imgHeight, 0, -vertical * av.charHeight);
\r
101 int ss = av.startSeq;
\r
102 int es = av.endSeq;
\r
105 if (vertical > 0) // scroll down
\r
107 ss = es - vertical;
\r
109 if (ss < av.startSeq)
\r
110 { // ie scrolling too fast, more than a page at a time
\r
115 transY = imgHeight - (vertical * av.charHeight);
\r
118 else if (vertical < 0)
\r
120 es = ss - vertical;
\r
122 if (es > av.endSeq)
\r
128 gg.translate(0, transY);
\r
132 gg.translate(0, -transY);
\r
138 public void paintComponent(Graphics g)
\r
140 g.setColor(Color.white);
\r
141 g.fillRect(0, 0, getWidth(), getHeight());
\r
146 g.drawImage(image, 0, 0, this);
\r
151 imgHeight = getHeight();
\r
152 imgHeight -= (imgHeight % av.charHeight);
\r
159 image = new BufferedImage(getWidth(), imgHeight,
\r
160 BufferedImage.TYPE_INT_RGB);
\r
161 gg = (Graphics2D) image.getGraphics();
\r
163 //Fill in the background
\r
164 gg.setColor(Color.white);
\r
165 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
166 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
167 RenderingHints.VALUE_ANTIALIAS_ON);
\r
169 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
170 av.getFont().getSize());
\r
171 gg.setFont(italic);
\r
173 drawIds(av.getStartSeq(), av.endSeq);
\r
175 g.drawImage(image, 0, 0, this);
\r
178 void drawIds(int starty, int endy)
\r
181 Color currentColor = Color.white;
\r
182 Color currentTextColor = Color.black;
\r
184 if (av.getWrapAlignment())
\r
186 int rowSize = av.getEndRes() - av.getStartRes();
\r
188 // Draw the rest of the panels
\r
189 for (int ypos = 2 * av.charHeight, row = av.startRes;
\r
190 (ypos <= getHeight()) && (row < av.alignment.getWidth());
\r
191 ypos += av.chunkHeight, row += rowSize)
\r
193 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
195 SequenceI s = av.alignment.getSequenceAt(i);
\r
196 drawIdString(gg, s, i, 0, ypos);
\r
202 //Now draw the id strings
\r
203 for (int i = starty; i < endy; i++)
\r
205 // Selected sequence colours
\r
206 if ( (searchResults != null) &&
\r
207 searchResults.contains(av.alignment.getSequenceAt(i)))
\r
209 gg.setColor(Color.black);
\r
210 currentColor = Color.black;
\r
211 currentTextColor = Color.white;
\r
213 else if ( (av.getSelectionGroup() != null) &&
\r
214 av.getSelectionGroup().sequences.contains(
\r
215 av.alignment.getSequenceAt(i)))
\r
217 currentColor = Color.lightGray;
\r
218 currentTextColor = Color.black;
\r
222 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
223 currentTextColor = Color.black;
\r
226 gg.setColor(currentColor);
\r
229 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
230 getWidth(), av.charHeight);
\r
232 gg.setColor(currentTextColor);
\r
234 String string = av.alignment.getSequenceAt(i).getName();
\r
236 if (av.getShowFullId())
\r
238 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
241 gg.drawString(string, 0,
\r
242 (AlignmentUtil.getPixelHeight(starty, i, av.charHeight) +
\r
243 av.charHeight) - (av.charHeight / 5));
\r
247 gg.setColor(Color.white);
\r
248 gg.fillRect(getWidth() - 4, 0, 4, getHeight());
\r
252 public void setHighlighted(java.util.Vector found)
\r
254 searchResults = found;
\r