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.util.Locale;
25 import jalview.analysis.AlignSeq;
26 import jalview.analysis.AlignmentUtils;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.HiddenColumns;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.io.FileFormat;
35 import jalview.io.FormatAdapter;
36 import jalview.util.Comparison;
37 import jalview.util.MessageManager;
38 import jalview.util.Platform;
39 import jalview.workers.InformationThread;
41 import java.awt.Color;
42 import java.awt.Cursor;
43 import java.awt.Dimension;
45 import java.awt.FontMetrics;
46 import java.awt.Graphics;
47 import java.awt.Graphics2D;
48 import java.awt.RenderingHints;
49 import java.awt.Toolkit;
50 import java.awt.datatransfer.StringSelection;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ActionListener;
53 import java.awt.event.MouseEvent;
54 import java.awt.event.MouseListener;
55 import java.awt.event.MouseMotionListener;
56 import java.awt.geom.AffineTransform;
57 import java.util.Arrays;
58 import java.util.Collections;
59 import java.util.Iterator;
61 import javax.swing.JCheckBoxMenuItem;
62 import javax.swing.JMenuItem;
63 import javax.swing.JPanel;
64 import javax.swing.JPopupMenu;
65 import javax.swing.SwingUtilities;
66 import javax.swing.ToolTipManager;
69 * The panel that holds the labels for alignment annotations, providing
70 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
73 public class AnnotationLabels extends JPanel
74 implements MouseListener, MouseMotionListener, ActionListener
76 private static final String HTML_END_TAG = "</html>";
78 private static final String HTML_START_TAG = "<html>";
81 * width in pixels within which height adjuster arrows are shown and active
83 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
86 * height in pixels for allowing height adjuster to be active
88 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
90 private static final Font font = new Font("Arial", Font.PLAIN, 11);
92 private static final String TOGGLE_LABELSCALE = MessageManager
93 .getString("label.scale_label_to_column");
95 private static final String ADDNEW = MessageManager
96 .getString("label.add_new_row");
98 private static final String EDITNAME = MessageManager
99 .getString("label.edit_label_description");
101 private static final String HIDE = MessageManager
102 .getString("label.hide_row");
104 private static final String DELETE = MessageManager
105 .getString("label.delete_row");
107 private static final String SHOWALL = MessageManager
108 .getString("label.show_all_hidden_rows");
110 private static final String OUTPUT_TEXT = MessageManager
111 .getString("label.export_annotation");
113 private static final String COPYCONS_SEQ = MessageManager
114 .getString("label.copy_consensus_sequence");
116 private final boolean debugRedraw = false;
118 private AlignmentPanel ap;
122 private MouseEvent dragEvent;
126 private int selectedRow;
128 private int scrollOffset = 0;
130 private boolean hasHiddenRows;
132 private boolean resizePanel = false;
135 * Creates a new AnnotationLabels object
139 public AnnotationLabels(AlignmentPanel ap)
144 ToolTipManager.sharedInstance().registerComponent(this);
146 addMouseListener(this);
147 addMouseMotionListener(this);
148 addMouseWheelListener(ap.getAnnotationPanel());
151 public AnnotationLabels(AlignViewport av)
162 public void setScrollOffset(int y)
169 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
173 * coordinate position to search for a row
175 void getSelectedRow(int y)
178 AlignmentAnnotation[] aa = ap.av.getAlignment()
179 .getAlignmentAnnotation();
183 for (int i = 0; i < aa.length; i++)
191 height += aa[i].height;
210 public void actionPerformed(ActionEvent evt)
212 AlignmentAnnotation[] aa = ap.av.getAlignment()
213 .getAlignmentAnnotation();
215 String action = evt.getActionCommand();
216 if (ADDNEW.equals(action))
219 * non-returning dialog
221 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
222 null, new Annotation[ap.av.getAlignment().getWidth()]);
223 editLabelDescription(newAnnotation, true);
225 else if (EDITNAME.equals(action))
228 * non-returning dialog
230 editLabelDescription(aa[selectedRow], false);
232 else if (HIDE.equals(action))
234 aa[selectedRow].visible = false;
236 else if (DELETE.equals(action))
238 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
239 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
241 else if (SHOWALL.equals(action))
243 for (int i = 0; i < aa.length; i++)
245 if (!aa[i].visible && aa[i].annotations != null)
247 aa[i].visible = true;
251 else if (OUTPUT_TEXT.equals(action))
253 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
255 else if (COPYCONS_SEQ.equals(action))
257 SequenceI cons = null;
258 if (aa[selectedRow].groupRef != null)
260 cons = aa[selectedRow].groupRef.getConsensusSeq();
264 cons = av.getConsensusSeq();
268 copy_annotseqtoclipboard(cons);
271 else if (TOGGLE_LABELSCALE.equals(action))
273 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
280 * Shows a dialog where the annotation name and description may be edited. If
281 * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
282 * is added, else an existing annotation is updated.
287 void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
289 String name = MessageManager.getString("label.annotation_name");
290 String description = MessageManager
291 .getString("label.annotation_description");
292 String title = MessageManager
293 .getString("label.edit_annotation_name_description");
294 EditNameDialog dialog = new EditNameDialog(annotation.label,
295 annotation.description, name, description);
297 dialog.showDialog(ap.alignFrame, title, new Runnable()
302 annotation.label = dialog.getName();
303 String text = dialog.getDescription();
304 if (text != null && text.length() == 0)
308 annotation.description = text;
311 ap.av.getAlignment().addAnnotation(annotation);
312 ap.av.getAlignment().setAnnotationIndex(annotation, 0);
320 public void mousePressed(MouseEvent evt)
322 getSelectedRow(evt.getY() - getScrollOffset());
324 if (evt.isPopupTrigger())
331 * Build and show the Pop-up menu at the right-click mouse position
335 void showPopupMenu(MouseEvent evt)
338 final AlignmentAnnotation[] aa = ap.av.getAlignment()
339 .getAlignmentAnnotation();
341 JPopupMenu pop = new JPopupMenu(
342 MessageManager.getString("label.annotations"));
343 JMenuItem item = new JMenuItem(ADDNEW);
344 item.addActionListener(this);
349 { // let the user make everything visible again
350 item = new JMenuItem(SHOWALL);
351 item.addActionListener(this);
354 pop.show(this, evt.getX(), evt.getY());
357 final AlignmentAnnotation ann = aa[selectedRow];
358 final boolean isSequenceAnnotation = ann.sequenceRef != null;
359 item = new JMenuItem(EDITNAME);
360 item.addActionListener(this);
362 item = new JMenuItem(HIDE);
363 item.addActionListener(this);
365 // JAL-1264 hide all sequence-specific annotations of this type
366 if (selectedRow < aa.length)
368 if (aa[selectedRow].sequenceRef != null)
370 final String label = aa[selectedRow].label;
371 JMenuItem hideType = new JMenuItem();
372 String text = MessageManager.getString("label.hide_all") + " "
374 hideType.setText(text);
375 hideType.addActionListener(new ActionListener()
378 public void actionPerformed(ActionEvent e)
380 AlignmentUtils.showOrHideSequenceAnnotations(
381 ap.av.getAlignment(), Collections.singleton(label),
389 item = new JMenuItem(DELETE);
390 item.addActionListener(this);
394 item = new JMenuItem(SHOWALL);
395 item.addActionListener(this);
398 item = new JMenuItem(OUTPUT_TEXT);
399 item.addActionListener(this);
401 // TODO: annotation object should be typed for autocalculated/derived
403 if (selectedRow < aa.length)
405 final String label = aa[selectedRow].label;
406 if (!(aa[selectedRow].autoCalculated)
407 && !(InformationThread.HMM_CALC_ID.equals(ann.getCalcId())))
409 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
411 // display formatting settings for this row.
413 // av and sequencegroup need to implement same interface for
414 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
415 aa[selectedRow].scaleColLabel);
416 item.addActionListener(this);
420 else if (label.indexOf("Consensus") > -1)
422 addConsensusMenuOptions(ap, aa[selectedRow], pop);
424 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
425 consclipbrd.addActionListener(this);
426 pop.add(consclipbrd);
428 else if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))
430 addHmmerMenu(pop, ann);
433 pop.show(this, evt.getX(), evt.getY());
437 * Adds context menu options for (alignment or group) Hmmer annotation
442 protected void addHmmerMenu(JPopupMenu pop, final AlignmentAnnotation ann)
444 final boolean isGroupAnnotation = ann.groupRef != null;
446 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
447 MessageManager.getString(
448 "label.ignore_below_background_frequency"),
451 .isIgnoreBelowBackground()
452 : ap.av.isIgnoreBelowBackground());
453 cbmi.addActionListener(new ActionListener()
456 public void actionPerformed(ActionEvent e)
458 if (isGroupAnnotation)
460 if (!ann.groupRef.isUseInfoLetterHeight())
462 ann.groupRef.setIgnoreBelowBackground(cbmi.getState());
463 // todo and recompute group annotation
466 else if (!ap.av.isInfoLetterHeight())
468 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
469 // todo and recompute annotation
471 ap.alignmentChanged(); // todo not like this
475 final JCheckBoxMenuItem letterHeight = new JCheckBoxMenuItem(
476 MessageManager.getString("label.use_info_for_height"),
477 isGroupAnnotation ? ann.groupRef.isUseInfoLetterHeight()
478 : ap.av.isInfoLetterHeight());
479 letterHeight.addActionListener(new ActionListener()
482 public void actionPerformed(ActionEvent e)
484 if (isGroupAnnotation)
486 ann.groupRef.setInfoLetterHeight((letterHeight.getState()));
487 ann.groupRef.setIgnoreBelowBackground(true);
488 // todo and recompute group annotation
492 ap.av.setInfoLetterHeight(letterHeight.getState(), ap);
493 ap.av.setIgnoreBelowBackground(true, ap);
494 // todo and recompute annotation
496 ap.alignmentChanged();
499 pop.add(letterHeight);
500 if (isGroupAnnotation)
502 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
503 MessageManager.getString("label.show_group_histogram"),
504 ann.groupRef.isShowInformationHistogram());
505 chist.addActionListener(new ActionListener()
508 public void actionPerformed(ActionEvent e)
510 ann.groupRef.setShowInformationHistogram(chist.getState());
515 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
516 MessageManager.getString("label.show_group_logo"),
517 ann.groupRef.isShowHMMSequenceLogo());
518 cprofl.addActionListener(new ActionListener()
521 public void actionPerformed(ActionEvent e)
523 ann.groupRef.setShowHMMSequenceLogo(cprofl.getState());
528 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
529 MessageManager.getString("label.normalise_group_logo"),
530 ann.groupRef.isNormaliseHMMSequenceLogo());
531 cproflnorm.addActionListener(new ActionListener()
534 public void actionPerformed(ActionEvent e)
537 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
538 // automatically enable logo display if we're clicked
539 ann.groupRef.setShowHMMSequenceLogo(true);
547 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
548 MessageManager.getString("label.show_histogram"),
549 av.isShowInformationHistogram());
550 chist.addActionListener(new ActionListener()
553 public void actionPerformed(ActionEvent e)
555 av.setShowInformationHistogram(chist.getState());
560 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
561 MessageManager.getString("label.show_logo"),
562 av.isShowHMMSequenceLogo());
563 cprof.addActionListener(new ActionListener()
566 public void actionPerformed(ActionEvent e)
568 av.setShowHMMSequenceLogo(cprof.getState());
573 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
574 MessageManager.getString("label.normalise_logo"),
575 av.isNormaliseHMMSequenceLogo());
576 cprofnorm.addActionListener(new ActionListener()
579 public void actionPerformed(ActionEvent e)
581 av.setShowHMMSequenceLogo(true);
582 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
591 * A helper method that adds menu options for calculation and visualisation of
592 * group and/or alignment consensus annotation to a popup menu. This is
593 * designed to be reusable for either unwrapped mode (popup menu is shown on
594 * component AnnotationLabels), or wrapped mode (popup menu is shown on
595 * IdPanel when the mouse is over an annotation label).
601 static void addConsensusMenuOptions(AlignmentPanel ap,
602 AlignmentAnnotation ann, JPopupMenu pop)
606 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
607 MessageManager.getString("label.ignore_gaps_consensus"),
608 (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
609 : ap.av.isIgnoreGapsConsensus());
610 final AlignmentAnnotation aaa = ann;
611 cbmi.addActionListener(new ActionListener()
614 public void actionPerformed(ActionEvent e)
616 if (aaa.groupRef != null)
618 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
619 ap.getAnnotationPanel()
620 .paint(ap.getAnnotationPanel().getGraphics());
624 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
626 ap.alignmentChanged();
631 if (aaa.groupRef != null)
634 * group consensus options
636 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
637 MessageManager.getString("label.show_group_histogram"),
638 ann.groupRef.isShowConsensusHistogram());
639 chist.addActionListener(new ActionListener()
642 public void actionPerformed(ActionEvent e)
644 aaa.groupRef.setShowConsensusHistogram(chist.getState());
649 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
650 MessageManager.getString("label.show_group_logo"),
651 ann.groupRef.isShowSequenceLogo());
652 cprofl.addActionListener(new ActionListener()
655 public void actionPerformed(ActionEvent e)
657 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
662 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
663 MessageManager.getString("label.normalise_group_logo"),
664 ann.groupRef.isNormaliseSequenceLogo());
665 cproflnorm.addActionListener(new ActionListener()
668 public void actionPerformed(ActionEvent e)
670 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
671 // automatically enable logo display if we're clicked
672 aaa.groupRef.setshowSequenceLogo(true);
681 * alignment consensus options
683 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
684 MessageManager.getString("label.show_histogram"),
685 ap.av.isShowConsensusHistogram());
686 chist.addActionListener(new ActionListener()
689 public void actionPerformed(ActionEvent e)
691 ap.av.setShowConsensusHistogram(chist.getState());
692 ap.alignFrame.setMenusForViewport();
697 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
698 MessageManager.getString("label.show_logo"),
699 ap.av.isShowSequenceLogo());
700 cprof.addActionListener(new ActionListener()
703 public void actionPerformed(ActionEvent e)
705 ap.av.setShowSequenceLogo(cprof.getState());
706 ap.alignFrame.setMenusForViewport();
711 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
712 MessageManager.getString("label.normalise_logo"),
713 ap.av.isNormaliseSequenceLogo());
714 cprofnorm.addActionListener(new ActionListener()
717 public void actionPerformed(ActionEvent e)
719 ap.av.setShowSequenceLogo(true);
720 ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
721 ap.alignFrame.setMenusForViewport();
730 * Reorders annotation rows after a drag of a label
735 public void mouseReleased(MouseEvent evt)
737 if (evt.isPopupTrigger())
743 int start = selectedRow;
744 getSelectedRow(evt.getY() - getScrollOffset());
745 int end = selectedRow;
748 * if dragging to resize instead, start == end
752 // Swap these annotations
753 AlignmentAnnotation startAA = ap.av.getAlignment()
754 .getAlignmentAnnotation()[start];
757 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
759 AlignmentAnnotation endAA = ap.av.getAlignment()
760 .getAlignmentAnnotation()[end];
762 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
763 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
769 ap.getAnnotationPanel().repaint();
773 * Removes the height adjuster image on leaving the panel, unless currently
777 public void mouseExited(MouseEvent evt)
779 if (resizePanel && dragEvent == null)
787 * A mouse drag may be either an adjustment of the panel height (if flag
788 * resizePanel is set on), or a reordering of the annotation rows. The former
789 * is dealt with by this method, the latter in mouseReleased.
794 public void mouseDragged(MouseEvent evt)
800 Dimension d = ap.annotationScroller.getPreferredSize();
801 int dif = evt.getY() - oldY;
803 dif /= ap.av.getCharHeight();
804 dif *= ap.av.getCharHeight();
806 if ((d.height - dif) > 20)
808 ap.annotationScroller
809 .setPreferredSize(new Dimension(d.width, d.height - dif));
810 d = ap.annotationSpaceFillerHolder.getPreferredSize();
811 ap.annotationSpaceFillerHolder
812 .setPreferredSize(new Dimension(d.width, d.height - dif));
813 ap.paintAlignment(true, false);
825 * Updates the tooltip as the mouse moves over the labels
830 public void mouseMoved(MouseEvent evt)
832 showOrHideAdjuster(evt);
834 getSelectedRow(evt.getY() - getScrollOffset());
836 if (selectedRow > -1 && ap.av.getAlignment()
837 .getAlignmentAnnotation().length > selectedRow)
839 AlignmentAnnotation[] anns = ap.av.getAlignment()
840 .getAlignmentAnnotation();
841 AlignmentAnnotation aa = anns[selectedRow];
843 String desc = getTooltip(aa);
844 this.setToolTipText(desc);
845 String msg = getStatusMessage(aa, anns);
846 ap.alignFrame.setStatus(msg);
851 * Constructs suitable text to show in the status bar when over an annotation
852 * label, containing the associated sequence name (if any), and the annotation
853 * labels (or all labels for a graph group annotation)
859 static String getStatusMessage(AlignmentAnnotation aa,
860 AlignmentAnnotation[] anns)
867 StringBuilder msg = new StringBuilder(32);
868 if (aa.sequenceRef != null)
870 msg.append(aa.sequenceRef.getName()).append(" : ");
873 if (aa.graphGroup == -1)
875 msg.append(aa.label);
877 else if (anns != null)
879 boolean first = true;
880 for (int i = anns.length - 1; i >= 0; i--)
882 if (anns[i].graphGroup == aa.graphGroup)
888 msg.append(anns[i].label);
894 return msg.toString();
898 * Answers a tooltip, formatted as html, containing the annotation description
899 * (prefixed by associated sequence id if applicable), and the annotation
900 * (non-positional) score if it has one. Answers null if neither description
901 * nor score is found.
906 static String getTooltip(AlignmentAnnotation aa)
912 StringBuilder tooltip = new StringBuilder();
913 if (aa.description != null && !aa.description.equals("New description"))
915 // TODO: we could refactor and merge this code with the code in
916 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
918 String desc = aa.getDescription(true).trim();
919 if (!desc.toLowerCase(Locale.ROOT).startsWith(HTML_START_TAG))
921 tooltip.append(HTML_START_TAG);
922 desc = desc.replace("<", "<");
924 else if (desc.toLowerCase(Locale.ROOT).endsWith(HTML_END_TAG))
926 desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
928 tooltip.append(desc);
932 // begin the tooltip's html fragment
933 tooltip.append(HTML_START_TAG);
937 if (tooltip.length() > HTML_START_TAG.length())
939 tooltip.append("<br/>");
941 // TODO: limit precision of score to avoid noise from imprecise
943 // (64.7 becomes 64.7+/some tiny value).
944 tooltip.append(" Score: ").append(String.valueOf(aa.score));
947 if (tooltip.length() > HTML_START_TAG.length())
949 return tooltip.append(HTML_END_TAG).toString();
953 * nothing in the tooltip (except "<html>")
959 * Shows the height adjuster image if the mouse moves into the top left
960 * region, or hides it if the mouse leaves the regio
964 protected void showOrHideAdjuster(MouseEvent evt)
966 boolean was = resizePanel;
967 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
968 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
970 if (resizePanel != was)
973 .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
974 : Cursor.DEFAULT_CURSOR));
980 public void mouseClicked(MouseEvent evt)
982 final AlignmentAnnotation[] aa = ap.av.getAlignment()
983 .getAlignmentAnnotation();
984 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
986 if (selectedRow > -1 && selectedRow < aa.length)
988 if (aa[selectedRow].groupRef != null)
990 if (evt.getClickCount() >= 2)
992 // todo: make the ap scroll to the selection - not necessary, first
993 // click highlights/scrolls, second selects
994 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
996 SequenceGroup sg = ap.av.getSelectionGroup();
997 if (sg == null || sg == aa[selectedRow].groupRef
998 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
1000 if (Platform.isControlDown(evt) || evt.isShiftDown())
1002 // clone a new selection group from the associated group
1003 ap.av.setSelectionGroup(
1004 new SequenceGroup(aa[selectedRow].groupRef));
1008 // set selection to the associated group so it can be edited
1009 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1014 // modify current selection with associated group
1015 int remainToAdd = aa[selectedRow].groupRef.getSize();
1016 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1018 if (jalview.util.Platform.isControlDown(evt))
1020 sg.addOrRemove(sgs, --remainToAdd == 0);
1024 // notionally, we should also add intermediate sequences from
1025 // last added sequence ?
1026 sg.addSequence(sgs, --remainToAdd == 0);
1031 ap.paintAlignment(false, false);
1032 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1033 ap.av.sendSelection();
1037 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1038 aa[selectedRow].groupRef.getSequences(null));
1042 else if (aa[selectedRow].sequenceRef != null)
1044 if (evt.getClickCount() == 1)
1046 ap.getSeqPanel().ap.getIdPanel()
1047 .highlightSearchResults(Arrays.asList(new SequenceI[]
1048 { aa[selectedRow].sequenceRef }));
1050 else if (evt.getClickCount() >= 2)
1052 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1053 SequenceGroup sg = ap.av.getSelectionGroup();
1056 // we make a copy rather than edit the current selection if no
1057 // modifiers pressed
1058 // see Enhancement JAL-1557
1059 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
1061 sg = new SequenceGroup(sg);
1063 sg.addSequence(aa[selectedRow].sequenceRef, false);
1067 if (Platform.isControlDown(evt))
1069 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1073 // notionally, we should also add intermediate sequences from
1074 // last added sequence ?
1075 sg.addSequence(aa[selectedRow].sequenceRef, true);
1081 sg = new SequenceGroup();
1083 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1084 sg.addSequence(aa[selectedRow].sequenceRef, false);
1086 ap.av.setSelectionGroup(sg);
1087 ap.paintAlignment(false, false);
1088 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1089 ap.av.sendSelection();
1099 * do a single sequence copy to jalview and the system clipboard
1102 * sequence to be copied to clipboard
1104 protected void copy_annotseqtoclipboard(SequenceI sq)
1106 SequenceI[] seqs = new SequenceI[] { sq };
1107 String[] omitHidden = null;
1108 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1109 if (dseqs[0] == null)
1111 dseqs[0] = new Sequence(sq);
1112 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
1113 sq.getSequenceAsString()));
1115 sq.setDatasetSequence(dseqs[0]);
1117 Alignment ds = new Alignment(dseqs);
1118 if (av.hasHiddenColumns())
1120 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
1121 .getVisContigsIterator(0, sq.getLength(), false);
1122 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
1125 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1126 if (av.hasHiddenColumns())
1128 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1129 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1132 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1133 seqs, omitHidden, alignmentStartEnd);
1135 Toolkit.getDefaultToolkit().getSystemClipboard()
1136 .setContents(new StringSelection(output), Desktop.getInstance());
1138 HiddenColumns hiddenColumns = null;
1140 if (av.hasHiddenColumns())
1142 hiddenColumns = new HiddenColumns(
1143 av.getAlignment().getHiddenColumns());
1146 // what is the dataset of a consensus sequence?
1147 // need to flag sequence as special.
1148 Desktop.getInstance().jalviewClipboard = new Object[] { seqs, ds,
1153 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);
1174 * Draw the full set of annotation Labels for the alignment at the given
1178 * Graphics2D instance (needed for font scaling)
1180 * Width for scaling labels
1183 public void drawComponent(Graphics g, int width)
1185 drawComponent(g, false, width);
1189 * Draw the full set of annotation Labels for the alignment at the given
1193 * Graphics2D instance (needed for font scaling)
1195 * - true indicates that only current visible area needs to be
1198 * Width for scaling labels
1200 public void drawComponent(Graphics g, boolean clip, int width)
1202 if (av.getFont().getSize() < 10)
1208 g.setFont(av.getFont());
1211 FontMetrics fm = g.getFontMetrics(g.getFont());
1212 g.setColor(Color.white);
1213 g.fillRect(0, 0, getWidth(), getHeight());
1215 g.translate(0, getScrollOffset());
1216 g.setColor(Color.black);
1218 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1219 int fontHeight = g.getFont().getSize();
1222 int graphExtras = 0;
1224 Font baseFont = g.getFont();
1225 FontMetrics baseMetrics = fm;
1226 int ofontH = fontHeight;
1229 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1230 ? ap.getAnnotationPanel().getVisibleVRange()
1232 if (clip && visr != null)
1235 visHeight = visr[1];
1237 boolean visible = true, before = false, after = false;
1240 hasHiddenRows = false;
1242 for (int i = 0; i < aa.length; i++)
1247 hasHiddenRows = true;
1260 System.out.println("before vis: " + i);
1264 // don't draw what isn't visible
1267 if (olY > visHeight)
1275 "Scroll offset: " + sOffset + " after vis: " + i);
1279 // don't draw what isn't visible
1283 g.setColor(Color.black);
1285 offset = -aa[i].height / 2;
1289 offset += fm.getHeight() / 2;
1290 offset -= fm.getDescent();
1294 offset += fm.getDescent();
1297 x = width - fm.stringWidth(aa[i].label) - 3;
1299 if (aa[i].graphGroup > -1)
1302 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1303 // computed efficiently for all visible labels
1304 for (int gg = 0; gg < aa.length; gg++)
1306 if (aa[gg].graphGroup == aa[i].graphGroup)
1311 if (groupSize * (fontHeight + 8) < aa[i].height)
1313 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1318 // scale font to fit
1319 float h = aa[i].height / (float) groupSize, s;
1326 fontHeight = -8 + (int) h;
1327 s = ((float) fontHeight) / (float) ofontH;
1329 .deriveFont(AffineTransform.getScaleInstance(s, s));
1331 fm = g.getFontMetrics();
1332 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1338 for (int gg = 0; gg < aa.length; gg++)
1340 if (aa[gg].graphGroup == aa[i].graphGroup)
1342 x = width - fm.stringWidth(aa[gg].label) - 3;
1343 g.drawString(aa[gg].label, x, y - graphExtras);
1345 if (aa[gg]._linecolour != null)
1348 g.setColor(aa[gg]._linecolour);
1349 g.drawLine(x, y - graphExtras + 3,
1350 x + fm.stringWidth(aa[gg].label),
1351 y - graphExtras + 3);
1354 g.setColor(Color.black);
1355 graphExtras += fontHeight + 8;
1359 g.setFont(baseFont);
1361 fontHeight = ofontH;
1365 g.drawString(aa[i].label, x, y + offset);
1370 if (!resizePanel && dragEvent != null && aa != null)
1372 g.setColor(Color.lightGray);
1373 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1374 dragEvent.getY() - getScrollOffset());
1377 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1379 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1380 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1385 public int getScrollOffset()
1387 return scrollOffset;
1391 public void mouseEntered(MouseEvent e)