1 package jalview.appletgui;
\r
3 import jalview.datamodel.*;
\r
6 import java.awt.event.*;
\r
9 public class AnnotationPanel extends Panel implements AdjustmentListener
\r
16 static String HELIX ="Helix";
\r
17 static String SHEET ="Sheet";
\r
18 static String LABEL ="Label";
\r
19 static String REMOVE="Remove Annotation";
\r
20 static String COLOUR="Colour";
\r
21 static Color HELIX_COLOUR = Color.red.darker();
\r
22 static Color SHEET_COLOUR = Color.green.darker().darker();
\r
30 boolean fastPaint = false;
\r
32 public static int GRAPH_HEIGHT = 40;
\r
36 public AnnotationPanel(AlignmentPanel ap)
\r
40 this.setLayout(null);
\r
41 adjustPanelHeight();
\r
43 addMouseMotionListener(new MouseMotionAdapter()
\r
44 {public void mouseMoved(MouseEvent evt)
\r
45 { doMouseMoved(evt); }
\r
48 // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
\r
51 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
53 ap.alabels.setScrollOffset( -evt.getValue() );
\r
56 public void adjustPanelHeight()
\r
58 // setHeight of panels
\r
59 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
62 for (int i = 0; i < aa.length; i++)
\r
70 aa[i].height += av.charHeight;
\r
75 aa[i].height += GRAPH_HEIGHT;
\r
79 height += aa[i].height;
\r
83 this.setSize(getSize().width, height);
\r
84 ap.annotationScroller.setSize(getSize().width, height);
\r
86 // ap.annotationSpaceFillerHolder.setSize(d.width,annotationPanel.getSize().height);
\r
92 public void addEditableColumn(int i)
\r
96 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
97 for(int j=0; j<aa.length; j++)
\r
105 if(activeRes==null)
\r
107 activeRes = new Vector();
\r
108 activeRes.addElement(String.valueOf(i));
\r
112 activeRes.addElement(String.valueOf(i));
\r
115 public void doMouseMoved(MouseEvent evt)
\r
117 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
123 for(int i=0; i<aa.length; i++)
\r
126 if( aa[i].visible )
\r
127 height += aa[i].height;
\r
129 if(evt.getY()<height)
\r
136 int res = evt.getX() / av.getCharWidth() + av.getStartRes();
\r
137 if(row>-1 && res<aa[row].annotations.length && aa[row].annotations[res]!=null)
\r
139 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
141 aa[row].annotations[res].description);
\r
142 ap.alignFrame.statusBar.setText(text.toString());
\r
148 public void update(Graphics g)
\r
153 public void paint(Graphics g)
\r
155 imgWidth = (av.endRes-av.startRes+1) *av.charWidth;
\r
157 if(image==null || imgWidth != image.getWidth(this))
\r
159 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
160 gg = image.getGraphics();
\r
161 gg.setFont(av.getFont());
\r
162 fm = gg.getFontMetrics();
\r
168 g.drawImage(image, 0, 0, this);
\r
173 drawComponent( gg, av.startRes, av.endRes+1);
\r
174 g.drawImage( image, 0, 0, this);
\r
178 public void fastPaint(int horizontal)
\r
180 if( horizontal == 0
\r
181 || av.alignment.getAlignmentAnnotation()==null
\r
182 || av.alignment.getAlignmentAnnotation().length<1
\r
189 gg.copyArea( 0,0, imgWidth, getSize().height, -horizontal*av.charWidth, 0 );
\r
190 int sr=av.startRes, er=av.endRes+1, transX=0;
\r
192 if(horizontal>0) // scrollbar pulled right, image to the left
\r
194 transX = (er-sr-horizontal)*av.charWidth;
\r
195 sr = er - horizontal ;
\r
197 else if(horizontal<0)
\r
199 er = sr-horizontal;
\r
203 gg.translate(transX, 0);
\r
205 drawComponent(gg, sr, er);
\r
207 gg.translate( -transX, 0 );
\r
214 public void drawComponent(Graphics g, int startRes, int endRes)
\r
216 g.setColor(Color.white);
\r
217 g.fillRect(0,0,(endRes-startRes) *av.charWidth, getSize().height);
\r
218 if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1)
\r
220 g.setColor(Color.white);
\r
221 g.fillRect(0,0,getSize().width, getSize().height);
\r
222 g.setColor(Color.black);
\r
223 g.drawString("Alignment has no annotations",20,15);
\r
227 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
230 char [] lastSS = new char[aa.length];
\r
231 int [] lastSSX= new int[aa.length] ;
\r
232 int iconOffset = av.charHeight/2;
\r
233 boolean validRes = false;
\r
236 for(int i=0; i<aa.length; i++)
\r
238 AlignmentAnnotation row = aa[i];
\r
244 // this is so that we draw the characters below the graph
\r
247 y -= av.charHeight;
\r
250 iconOffset = av.charHeight/2;
\r
254 for(j=startRes; j<endRes; j++)
\r
256 if(row.annotations.length<=j || row.annotations[j]==null)
\r
261 x = (j-startRes)*av.charWidth;
\r
267 g.setColor(Color.red);
\r
269 if(activeRes!=null)
\r
270 for (int n = 0; n < activeRes.size(); n++)
\r
272 int v = Integer.parseInt(activeRes.elementAt(n).toString()) ;
\r
274 g.fillRect( (j-startRes) * av.charWidth, y, av.charWidth, row.height);
\r
280 if(validRes && row.annotations[j].displayCharacter.length()>0)
\r
282 int charOffset = (av.charWidth - fm.charWidth(row.annotations[j].displayCharacter.charAt(0)))/2;
\r
283 g.setColor( row.annotations[j].colour);
\r
286 if (row.annotations[0].secondaryStructure == 'H'
\r
287 || row.annotations[0].secondaryStructure == 'E')
\r
288 g.drawString(row.annotations[j].displayCharacter, x,
\r
289 y + iconOffset + 2);
\r
291 else if( (row.annotations[j].secondaryStructure=='H'
\r
292 || row.annotations[j].secondaryStructure=='E') &&
\r
293 (row.annotations[j-1]==null ||
\r
294 row.annotations[j].secondaryStructure!=row.annotations[j-1].secondaryStructure))
\r
296 g.drawString(row.annotations[j].displayCharacter, x, y + iconOffset + 2);
\r
299 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
300 y + iconOffset + 2);
\r
304 if(!validRes || row.annotations[j].secondaryStructure!=lastSS[i])
\r
309 g.setColor(HELIX_COLOUR);
\r
310 g.fillRoundRect(lastSSX[i], y+4 + iconOffset, x-lastSSX[i], 7, 8, 8);
\r
313 g.setColor(SHEET_COLOUR);
\r
314 g.fillRect(lastSSX[i], y + 4 + iconOffset, x-lastSSX[i]-4, 7);
\r
315 g.fillPolygon(new int[] {x - 4, x- 4, x }
\r
316 , new int[]{y+ iconOffset, y + 14+ iconOffset, y + 8+ iconOffset}, 3);
\r
321 g.setColor(Color.gray);
\r
322 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
327 lastSS[i] = row.annotations[j].secondaryStructure;
\r
333 if (validRes && row.isGraph)
\r
335 g.setColor(new Color(0,0,180));
\r
336 int height = (int)((row.annotations[j].value / row.graphMax)*GRAPH_HEIGHT);
\r
338 if(row.windowLength>1)
\r
341 for(int i2=j- (row.windowLength/2); i2<j+(row.windowLength/2); i2++)
\r
343 if(i2<0 || i2>=av.alignment.getWidth())
\r
346 total += row.annotations[i2].value;
\r
349 total/=row.windowLength;
\r
350 height = (int)( (total / row.graphMax) *GRAPH_HEIGHT);
\r
353 g.setColor(row.annotations[j].colour);
\r
354 g.fillRect(x, y-height, av.charWidth, height );
\r
366 g.setColor(HELIX_COLOUR);
\r
367 g.fillRoundRect(lastSSX[i], y+4+ iconOffset, x - lastSSX[i], 7, 8, 8);
\r
370 g.setColor(SHEET_COLOUR);
\r
371 g.fillRect(lastSSX[i], y + 4+ iconOffset, x - lastSSX[i] - 4, 7);
\r
372 g.fillPolygon(new int[]
\r
375 {y + iconOffset, y + 14+ iconOffset, y + 7+ iconOffset}
\r
381 g.setColor(Color.gray);
\r
382 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
387 if(row.isGraph && row.hasText)
\r
394 // used by overview window
\r
395 public void drawGraph(Graphics g, AlignmentAnnotation aa,int width, int y)
\r
397 g.setColor(Color.white);
\r
398 g.fillRect(0,0,width, y);
\r
399 g.setColor(new Color(0,0,180));
\r
401 for(int j=0; j<aa.annotations.length; j++)
\r
403 g.setColor(new Color(0, 0, 180));
\r
404 int height = (int) ( (aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT );
\r
405 g.fillRect(x, y - height, av.charWidth, height);
\r