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.analysis.*;
\r
25 import jalview.datamodel.*;
\r
27 public class IdCanvas
\r
30 protected AlignViewport av;
\r
32 protected boolean showScores = true;
\r
34 protected int maxIdLength = -1;
\r
35 protected String maxIdStr = null;
\r
39 boolean fastPaint = false;
\r
41 java.util.Vector searchResults;
\r
43 public IdCanvas(AlignViewport av)
\r
47 PaintRefresher.Register(this, av.alignment);
\r
50 public void drawIdString(Graphics gg, SequenceI s, int i, int starty,
\r
53 int charHeight = av.getCharHeight();
\r
55 if (searchResults != null && searchResults.contains(s))
\r
57 gg.setColor(Color.black);
\r
58 gg.fillRect(0, ((i - starty) * charHeight) + ypos,
\r
59 getSize().width, charHeight);
\r
60 gg.setColor(Color.white);
\r
62 else if (av.getSelectionGroup() != null &&
\r
63 av.getSelectionGroup().sequences.contains(s))
\r
65 gg.setColor(Color.lightGray);
\r
66 gg.fillRect(0, ((i - starty) * charHeight) + ypos,
\r
67 getSize().width, charHeight);
\r
68 gg.setColor(Color.white);
\r
72 gg.setColor(s.getColor());
\r
73 gg.fillRect(0, ((i - starty) * charHeight) + ypos,
\r
74 getSize().width, charHeight);
\r
75 gg.setColor(Color.black);
\r
78 String string = s.getName();
\r
79 if (av.getShowFullId())
\r
81 string = s.getDisplayId();
\r
84 gg.drawString(string, 0,
\r
85 ((i - starty) * charHeight) + ypos +
\r
86 charHeight - (charHeight / 5));
\r
90 public void fastPaint(int vertical)
\r
98 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
\r
100 int ss = av.startSeq, es = av.endSeq, transY = 0;
\r
101 if (vertical > 0) // scroll down
\r
103 ss = es - vertical;
\r
104 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
\r
110 transY = imgHeight - vertical * av.charHeight;
\r
113 else if (vertical < 0)
\r
115 es = ss - vertical;
\r
116 if (es > av.endSeq)
\r
122 gg.translate(0, transY);
\r
126 gg.translate(0, -transY);
\r
132 public void update(Graphics g)
\r
137 public void paint(Graphics g)
\r
139 if (getSize().height < 0 || getSize().width < 0)
\r
146 g.drawImage(image, 0, 0, this);
\r
150 imgHeight = getSize().height;
\r
151 imgHeight -= imgHeight % av.charHeight;
\r
158 if (image == null || imgHeight != image.getHeight(this))
\r
160 image = createImage(getSize().width, imgHeight);
\r
161 gg = image.getGraphics();
\r
162 gg.setFont(av.getFont());
\r
165 //Fill in the background
\r
166 gg.setColor(Color.white);
\r
167 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
168 av.getFont().getSize());
\r
169 gg.setFont(italic);
\r
171 gg.fillRect(0, 0, getSize().width, getSize().height);
\r
172 drawIds(av.getStartSeq(), av.endSeq);
\r
173 g.drawImage(image, 0, 0, this);
\r
176 void drawIds(int starty, int endy)
\r
178 Color currentColor = Color.white;
\r
179 Color currentTextColor = Color.black;
\r
181 if (av.getWrapAlignment())
\r
184 int rowSize = av.getEndRes() - av.getStartRes();
\r
185 // Draw the rest of the panels
\r
187 for (int ypos = 2 * av.charHeight, row = av.startRes;
\r
188 ypos <= getSize().height && row < av.alignment.getWidth();
\r
189 ypos += av.chunkHeight, row += rowSize)
\r
191 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
193 SequenceI s = av.alignment.getSequenceAt(i);
\r
194 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
207 if (searchResults != null &&
\r
208 searchResults.contains(av.alignment.getSequenceAt(i)))
\r
210 gg.setColor(Color.black);
\r
211 currentColor = Color.black;
\r
212 currentTextColor = Color.white;
\r
214 else if (av.getSelectionGroup() != null
\r
216 av.getSelectionGroup().sequences.contains(av.alignment.
\r
219 currentColor = Color.lightGray;
\r
220 currentTextColor = Color.black;
\r
224 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
225 currentTextColor = Color.black;
\r
228 gg.setColor(currentColor);
\r
231 ((i - starty) * av.charHeight),
\r
235 gg.setColor(currentTextColor);
\r
236 String string = av.alignment.getSequenceAt(i).getName();
\r
237 if (av.getShowFullId())
\r
239 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
241 gg.drawString(string, 0,
\r
242 ((i - starty) * av.charHeight) +
\r
243 av.charHeight - (av.charHeight / 5));
\r
247 gg.setColor(Color.white);
\r
248 gg.fillRect(getSize().width - 4, 0, 4, getSize().height);
\r
253 public void setHighlighted(java.util.Vector found)
\r
255 searchResults = found;
\r