5dca40468bace6efb1f3934fa5c33c616e5a050e
[jalview.git] / src / jalview / appletgui / AnnotationLabels.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.appletgui;
22
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.Annotation;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.datamodel.SequenceI;
27 import jalview.util.MessageManager;
28 import jalview.util.ParseHtmlBodyAndLinks;
29
30 import java.awt.Checkbox;
31 import java.awt.CheckboxMenuItem;
32 import java.awt.Color;
33 import java.awt.Dimension;
34 import java.awt.FlowLayout;
35 import java.awt.FontMetrics;
36 import java.awt.Frame;
37 import java.awt.Graphics;
38 import java.awt.Image;
39 import java.awt.MenuItem;
40 import java.awt.Panel;
41 import java.awt.PopupMenu;
42 import java.awt.event.ActionEvent;
43 import java.awt.event.ActionListener;
44 import java.awt.event.InputEvent;
45 import java.awt.event.ItemEvent;
46 import java.awt.event.ItemListener;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseListener;
49 import java.awt.event.MouseMotionListener;
50 import java.util.Arrays;
51 import java.util.Vector;
52
53 public class AnnotationLabels extends Panel implements ActionListener,
54         MouseListener, MouseMotionListener
55 {
56   Image image;
57
58   boolean active = false;
59
60   AlignmentPanel ap;
61
62   AlignViewport av;
63
64   boolean resizing = false;
65
66   int oldY, mouseX;
67
68   static String ADDNEW = "Add New Row";
69
70   static String EDITNAME = "Edit Label/Description";
71
72   static String HIDE = "Hide This Row";
73
74   static String SHOWALL = "Show All Hidden Rows";
75
76   static String OUTPUT_TEXT = "Show Values In Textbox";
77
78   static String COPYCONS_SEQ = "Copy Consensus Sequence";
79
80   int scrollOffset = 0;
81
82   int selectedRow = -1;
83
84   Tooltip tooltip;
85
86   private boolean hasHiddenRows;
87
88   public AnnotationLabels(AlignmentPanel ap)
89   {
90     this.ap = ap;
91     this.av = ap.av;
92     setLayout(null);
93
94     /**
95      * this retrieves the adjustable height glyph from resources. we don't use
96      * it at the moment. java.net.URL url =
97      * getClass().getResource("/images/idwidth.gif"); Image temp = null;
98      * 
99      * if (url != null) { temp =
100      * java.awt.Toolkit.getDefaultToolkit().createImage(url); }
101      * 
102      * try { MediaTracker mt = new MediaTracker(this); mt.addImage(temp, 0);
103      * mt.waitForID(0); } catch (Exception ex) { }
104      * 
105      * BufferedImage bi = new BufferedImage(temp.getHeight(this),
106      * temp.getWidth(this), BufferedImage.TYPE_INT_RGB); Graphics2D g =
107      * (Graphics2D) bi.getGraphics(); g.rotate(Math.toRadians(90));
108      * g.drawImage(temp, 0, -bi.getWidth(this), this); image = (Image) bi;
109      */
110     addMouseListener(this);
111     addMouseMotionListener(this);
112   }
113
114   public AnnotationLabels(AlignViewport av)
115   {
116     this.av = av;
117   }
118
119   public void setScrollOffset(int y, boolean repaint)
120   {
121     scrollOffset = y;
122     if (repaint)
123     {
124       repaint();
125     }
126   }
127
128   /**
129    * 
130    * @param y
131    * @return -2 if no rows are visible at all, -1 if no visible rows were
132    *         selected
133    */
134   int getSelectedRow(int y)
135   {
136     int row = -2;
137     AlignmentAnnotation[] aa = ap.av.getAlignment()
138             .getAlignmentAnnotation();
139
140     if (aa == null)
141     {
142       return row;
143     }
144     int height = 0;
145     for (int i = 0; i < aa.length; i++)
146     {
147       row = -1;
148       if (!aa[i].visible)
149       {
150         continue;
151       }
152       height += aa[i].height;
153       if (y < height)
154       {
155         row = i;
156         break;
157       }
158     }
159
160     return row;
161   }
162
163   public void actionPerformed(ActionEvent evt)
164   {
165     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
166
167     if (evt.getActionCommand().equals(ADDNEW))
168     {
169       AlignmentAnnotation newAnnotation = new AlignmentAnnotation("", null,
170               new Annotation[ap.av.getAlignment().getWidth()]);
171
172       if (!editLabelDescription(newAnnotation))
173       {
174         return;
175       }
176
177       ap.av.getAlignment().addAnnotation(newAnnotation);
178       ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
179     }
180     else if (evt.getActionCommand().equals(EDITNAME))
181     {
182       editLabelDescription(aa[selectedRow]);
183     }
184     else if (evt.getActionCommand().equals(HIDE))
185     {
186       aa[selectedRow].visible = false;
187     }
188     else if (evt.getActionCommand().equals(SHOWALL))
189     {
190       for (int i = 0; i < aa.length; i++)
191       {
192         aa[i].visible = (aa[i].annotations == null) ? false : true;
193       }
194     }
195     else if (evt.getActionCommand().equals(OUTPUT_TEXT))
196     {
197       CutAndPasteTransfer cap = new CutAndPasteTransfer(false,
198               ap.alignFrame);
199       Frame frame = new Frame();
200       frame.add(cap);
201       jalview.bin.JalviewLite.addFrame(frame, ap.alignFrame.getTitle()
202               + " - " + aa[selectedRow].label, 500, 100);
203       cap.setText(aa[selectedRow].toString());
204     }
205     else if (evt.getActionCommand().equals(COPYCONS_SEQ))
206     {
207       SequenceI cons = av.getConsensusSeq();
208       if (cons != null)
209       {
210         copy_annotseqtoclipboard(cons);
211       }
212
213     }
214     ap.annotationPanel.adjustPanelHeight();
215     setSize(getSize().width, ap.annotationPanel.getSize().height);
216     ap.validate();
217     ap.paintAlignment(true);
218   }
219
220   boolean editLabelDescription(AlignmentAnnotation annotation)
221   {
222     Checkbox padGaps = new Checkbox("Fill Empty Gaps With \""
223             + ap.av.getGapCharacter() + "\"", annotation.padGaps);
224
225     EditNameDialog dialog = new EditNameDialog(annotation.label,
226             annotation.description, "      Annotation Label",
227             "Annotation Description", ap.alignFrame,
228             "Edit Annotation Name / Description", 500, 180, false);
229
230     Panel empty = new Panel(new FlowLayout());
231     empty.add(padGaps);
232     dialog.add(empty);
233     dialog.pack();
234
235     dialog.setVisible(true);
236
237     if (dialog.accept)
238     {
239       annotation.label = dialog.getName();
240       annotation.description = dialog.getDescription();
241       annotation.setPadGaps(padGaps.getState(), av.getGapCharacter());
242       repaint();
243       return true;
244     }
245     else
246     {
247       return false;
248     }
249
250   }
251
252   boolean resizePanel = false;
253
254   public void mouseMoved(MouseEvent evt)
255   {
256     resizePanel = evt.getY() < 10 && evt.getX() < 14;
257     int row = getSelectedRow(evt.getY() + scrollOffset);
258
259     if (row > -1)
260     {
261       ParseHtmlBodyAndLinks phb = new ParseHtmlBodyAndLinks(
262               av.getAlignment().getAlignmentAnnotation()[row]
263                       .getDescription(true),
264               true, "\n");
265       if (tooltip == null)
266       {
267         tooltip = new Tooltip(phb.getNonHtmlContent(), this);
268       }
269       else
270       {
271         tooltip.setTip(phb.getNonHtmlContent());
272       }
273     }
274     else if (tooltip != null)
275     {
276       tooltip.setTip("");
277     }
278   }
279
280   /**
281    * curent drag position
282    */
283   MouseEvent dragEvent = null;
284
285   /**
286    * flag to indicate drag events should be ignored
287    */
288   private boolean dragCancelled = false;
289
290   /**
291    * clear any drag events in progress
292    */
293   public void cancelDrag()
294   {
295     dragEvent = null;
296     dragCancelled = true;
297   }
298
299   public void mouseDragged(MouseEvent evt)
300   {
301     if (dragCancelled)
302     {
303       return;
304     }
305     ;
306     dragEvent = evt;
307
308     if (resizePanel)
309     {
310       Dimension d = ap.annotationPanelHolder.getSize(), e = ap.annotationSpaceFillerHolder
311               .getSize(), f = ap.seqPanelHolder.getSize();
312       int dif = evt.getY() - oldY;
313
314       dif /= ap.av.charHeight;
315       dif *= ap.av.charHeight;
316
317       if ((d.height - dif) > 20 && (f.height + dif) > 20)
318       {
319         ap.annotationPanel.setSize(d.width, d.height - dif);
320         setSize(new Dimension(e.width, d.height - dif));
321         ap.annotationSpaceFillerHolder.setSize(new Dimension(e.width,
322                 d.height - dif));
323         ap.annotationPanelHolder.setSize(new Dimension(d.width, d.height
324                 - dif));
325         ap.apvscroll.setValues(ap.apvscroll.getValue(), d.height - dif, 0,
326                 av.calcPanelHeight());
327         f.height += dif;
328         ap.seqPanelHolder.setPreferredSize(f);
329         ap.setScrollValues(av.getStartRes(), av.getStartSeq());
330         ap.validate();
331         // ap.paintAlignment(true);
332         ap.addNotify();
333       }
334
335     }
336     else
337     {
338       int diff;
339       if ((diff = 6 - evt.getY()) > 0)
340       {
341         // nudge scroll up
342         ap.apvscroll.setValue(ap.apvscroll.getValue() - diff);
343         ap.adjustmentValueChanged(null);
344
345       }
346       else if ((0 < (diff = 6
347               - ap.annotationSpaceFillerHolder.getSize().height
348               + evt.getY())))
349       {
350         // nudge scroll down
351         ap.apvscroll.setValue(ap.apvscroll.getValue() + diff);
352         ap.adjustmentValueChanged(null);
353       }
354       repaint();
355     }
356   }
357
358   public void mouseClicked(MouseEvent evt)
359   {
360   }
361
362   public void mouseReleased(MouseEvent evt)
363   {
364     if (!resizePanel && !dragCancelled)
365     {
366       int start = selectedRow;
367
368       int end = getSelectedRow(evt.getY() + scrollOffset);
369
370       if (start > -1 && start != end)
371       {
372         // Swap these annotations
373         AlignmentAnnotation startAA = ap.av.getAlignment()
374                 .getAlignmentAnnotation()[start];
375         if (end == -1)
376         {
377           end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
378         }
379         AlignmentAnnotation endAA = ap.av.getAlignment()
380                 .getAlignmentAnnotation()[end];
381
382         ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
383         ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
384       }
385     }
386     resizePanel = false;
387     dragEvent = null;
388     dragCancelled = false;
389     repaint();
390     ap.annotationPanel.repaint();
391   }
392
393   public void mouseEntered(MouseEvent evt)
394   {
395     if (evt.getY() < 10 && evt.getX() < 14)
396     {
397       resizePanel = true;
398       repaint();
399     }
400   }
401
402   public void mouseExited(MouseEvent evt)
403   {
404     dragCancelled = false;
405
406     if (dragEvent == null)
407     {
408       resizePanel = false;
409     }
410     else
411     {
412       if (!resizePanel)
413       {
414         dragEvent = null;
415       }
416     }
417     repaint();
418   }
419
420   public void mousePressed(MouseEvent evt)
421   {
422     oldY = evt.getY();
423     if (resizePanel)
424     {
425       return;
426     }
427     dragCancelled = false;
428     // todo: move below to mouseClicked ?
429     selectedRow = getSelectedRow(evt.getY() + scrollOffset);
430
431     AlignmentAnnotation[] aa = ap.av.getAlignment()
432             .getAlignmentAnnotation();
433
434     // DETECT RIGHT MOUSE BUTTON IN AWT
435     if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
436     {
437
438       PopupMenu popup = new PopupMenu(
439               MessageManager.getString("label.annotations"));
440
441       MenuItem item = new MenuItem(ADDNEW);
442       item.addActionListener(this);
443       popup.add(item);
444       if (selectedRow < 0)
445       {
446         // this never happens at moment: - see comment on JAL-563
447         if (hasHiddenRows)
448         {
449           item = new MenuItem(SHOWALL);
450           item.addActionListener(this);
451           popup.add(item);
452         }
453         this.add(popup);
454         popup.show(this, evt.getX(), evt.getY());
455         return;
456       }
457       // add the rest if there are actually rows to show
458       item = new MenuItem(EDITNAME);
459       item.addActionListener(this);
460       popup.add(item);
461       item = new MenuItem(HIDE);
462       item.addActionListener(this);
463       popup.add(item);
464       if (hasHiddenRows)
465       {
466         item = new MenuItem(SHOWALL);
467         item.addActionListener(this);
468         popup.add(item);
469       }
470       this.add(popup);
471       item = new MenuItem(OUTPUT_TEXT);
472       item.addActionListener(this);
473       popup.add(item);
474       if (selectedRow < aa.length)
475       {
476         if (aa[selectedRow].autoCalculated)
477         {
478           if (aa[selectedRow].label.indexOf("Consensus") > -1)
479           {
480             popup.addSeparator();
481             final CheckboxMenuItem cbmi = new CheckboxMenuItem(
482                     MessageManager.getString("label.ignore_gaps_consensus"),
483                     (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
484                             .getIgnoreGapsConsensus() : ap.av
485                             .getIgnoreGapsConsensus());
486             final AlignmentAnnotation aaa = aa[selectedRow];
487             cbmi.addItemListener(new ItemListener()
488             {
489               public void itemStateChanged(ItemEvent e)
490               {
491                 if (aaa.groupRef != null)
492                 {
493                   // TODO: pass on reference to ap so the view can be updated.
494                   aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
495                 }
496                 else
497                 {
498                   ap.av.setIgnoreGapsConsensus(cbmi.getState());
499                 }
500                 ap.paintAlignment(true);
501               }
502             });
503             popup.add(cbmi);
504             if (aaa.groupRef != null)
505             {
506               final CheckboxMenuItem chist = new CheckboxMenuItem(
507                       MessageManager.getString("label.show_group_histogram"),
508                       aa[selectedRow].groupRef.isShowConsensusHistogram());
509               chist.addItemListener(new ItemListener()
510               {
511                 public void itemStateChanged(ItemEvent e)
512                 {
513                   // TODO: pass on reference
514                   // to ap
515                   // so the
516                   // view
517                   // can be
518                   // updated.
519                   aaa.groupRef.setShowConsensusHistogram(chist.getState());
520                   ap.repaint();
521                   // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
522                 }
523               });
524               popup.add(chist);
525               final CheckboxMenuItem cprofl = new CheckboxMenuItem(
526                       MessageManager.getString("label.show_group_logo"),
527                       aa[selectedRow].groupRef.isShowSequenceLogo());
528               cprofl.addItemListener(new ItemListener()
529               {
530                 public void itemStateChanged(ItemEvent e)
531                 {
532                   // TODO: pass on reference
533                   // to ap
534                   // so the
535                   // view
536                   // can be
537                   // updated.
538                   aaa.groupRef.setshowSequenceLogo(cprofl.getState());
539                   ap.repaint();
540                   // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
541                 }
542               });
543
544               popup.add(cprofl);
545               final CheckboxMenuItem cprofn = new CheckboxMenuItem(
546                       MessageManager.getString("label.normalise_group_logo"),
547                       aa[selectedRow].groupRef.isNormaliseSequenceLogo());
548               cprofn.addItemListener(new ItemListener()
549               {
550                 public void itemStateChanged(ItemEvent e)
551                 {
552                   // TODO: pass on reference
553                   // to ap
554                   // so the
555                   // view
556                   // can be
557                   // updated.
558                   aaa.groupRef.setshowSequenceLogo(true);
559                   aaa.groupRef.setNormaliseSequenceLogo(cprofn.getState());
560                   ap.repaint();
561                   // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
562                 }
563               });
564               popup.add(cprofn);
565             }
566             else
567             {
568               final CheckboxMenuItem chist = new CheckboxMenuItem(
569                       MessageManager.getString("label.show_histogram"), av.isShowConsensusHistogram());
570               chist.addItemListener(new ItemListener()
571               {
572                 public void itemStateChanged(ItemEvent e)
573                 {
574                   // TODO: pass on reference
575                   // to ap
576                   // so the
577                   // view
578                   // can be
579                   // updated.
580                   av.setShowConsensusHistogram(chist.getState());
581                   ap.alignFrame.showConsensusHistogram.setState(chist
582                           .getState()); // TODO: implement
583                                         // ap.updateGUI()/alignFrame.updateGUI
584                                         // for applet
585                   ap.repaint();
586                   // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
587                 }
588               });
589               popup.add(chist);
590               final CheckboxMenuItem cprof = new CheckboxMenuItem(
591                       MessageManager.getString("label.show_logo"), av.isShowSequenceLogo());
592               cprof.addItemListener(new ItemListener()
593               {
594                 public void itemStateChanged(ItemEvent e)
595                 {
596                   // TODO: pass on reference
597                   // to ap
598                   // so the
599                   // view
600                   // can be
601                   // updated.
602                   av.setShowSequenceLogo(cprof.getState());
603                   ap.alignFrame.showSequenceLogo.setState(cprof.getState()); // TODO:
604                                                                              // implement
605                                                                              // ap.updateGUI()/alignFrame.updateGUI
606                                                                              // for
607                                                                              // applet
608                   ap.repaint();
609                   // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
610                 }
611               });
612               popup.add(cprof);
613               final CheckboxMenuItem cprofn = new CheckboxMenuItem(
614                       MessageManager.getString("label.normalise_logo"), av.isNormaliseSequenceLogo());
615               cprofn.addItemListener(new ItemListener()
616               {
617                 public void itemStateChanged(ItemEvent e)
618                 {
619                   // TODO: pass on reference
620                   // to ap
621                   // so the
622                   // view
623                   // can be
624                   // updated.
625                   av.setShowSequenceLogo(true);
626                   ap.alignFrame.normSequenceLogo.setState(cprofn.getState()); // TODO:
627                                                                               // implement
628                                                                               // ap.updateGUI()/alignFrame.updateGUI
629                                                                               // for
630                                                                               // applet
631                   av.setNormaliseSequenceLogo(cprofn.getState());
632                   ap.repaint();
633                   // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
634                 }
635               });
636               popup.add(cprofn);
637             }
638
639             item = new MenuItem(COPYCONS_SEQ);
640             item.addActionListener(this);
641             popup.add(item);
642           }
643         }
644       }
645       popup.show(this, evt.getX(), evt.getY());
646     }
647     else
648     {
649       // selection action.
650       if (selectedRow > -1 && selectedRow < aa.length)
651       {
652         if (aa[selectedRow].groupRef != null)
653         {
654           if (evt.getClickCount() >= 2)
655           {
656             // todo: make the ap scroll to the selection - not necessary, first
657             // click highlights/scrolls, second selects
658             ap.seqPanel.ap.idPanel.highlightSearchResults(null);
659             ap.av.setSelectionGroup(// new SequenceGroup(
660             aa[selectedRow].groupRef); // );
661             ap.av.sendSelection();
662             ap.paintAlignment(false);
663             PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
664           }
665           else
666           {
667             ap.seqPanel.ap.idPanel
668                     .highlightSearchResults(aa[selectedRow].groupRef
669                             .getSequences(null));
670           }
671           return;
672         }
673         else if (aa[selectedRow].sequenceRef != null)
674         {
675           if (evt.getClickCount() == 1)
676           {
677             ap.seqPanel.ap.idPanel.highlightSearchResults(Arrays
678                     .asList(new SequenceI[]
679                     { aa[selectedRow].sequenceRef }));
680           }
681           else if (evt.getClickCount() >= 2)
682           {
683             ap.seqPanel.ap.idPanel.highlightSearchResults(null);
684             SequenceGroup sg = ap.av.getSelectionGroup();
685             if (sg!=null)
686             {
687               // we make a copy rather than edit the current selection if no modifiers pressed
688               // see Enhancement JAL-1557
689               if (!(evt.isControlDown() || evt.isShiftDown()))
690               {
691                 sg = new SequenceGroup(sg);
692                 sg.clear();
693                 sg.addSequence(aa[selectedRow].sequenceRef, false);
694               } else {
695                 if (evt.isControlDown())
696                 {
697                   sg.addOrRemove(aa[selectedRow].sequenceRef, true);
698                 } else {
699                   // notionally, we should also add intermediate sequences from last added sequence ?
700                   sg.addSequence(aa[selectedRow].sequenceRef, true);
701                 }
702               }
703             } else {
704               sg = new SequenceGroup();
705               sg.setStartRes(0);
706               sg.setEndRes(ap.av.getAlignment().getWidth()-1);
707               sg.addSequence(aa[selectedRow].sequenceRef, false);
708             }
709             ap.av.setSelectionGroup(sg);
710             ap.paintAlignment(false);
711             PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
712             ap.av.sendSelection();
713           }
714
715         }
716       }
717
718     }
719   }
720
721   /**
722    * DOCUMENT ME!
723    * 
724    * @param e
725    *          DOCUMENT ME!
726    */
727   protected void copy_annotseqtoclipboard(SequenceI sq)
728   {
729     if (sq == null || sq.getLength() < 1)
730     {
731       return;
732     }
733     jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
734     jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t"
735             + sq.getStart() + "\t" + sq.getEnd() + "\t"
736             + sq.getSequenceAsString() + "\n");
737     if (av.hasHiddenColumns())
738     {
739       jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
740       for (int[] region : av.getColumnSelection().getHiddenColumns())
741       {
742         jalview.appletgui.AlignFrame.copiedHiddenColumns
743                 .addElement(new int[]
744                 { region[0], region[1] });
745       }
746     }
747   }
748
749   public void update(Graphics g)
750   {
751     paint(g);
752   }
753
754   public void paint(Graphics g)
755   {
756     int w = getSize().width;
757     int h = getSize().height;
758     if (image == null || w != image.getWidth(this)
759             || h != image.getHeight(this))
760     {
761       image = createImage(w, ap.annotationPanel.getSize().height);
762     }
763
764     drawComponent(image.getGraphics(), w);
765     g.drawImage(image, 0, 0, this);
766   }
767
768   public void drawComponent(Graphics g, int width)
769   {
770     g.setFont(av.getFont());
771     FontMetrics fm = g.getFontMetrics(av.getFont());
772     g.setColor(Color.white);
773     g.fillRect(0, 0, getSize().width, getSize().height);
774
775     g.translate(0, -scrollOffset);
776     g.setColor(Color.black);
777
778     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
779     int y = 0, fy = g.getFont().getSize();
780     int x = 0, offset;
781
782     if (aa != null)
783     {
784       hasHiddenRows = false;
785       for (int i = 0; i < aa.length; i++)
786       {
787         if (!aa[i].visible)
788         {
789           hasHiddenRows = true;
790           continue;
791         }
792
793         x = width - fm.stringWidth(aa[i].label) - 3;
794
795         y += aa[i].height;
796         offset = -(aa[i].height - fy) / 2;
797
798         g.drawString(aa[i].label, x, y + offset);
799       }
800     }
801     g.translate(0, +scrollOffset);
802     if (resizePanel)
803     {
804       g.setColor(Color.red);
805       g.setPaintMode();
806       g.drawLine(2, 8, 5, 2);
807       g.drawLine(5, 2, 8, 8);
808     }
809     else if (!dragCancelled && dragEvent != null && aa != null)
810     {
811       g.setColor(Color.lightGray);
812       g.drawString(aa[selectedRow].label, dragEvent.getX(),
813               dragEvent.getY());
814     }
815
816     if (!av.wrapAlignment && ((aa == null) || (aa.length < 1)))
817     {
818       g.setColor(Color.black);
819       g.drawString(MessageManager.getString("label.right_click"), 2, 8);
820       g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
821               18);
822     }
823   }
824 }