2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import java.awt.Color;
24 import java.awt.Cursor;
25 import java.awt.Dimension;
27 import java.awt.FontMetrics;
28 import java.awt.Graphics;
29 import java.awt.Graphics2D;
30 import java.awt.RenderingHints;
31 import java.awt.Toolkit;
32 import java.awt.datatransfer.StringSelection;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.MouseEvent;
36 import java.awt.event.MouseListener;
37 import java.awt.event.MouseMotionListener;
38 import java.awt.geom.AffineTransform;
39 import java.util.Arrays;
40 import java.util.Collections;
41 import java.util.Iterator;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JMenuItem;
45 import javax.swing.JPanel;
46 import javax.swing.JPopupMenu;
47 import javax.swing.SwingUtilities;
48 import javax.swing.ToolTipManager;
50 import jalview.analysis.AlignSeq;
51 import jalview.analysis.AlignmentUtils;
52 import jalview.datamodel.Alignment;
53 import jalview.datamodel.AlignmentAnnotation;
54 import jalview.datamodel.Annotation;
55 import jalview.datamodel.HiddenColumns;
56 import jalview.datamodel.Sequence;
57 import jalview.datamodel.SequenceGroup;
58 import jalview.datamodel.SequenceI;
59 import jalview.io.FileFormat;
60 import jalview.io.FormatAdapter;
61 import jalview.util.Comparison;
62 import jalview.util.MessageManager;
63 import jalview.util.Platform;
64 import jalview.workers.InformationThread;
67 * The panel that holds the labels for alignment annotations, providing
68 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
71 public class AnnotationLabels extends JPanel
72 implements MouseListener, MouseMotionListener, ActionListener
74 private static final String HTML_END_TAG = "</html>";
76 private static final String HTML_START_TAG = "<html>";
79 * width in pixels within which height adjuster arrows are shown and active
81 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
84 * height in pixels for allowing height adjuster to be active
86 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
88 private static final Font font = new Font("Arial", Font.PLAIN, 11);
90 private static final String TOGGLE_LABELSCALE = MessageManager
91 .getString("label.scale_label_to_column");
93 private static final String ADDNEW = MessageManager
94 .getString("label.add_new_row");
96 private static final String EDITNAME = MessageManager
97 .getString("label.edit_label_description");
99 private static final String HIDE = MessageManager
100 .getString("label.hide_row");
102 private static final String DELETE = MessageManager
103 .getString("label.delete_row");
105 private static final String SHOWALL = MessageManager
106 .getString("label.show_all_hidden_rows");
108 private static final String OUTPUT_TEXT = MessageManager
109 .getString("label.export_annotation");
111 private static final String COPYCONS_SEQ = MessageManager
112 .getString("label.copy_consensus_sequence");
114 private final boolean debugRedraw = false;
116 private AlignmentPanel ap;
120 private MouseEvent dragEvent;
124 private int selectedRow;
126 private int scrollOffset = 0;
128 private boolean hasHiddenRows;
130 private boolean resizePanel = false;
133 * Creates a new AnnotationLabels object
137 public AnnotationLabels(AlignmentPanel ap)
142 ToolTipManager.sharedInstance().registerComponent(this);
144 addMouseListener(this);
145 addMouseMotionListener(this);
146 addMouseWheelListener(ap.getAnnotationPanel());
149 public AnnotationLabels(AlignViewport av)
160 public void setScrollOffset(int y)
167 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
171 * coordinate position to search for a row
173 void getSelectedRow(int y)
176 AlignmentAnnotation[] aa = ap.av.getAlignment()
177 .getAlignmentAnnotation();
181 for (int i = 0; i < aa.length; i++)
189 height += aa[i].height;
208 public void actionPerformed(ActionEvent evt)
210 AlignmentAnnotation[] aa = ap.av.getAlignment()
211 .getAlignmentAnnotation();
213 String action = evt.getActionCommand();
214 if (ADDNEW.equals(action))
217 * non-returning dialog
219 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
220 null, new Annotation[ap.av.getAlignment().getWidth()]);
221 editLabelDescription(newAnnotation, true);
223 else if (EDITNAME.equals(action))
226 * non-returning dialog
228 editLabelDescription(aa[selectedRow], false);
230 else if (HIDE.equals(action))
232 aa[selectedRow].visible = false;
234 else if (DELETE.equals(action))
236 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
237 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
239 else if (SHOWALL.equals(action))
241 for (int i = 0; i < aa.length; i++)
243 if (!aa[i].visible && aa[i].annotations != null)
245 aa[i].visible = true;
249 else if (OUTPUT_TEXT.equals(action))
251 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
253 else if (COPYCONS_SEQ.equals(action))
255 SequenceI cons = null;
256 if (aa[selectedRow].groupRef != null)
258 cons = aa[selectedRow].groupRef.getConsensusSeq();
262 cons = av.getConsensusSeq();
266 copy_annotseqtoclipboard(cons);
269 else if (TOGGLE_LABELSCALE.equals(action))
271 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
278 * Shows a dialog where the annotation name and description may be edited. If
279 * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
280 * is added, else an existing annotation is updated.
285 void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
287 String name = MessageManager.getString("label.annotation_name");
288 String description = MessageManager
289 .getString("label.annotation_description");
290 String title = MessageManager
291 .getString("label.edit_annotation_name_description");
292 EditNameDialog dialog = new EditNameDialog(annotation.label,
293 annotation.description, name, description);
295 dialog.showDialog(ap.alignFrame, title,
301 annotation.label = dialog.getName();
302 String text = dialog.getDescription();
303 if (text != null && text.length() == 0)
307 annotation.description = text;
310 ap.av.getAlignment().addAnnotation(annotation);
311 ap.av.getAlignment().setAnnotationIndex(annotation, 0);
319 public void mousePressed(MouseEvent evt)
321 getSelectedRow(evt.getY() - getScrollOffset());
323 if (evt.isPopupTrigger())
330 * Build and show the Pop-up menu at the right-click mouse position
334 void showPopupMenu(MouseEvent evt)
337 final AlignmentAnnotation[] aa = ap.av.getAlignment()
338 .getAlignmentAnnotation();
340 JPopupMenu pop = new JPopupMenu(
341 MessageManager.getString("label.annotations"));
342 JMenuItem item = new JMenuItem(ADDNEW);
343 item.addActionListener(this);
348 { // let the user make everything visible again
349 item = new JMenuItem(SHOWALL);
350 item.addActionListener(this);
353 pop.show(this, evt.getX(), evt.getY());
357 final AlignmentAnnotation ann = aa[selectedRow];
358 final boolean isSequenceAnnotation = ann.sequenceRef != null;
360 item = new JMenuItem(EDITNAME);
361 item.addActionListener(this);
363 item = new JMenuItem(HIDE);
364 item.addActionListener(this);
366 // JAL-1264 hide all sequence-specific annotations of this type
367 if (selectedRow < aa.length)
369 if (aa[selectedRow].sequenceRef != null)
371 final String label = aa[selectedRow].label;
372 JMenuItem hideType = new JMenuItem();
373 String text = MessageManager.getString("label.hide_all") + " "
375 hideType.setText(text);
376 hideType.addActionListener(new ActionListener()
379 public void actionPerformed(ActionEvent e)
381 AlignmentUtils.showOrHideSequenceAnnotations(
382 ap.av.getAlignment(), Collections.singleton(label),
390 item = new JMenuItem(DELETE);
391 item.addActionListener(this);
395 item = new JMenuItem(SHOWALL);
396 item.addActionListener(this);
399 item = new JMenuItem(OUTPUT_TEXT);
400 item.addActionListener(this);
402 // TODO: annotation object should be typed for autocalculated/derived
404 if (selectedRow < aa.length)
406 final String label = aa[selectedRow].label;
407 if (!(aa[selectedRow].autoCalculated)
408 && !(InformationThread.HMM_CALC_ID.equals(ann.getCalcId())))
410 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
412 // display formatting settings for this row.
414 // av and sequencegroup need to implement same interface for
415 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
416 aa[selectedRow].scaleColLabel);
417 item.addActionListener(this);
421 else if (label.indexOf("Consensus") > -1)
423 addConsensusMenuOptions(ap, aa[selectedRow], pop);
425 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
426 consclipbrd.addActionListener(this);
427 pop.add(consclipbrd);
429 else if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))
431 addHmmerMenu(pop, ann);
434 pop.show(this, evt.getX(), evt.getY());
438 * Adds context menu options for (alignment or group) Hmmer annotation
443 protected void addHmmerMenu(JPopupMenu pop, final AlignmentAnnotation ann)
445 final boolean isGroupAnnotation = ann.groupRef != null;
447 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
448 MessageManager.getString(
449 "label.ignore_below_background_frequency"),
452 .isIgnoreBelowBackground()
453 : ap.av.isIgnoreBelowBackground());
454 cbmi.addActionListener(new ActionListener()
457 public void actionPerformed(ActionEvent e)
459 if (isGroupAnnotation)
461 if (!ann.groupRef.isUseInfoLetterHeight())
463 ann.groupRef.setIgnoreBelowBackground(cbmi.getState());
464 // todo and recompute group annotation
467 else if (!ap.av.isInfoLetterHeight())
469 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
470 // todo and recompute annotation
472 ap.alignmentChanged(); // todo not like this
476 final JCheckBoxMenuItem letterHeight = new JCheckBoxMenuItem(
477 MessageManager.getString("label.use_info_for_height"),
478 isGroupAnnotation ? ann.groupRef.isUseInfoLetterHeight()
479 : ap.av.isInfoLetterHeight());
480 letterHeight.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent e)
485 if (isGroupAnnotation)
487 ann.groupRef.setInfoLetterHeight((letterHeight.getState()));
488 ann.groupRef.setIgnoreBelowBackground(true);
489 // todo and recompute group annotation
493 ap.av.setInfoLetterHeight(letterHeight.getState(), ap);
494 ap.av.setIgnoreBelowBackground(true, ap);
495 // todo and recompute annotation
497 ap.alignmentChanged();
500 pop.add(letterHeight);
501 if (isGroupAnnotation)
503 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
504 MessageManager.getString("label.show_group_histogram"),
505 ann.groupRef.isShowInformationHistogram());
506 chist.addActionListener(new ActionListener()
509 public void actionPerformed(ActionEvent e)
511 ann.groupRef.setShowInformationHistogram(chist.getState());
516 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
517 MessageManager.getString("label.show_group_logo"),
518 ann.groupRef.isShowHMMSequenceLogo());
519 cprofl.addActionListener(new ActionListener()
522 public void actionPerformed(ActionEvent e)
524 ann.groupRef.setShowHMMSequenceLogo(cprofl.getState());
529 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
530 MessageManager.getString("label.normalise_group_logo"),
531 ann.groupRef.isNormaliseHMMSequenceLogo());
532 cproflnorm.addActionListener(new ActionListener()
535 public void actionPerformed(ActionEvent e)
538 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
539 // automatically enable logo display if we're clicked
540 ann.groupRef.setShowHMMSequenceLogo(true);
548 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
549 MessageManager.getString("label.show_histogram"),
550 av.isShowInformationHistogram());
551 chist.addActionListener(new ActionListener()
554 public void actionPerformed(ActionEvent e)
556 av.setShowInformationHistogram(chist.getState());
561 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
562 MessageManager.getString("label.show_logo"),
563 av.isShowHMMSequenceLogo());
564 cprof.addActionListener(new ActionListener()
567 public void actionPerformed(ActionEvent e)
569 av.setShowHMMSequenceLogo(cprof.getState());
574 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
575 MessageManager.getString("label.normalise_logo"),
576 av.isNormaliseHMMSequenceLogo());
577 cprofnorm.addActionListener(new ActionListener()
580 public void actionPerformed(ActionEvent e)
582 av.setShowHMMSequenceLogo(true);
583 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
592 * A helper method that adds menu options for calculation and visualisation of
593 * group and/or alignment consensus annotation to a popup menu. This is
594 * designed to be reusable for either unwrapped mode (popup menu is shown on
595 * component AnnotationLabels), or wrapped mode (popup menu is shown on
596 * IdPanel when the mouse is over an annotation label).
602 static void addConsensusMenuOptions(AlignmentPanel ap,
603 AlignmentAnnotation ann,
608 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
609 MessageManager.getString("label.ignore_gaps_consensus"),
610 (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
611 : ap.av.isIgnoreGapsConsensus());
612 final AlignmentAnnotation aaa = ann;
613 cbmi.addActionListener(new ActionListener()
616 public void actionPerformed(ActionEvent e)
618 if (aaa.groupRef != null)
620 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
621 ap.getAnnotationPanel()
622 .paint(ap.getAnnotationPanel().getGraphics());
626 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
628 ap.alignmentChanged();
633 if (aaa.groupRef != null)
636 * group consensus options
638 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
639 MessageManager.getString("label.show_group_histogram"),
640 ann.groupRef.isShowConsensusHistogram());
641 chist.addActionListener(new ActionListener()
644 public void actionPerformed(ActionEvent e)
646 aaa.groupRef.setShowConsensusHistogram(chist.getState());
651 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
652 MessageManager.getString("label.show_group_logo"),
653 ann.groupRef.isShowSequenceLogo());
654 cprofl.addActionListener(new ActionListener()
657 public void actionPerformed(ActionEvent e)
659 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
664 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
665 MessageManager.getString("label.normalise_group_logo"),
666 ann.groupRef.isNormaliseSequenceLogo());
667 cproflnorm.addActionListener(new ActionListener()
670 public void actionPerformed(ActionEvent e)
672 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
673 // automatically enable logo display if we're clicked
674 aaa.groupRef.setshowSequenceLogo(true);
683 * alignment consensus options
685 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
686 MessageManager.getString("label.show_histogram"),
687 ap.av.isShowConsensusHistogram());
688 chist.addActionListener(new ActionListener()
691 public void actionPerformed(ActionEvent e)
693 ap.av.setShowConsensusHistogram(chist.getState());
694 ap.alignFrame.setMenusForViewport();
699 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
700 MessageManager.getString("label.show_logo"),
701 ap.av.isShowSequenceLogo());
702 cprof.addActionListener(new ActionListener()
705 public void actionPerformed(ActionEvent e)
707 ap.av.setShowSequenceLogo(cprof.getState());
708 ap.alignFrame.setMenusForViewport();
713 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
714 MessageManager.getString("label.normalise_logo"),
715 ap.av.isNormaliseSequenceLogo());
716 cprofnorm.addActionListener(new ActionListener()
719 public void actionPerformed(ActionEvent e)
721 ap.av.setShowSequenceLogo(true);
722 ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
723 ap.alignFrame.setMenusForViewport();
732 * Reorders annotation rows after a drag of a label
737 public void mouseReleased(MouseEvent evt)
739 if (evt.isPopupTrigger())
745 int start = selectedRow;
746 getSelectedRow(evt.getY() - getScrollOffset());
747 int end = selectedRow;
750 * if dragging to resize instead, start == end
754 // Swap these annotations
755 AlignmentAnnotation startAA = ap.av.getAlignment()
756 .getAlignmentAnnotation()[start];
759 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
761 AlignmentAnnotation endAA = ap.av.getAlignment()
762 .getAlignmentAnnotation()[end];
764 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
765 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
771 ap.getAnnotationPanel().repaint();
775 * Removes the height adjuster image on leaving the panel, unless currently
779 public void mouseExited(MouseEvent evt)
781 if (resizePanel && dragEvent == null)
789 * A mouse drag may be either an adjustment of the panel height (if flag
790 * resizePanel is set on), or a reordering of the annotation rows. The former
791 * is dealt with by this method, the latter in mouseReleased.
796 public void mouseDragged(MouseEvent evt)
802 Dimension d = ap.annotationScroller.getPreferredSize();
803 int dif = evt.getY() - oldY;
805 dif /= ap.av.getCharHeight();
806 dif *= ap.av.getCharHeight();
808 if ((d.height - dif) > 20)
810 ap.annotationScroller
811 .setPreferredSize(new Dimension(d.width, d.height - dif));
812 d = ap.annotationSpaceFillerHolder.getPreferredSize();
813 ap.annotationSpaceFillerHolder
814 .setPreferredSize(new Dimension(d.width, d.height - dif));
815 ap.paintAlignment(true, false);
827 * Updates the tooltip as the mouse moves over the labels
832 public void mouseMoved(MouseEvent evt)
834 showOrHideAdjuster(evt);
836 getSelectedRow(evt.getY() - getScrollOffset());
838 if (selectedRow > -1 && ap.av.getAlignment()
839 .getAlignmentAnnotation().length > selectedRow)
841 AlignmentAnnotation[] anns = ap.av.getAlignment()
842 .getAlignmentAnnotation();
843 AlignmentAnnotation aa = anns[selectedRow];
845 String desc = getTooltip(aa);
846 this.setToolTipText(desc);
847 String msg = getStatusMessage(aa, anns);
848 ap.alignFrame.setStatus(msg);
853 * Constructs suitable text to show in the status bar when over an annotation
854 * label, containing the associated sequence name (if any), and the annotation
855 * labels (or all labels for a graph group annotation)
861 static String getStatusMessage(AlignmentAnnotation aa,
862 AlignmentAnnotation[] anns)
869 StringBuilder msg = new StringBuilder(32);
870 if (aa.sequenceRef != null)
872 msg.append(aa.sequenceRef.getName()).append(" : ");
875 if (aa.graphGroup == -1)
877 msg.append(aa.label);
879 else if (anns != null)
881 boolean first = true;
882 for (int i = anns.length - 1; i >= 0; i--)
884 if (anns[i].graphGroup == aa.graphGroup)
890 msg.append(anns[i].label);
896 return msg.toString();
900 * Answers a tooltip, formatted as html, containing the annotation description
901 * (prefixed by associated sequence id if applicable), and the annotation
902 * (non-positional) score if it has one. Answers null if neither description
903 * nor score is found.
908 static String getTooltip(AlignmentAnnotation aa)
914 StringBuilder tooltip = new StringBuilder();
915 if (aa.description != null && !aa.description.equals("New description"))
917 // TODO: we could refactor and merge this code with the code in
918 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
920 String desc = aa.getDescription(true).trim();
921 if (!desc.toLowerCase().startsWith(HTML_START_TAG))
923 tooltip.append(HTML_START_TAG);
924 desc = desc.replace("<", "<");
926 else if (desc.toLowerCase().endsWith(HTML_END_TAG))
928 desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
930 tooltip.append(desc);
934 // begin the tooltip's html fragment
935 tooltip.append(HTML_START_TAG);
939 if (tooltip.length() > HTML_START_TAG.length())
941 tooltip.append("<br/>");
943 // TODO: limit precision of score to avoid noise from imprecise
945 // (64.7 becomes 64.7+/some tiny value).
946 tooltip.append(" Score: ").append(String.valueOf(aa.score));
949 if (tooltip.length() > HTML_START_TAG.length())
951 return tooltip.append(HTML_END_TAG).toString();
955 * nothing in the tooltip (except "<html>")
961 * Shows the height adjuster image if the mouse moves into the top left
962 * region, or hides it if the mouse leaves the regio
966 protected void showOrHideAdjuster(MouseEvent evt)
968 boolean was = resizePanel;
969 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
970 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
972 if (resizePanel != was)
975 .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
976 : Cursor.DEFAULT_CURSOR));
982 public void mouseClicked(MouseEvent evt)
984 final AlignmentAnnotation[] aa = ap.av.getAlignment()
985 .getAlignmentAnnotation();
986 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
988 if (selectedRow > -1 && selectedRow < aa.length)
990 if (aa[selectedRow].groupRef != null)
992 if (evt.getClickCount() >= 2)
994 // todo: make the ap scroll to the selection - not necessary, first
995 // click highlights/scrolls, second selects
996 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
998 SequenceGroup sg = ap.av.getSelectionGroup();
999 if (sg == null || sg == aa[selectedRow].groupRef
1000 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
1002 if (Platform.isControlDown(evt) || evt.isShiftDown())
1004 // clone a new selection group from the associated group
1005 ap.av.setSelectionGroup(
1006 new SequenceGroup(aa[selectedRow].groupRef));
1010 // set selection to the associated group so it can be edited
1011 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1016 // modify current selection with associated group
1017 int remainToAdd = aa[selectedRow].groupRef.getSize();
1018 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1020 if (jalview.util.Platform.isControlDown(evt))
1022 sg.addOrRemove(sgs, --remainToAdd == 0);
1026 // notionally, we should also add intermediate sequences from
1027 // last added sequence ?
1028 sg.addSequence(sgs, --remainToAdd == 0);
1033 ap.paintAlignment(false, false);
1034 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1035 ap.av.sendSelection();
1039 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1040 aa[selectedRow].groupRef.getSequences(null));
1044 else if (aa[selectedRow].sequenceRef != null)
1046 if (evt.getClickCount() == 1)
1048 ap.getSeqPanel().ap.getIdPanel()
1049 .highlightSearchResults(Arrays.asList(new SequenceI[]
1050 { aa[selectedRow].sequenceRef }));
1052 else if (evt.getClickCount() >= 2)
1054 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1055 SequenceGroup sg = ap.av.getSelectionGroup();
1058 // we make a copy rather than edit the current selection if no
1059 // modifiers pressed
1060 // see Enhancement JAL-1557
1061 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
1063 sg = new SequenceGroup(sg);
1065 sg.addSequence(aa[selectedRow].sequenceRef, false);
1069 if (Platform.isControlDown(evt))
1071 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1075 // notionally, we should also add intermediate sequences from
1076 // last added sequence ?
1077 sg.addSequence(aa[selectedRow].sequenceRef, true);
1083 sg = new SequenceGroup();
1085 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1086 sg.addSequence(aa[selectedRow].sequenceRef, false);
1088 ap.av.setSelectionGroup(sg);
1089 ap.paintAlignment(false, false);
1090 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1091 ap.av.sendSelection();
1100 * do a single sequence copy to jalview and the system clipboard
1103 * sequence to be copied to clipboard
1105 protected void copy_annotseqtoclipboard(SequenceI sq)
1107 SequenceI[] seqs = new SequenceI[] { sq };
1108 String[] omitHidden = null;
1109 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1110 if (dseqs[0] == null)
1112 dseqs[0] = new Sequence(sq);
1113 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
1114 sq.getSequenceAsString()));
1116 sq.setDatasetSequence(dseqs[0]);
1118 Alignment ds = new Alignment(dseqs);
1119 if (av.hasHiddenColumns())
1121 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
1122 .getVisContigsIterator(0, sq.getLength(), false);
1123 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
1126 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1127 if (av.hasHiddenColumns())
1129 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1130 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1133 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1134 seqs, omitHidden, alignmentStartEnd);
1136 Toolkit.getDefaultToolkit().getSystemClipboard()
1137 .setContents(new StringSelection(output), Desktop.getInstance());
1139 HiddenColumns hiddenColumns = null;
1141 if (av.hasHiddenColumns())
1143 hiddenColumns = new HiddenColumns(
1144 av.getAlignment().getHiddenColumns());
1147 // what is the dataset of a consensus sequence?
1148 // need to flag sequence as special.
1149 Desktop.getInstance().jalviewClipboard = new Object[] { seqs, ds,
1154 public void paintComponent(Graphics g)
1156 int width = getWidth();
1159 width = ap.calculateIdWidth().width;
1162 Graphics2D g2 = (Graphics2D) g;
1165 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1166 RenderingHints.VALUE_ANTIALIAS_ON);
1169 drawComponent(g2, true, width);
1173 * Draw the full set of annotation Labels for the alignment at the given
1177 * Graphics2D instance (needed for font scaling)
1179 * Width for scaling labels
1182 public void drawComponent(Graphics g, int width)
1184 drawComponent(g, false, width);
1188 * Draw the full set of annotation Labels for the alignment at the given
1192 * Graphics2D instance (needed for font scaling)
1194 * - true indicates that only current visible area needs to be
1197 * Width for scaling labels
1199 public void drawComponent(Graphics g, boolean clip, int width)
1201 if (av.getFont().getSize() < 10)
1207 g.setFont(av.getFont());
1210 FontMetrics fm = g.getFontMetrics(g.getFont());
1211 g.setColor(Color.white);
1212 g.fillRect(0, 0, getWidth(), getHeight());
1214 g.translate(0, getScrollOffset());
1215 g.setColor(Color.black);
1217 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1218 int fontHeight = g.getFont().getSize();
1221 int graphExtras = 0;
1223 Font baseFont = g.getFont();
1224 FontMetrics baseMetrics = fm;
1225 int ofontH = fontHeight;
1228 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1229 ? ap.getAnnotationPanel().getVisibleVRange()
1231 if (clip && visr != null)
1234 visHeight = visr[1];
1236 boolean visible = true, before = false, after = false;
1239 hasHiddenRows = false;
1241 for (int i = 0; i < aa.length; i++)
1246 hasHiddenRows = true;
1259 System.out.println("before vis: " + i);
1263 // don't draw what isn't visible
1266 if (olY > visHeight)
1274 "Scroll offset: " + sOffset + " after vis: " + i);
1278 // don't draw what isn't visible
1282 g.setColor(Color.black);
1284 offset = -aa[i].height / 2;
1288 offset += fm.getHeight() / 2;
1289 offset -= fm.getDescent();
1293 offset += fm.getDescent();
1296 x = width - fm.stringWidth(aa[i].label) - 3;
1298 if (aa[i].graphGroup > -1)
1301 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1302 // computed efficiently for all visible labels
1303 for (int gg = 0; gg < aa.length; gg++)
1305 if (aa[gg].graphGroup == aa[i].graphGroup)
1310 if (groupSize * (fontHeight + 8) < aa[i].height)
1312 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1317 // scale font to fit
1318 float h = aa[i].height / (float) groupSize, s;
1325 fontHeight = -8 + (int) h;
1326 s = ((float) fontHeight) / (float) ofontH;
1328 .deriveFont(AffineTransform.getScaleInstance(s, s));
1330 fm = g.getFontMetrics();
1331 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1337 for (int gg = 0; gg < aa.length; gg++)
1339 if (aa[gg].graphGroup == aa[i].graphGroup)
1341 x = width - fm.stringWidth(aa[gg].label) - 3;
1342 g.drawString(aa[gg].label, x, y - graphExtras);
1344 if (aa[gg]._linecolour != null)
1347 g.setColor(aa[gg]._linecolour);
1348 g.drawLine(x, y - graphExtras + 3,
1349 x + fm.stringWidth(aa[gg].label),
1350 y - graphExtras + 3);
1353 g.setColor(Color.black);
1354 graphExtras += fontHeight + 8;
1358 g.setFont(baseFont);
1360 fontHeight = ofontH;
1364 g.drawString(aa[i].label, x, y + offset);
1369 if (!resizePanel && dragEvent != null && aa != null)
1371 g.setColor(Color.lightGray);
1372 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1373 dragEvent.getY() - getScrollOffset());
1376 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1378 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1379 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1384 public int getScrollOffset()
1386 return scrollOffset;
1390 public void mouseEntered(MouseEvent e)