Merge branch 'develop' into bug/JAL-4059_update_swingJS_for_JalviewJS_2_11_2_and_2_11_3
[jalview.git] / src / jalview / gui / 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.gui;
22
23 import java.awt.Canvas;
24 import java.awt.Color;
25 import java.awt.Cursor;
26 import java.awt.Dimension;
27 import java.awt.Font;
28 import java.awt.FontMetrics;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.RenderingHints;
32 import java.awt.Toolkit;
33 import java.awt.datatransfer.StringSelection;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.MouseEvent;
37 import java.awt.event.MouseListener;
38 import java.awt.event.MouseMotionListener;
39 import java.awt.geom.AffineTransform;
40 import java.util.Arrays;
41 import java.util.Collections;
42 import java.util.Iterator;
43 import java.util.Locale;
44
45 import javax.swing.JCheckBoxMenuItem;
46 import javax.swing.JMenuItem;
47 import javax.swing.JPanel;
48 import javax.swing.JPopupMenu;
49 import javax.swing.SwingUtilities;
50 import javax.swing.ToolTipManager;
51
52 import jalview.analysis.AlignSeq;
53 import jalview.analysis.AlignmentUtils;
54 import jalview.bin.Cache;
55 import jalview.bin.Jalview;
56 import jalview.datamodel.Alignment;
57 import jalview.datamodel.AlignmentAnnotation;
58 import jalview.datamodel.Annotation;
59 import jalview.datamodel.ContactMatrixI;
60 import jalview.datamodel.GroupSet;
61 import jalview.datamodel.HiddenColumns;
62 import jalview.datamodel.Sequence;
63 import jalview.datamodel.SequenceGroup;
64 import jalview.datamodel.SequenceI;
65 import jalview.io.FileFormat;
66 import jalview.io.FormatAdapter;
67 import jalview.util.Comparison;
68 import jalview.util.IdUtils;
69 import jalview.util.IdUtils.IdType;
70 import jalview.util.MessageManager;
71 import jalview.util.Platform;
72
73 /**
74  * The panel that holds the labels for alignment annotations, providing
75  * tooltips, context menus, drag to reorder rows, and drag to adjust panel
76  * height
77  */
78 public class AnnotationLabels extends JPanel
79         implements MouseListener, MouseMotionListener, ActionListener
80 {
81   private static final String HTML_END_TAG = "</html>";
82
83   private static final String HTML_START_TAG = "<html>";
84
85   /**
86    * width in pixels within which height adjuster arrows are shown and active
87    */
88   private static final int HEIGHT_ADJUSTER_WIDTH = 50;
89
90   /**
91    * height in pixels for allowing height adjuster to be active
92    */
93   public static int HEIGHT_ADJUSTER_HEIGHT = 10;
94
95   private static final Font font = new Font("Arial", Font.PLAIN, 11);
96
97   private static final String TOGGLE_LABELSCALE = MessageManager
98           .getString("label.scale_label_to_column");
99
100   private static final String ADDNEW = MessageManager
101           .getString("label.add_new_row");
102
103   private static final String EDITNAME = MessageManager
104           .getString("label.edit_label_description");
105
106   private static final String HIDE = MessageManager
107           .getString("label.hide_row");
108
109   private static final String DELETE = MessageManager
110           .getString("label.delete_row");
111
112   private static final String SHOWALL = MessageManager
113           .getString("label.show_all_hidden_rows");
114
115   private static final String OUTPUT_TEXT = MessageManager
116           .getString("label.export_annotation");
117
118   private static final String COPYCONS_SEQ = MessageManager
119           .getString("label.copy_consensus_sequence");
120
121   private static final String ADJUST_ANNOTATION_LABELS_WIDTH_PREF = "ADJUST_ANNOTATION_LABELS_WIDTH";
122
123   private final boolean debugRedraw = false;
124
125   private AlignmentPanel ap;
126
127   AlignViewport av;
128
129   private MouseEvent dragEvent;
130
131   private int oldY;
132
133   private int selectedRow;
134
135   private int scrollOffset = 0;
136
137   private boolean hasHiddenRows;
138
139   private boolean resizePanel = false;
140
141   private int annotationIdWidth = -1;
142
143   public static final String RESIZE_MARGINS_MARK_PREF = "RESIZE_MARGINS_MARK";
144
145   /**
146    * Creates a new AnnotationLabels object
147    * 
148    * @param ap
149    */
150   public AnnotationLabels(AlignmentPanel ap)
151   {
152     this.ap = ap;
153     av = ap.av;
154     ToolTipManager.sharedInstance().registerComponent(this);
155
156     addMouseListener(this);
157     addMouseMotionListener(this);
158     addMouseWheelListener(ap.getAnnotationPanel());
159   }
160
161   public AnnotationLabels(AlignViewport av)
162   {
163     this.av = av;
164   }
165
166   /**
167    * DOCUMENT ME!
168    * 
169    * @param y
170    *          DOCUMENT ME!
171    */
172   public void setScrollOffset(int y)
173   {
174     scrollOffset = y;
175     repaint();
176   }
177
178   /**
179    * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
180    * y
181    * 
182    * @param y
183    *          coordinate position to search for a row
184    */
185   void getSelectedRow(int y)
186   {
187     int height = 0;
188     AlignmentAnnotation[] aa = ap.av.getAlignment()
189             .getAlignmentAnnotation();
190     selectedRow = -2;
191     if (aa != null)
192     {
193       for (int i = 0; i < aa.length; i++)
194       {
195         selectedRow = -1;
196         if (!aa[i].visible)
197         {
198           continue;
199         }
200
201         height += aa[i].height;
202
203         if (y < height)
204         {
205           selectedRow = i;
206
207           break;
208         }
209       }
210     }
211   }
212
213   /**
214    * DOCUMENT ME!
215    * 
216    * @param evt
217    *          DOCUMENT ME!
218    */
219   @Override
220   public void actionPerformed(ActionEvent evt)
221   {
222     AlignmentAnnotation[] aa = ap.av.getAlignment()
223             .getAlignmentAnnotation();
224
225     String action = evt.getActionCommand();
226     if (ADDNEW.equals(action))
227     {
228       /*
229        * non-returning dialog
230        */
231       AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
232               null, new Annotation[ap.av.getAlignment().getWidth()]);
233       editLabelDescription(newAnnotation, true);
234     }
235     else if (EDITNAME.equals(action))
236     {
237       /*
238        * non-returning dialog
239        */
240       editLabelDescription(aa[selectedRow], false);
241     }
242     else if (HIDE.equals(action))
243     {
244       aa[selectedRow].visible = false;
245     }
246     else if (DELETE.equals(action))
247     {
248       ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
249       ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
250     }
251     else if (SHOWALL.equals(action))
252     {
253       for (int i = 0; i < aa.length; i++)
254       {
255         if (!aa[i].visible && aa[i].annotations != null)
256         {
257           aa[i].visible = true;
258         }
259       }
260     }
261     else if (OUTPUT_TEXT.equals(action))
262     {
263       new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
264     }
265     else if (COPYCONS_SEQ.equals(action))
266     {
267       SequenceI cons = null;
268       if (aa[selectedRow].groupRef != null)
269       {
270         cons = aa[selectedRow].groupRef.getConsensusSeq();
271       }
272       else
273       {
274         cons = av.getConsensusSeq();
275       }
276       if (cons != null)
277       {
278         copy_annotseqtoclipboard(cons);
279       }
280     }
281     else if (TOGGLE_LABELSCALE.equals(action))
282     {
283       aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
284     }
285
286     ap.refresh(true);
287   }
288
289   /**
290    * Shows a dialog where the annotation name and description may be edited. If
291    * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
292    * is added, else an existing annotation is updated.
293    * 
294    * @param annotation
295    * @param addNew
296    */
297   void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
298   {
299     String name = MessageManager.getString("label.annotation_name");
300     String description = MessageManager
301             .getString("label.annotation_description");
302     String title = MessageManager
303             .getString("label.edit_annotation_name_description");
304     EditNameDialog dialog = new EditNameDialog(annotation.label,
305             annotation.description, name, description);
306
307     dialog.showDialog(ap.alignFrame, title, () -> {
308       annotation.label = dialog.getName();
309       String text = dialog.getDescription();
310       if (text != null && text.length() == 0)
311       {
312         text = null;
313       }
314       annotation.description = text;
315       if (addNew)
316       {
317         ap.av.getAlignment().addAnnotation(annotation);
318         ap.av.getAlignment().setAnnotationIndex(annotation, 0);
319       }
320       ap.refresh(true);
321     });
322   }
323
324   @Override
325   public void mousePressed(MouseEvent evt)
326   {
327     getSelectedRow(evt.getY() - getScrollOffset());
328     oldY = evt.getY();
329     if (evt.isPopupTrigger())
330     {
331       showPopupMenu(evt);
332     }
333   }
334
335   /**
336    * Build and show the Pop-up menu at the right-click mouse position
337    * 
338    * @param evt
339    */
340   void showPopupMenu(MouseEvent evt)
341   {
342     evt.consume();
343     final AlignmentAnnotation[] aa = ap.av.getAlignment()
344             .getAlignmentAnnotation();
345
346     JPopupMenu pop = new JPopupMenu(
347             MessageManager.getString("label.annotations"));
348     JMenuItem item = new JMenuItem(ADDNEW);
349     item.addActionListener(this);
350     pop.add(item);
351     if (selectedRow < 0)
352     {
353       if (hasHiddenRows)
354       { // let the user make everything visible again
355         item = new JMenuItem(SHOWALL);
356         item.addActionListener(this);
357         pop.add(item);
358       }
359       pop.show(this, evt.getX(), evt.getY());
360       return;
361     }
362     item = new JMenuItem(EDITNAME);
363     item.addActionListener(this);
364     pop.add(item);
365     item = new JMenuItem(HIDE);
366     item.addActionListener(this);
367     pop.add(item);
368     // JAL-1264 hide all sequence-specific annotations of this type
369     if (selectedRow < aa.length)
370     {
371       if (aa[selectedRow].sequenceRef != null)
372       {
373         final String label = aa[selectedRow].label;
374         JMenuItem hideType = new JMenuItem();
375         String text = MessageManager.getString("label.hide_all") + " "
376                 + label;
377         hideType.setText(text);
378         hideType.addActionListener(new ActionListener()
379         {
380           @Override
381           public void actionPerformed(ActionEvent e)
382           {
383             AlignmentUtils.showOrHideSequenceAnnotations(
384                     ap.av.getAlignment(), Collections.singleton(label),
385                     null, false, false);
386             ap.refresh(true);
387           }
388         });
389         pop.add(hideType);
390       }
391     }
392     item = new JMenuItem(DELETE);
393     item.addActionListener(this);
394     pop.add(item);
395     if (hasHiddenRows)
396     {
397       item = new JMenuItem(SHOWALL);
398       item.addActionListener(this);
399       pop.add(item);
400     }
401     item = new JMenuItem(OUTPUT_TEXT);
402     item.addActionListener(this);
403     pop.add(item);
404     // TODO: annotation object should be typed for autocalculated/derived
405     // property methods
406     if (selectedRow < aa.length)
407     {
408       final String label = aa[selectedRow].label;
409       if (!aa[selectedRow].autoCalculated)
410       {
411         if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
412         {
413           // display formatting settings for this row.
414           pop.addSeparator();
415           // av and sequencegroup need to implement same interface for
416           item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
417                   aa[selectedRow].scaleColLabel);
418           item.addActionListener(this);
419           pop.add(item);
420         }
421       }
422       else if (label.indexOf("Consensus") > -1)
423       {
424         addConsensusMenuOptions(ap, aa[selectedRow], pop);
425
426         final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
427         consclipbrd.addActionListener(this);
428         pop.add(consclipbrd);
429       }
430
431       addColourOrFilterByOptions(ap, aa[selectedRow], pop);
432
433       if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP)
434       {
435         addContactMatrixOptions(ap, aa[selectedRow], pop);
436         // Set/adjust threshold for grouping ?
437         // colour alignment by this [type]
438         // select/hide columns by this row
439
440       }
441     }
442
443     pop.show(this, evt.getX(), evt.getY());
444   }
445
446   static void addColourOrFilterByOptions(final AlignmentPanel ap,
447           final AlignmentAnnotation alignmentAnnotation,
448           final JPopupMenu pop)
449   {
450     JMenuItem item;
451     item = new JMenuItem(
452             MessageManager.getString("label.colour_by_annotation"));
453     item.addActionListener(new ActionListener()
454     {
455
456       @Override
457       public void actionPerformed(ActionEvent e)
458       {
459         AnnotationColourChooser.displayFor(ap.av, ap, alignmentAnnotation,
460                 false);
461       };
462     });
463     pop.add(item);
464     if (alignmentAnnotation.sequenceRef != null)
465     {
466       item = new JMenuItem(
467               MessageManager.getString("label.colour_by_annotation") + " ("
468                       + MessageManager.getString("label.per_seq") + ")");
469       item.addActionListener(new ActionListener()
470       {
471         @Override
472         public void actionPerformed(ActionEvent e)
473         {
474           AnnotationColourChooser.displayFor(ap.av, ap, alignmentAnnotation,
475                   true);
476         };
477       });
478       pop.add(item);
479     }
480     item = new JMenuItem(
481             MessageManager.getString("action.select_by_annotation"));
482     item.addActionListener(new ActionListener()
483     {
484
485       @Override
486       public void actionPerformed(ActionEvent e)
487       {
488         AnnotationColumnChooser.displayFor(ap.av, ap, alignmentAnnotation);
489       };
490     });
491     pop.add(item);
492   }
493
494   static void addContactMatrixOptions(final AlignmentPanel ap,
495           final AlignmentAnnotation alignmentAnnotation,
496           final JPopupMenu pop)
497   {
498
499     final ContactMatrixI cm = ap.av.getContactMatrix(alignmentAnnotation);
500     JMenuItem item;
501     if (cm != null)
502     {
503       pop.addSeparator();
504
505       if (cm.hasGroups())
506       {
507         JCheckBoxMenuItem chitem = new JCheckBoxMenuItem(
508                 MessageManager.getString("action.show_groups_on_matrix"));
509         chitem.setToolTipText(MessageManager
510                 .getString("action.show_groups_on_matrix_tooltip"));
511         boolean showGroups = alignmentAnnotation
512                 .isShowGroupsForContactMatrix();
513         final AlignmentAnnotation sel_row = alignmentAnnotation;
514         chitem.setState(showGroups);
515         chitem.addActionListener(new ActionListener()
516         {
517
518           @Override
519           public void actionPerformed(ActionEvent e)
520           {
521             sel_row.setShowGroupsForContactMatrix(chitem.getState());
522             // so any annotation colour changes are propagated - though they
523             // probably won't be unless the annotation row colours are removed
524             // too!
525             ap.alignmentChanged();
526           }
527         });
528         pop.add(chitem);
529       }
530       if (cm.hasTree())
531       {
532         item = new JMenuItem(
533                 MessageManager.getString("action.show_tree_for_matrix"));
534         item.setToolTipText(MessageManager
535                 .getString("action.show_tree_for_matrix_tooltip"));
536         item.addActionListener(new ActionListener()
537         {
538
539           @Override
540           public void actionPerformed(ActionEvent e)
541           {
542
543             ap.alignFrame.showContactMapTree(alignmentAnnotation, cm);
544
545           }
546         });
547         pop.add(item);
548       }
549       else
550       {
551         item = new JMenuItem(
552                 MessageManager.getString("action.cluster_matrix"));
553         item.setToolTipText(
554                 MessageManager.getString("action.cluster_matrix_tooltip"));
555         item.addActionListener(new ActionListener()
556         {
557           @Override
558           public void actionPerformed(ActionEvent e)
559           {
560             new Thread(new Runnable()
561             {
562               @Override
563               public void run()
564               {
565                 final long progBar;
566                 ap.alignFrame.setProgressBar(
567                         MessageManager.formatMessage(
568                                 "action.clustering_matrix_for",
569                                 cm.getAnnotDescr(), 5f),
570                         progBar = IdUtils.newId(IdType.PROGRESS));
571                 cm.setGroupSet(GroupSet.makeGroups(cm, true));
572                 cm.randomlyReColourGroups();
573                 cm.transferGroupColorsTo(alignmentAnnotation);
574                 ap.alignmentChanged();
575                 ap.alignFrame.showContactMapTree(alignmentAnnotation, cm);
576                 ap.alignFrame.setProgressBar(null, progBar);
577               }
578             }).start();
579           }
580         });
581         pop.add(item);
582       }
583     }
584   }
585
586   /**
587    * A helper method that adds menu options for calculation and visualisation of
588    * group and/or alignment consensus annotation to a popup menu. This is
589    * designed to be reusable for either unwrapped mode (popup menu is shown on
590    * component AnnotationLabels), or wrapped mode (popup menu is shown on
591    * IdPanel when the mouse is over an annotation label).
592    * 
593    * @param ap
594    * @param ann
595    * @param pop
596    */
597   static void addConsensusMenuOptions(AlignmentPanel ap,
598           AlignmentAnnotation ann, JPopupMenu pop)
599   {
600     pop.addSeparator();
601
602     final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
603             MessageManager.getString("label.ignore_gaps_consensus"),
604             (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
605                     : ap.av.isIgnoreGapsConsensus());
606     final AlignmentAnnotation aaa = ann;
607     cbmi.addActionListener(new ActionListener()
608     {
609       @Override
610       public void actionPerformed(ActionEvent e)
611       {
612         if (aaa.groupRef != null)
613         {
614           aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
615           ap.getAnnotationPanel()
616                   .paint(ap.getAnnotationPanel().getGraphics());
617         }
618         else
619         {
620           ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
621         }
622         ap.alignmentChanged();
623       }
624     });
625     pop.add(cbmi);
626
627     if (aaa.groupRef != null)
628     {
629       /*
630        * group consensus options
631        */
632       final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
633               MessageManager.getString("label.show_group_histogram"),
634               ann.groupRef.isShowConsensusHistogram());
635       chist.addActionListener(new ActionListener()
636       {
637         @Override
638         public void actionPerformed(ActionEvent e)
639         {
640           aaa.groupRef.setShowConsensusHistogram(chist.getState());
641           ap.repaint();
642         }
643       });
644       pop.add(chist);
645       final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
646               MessageManager.getString("label.show_group_logo"),
647               ann.groupRef.isShowSequenceLogo());
648       cprofl.addActionListener(new ActionListener()
649       {
650         @Override
651         public void actionPerformed(ActionEvent e)
652         {
653           aaa.groupRef.setshowSequenceLogo(cprofl.getState());
654           ap.repaint();
655         }
656       });
657       pop.add(cprofl);
658       final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
659               MessageManager.getString("label.normalise_group_logo"),
660               ann.groupRef.isNormaliseSequenceLogo());
661       cproflnorm.addActionListener(new ActionListener()
662       {
663         @Override
664         public void actionPerformed(ActionEvent e)
665         {
666           aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
667           // automatically enable logo display if we're clicked
668           aaa.groupRef.setshowSequenceLogo(true);
669           ap.repaint();
670         }
671       });
672       pop.add(cproflnorm);
673     }
674     else
675     {
676       /*
677        * alignment consensus options
678        */
679       final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
680               MessageManager.getString("label.show_histogram"),
681               ap.av.isShowConsensusHistogram());
682       chist.addActionListener(new ActionListener()
683       {
684         @Override
685         public void actionPerformed(ActionEvent e)
686         {
687           ap.av.setShowConsensusHistogram(chist.getState());
688           ap.alignFrame.setMenusForViewport();
689           ap.repaint();
690         }
691       });
692       pop.add(chist);
693       final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
694               MessageManager.getString("label.show_logo"),
695               ap.av.isShowSequenceLogo());
696       cprof.addActionListener(new ActionListener()
697       {
698         @Override
699         public void actionPerformed(ActionEvent e)
700         {
701           ap.av.setShowSequenceLogo(cprof.getState());
702           ap.alignFrame.setMenusForViewport();
703           ap.repaint();
704         }
705       });
706       pop.add(cprof);
707       final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
708               MessageManager.getString("label.normalise_logo"),
709               ap.av.isNormaliseSequenceLogo());
710       cprofnorm.addActionListener(new ActionListener()
711       {
712         @Override
713         public void actionPerformed(ActionEvent e)
714         {
715           ap.av.setShowSequenceLogo(true);
716           ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
717           ap.alignFrame.setMenusForViewport();
718           ap.repaint();
719         }
720       });
721       pop.add(cprofnorm);
722     }
723   }
724
725   /**
726    * Reorders annotation rows after a drag of a label
727    * 
728    * @param evt
729    */
730   @Override
731   public void mouseReleased(MouseEvent evt)
732   {
733     if (evt.isPopupTrigger())
734     {
735       showPopupMenu(evt);
736       return;
737     }
738
739     int start = selectedRow;
740     getSelectedRow(evt.getY() - getScrollOffset());
741     int end = selectedRow;
742
743     /*
744      * if dragging to resize instead, start == end
745      */
746     if (start != end)
747     {
748       // Swap these annotations
749       AlignmentAnnotation startAA = ap.av.getAlignment()
750               .getAlignmentAnnotation()[start];
751       if (end == -1)
752       {
753         end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
754       }
755       AlignmentAnnotation endAA = ap.av.getAlignment()
756               .getAlignmentAnnotation()[end];
757
758       ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
759       ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
760     }
761
762     resizePanel = false;
763     dragEvent = null;
764     repaint();
765     ap.getAnnotationPanel().repaint();
766   }
767
768   /**
769    * Removes the height adjuster image on leaving the panel, unless currently
770    * dragging it
771    */
772   @Override
773   public void mouseExited(MouseEvent evt)
774   {
775     if (resizePanel && dragEvent == null)
776     {
777       resizePanel = false;
778       repaint();
779     }
780   }
781
782   /**
783    * A mouse drag may be either an adjustment of the panel height (if flag
784    * resizePanel is set on), or a reordering of the annotation rows. The former
785    * is dealt with by this method, the latter in mouseReleased.
786    * 
787    * @param evt
788    */
789   @Override
790   public void mouseDragged(MouseEvent evt)
791   {
792     dragEvent = evt;
793
794     if (resizePanel)
795     {
796       Dimension d = ap.annotationScroller.getPreferredSize();
797       int dif = evt.getY() - oldY;
798
799       dif /= ap.av.getCharHeight();
800       dif *= ap.av.getCharHeight();
801
802       if ((d.height - dif) > 20)
803       {
804         ap.annotationScroller
805                 .setPreferredSize(new Dimension(d.width, d.height - dif));
806         d = ap.annotationSpaceFillerHolder.getPreferredSize();
807         ap.annotationSpaceFillerHolder
808                 .setPreferredSize(new Dimension(d.width, d.height - dif));
809         ap.paintAlignment(true, false);
810       }
811
812       ap.addNotify();
813     }
814     else
815     {
816       repaint();
817     }
818   }
819
820   /**
821    * Updates the tooltip as the mouse moves over the labels
822    * 
823    * @param evt
824    */
825   @Override
826   public void mouseMoved(MouseEvent evt)
827   {
828     showOrHideAdjuster(evt);
829
830     getSelectedRow(evt.getY() - getScrollOffset());
831
832     if (selectedRow > -1 && ap.av.getAlignment()
833             .getAlignmentAnnotation().length > selectedRow)
834     {
835       AlignmentAnnotation[] anns = ap.av.getAlignment()
836               .getAlignmentAnnotation();
837       AlignmentAnnotation aa = anns[selectedRow];
838
839       String desc = getTooltip(aa);
840       this.setToolTipText(desc);
841       String msg = getStatusMessage(aa, anns);
842       ap.alignFrame.setStatus(msg);
843     }
844   }
845
846   /**
847    * Constructs suitable text to show in the status bar when over an annotation
848    * label, containing the associated sequence name (if any), and the annotation
849    * labels (or all labels for a graph group annotation)
850    * 
851    * @param aa
852    * @param anns
853    * @return
854    */
855   static String getStatusMessage(AlignmentAnnotation aa,
856           AlignmentAnnotation[] anns)
857   {
858     if (aa == null)
859     {
860       return null;
861     }
862
863     StringBuilder msg = new StringBuilder(32);
864     if (aa.sequenceRef != null)
865     {
866       msg.append(aa.sequenceRef.getName()).append(" : ");
867     }
868
869     if (aa.graphGroup == -1)
870     {
871       msg.append(aa.label);
872     }
873     else if (anns != null)
874     {
875       boolean first = true;
876       for (int i = anns.length - 1; i >= 0; i--)
877       {
878         if (anns[i].graphGroup == aa.graphGroup)
879         {
880           if (!first)
881           {
882             msg.append(", ");
883           }
884           msg.append(anns[i].label);
885           first = false;
886         }
887       }
888     }
889
890     return msg.toString();
891   }
892
893   /**
894    * Answers a tooltip, formatted as html, containing the annotation description
895    * (prefixed by associated sequence id if applicable), and the annotation
896    * (non-positional) score if it has one. Answers null if neither description
897    * nor score is found.
898    * 
899    * @param aa
900    * @return
901    */
902   static String getTooltip(AlignmentAnnotation aa)
903   {
904     if (aa == null)
905     {
906       return null;
907     }
908     StringBuilder tooltip = new StringBuilder();
909     if (aa.description != null && !aa.description.equals("New description"))
910     {
911       // TODO: we could refactor and merge this code with the code in
912       // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
913       // tooltips
914       String desc = aa.getDescription(true).trim();
915       if (!desc.toLowerCase(Locale.ROOT).startsWith(HTML_START_TAG))
916       {
917         tooltip.append(HTML_START_TAG);
918         desc = desc.replace("<", "&lt;");
919       }
920       else if (desc.toLowerCase(Locale.ROOT).endsWith(HTML_END_TAG))
921       {
922         desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
923       }
924       tooltip.append(desc);
925     }
926     else
927     {
928       // begin the tooltip's html fragment
929       tooltip.append(HTML_START_TAG);
930     }
931     if (aa.hasScore())
932     {
933       if (tooltip.length() > HTML_START_TAG.length())
934       {
935         tooltip.append("<br/>");
936       }
937       // TODO: limit precision of score to avoid noise from imprecise
938       // doubles
939       // (64.7 becomes 64.7+/some tiny value).
940       tooltip.append(" Score: ").append(String.valueOf(aa.score));
941     }
942
943     if (tooltip.length() > HTML_START_TAG.length())
944     {
945       return tooltip.append(HTML_END_TAG).toString();
946     }
947
948     /*
949      * nothing in the tooltip (except "<html>")
950      */
951     return null;
952   }
953
954   /**
955    * Shows the height adjuster image if the mouse moves into the top left
956    * region, or hides it if the mouse leaves the regio
957    * 
958    * @param evt
959    */
960   protected void showOrHideAdjuster(MouseEvent evt)
961   {
962     boolean was = resizePanel;
963     resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
964             && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
965
966     if (resizePanel != was)
967     {
968       setCursor(Cursor
969               .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
970                       : Cursor.DEFAULT_CURSOR));
971       repaint();
972     }
973   }
974
975   @Override
976   public void mouseClicked(MouseEvent evt)
977   {
978     final AlignmentAnnotation[] aa = ap.av.getAlignment()
979             .getAlignmentAnnotation();
980     if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
981     {
982       if (selectedRow > -1 && selectedRow < aa.length)
983       {
984         if (aa[selectedRow].groupRef != null)
985         {
986           if (evt.getClickCount() >= 2)
987           {
988             // todo: make the ap scroll to the selection - not necessary, first
989             // click highlights/scrolls, second selects
990             ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
991             // process modifiers
992             SequenceGroup sg = ap.av.getSelectionGroup();
993             if (sg == null || sg == aa[selectedRow].groupRef
994                     || !(Platform.isControlDown(evt) || evt.isShiftDown()))
995             {
996               if (Platform.isControlDown(evt) || evt.isShiftDown())
997               {
998                 // clone a new selection group from the associated group
999                 ap.av.setSelectionGroup(
1000                         new SequenceGroup(aa[selectedRow].groupRef));
1001               }
1002               else
1003               {
1004                 // set selection to the associated group so it can be edited
1005                 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1006               }
1007             }
1008             else
1009             {
1010               // modify current selection with associated group
1011               int remainToAdd = aa[selectedRow].groupRef.getSize();
1012               for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1013               {
1014                 if (jalview.util.Platform.isControlDown(evt))
1015                 {
1016                   sg.addOrRemove(sgs, --remainToAdd == 0);
1017                 }
1018                 else
1019                 {
1020                   // notionally, we should also add intermediate sequences from
1021                   // last added sequence ?
1022                   sg.addSequence(sgs, --remainToAdd == 0);
1023                 }
1024               }
1025             }
1026
1027             ap.paintAlignment(false, false);
1028             PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1029             ap.av.sendSelection();
1030           }
1031           else
1032           {
1033             ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1034                     aa[selectedRow].groupRef.getSequences(null));
1035           }
1036           return;
1037         }
1038         else if (aa[selectedRow].sequenceRef != null)
1039         {
1040           if (evt.getClickCount() == 1)
1041           {
1042             ap.getSeqPanel().ap.getIdPanel()
1043                     .highlightSearchResults(Arrays.asList(new SequenceI[]
1044                     { aa[selectedRow].sequenceRef }));
1045           }
1046           else if (evt.getClickCount() >= 2)
1047           {
1048             ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1049             SequenceGroup sg = ap.av.getSelectionGroup();
1050             if (sg != null)
1051             {
1052               // we make a copy rather than edit the current selection if no
1053               // modifiers pressed
1054               // see Enhancement JAL-1557
1055               if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
1056               {
1057                 sg = new SequenceGroup(sg);
1058                 sg.clear();
1059                 sg.addSequence(aa[selectedRow].sequenceRef, false);
1060               }
1061               else
1062               {
1063                 if (Platform.isControlDown(evt))
1064                 {
1065                   sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1066                 }
1067                 else
1068                 {
1069                   // notionally, we should also add intermediate sequences from
1070                   // last added sequence ?
1071                   sg.addSequence(aa[selectedRow].sequenceRef, true);
1072                 }
1073               }
1074             }
1075             else
1076             {
1077               sg = new SequenceGroup();
1078               sg.setStartRes(0);
1079               sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1080               sg.addSequence(aa[selectedRow].sequenceRef, false);
1081             }
1082             ap.av.setSelectionGroup(sg);
1083             ap.paintAlignment(false, false);
1084             PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1085             ap.av.sendSelection();
1086           }
1087
1088         }
1089       }
1090       return;
1091     }
1092   }
1093
1094   /**
1095    * do a single sequence copy to jalview and the system clipboard
1096    * 
1097    * @param sq
1098    *          sequence to be copied to clipboard
1099    */
1100   protected void copy_annotseqtoclipboard(SequenceI sq)
1101   {
1102     SequenceI[] seqs = new SequenceI[] { sq };
1103     String[] omitHidden = null;
1104     SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1105     if (dseqs[0] == null)
1106     {
1107       dseqs[0] = new Sequence(sq);
1108       dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
1109               sq.getSequenceAsString()));
1110
1111       sq.setDatasetSequence(dseqs[0]);
1112     }
1113     Alignment ds = new Alignment(dseqs);
1114     if (av.hasHiddenColumns())
1115     {
1116       Iterator<int[]> it = av.getAlignment().getHiddenColumns()
1117               .getVisContigsIterator(0, sq.getLength(), false);
1118       omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
1119     }
1120
1121     int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1122     if (av.hasHiddenColumns())
1123     {
1124       alignmentStartEnd = av.getAlignment().getHiddenColumns()
1125               .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1126     }
1127
1128     String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1129             seqs, omitHidden, alignmentStartEnd);
1130
1131     Toolkit.getDefaultToolkit().getSystemClipboard()
1132             .setContents(new StringSelection(output), Desktop.instance);
1133
1134     HiddenColumns hiddenColumns = null;
1135
1136     if (av.hasHiddenColumns())
1137     {
1138       hiddenColumns = new HiddenColumns(
1139               av.getAlignment().getHiddenColumns());
1140     }
1141
1142     Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1143                                                         // of a consensus
1144                                                         // sequence ? need to
1145                                                         // flag
1146         // sequence as special.
1147         hiddenColumns };
1148   }
1149
1150   /**
1151    * DOCUMENT ME!
1152    * 
1153    * @param g1
1154    *          DOCUMENT ME!
1155    */
1156   @Override
1157   public void paintComponent(Graphics g)
1158   {
1159
1160     int width = getWidth();
1161     if (width == 0)
1162     {
1163       width = ap.calculateIdWidth().width;
1164     }
1165
1166     Graphics2D g2 = (Graphics2D) g;
1167     if (av.antiAlias)
1168     {
1169       g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1170               RenderingHints.VALUE_ANTIALIAS_ON);
1171     }
1172
1173     drawComponent(g2, true, width, true);
1174   }
1175
1176   /**
1177    * Draw the full set of annotation Labels for the alignment at the given
1178    * cursor
1179    * 
1180    * @param g
1181    *          Graphics2D instance (needed for font scaling)
1182    * @param width
1183    *          Width for scaling labels
1184    * 
1185    */
1186   public void drawComponent(Graphics g, int width)
1187   {
1188     drawComponent(g, false, width, true);
1189   }
1190
1191   /**
1192    * Draw the full set of annotation Labels for the alignment at the given
1193    * cursor
1194    * 
1195    * @param g
1196    *          Graphics2D instance (needed for font scaling)
1197    * @param clip
1198    *          - true indicates that only current visible area needs to be
1199    *          rendered
1200    * @param width
1201    *          Width for scaling labels
1202    */
1203   public void drawComponent(Graphics g, boolean clip, int givenWidth,
1204           boolean forGUI)
1205   {
1206     int width = givenWidth;
1207     IdwidthAdjuster iwa = null;
1208     if (ap != null)
1209     {
1210       iwa = ap.idwidthAdjuster;
1211       if ((Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true)
1212               || Jalview.isHeadlessMode()))
1213       {
1214         Graphics2D g2d = (Graphics2D) g;
1215         Graphics dummy = g2d.create();
1216         int newAnnotationIdWidth = drawLabels(dummy, clip, width, false,
1217                 forGUI, null, false);
1218         dummy.dispose();
1219         Dimension d = ap.calculateDefaultAlignmentIdWidth();
1220         int alignmentIdWidth = d.width;
1221         if (iwa != null && !iwa.manuallyAdjusted())
1222         {
1223           // If no manual adjustment to ID column with has been made then adjust
1224           // width match widest of alignment or annotation id widths
1225           boolean allowShrink = Cache.getDefault("ALLOW_SHRINK_ID_WIDTH",
1226                   false);
1227           width = Math.max(alignmentIdWidth, newAnnotationIdWidth);
1228           if (clip && width < givenWidth && !allowShrink)
1229           {
1230             width = givenWidth;
1231           }
1232         }
1233         else if (newAnnotationIdWidth != annotationIdWidth
1234                 && newAnnotationIdWidth > givenWidth
1235                 && newAnnotationIdWidth > alignmentIdWidth)
1236         {
1237           // otherwise if the annotation id width has become larger than the
1238           // current id width, increase
1239           width = newAnnotationIdWidth;
1240           annotationIdWidth = newAnnotationIdWidth;
1241         }
1242         // set the width if it's changed
1243         if (width != ap.av.getIdWidth())
1244         {
1245           iwa.setWidth(width);
1246         }
1247       }
1248     }
1249     else
1250     {
1251       int newAnnotationIdWidth = drawLabels(g, clip, width, false, forGUI,
1252               null, false);
1253       width = newAnnotationIdWidth < givenWidth ? givenWidth
1254               : Math.min(newAnnotationIdWidth, givenWidth);
1255     }
1256     drawLabels(g, clip, width, true, forGUI, null, false);
1257   }
1258
1259   /**
1260    * Render the full set of annotation Labels for the alignment at the given
1261    * cursor. If actuallyDraw is false or g is null then no actual drawing will
1262    * occur, but the widest label width will be returned. If g is null then
1263    * fmetrics must be supplied.
1264    * 
1265    * @param g
1266    *          Graphics2D instance (used for rendering and font scaling if no
1267    *          fmetrics supplied)
1268    * @param clip
1269    *          - true indicates that only current visible area needs to be
1270    *          rendered
1271    * @param width
1272    *          Width for scaling labels
1273    * @param actuallyDraw
1274    *          - when false, no graphics are rendered to g0
1275    * @param forGUI
1276    *          - when false, GUI relevant marks like indicators for dragging
1277    *          annotation panel height are not rendered
1278    * @param fmetrics
1279    *          FontMetrics if Graphics object g is null
1280    * @param includeHidden
1281    *          - when true returned width includes labels in hidden row width
1282    *          calculation
1283    * @return the width of the annotation labels.
1284    */
1285   public int drawLabels(Graphics g0, boolean clip, int width,
1286           boolean actuallyDraw, boolean forGUI, FontMetrics fmetrics,
1287           boolean includeHidden)
1288   {
1289     if (clip)
1290     {
1291       clip = Cache.getDefault("MOVE_SEQUENCE_ID_WITH_VISIBLE_ANNOTATIONS",
1292               true);
1293     }
1294     Graphics g = null;
1295     // create a dummy Graphics object if not drawing and one is supplied
1296     if (g0 != null)
1297     {
1298       if (!actuallyDraw)
1299       {
1300         Graphics2D g2d = (Graphics2D) g0;
1301         g = g2d.create();
1302       }
1303       else
1304       {
1305         g = g0;
1306       }
1307     }
1308     int actualWidth = 0;
1309     if (g != null)
1310     {
1311       if (av.getFont().getSize() < 10)
1312       {
1313         g.setFont(font);
1314       }
1315       else
1316       {
1317         g.setFont(av.getFont());
1318       }
1319     }
1320
1321     FontMetrics fm = fmetrics == null ? g.getFontMetrics(g.getFont())
1322             : fmetrics;
1323     if (actuallyDraw)
1324     {
1325       g.setColor(Color.white);
1326       g.fillRect(0, 0, getWidth(), getHeight());
1327
1328       if (!Cache.getDefault(RESIZE_MARGINS_MARK_PREF, false)
1329               && !av.getWrapAlignment() && forGUI)
1330       {
1331         g.setColor(Color.LIGHT_GRAY);
1332         g.drawLine(0, HEIGHT_ADJUSTER_HEIGHT / 4, HEIGHT_ADJUSTER_WIDTH / 4,
1333                 HEIGHT_ADJUSTER_HEIGHT / 4);
1334         g.drawLine(0, 3 * HEIGHT_ADJUSTER_HEIGHT / 4,
1335                 HEIGHT_ADJUSTER_WIDTH / 4, 3 * HEIGHT_ADJUSTER_HEIGHT / 4);
1336
1337       }
1338     }
1339
1340     if (actuallyDraw)
1341     {
1342       g.translate(0, getScrollOffset());
1343       g.setColor(Color.black);
1344     }
1345     SequenceI lastSeqRef = null;
1346     String lastLabel = null;
1347     AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1348     int fontHeight = g != null ? g.getFont().getSize()
1349             : fm.getFont().getSize();
1350     int y = 0;
1351     int x = 0;
1352     int graphExtras = 0;
1353     int offset = 0;
1354     Font baseFont = g != null ? g.getFont() : fm.getFont();
1355     FontMetrics baseMetrics = fm;
1356     int ofontH = fontHeight;
1357     int sOffset = 0;
1358     int visHeight = 0;
1359     int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1360             ? ap.getAnnotationPanel().getVisibleVRange()
1361             : null;
1362     if (clip && visr != null)
1363     {
1364       sOffset = visr[0];
1365       visHeight = visr[1];
1366     }
1367     boolean visible = true, before = false, after = false;
1368     if (aa != null)
1369     {
1370       hasHiddenRows = false;
1371       int olY = 0;
1372       int nexAA = 0;
1373       for (int i = 0; i < aa.length; i++)
1374       {
1375         visible = true;
1376         if (!aa[i].visible && !includeHidden)
1377         {
1378           hasHiddenRows = true;
1379           continue;
1380         }
1381         olY = y;
1382         // look ahead to next annotation
1383         for (nexAA = i + 1; nexAA < aa.length
1384                 && (!aa[nexAA].visible && includeHidden); nexAA++)
1385           ;
1386         y += aa[i].height;
1387         if (clip)
1388         {
1389           if (y < sOffset)
1390           {
1391             if (!before)
1392             {
1393               if (debugRedraw)
1394               {
1395                 jalview.bin.Console.outPrintln("before vis: " + i);
1396               }
1397               before = true;
1398             }
1399             // don't draw what isn't visible
1400             continue;
1401           }
1402           if (olY > visHeight)
1403           {
1404
1405             if (!after)
1406             {
1407               if (debugRedraw)
1408               {
1409                 jalview.bin.Console.outPrintln(
1410                         "Scroll offset: " + sOffset + " after vis: " + i);
1411               }
1412               after = true;
1413             }
1414             // don't draw what isn't visible
1415             continue;
1416           }
1417         }
1418         if (actuallyDraw && g != null)
1419         {
1420           g.setColor(Color.black);
1421         }
1422         offset = -aa[i].height / 2;
1423
1424         if (aa[i].hasText)
1425         {
1426           offset += fm.getHeight() / 2;
1427           offset -= fm.getDescent();
1428         }
1429         else
1430         {
1431           offset += fm.getDescent();
1432         }
1433         String label = aa[i].label;
1434         boolean vertBar = false;
1435         if ((lastLabel != null && lastLabel.equals(label)))
1436         {
1437           label = aa[i].description;
1438         }
1439         else
1440         {
1441           if (nexAA < aa.length && label.equals(aa[nexAA].label)) // &&
1442                                                                   // aa[nexY].sequenceRef==aa[i].sequenceRef)
1443           {
1444             lastLabel = label;
1445             // next label is the same as this label
1446             label = aa[i].description;
1447           }
1448           else
1449           {
1450             lastLabel = label;
1451           }
1452         }
1453         if (aa[i].sequenceRef != null)
1454         {
1455           if (aa[i].sequenceRef != lastSeqRef)
1456           {
1457             label = aa[i].sequenceRef.getName() + " " + label;
1458             // TODO record relationship between sequence and this annotation and
1459             // display it here
1460           }
1461           else
1462           {
1463             vertBar = true;
1464           }
1465         }
1466
1467         int labelWidth = fm.stringWidth(label) + 3;
1468         x = width - labelWidth;
1469
1470         if (aa[i].graphGroup > -1)
1471         {
1472           int groupSize = 0;
1473           // TODO: JAL-1291 revise rendering model so the graphGroup map is
1474           // computed efficiently for all visible labels
1475           for (int gg = 0; gg < aa.length; gg++)
1476           {
1477             if (aa[gg].graphGroup == aa[i].graphGroup)
1478             {
1479               groupSize++;
1480             }
1481           }
1482           if (groupSize * (fontHeight + 8) < aa[i].height)
1483           {
1484             graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1485                     / 2;
1486           }
1487           else
1488           {
1489             // scale font to fit
1490             float h = aa[i].height / (float) groupSize, s;
1491             if (h < 9)
1492             {
1493               visible = false;
1494             }
1495             else
1496             {
1497               fontHeight = -8 + (int) h;
1498               s = ((float) fontHeight) / (float) ofontH;
1499               Font f = baseFont
1500                       .deriveFont(AffineTransform.getScaleInstance(s, s));
1501               Canvas c = new Canvas();
1502               fm = c.getFontMetrics(f);
1503               if (actuallyDraw && g != null)
1504               {
1505                 g.setFont(f);
1506                 // fm = g.getFontMetrics();
1507                 graphExtras = (aa[i].height
1508                         - (groupSize * (fontHeight + 8))) / 2;
1509               }
1510             }
1511           }
1512           if (visible)
1513           {
1514             for (int gg = 0; gg < aa.length; gg++)
1515             {
1516               if (aa[gg].graphGroup == aa[i].graphGroup)
1517               {
1518                 labelWidth = fm.stringWidth(aa[gg].label) + 3;
1519                 x = width - labelWidth;
1520                 if (actuallyDraw && g != null)
1521                 {
1522                   g.drawString(aa[gg].label, x, y - graphExtras);
1523
1524                   if (aa[gg]._linecolour != null)
1525                   {
1526
1527                     g.setColor(aa[gg]._linecolour);
1528                     g.drawLine(x, y - graphExtras + 3,
1529                             x + fm.stringWidth(aa[gg].label),
1530                             y - graphExtras + 3);
1531                   }
1532
1533                   g.setColor(Color.black);
1534                 }
1535                 graphExtras += fontHeight + 8;
1536               }
1537             }
1538           }
1539           if (actuallyDraw && g != null)
1540           {
1541             g.setFont(baseFont);
1542           }
1543           fm = baseMetrics;
1544           fontHeight = ofontH;
1545         }
1546         else
1547         {
1548           if (actuallyDraw && g != null)
1549           {
1550             if (vertBar)
1551             {
1552               g.drawLine(width - 3, y + offset - fontHeight, width - 3,
1553                       (int) (y - 1.5 * aa[i].height - offset - fontHeight));
1554               // g.drawLine(20, y + offset, x - 20, y + offset);
1555
1556             }
1557             g.drawString(label, x, y + offset);
1558           }
1559         }
1560         lastSeqRef = aa[i].sequenceRef;
1561
1562         if (labelWidth > actualWidth)
1563         {
1564           actualWidth = labelWidth;
1565         }
1566       }
1567     }
1568
1569     if (!resizePanel && dragEvent != null && aa != null && selectedRow > -1
1570             && selectedRow < aa.length)
1571     {
1572       if (actuallyDraw && g != null)
1573       {
1574         g.setColor(Color.lightGray);
1575         g.drawString(
1576                 (aa[selectedRow].sequenceRef == null ? ""
1577                         : aa[selectedRow].sequenceRef.getName())
1578                         + aa[selectedRow].label,
1579                 dragEvent.getX(), dragEvent.getY() - getScrollOffset());
1580       }
1581     }
1582
1583     if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1584     {
1585       if (actuallyDraw && g != null)
1586       {
1587         g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1588         g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1589                 18);
1590       }
1591     }
1592
1593     return actualWidth;
1594   }
1595
1596   public int getScrollOffset()
1597   {
1598     return scrollOffset;
1599   }
1600
1601   @Override
1602   public void mouseEntered(MouseEvent e)
1603   {
1604   }
1605
1606   public void drawComponentNotGUI(Graphics idGraphics, int idWidth)
1607   {
1608     drawComponent(idGraphics, false, idWidth, false);
1609   }
1610 }