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
84 public void fastPaint(int vertical)
\r
92 gg.copyArea(0, 0, getSize().width, imgHeight, 0, -vertical * av.charHeight);
\r
94 int ss = av.startSeq, es = av.endSeq, transY = 0;
\r
95 if (vertical > 0) // scroll down
\r
98 if (ss < av.startSeq) // ie scrolling too fast, more than a page at a time
\r
104 transY = imgHeight - vertical * av.charHeight;
\r
107 else if (vertical < 0)
\r
109 es = ss - vertical;
\r
110 if (es > av.endSeq)
\r
116 gg.translate(0, transY);
\r
120 gg.translate(0, -transY);
\r
126 public void update(Graphics g)
\r
131 public void paint(Graphics g)
\r
133 if (getSize().height < 0 || getSize().width < 0)
\r
140 g.drawImage(image, 0, 0, this);
\r
144 imgHeight = getSize().height;
\r
145 imgHeight -= imgHeight % av.charHeight;
\r
152 if (image == null || imgHeight != image.getHeight(this))
\r
154 image = createImage(getSize().width, imgHeight);
\r
155 gg = image.getGraphics();
\r
156 gg.setFont(av.getFont());
\r
159 //Fill in the background
\r
160 gg.setColor(Color.white);
\r
161 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
162 av.getFont().getSize());
\r
163 gg.setFont(italic);
\r
165 gg.fillRect(0, 0, getSize().width, getSize().height);
\r
166 drawIds(av.getStartSeq(), av.endSeq);
\r
167 g.drawImage(image, 0, 0, this);
\r
170 void drawIds(int starty, int endy)
\r
172 Color currentColor = Color.white;
\r
173 Color currentTextColor = Color.black;
\r
174 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
175 av.getFont().getSize());
\r
177 if (av.getWrapAlignment())
\r
179 int annotationHeight = 0;
\r
180 AnnotationLabels labels = null;
\r
182 if(av.showAnnotation)
\r
184 AnnotationPanel ap = new AnnotationPanel(av);
\r
185 annotationHeight = ap.adjustPanelHeight();
\r
186 labels = new AnnotationLabels(av);
\r
189 int hgap = av.charHeight;
\r
190 if (av.scaleAboveWrapped)
\r
191 hgap += av.charHeight;
\r
193 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
195 + annotationHeight;
\r
197 int rowSize = av.getEndRes() - av.getStartRes();
\r
199 // Draw the rest of the panels
\r
200 for (int ypos = hgap, row = av.startRes;
\r
201 (ypos <= getSize().height) && (row < av.alignment.getWidth());
\r
202 ypos += cHeight, row += rowSize)
\r
204 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
206 SequenceI s = av.alignment.getSequenceAt(i);
\r
207 gg.setFont(italic);
\r
208 drawIdString(gg, s, i, 0, ypos);
\r
213 gg.translate(0, ypos+(av.getAlignment().getHeight() * av.charHeight));
\r
214 labels.drawComponent(gg, getSize().width);
\r
215 gg.translate(0, -ypos-(av.getAlignment().getHeight() * av.charHeight));
\r
223 //Now draw the id strings
\r
224 for (int i = starty; i < endy; i++)
\r
226 // Selected sequence colours
\r
228 if (searchResults != null &&
\r
229 searchResults.contains(av.alignment.getSequenceAt(i)))
\r
231 gg.setColor(Color.black);
\r
232 currentColor = Color.black;
\r
233 currentTextColor = Color.white;
\r
235 else if (av.getSelectionGroup() != null
\r
237 av.getSelectionGroup().getSequences(false).contains(av.alignment.
\r
240 currentColor = Color.lightGray;
\r
241 currentTextColor = Color.black;
\r
245 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
246 currentTextColor = Color.black;
\r
249 gg.setColor(currentColor);
\r
252 ((i - starty) * av.charHeight),
\r
256 gg.setColor(currentTextColor);
\r
258 gg.drawString(av.alignment.getSequenceAt(i)
\r
259 .getDisplayId(av.getShowJVSuffix()), 0,
\r
260 ((i - starty) * av.charHeight) +
\r
261 av.charHeight - (av.charHeight / 5));
\r
265 gg.setColor(Color.white);
\r
266 gg.fillRect(getSize().width - 4, 0, 4, getSize().height);
\r
271 public void setHighlighted(java.util.Vector found)
\r
273 searchResults = found;
\r