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 validRes = row.annotations[j]==null?false:true;
\r
258 x = (j-startRes)*av.charWidth;
\r
264 g.setColor(Color.red);
\r
266 if(activeRes!=null)
\r
267 for (int n = 0; n < activeRes.size(); n++)
\r
269 int v = Integer.parseInt(activeRes.elementAt(n).toString()) ;
\r
271 g.fillRect( (j-startRes) * av.charWidth, y, av.charWidth, row.height);
\r
277 if(validRes && row.annotations[j].displayCharacter.length()>0)
\r
279 int charOffset = (av.charWidth - fm.charWidth(row.annotations[j].displayCharacter.charAt(0)))/2;
\r
280 g.setColor( row.annotations[j].colour);
\r
283 if (row.annotations[0].secondaryStructure == 'H'
\r
284 || row.annotations[0].secondaryStructure == 'E')
\r
285 g.drawString(row.annotations[j].displayCharacter, x,
\r
286 y + iconOffset + 2);
\r
288 else if( (row.annotations[j].secondaryStructure=='H'
\r
289 || row.annotations[j].secondaryStructure=='E') &&
\r
290 (row.annotations[j-1]==null ||
\r
291 row.annotations[j].secondaryStructure!=row.annotations[j-1].secondaryStructure))
\r
293 g.drawString(row.annotations[j].displayCharacter, x, y + iconOffset + 2);
\r
296 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
297 y + iconOffset + 2);
\r
301 if(!validRes || row.annotations[j].secondaryStructure!=lastSS[i])
\r
306 g.setColor(HELIX_COLOUR);
\r
307 g.fillRoundRect(lastSSX[i], y+4 + iconOffset, x-lastSSX[i], 7, 8, 8);
\r
310 g.setColor(SHEET_COLOUR);
\r
311 g.fillRect(lastSSX[i], y + 4 + iconOffset, x-lastSSX[i]-4, 7);
\r
312 g.fillPolygon(new int[] {x - 4, x- 4, x }
\r
313 , new int[]{y+ iconOffset, y + 14+ iconOffset, y + 8+ iconOffset}, 3);
\r
318 g.setColor(Color.gray);
\r
319 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
324 lastSS[i] = row.annotations[j].secondaryStructure;
\r
330 if (validRes && row.isGraph)
\r
332 g.setColor(new Color(0,0,180));
\r
333 int height = (int)((row.annotations[j].value / row.graphMax)*GRAPH_HEIGHT);
\r
335 if(row.windowLength>1)
\r
338 for(int i2=j- (row.windowLength/2); i2<j+(row.windowLength/2); i2++)
\r
340 if(i2<0 || i2>=av.alignment.getWidth())
\r
343 total += row.annotations[i2].value;
\r
346 total/=row.windowLength;
\r
347 height = (int)( (total / row.graphMax) *GRAPH_HEIGHT);
\r
350 g.setColor(row.annotations[j].colour);
\r
351 g.fillRect(x, y-height, av.charWidth, height );
\r
363 g.setColor(HELIX_COLOUR);
\r
364 g.fillRoundRect(lastSSX[i], y+4+ iconOffset, x - lastSSX[i], 7, 8, 8);
\r
367 g.setColor(SHEET_COLOUR);
\r
368 g.fillRect(lastSSX[i], y + 4+ iconOffset, x - lastSSX[i] - 4, 7);
\r
369 g.fillPolygon(new int[]
\r
372 {y + iconOffset, y + 14+ iconOffset, y + 7+ iconOffset}
\r
378 g.setColor(Color.gray);
\r
379 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
384 if(row.isGraph && row.hasText)
\r
391 // used by overview window
\r
392 public void drawGraph(Graphics g, AlignmentAnnotation aa,int width, int y)
\r
394 g.setColor(Color.white);
\r
395 g.fillRect(0,0,width, y);
\r
396 g.setColor(new Color(0,0,180));
\r
398 for(int j=0; j<aa.annotations.length; j++)
\r
400 g.setColor(new Color(0, 0, 180));
\r
401 int height = (int) ( (aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT );
\r
402 g.fillRect(x, y - height, av.charWidth, height);
\r