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
22 import jalview.datamodel.*;
\r
25 import java.awt.event.*;
\r
28 public class AnnotationPanel extends Panel implements AdjustmentListener
\r
35 static String HELIX ="Helix";
\r
36 static String SHEET ="Sheet";
\r
37 static String LABEL ="Label";
\r
38 static String REMOVE="Remove Annotation";
\r
39 static String COLOUR="Colour";
\r
40 static Color HELIX_COLOUR = Color.red.darker();
\r
41 static Color SHEET_COLOUR = Color.green.darker().darker();
\r
49 boolean fastPaint = false;
\r
51 public static int GRAPH_HEIGHT = 40;
\r
55 public AnnotationPanel(AlignmentPanel ap)
\r
59 this.setLayout(null);
\r
60 adjustPanelHeight();
\r
62 addMouseMotionListener(new MouseMotionAdapter()
\r
63 {public void mouseMoved(MouseEvent evt)
\r
64 { doMouseMoved(evt); }
\r
67 // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
\r
70 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
72 ap.alabels.setScrollOffset( -evt.getValue() );
\r
75 public void adjustPanelHeight()
\r
77 // setHeight of panels
\r
78 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
81 for (int i = 0; i < aa.length; i++)
\r
89 aa[i].height += av.charHeight;
\r
94 aa[i].height += GRAPH_HEIGHT;
\r
98 height += aa[i].height;
\r
102 this.setSize(getSize().width, height);
\r
103 ap.annotationScroller.setSize(getSize().width, height);
\r
105 // ap.annotationSpaceFillerHolder.setSize(d.width,annotationPanel.getSize().height);
\r
111 public void addEditableColumn(int i)
\r
115 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
116 for(int j=0; j<aa.length; j++)
\r
124 if(activeRes==null)
\r
126 activeRes = new Vector();
\r
127 activeRes.addElement(String.valueOf(i));
\r
131 activeRes.addElement(String.valueOf(i));
\r
134 public void doMouseMoved(MouseEvent evt)
\r
136 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
142 for(int i=0; i<aa.length; i++)
\r
145 if( aa[i].visible )
\r
146 height += aa[i].height;
\r
148 if(evt.getY()<height)
\r
155 int res = evt.getX() / av.getCharWidth() + av.getStartRes();
\r
156 if(row>-1 && res<aa[row].annotations.length && aa[row].annotations[res]!=null)
\r
158 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
160 aa[row].annotations[res].description);
\r
161 ap.alignFrame.statusBar.setText(text.toString());
\r
167 public void update(Graphics g)
\r
172 public void paint(Graphics g)
\r
174 imgWidth = (av.endRes-av.startRes+1) *av.charWidth;
\r
176 if(image==null || imgWidth != image.getWidth(this))
\r
178 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
179 gg = image.getGraphics();
\r
180 gg.setFont(av.getFont());
\r
181 fm = gg.getFontMetrics();
\r
187 g.drawImage(image, 0, 0, this);
\r
192 drawComponent( gg, av.startRes, av.endRes+1);
\r
193 g.drawImage( image, 0, 0, this);
\r
197 public void fastPaint(int horizontal)
\r
199 if( horizontal == 0
\r
200 || av.alignment.getAlignmentAnnotation()==null
\r
201 || av.alignment.getAlignmentAnnotation().length<1
\r
208 gg.copyArea( 0,0, imgWidth, getSize().height, -horizontal*av.charWidth, 0 );
\r
209 int sr=av.startRes, er=av.endRes+1, transX=0;
\r
211 if(horizontal>0) // scrollbar pulled right, image to the left
\r
213 transX = (er-sr-horizontal)*av.charWidth;
\r
214 sr = er - horizontal ;
\r
216 else if(horizontal<0)
\r
218 er = sr-horizontal;
\r
222 gg.translate(transX, 0);
\r
224 drawComponent(gg, sr, er);
\r
226 gg.translate( -transX, 0 );
\r
233 public void drawComponent(Graphics g, int startRes, int endRes)
\r
235 g.setColor(Color.white);
\r
236 g.fillRect(0,0,(endRes-startRes) *av.charWidth, getSize().height);
\r
237 if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1)
\r
239 g.setColor(Color.white);
\r
240 g.fillRect(0,0,getSize().width, getSize().height);
\r
241 g.setColor(Color.black);
\r
242 g.drawString("Alignment has no annotations",20,15);
\r
246 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
249 char [] lastSS = new char[aa.length];
\r
250 int [] lastSSX= new int[aa.length] ;
\r
251 int iconOffset = av.charHeight/2;
\r
252 boolean validRes = false;
\r
255 for(int i=0; i<aa.length; i++)
\r
257 AlignmentAnnotation row = aa[i];
\r
263 // this is so that we draw the characters below the graph
\r
266 y -= av.charHeight;
\r
269 iconOffset = av.charHeight/2;
\r
273 for(j=startRes; j<endRes; j++)
\r
275 if(row.annotations.length<=j || row.annotations[j]==null)
\r
280 x = (j-startRes)*av.charWidth;
\r
286 g.setColor(Color.red);
\r
288 if(activeRes!=null)
\r
289 for (int n = 0; n < activeRes.size(); n++)
\r
291 int v = Integer.parseInt(activeRes.elementAt(n).toString()) ;
\r
293 g.fillRect( (j-startRes) * av.charWidth, y, av.charWidth, row.height);
\r
299 if(validRes && row.annotations[j].displayCharacter.length()>0)
\r
301 int charOffset = (av.charWidth - fm.charWidth(row.annotations[j].displayCharacter.charAt(0)))/2;
\r
302 g.setColor( row.annotations[j].colour);
\r
305 if (row.annotations[0].secondaryStructure == 'H'
\r
306 || row.annotations[0].secondaryStructure == 'E')
\r
307 g.drawString(row.annotations[j].displayCharacter, x,
\r
308 y + iconOffset + 2);
\r
310 else if( (row.annotations[j].secondaryStructure=='H'
\r
311 || row.annotations[j].secondaryStructure=='E') &&
\r
312 (row.annotations[j-1]==null ||
\r
313 row.annotations[j].secondaryStructure!=row.annotations[j-1].secondaryStructure))
\r
315 g.drawString(row.annotations[j].displayCharacter, x, y + iconOffset + 2);
\r
318 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
319 y + iconOffset + 2);
\r
323 if(!validRes || row.annotations[j].secondaryStructure!=lastSS[i])
\r
328 g.setColor(HELIX_COLOUR);
\r
329 g.fillRoundRect(lastSSX[i], y+4 + iconOffset, x-lastSSX[i], 7, 8, 8);
\r
332 g.setColor(SHEET_COLOUR);
\r
333 g.fillRect(lastSSX[i], y + 4 + iconOffset, x-lastSSX[i]-4, 7);
\r
334 g.fillPolygon(new int[] {x - 4, x- 4, x }
\r
335 , new int[]{y+ iconOffset, y + 14+ iconOffset, y + 8+ iconOffset}, 3);
\r
340 g.setColor(Color.gray);
\r
341 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
346 lastSS[i] = row.annotations[j].secondaryStructure;
\r
352 if (validRes && row.isGraph)
\r
354 g.setColor(new Color(0,0,180));
\r
355 int height = (int)((row.annotations[j].value / row.graphMax)*GRAPH_HEIGHT);
\r
357 if(row.windowLength>1)
\r
360 for(int i2=j- (row.windowLength/2); i2<j+(row.windowLength/2); i2++)
\r
362 if(i2<0 || i2>=av.alignment.getWidth())
\r
365 total += row.annotations[i2].value;
\r
368 total/=row.windowLength;
\r
369 height = (int)( (total / row.graphMax) *GRAPH_HEIGHT);
\r
372 g.setColor(row.annotations[j].colour);
\r
373 g.fillRect(x, y-height, av.charWidth, height );
\r
385 g.setColor(HELIX_COLOUR);
\r
386 g.fillRoundRect(lastSSX[i], y+4+ iconOffset, x - lastSSX[i], 7, 8, 8);
\r
389 g.setColor(SHEET_COLOUR);
\r
390 g.fillRect(lastSSX[i], y + 4+ iconOffset, x - lastSSX[i] - 4, 7);
\r
391 g.fillPolygon(new int[]
\r
394 {y + iconOffset, y + 14+ iconOffset, y + 7+ iconOffset}
\r
400 g.setColor(Color.gray);
\r
401 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
406 if(row.isGraph && row.hasText)
\r
413 // used by overview window
\r
414 public void drawGraph(Graphics g, AlignmentAnnotation aa,int width, int y)
\r
416 g.setColor(Color.white);
\r
417 g.fillRect(0,0,width, y);
\r
418 g.setColor(new Color(0,0,180));
\r
420 for(int j=0; j<aa.annotations.length; j++)
\r
422 g.setColor(new Color(0, 0, 180));
\r
423 int height = (int) ( (aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT );
\r
424 g.fillRect(x, y - height, av.charWidth, height);
\r