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