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
44 ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
\r
47 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
49 ap.alabels.setScrollOffset( -evt.getValue() );
\r
52 public void adjustPanelHeight()
\r
54 // setHeight of panels
\r
55 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
58 for (int i = 0; i < aa.length; i++)
\r
66 aa[i].height += av.charHeight;
\r
71 aa[i].height += GRAPH_HEIGHT;
\r
75 height += aa[i].height;
\r
78 this.setSize(new Dimension(1, height));
\r
82 public void addEditableColumn(int i)
\r
86 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
87 for(int j=0; j<aa.length; j++)
\r
97 activeRes = new Vector();
\r
98 activeRes.addElement(String.valueOf(i));
\r
102 activeRes.addElement(String.valueOf(i));
\r
106 public void update(Graphics g)
\r
111 public void paint(Graphics g)
\r
113 imgWidth = (av.endRes-av.startRes+1) *av.charWidth;
\r
115 if(image==null || imgWidth != image.getWidth(this))
\r
117 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
118 gg = image.getGraphics();
\r
119 gg.setFont(av.getFont());
\r
120 fm = gg.getFontMetrics();
\r
126 g.drawImage(image, 0, 0, this);
\r
131 drawComponent( gg, av.startRes, av.endRes+1);
\r
132 g.drawImage( image, 0, 0, this);
\r
136 public void fastPaint(int horizontal)
\r
138 if( horizontal == 0
\r
139 || av.alignment.getAlignmentAnnotation()==null
\r
140 || av.alignment.getAlignmentAnnotation().length<1
\r
147 gg.copyArea( 0,0, imgWidth, getSize().height, -horizontal*av.charWidth, 0 );
\r
148 int sr=av.startRes, er=av.endRes+1, transX=0;
\r
150 if(horizontal>0) // scrollbar pulled right, image to the left
\r
152 transX = (er-sr-horizontal)*av.charWidth;
\r
153 sr = er - horizontal ;
\r
155 else if(horizontal<0)
\r
157 er = sr-horizontal;
\r
161 gg.translate(transX, 0);
\r
163 drawComponent(gg, sr, er);
\r
165 gg.translate( -transX, 0 );
\r
172 public void drawComponent(Graphics g, int startRes, int endRes)
\r
174 g.setColor(Color.white);
\r
175 g.fillRect(0,0,(endRes-startRes) *av.charWidth, getSize().height);
\r
176 if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1)
\r
178 g.setColor(Color.white);
\r
179 g.fillRect(0,0,getSize().width, getSize().height);
\r
180 g.setColor(Color.black);
\r
181 g.drawString("Alignment has no annotations",20,15);
\r
185 AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation();
\r
188 char [] lastSS = new char[aa.length];
\r
189 int [] lastSSX= new int[aa.length] ;
\r
190 int iconOffset = av.charHeight/2;
\r
191 boolean validRes = false;
\r
194 for(int i=0; i<aa.length; i++)
\r
196 AlignmentAnnotation row = aa[i];
\r
202 // this is so that we draw the characters below the graph
\r
205 y -= av.charHeight;
\r
208 iconOffset = av.charHeight/2;
\r
212 for(j=startRes; j<endRes; j++)
\r
214 validRes = row.annotations[j]==null?false:true;
\r
216 x = (j-startRes)*av.charWidth;
\r
222 g.setColor(Color.red);
\r
224 if(activeRes!=null)
\r
225 for (int n = 0; n < activeRes.size(); n++)
\r
227 int v = Integer.parseInt(activeRes.elementAt(n).toString()) ;
\r
229 g.fillRect( (j-startRes) * av.charWidth, y, av.charWidth, row.height);
\r
235 if(validRes && row.annotations[j].displayCharacter.length()>0)
\r
237 int charOffset = (av.charWidth - fm.charWidth(row.annotations[j].displayCharacter.charAt(0)))/2;
\r
238 g.setColor( row.annotations[j].colour);
\r
241 if (row.annotations[0].secondaryStructure == 'H'
\r
242 || row.annotations[0].secondaryStructure == 'E')
\r
243 g.drawString(row.annotations[j].displayCharacter, x,
\r
244 y + iconOffset + 2);
\r
246 else if( (row.annotations[j].secondaryStructure=='H'
\r
247 || row.annotations[j].secondaryStructure=='E') &&
\r
248 (row.annotations[j-1]==null ||
\r
249 row.annotations[j].secondaryStructure!=row.annotations[j-1].secondaryStructure))
\r
251 g.drawString(row.annotations[j].displayCharacter, x, y + iconOffset + 2);
\r
254 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
255 y + iconOffset + 2);
\r
259 if(!validRes || row.annotations[j].secondaryStructure!=lastSS[i])
\r
264 g.setColor(HELIX_COLOUR);
\r
265 g.fillRoundRect(lastSSX[i], y+4 + iconOffset, x-lastSSX[i], 7, 8, 8);
\r
268 g.setColor(SHEET_COLOUR);
\r
269 g.fillRect(lastSSX[i], y + 4 + iconOffset, x-lastSSX[i]-4, 7);
\r
270 g.fillPolygon(new int[] {x - 4, x- 4, x }
\r
271 , new int[]{y+ iconOffset, y + 14+ iconOffset, y + 8+ iconOffset}, 3);
\r
276 g.setColor(Color.gray);
\r
277 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
282 lastSS[i] = row.annotations[j].secondaryStructure;
\r
288 if (validRes && row.isGraph)
\r
290 g.setColor(new Color(0,0,180));
\r
291 int height = (int)((row.annotations[j].value / row.graphMax)*GRAPH_HEIGHT);
\r
293 if(row.windowLength>1)
\r
296 for(int i2=j- (row.windowLength/2); i2<j+(row.windowLength/2); i2++)
\r
298 if(i2<0 || i2>=av.alignment.getWidth())
\r
301 total += row.annotations[i2].value;
\r
304 total/=row.windowLength;
\r
305 height = (int)( (total / row.graphMax) *GRAPH_HEIGHT);
\r
308 g.setColor(row.annotations[j].colour);
\r
309 g.fillRect(x, y-height, av.charWidth, height );
\r
321 g.setColor(HELIX_COLOUR);
\r
322 g.fillRoundRect(lastSSX[i], y+4+ iconOffset, x - lastSSX[i], 7, 8, 8);
\r
325 g.setColor(SHEET_COLOUR);
\r
326 g.fillRect(lastSSX[i], y + 4+ iconOffset, x - lastSSX[i] - 4, 7);
\r
327 g.fillPolygon(new int[]
\r
330 {y + iconOffset, y + 14+ iconOffset, y + 7+ iconOffset}
\r
336 g.setColor(Color.gray);
\r
337 g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2);
\r
342 if(row.isGraph && row.hasText)
\r
349 // used by overview window
\r
350 public void drawGraph(Graphics g, AlignmentAnnotation aa,int width, int y)
\r
352 g.setColor(Color.white);
\r
353 g.fillRect(0,0,width, y);
\r
354 g.setColor(new Color(0,0,180));
\r
356 for(int j=0; j<aa.annotations.length; j++)
\r
358 g.setColor(new Color(0, 0, 180));
\r
359 int height = (int) ( (aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT );
\r
360 g.fillRect(x, y - height, av.charWidth, height);
\r