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.gui;
\r
23 import java.awt.Graphics2D.*;
\r
24 import java.awt.image.*;
\r
25 import javax.swing.*;
\r
26 import jalview.datamodel.*;
\r
27 import jalview.analysis.*;
\r
28 public class IdCanvas extends JPanel
\r
30 protected AlignViewport av;
\r
32 protected boolean showScores = true;
\r
34 protected int maxIdLength = -1;
\r
35 protected String maxIdStr = null;
\r
36 BufferedImage image;
\r
39 boolean fastPaint = false;
\r
41 java.util.Vector searchResults;
\r
43 public IdCanvas(AlignViewport av)
\r
45 setLayout(new BorderLayout());
\r
47 PaintRefresher.Register(this);
\r
50 public void drawIdString(Graphics2D gg,SequenceI s,int i, int starty, int ypos) {
\r
51 int charHeight = av.getCharHeight();
\r
53 if(searchResults!=null && searchResults.contains(s))
\r
55 gg.setColor(Color.black);
\r
56 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
57 gg.setColor(Color.white);
\r
59 else if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {
\r
60 gg.setColor(Color.lightGray);
\r
61 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
62 gg.setColor(Color.white);
\r
64 gg.setColor(s.getColor());
\r
65 gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);
\r
66 gg.setColor(Color.black);
\r
69 String string = s.getName();
\r
70 if(av.getShowFullId())
\r
71 string = s.getDisplayId();
\r
73 gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5));
\r
77 public void fastPaint(int vertical)
\r
80 { repaint(); return;}
\r
82 gg.copyArea( 0,0, getWidth(), imgHeight, 0, -vertical*av.charHeight );
\r
84 int ss=av.startSeq, es=av.endSeq, transY = 0;
\r
85 if (vertical > 0) // scroll down
\r
88 if(ss<av.startSeq) // ie scrolling too fast, more than a page at a time
\r
91 transY = imgHeight - vertical * av.charHeight;
\r
93 else if (vertical < 0)
\r
102 gg.translate(0, transY);
\r
106 gg.translate( 0, -transY );
\r
113 public void paintComponent(Graphics g)
\r
115 g.setColor(Color.white);
\r
116 g.fillRect(0, 0, getWidth(), getHeight());
\r
121 g.drawImage(image, 0, 0, this);
\r
125 imgHeight = getHeight();
\r
126 imgHeight -= imgHeight % av.charHeight;
\r
131 image = new BufferedImage(getWidth(), imgHeight, BufferedImage.TYPE_INT_RGB);
\r
132 gg = (Graphics2D) image.getGraphics();
\r
133 //Fill in the background
\r
134 gg.setColor(Color.white);
\r
135 gg.fillRect(0, 0, getWidth(), imgHeight);
\r
136 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
137 RenderingHints.VALUE_ANTIALIAS_ON);
\r
138 Font italic = new Font(av.getFont().getName(), Font.ITALIC,
\r
139 av.getFont().getSize());
\r
140 gg.setFont(italic);
\r
142 drawIds( av.getStartSeq(), av.endSeq);
\r
144 g.drawImage(image, 0, 0, this);
\r
147 void drawIds(int starty, int endy)
\r
149 Color currentColor = Color.white;
\r
150 Color currentTextColor = Color.black;
\r
152 if (av.getWrapAlignment())
\r
155 int rowSize = av.getEndRes() - av.getStartRes();
\r
156 // Draw the rest of the panels
\r
158 for(int ypos=2*av.charHeight, row=av.startRes;
\r
159 ypos <= getHeight() && row<av.alignment.getWidth();
\r
160 ypos += av.chunkHeight, row+=rowSize )
\r
162 for (int i = starty; i < av.alignment.getHeight(); i++)
\r
164 SequenceI s = av.alignment.getSequenceAt(i);
\r
165 drawIdString(gg, s, i, 0, ypos);
\r
173 //Now draw the id strings
\r
174 for (int i = starty; i < endy; i++)
\r
176 // Selected sequence colours
\r
178 if(searchResults!=null && searchResults.contains(av.alignment.getSequenceAt(i)))
\r
180 gg.setColor(Color.black);
\r
181 currentColor = Color.black;
\r
182 currentTextColor = Color.white;
\r
184 else if (av.getSelectionGroup()!= null
\r
185 && av.getSelectionGroup().sequences.contains(av.alignment.getSequenceAt(i)))
\r
187 currentColor = Color.lightGray;
\r
188 currentTextColor = Color.black;
\r
192 currentColor = av.alignment.getSequenceAt(i).getColor();
\r
193 currentTextColor = Color.black;
\r
196 gg.setColor(currentColor);
\r
199 AlignmentUtil.getPixelHeight(starty, i, av.charHeight),
\r
203 gg.setColor(currentTextColor);
\r
204 String string = av.alignment.getSequenceAt(i).getName();
\r
205 if(av.getShowFullId())
\r
206 string = av.alignment.getSequenceAt(i).getDisplayId();
\r
207 gg.drawString(string, 0,
\r
208 AlignmentUtil.getPixelHeight(starty, i, av.charHeight) +
\r
209 av.charHeight - (av.charHeight / 5));
\r
213 gg.setColor(Color.white);
\r
214 gg.fillRect(getWidth()-4,0,4,getHeight());
\r
219 public void setHighlighted(java.util.Vector found)
\r
221 searchResults = found;
\r