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
23 import jalview.datamodel.*;
\r
24 import jalview.analysis.*;
\r
25 public class IdCanvas extends Panel
\r
27 protected AlignViewport av;
\r
29 protected boolean showScores = true;
\r
31 protected int maxIdLength = -1;
\r
32 protected String maxIdStr = null;
\r
36 boolean fastPaint = false;
\r
38 java.util.Vector searchResults;
\r
40 public IdCanvas(AlignViewport av)
\r
44 PaintRefresher.Register(this);
\r
47 public void drawIdString(Graphics gg,SequenceI s,int i, int starty, int ypos) {
\r
48 int charHeight = av.getCharHeight();
\r
50 if(searchResults!=null && searchResults.contains(s))
\r
52 gg.setColor(Color.black);
\r
53 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getSize().width,charHeight);
\r
54 gg.setColor(Color.white);
\r
56 else if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {
\r
57 gg.setColor(Color.lightGray);
\r
58 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getSize().width,charHeight);
\r
59 gg.setColor(Color.white);
\r
61 gg.setColor(s.getColor());
\r
62 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getSize().width,charHeight);
\r
63 gg.setColor(Color.black);
\r
66 String string = s.getName();
\r
67 if(av.getShowFullId())
\r
68 string = s.getDisplayId();
\r
70 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5));
\r
74 public void fastPaint(int vertical)
\r
77 { repaint(); return;}
\r
79 gg.copyArea( 0,0, getSize().width, imgHeight, 0, -vertical*av.charHeight );
\r
81 int ss=av.startSeq, es=av.endSeq, transY = 0;
\r
82 if (vertical > 0) // scroll down
\r
85 if(ss<av.startSeq) // ie scrolling too fast, more than a page at a time
\r
88 transY = imgHeight - vertical * av.charHeight;
\r
90 else if (vertical < 0)
\r
99 gg.translate(0, transY);
\r
103 gg.translate( 0, -transY );
\r
110 public void update(Graphics g)
\r
114 public void paint(Graphics g)
\r
116 if(getSize().height<0 || getSize().width<0)
\r
121 g.drawImage(image, 0, 0, this);
\r
125 imgHeight = getSize().height;
\r
126 imgHeight -= imgHeight % av.charHeight;
\r
131 if(image==null || imgHeight!=image.getHeight(this))
\r
133 image = createImage(getSize().width, imgHeight);
\r
134 gg = image.getGraphics();
\r
135 gg.setFont(av.getFont());
\r
138 //Fill in the background
\r
139 gg.setColor(Color.white);
\r
140 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
141 av.getFont().getSize());
\r
142 gg.setFont(italic);
\r
144 gg.fillRect(0, 0, getSize().width, getSize().height);
\r
145 drawIds( av.getStartSeq(), av.endSeq);
\r
146 g.drawImage(image, 0, 0, this);
\r
149 void drawIds(int starty, int endy)
\r
151 Color currentColor = Color.white;
\r
152 Color currentTextColor = Color.black;
\r
154 if (av.getWrapAlignment())
\r
157 int rowSize = av.getEndRes() - av.getStartRes();
\r
158 // Draw the rest of the panels
\r
160 for(int ypos=2*av.charHeight, row=av.startRes;
\r
161 ypos <= getSize().height && row<av.alignment.getWidth();
\r
162 ypos += av.chunkHeight, row+=rowSize )
\r
164 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
166 SequenceI s = av.alignment.getSequenceAt(i);
\r
167 drawIdString(gg, s, i, 0, ypos);
\r
175 //Now draw the id strings
\r
176 for (int i = starty; i < endy; i++)
\r
178 // Selected sequence colours
\r
180 if(searchResults!=null && searchResults.contains(av.alignment.getSequenceAt(i)))
\r
182 gg.setColor(Color.black);
\r
183 currentColor = Color.black;
\r
184 currentTextColor = Color.white;
\r
186 else if (av.getSelectionGroup()!= null
\r
187 && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i)))
\r
189 currentColor = Color.lightGray;
\r
190 currentTextColor = Color.black;
\r
194 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
195 currentTextColor = Color.black;
\r
198 gg.setColor(currentColor);
\r
201 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
205 gg.setColor(currentTextColor);
\r
206 String string = av.alignment.getSequenceAt(i).getName();
\r
207 if(av.getShowFullId())
\r
208 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
209 gg.drawString(string, 0,
\r
210 AlignmentUtil.getPixelHeight(starty, i, av.charHeight) +
\r
211 av.charHeight - (av.charHeight / 5));
\r
215 gg.setColor(Color.white);
\r
216 gg.fillRect(getSize().width-4,0,4,getSize().height);
\r
221 public void setHighlighted(java.util.Vector found)
\r
223 searchResults = found;
\r