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 jalview.analysis.AlignSeq;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.Annotation;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.io.FileFormat;
32 import jalview.io.FormatAdapter;
33 import jalview.util.Comparison;
34 import jalview.util.MessageManager;
35 import jalview.util.Platform;
36 import jalview.workers.InformationThread;
38 import java.awt.Color;
39 import java.awt.Cursor;
40 import java.awt.Dimension;
42 import java.awt.FontMetrics;
43 import java.awt.Graphics;
44 import java.awt.Graphics2D;
45 import java.awt.Image;
46 import java.awt.MediaTracker;
47 import java.awt.RenderingHints;
48 import java.awt.Toolkit;
49 import java.awt.datatransfer.StringSelection;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.MouseEvent;
53 import java.awt.event.MouseListener;
54 import java.awt.event.MouseMotionListener;
55 import java.awt.geom.AffineTransform;
56 import java.awt.image.BufferedImage;
57 import java.util.ArrayList;
58 import java.util.Arrays;
59 import java.util.Collections;
60 import java.util.regex.Pattern;
62 import javax.swing.JCheckBoxMenuItem;
63 import javax.swing.JMenuItem;
64 import javax.swing.JPanel;
65 import javax.swing.JPopupMenu;
66 import javax.swing.SwingUtilities;
67 import javax.swing.ToolTipManager;
70 * The panel that holds the labels for alignment annotations, providing
71 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
74 public class AnnotationLabels extends JPanel
75 implements MouseListener, MouseMotionListener, ActionListener
77 // width in pixels within which height adjuster arrows are shown and active
78 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
80 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
83 private static final Font font = new Font("Arial", Font.PLAIN, 11);
85 private static final String TOGGLE_LABELSCALE = MessageManager
86 .getString("label.scale_label_to_column");
88 private static final String ADDNEW = MessageManager
89 .getString("label.add_new_row");
91 private static final String EDITNAME = MessageManager
92 .getString("label.edit_label_description");
94 private static final String HIDE = MessageManager
95 .getString("label.hide_row");
97 private static final String DELETE = MessageManager
98 .getString("label.delete_row");
100 private static final String SHOWALL = MessageManager
101 .getString("label.show_all_hidden_rows");
103 private static final String OUTPUT_TEXT = MessageManager
104 .getString("label.export_annotation");
106 private static final String COPYCONS_SEQ = MessageManager
107 .getString("label.copy_consensus_sequence");
109 private static Image adjusterImage;
111 private static int adjusterImageHeight;
113 private final boolean debugRedraw = false;
115 private AlignmentPanel ap;
119 private MouseEvent dragEvent;
123 private int selectedRow;
125 private int scrollOffset = 0;
127 private boolean hasHiddenRows;
129 private boolean resizePanel = false;
132 * Creates a new AnnotationLabels object
136 public AnnotationLabels(AlignmentPanel ap)
140 ToolTipManager.sharedInstance().registerComponent(this);
142 if (adjusterImage == null)
147 addMouseListener(this);
148 addMouseMotionListener(this);
149 addMouseWheelListener(ap.getAnnotationPanel());
152 public AnnotationLabels(AlignViewport av)
158 * Loads the gif for the panel height adjustment
160 protected void loadAdjusterImage()
162 java.net.URL url = getClass().getResource("/images/idwidth.gif");
167 temp = Toolkit.getDefaultToolkit().createImage(url);
172 MediaTracker mt = new MediaTracker(this);
173 mt.addImage(temp, 0);
175 } catch (Exception ex)
179 BufferedImage bi = new BufferedImage(temp.getHeight(this),
180 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
181 Graphics2D g = (Graphics2D) bi.getGraphics();
182 g.rotate(Math.toRadians(90));
183 g.drawImage(temp, 0, -bi.getWidth(this), this);
185 adjusterImageHeight = bi.getHeight();
194 public void setScrollOffset(int y)
201 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
205 * coordinate position to search for a row
207 void getSelectedRow(int y)
210 AlignmentAnnotation[] aa = ap.av.getAlignment()
211 .getAlignmentAnnotation();
215 for (int i = 0; i < aa.length; i++)
223 height += aa[i].height;
242 public void actionPerformed(ActionEvent evt)
244 AlignmentAnnotation[] aa = ap.av.getAlignment()
245 .getAlignmentAnnotation();
247 boolean fullRepaint = false;
248 if (evt.getActionCommand().equals(ADDNEW))
250 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
251 null, new Annotation[ap.av.getAlignment().getWidth()]);
253 if (!editLabelDescription(newAnnotation))
258 ap.av.getAlignment().addAnnotation(newAnnotation);
259 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
262 else if (evt.getActionCommand().equals(EDITNAME))
264 String name = aa[selectedRow].label;
265 editLabelDescription(aa[selectedRow]);
266 if (!name.equalsIgnoreCase(aa[selectedRow].label))
271 else if (evt.getActionCommand().equals(HIDE))
273 aa[selectedRow].visible = false;
275 else if (evt.getActionCommand().equals(DELETE))
277 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
278 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
281 else if (evt.getActionCommand().equals(SHOWALL))
283 for (int i = 0; i < aa.length; i++)
285 if (!aa[i].visible && aa[i].annotations != null)
287 aa[i].visible = true;
292 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
294 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
296 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
298 SequenceI cons = null;
299 if (aa[selectedRow].groupRef != null)
301 cons = aa[selectedRow].groupRef.getConsensusSeq();
305 cons = av.getConsensusSeq();
309 copy_annotseqtoclipboard(cons);
313 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
315 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
318 ap.refresh(fullRepaint);
328 boolean editLabelDescription(AlignmentAnnotation annotation)
331 EditNameDialog dialog = new EditNameDialog(annotation.label,
332 annotation.description, " Annotation Name ",
333 "Annotation Description ", "Edit Annotation Name/Description",
341 annotation.label = dialog.getName();
343 String text = dialog.getDescription();
344 if (text != null && text.length() == 0)
348 annotation.description = text;
354 public void mousePressed(MouseEvent evt)
356 getSelectedRow(evt.getY() - getScrollOffset());
358 if (evt.isPopupTrigger())
365 * Build and show the Pop-up menu at the right-click mouse position
369 void showPopupMenu(MouseEvent evt)
372 final AlignmentAnnotation[] aa = ap.av.getAlignment()
373 .getAlignmentAnnotation();
375 JPopupMenu pop = new JPopupMenu(
376 MessageManager.getString("label.annotations"));
377 JMenuItem item = new JMenuItem(ADDNEW);
378 item.addActionListener(this);
383 { // let the user make everything visible again
384 item = new JMenuItem(SHOWALL);
385 item.addActionListener(this);
388 pop.show(this, evt.getX(), evt.getY());
391 item = new JMenuItem(EDITNAME);
392 item.addActionListener(this);
394 item = new JMenuItem(HIDE);
395 item.addActionListener(this);
397 // JAL-1264 hide all sequence-specific annotations of this type
398 if (selectedRow < aa.length)
400 if (aa[selectedRow].sequenceRef != null)
402 final String label = aa[selectedRow].label;
403 JMenuItem hideType = new JMenuItem();
404 String text = MessageManager.getString("label.hide_all") + " "
406 hideType.setText(text);
407 hideType.addActionListener(new ActionListener()
410 public void actionPerformed(ActionEvent e)
412 AlignmentUtils.showOrHideSequenceAnnotations(
413 ap.av.getAlignment(), Collections.singleton(label),
415 // for (AlignmentAnnotation ann : ap.av.getAlignment()
416 // .getAlignmentAnnotation())
418 // if (ann.sequenceRef != null && ann.label != null
419 // && ann.label.equals(label))
421 // ann.visible = false;
430 item = new JMenuItem(DELETE);
431 item.addActionListener(this);
435 item = new JMenuItem(SHOWALL);
436 item.addActionListener(this);
439 item = new JMenuItem(OUTPUT_TEXT);
440 item.addActionListener(this);
442 // TODO: annotation object should be typed for autocalculated/derived
444 if (selectedRow < aa.length)
446 final String label = aa[selectedRow].label;
447 if (!(aa[selectedRow].autoCalculated)
448 && !(InformationThread.HMM_CALC_ID
449 .equals(aa[selectedRow].getCalcId())))
451 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
453 // display formatting settings for this row.
455 // av and sequencegroup need to implement same interface for
456 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
457 aa[selectedRow].scaleColLabel);
458 item.addActionListener(this);
462 else if (label.indexOf("Consensus") > -1)
467 // av and sequencegroup need to implement same interface for
469 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
470 MessageManager.getString("label.ignore_gaps_consensus"),
471 (aa[selectedRow].groupRef != null)
472 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
473 : ap.av.isIgnoreGapsConsensus());
474 final AlignmentAnnotation aaa = aa[selectedRow];
475 cbmi.addActionListener(new ActionListener()
478 public void actionPerformed(ActionEvent e)
480 if (aaa.groupRef != null)
482 // TODO: pass on reference to ap so the view can be updated.
483 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
484 ap.getAnnotationPanel()
485 .paint(ap.getAnnotationPanel().getGraphics());
489 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
491 ap.alignmentChanged();
495 // av and sequencegroup need to implement same interface for
496 if (aaa.groupRef != null)
498 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
499 MessageManager.getString("label.show_group_histogram"),
500 aa[selectedRow].groupRef.isShowConsensusHistogram());
501 chist.addActionListener(new ActionListener()
504 public void actionPerformed(ActionEvent e)
506 // TODO: pass on reference
512 aaa.groupRef.setShowConsensusHistogram(chist.getState());
514 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
518 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
519 MessageManager.getString("label.show_group_logo"),
520 aa[selectedRow].groupRef.isShowSequenceLogo());
521 cprofl.addActionListener(new ActionListener()
524 public void actionPerformed(ActionEvent e)
526 // TODO: pass on reference
532 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
534 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
538 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
539 MessageManager.getString("label.normalise_group_logo"),
540 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
541 cproflnorm.addActionListener(new ActionListener()
544 public void actionPerformed(ActionEvent e)
547 // TODO: pass on reference
553 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
554 // automatically enable logo display if we're clicked
555 aaa.groupRef.setshowSequenceLogo(true);
557 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
564 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
565 MessageManager.getString("label.show_histogram"),
566 av.isShowConsensusHistogram());
567 chist.addActionListener(new ActionListener()
570 public void actionPerformed(ActionEvent e)
572 // TODO: pass on reference
578 av.setShowConsensusHistogram(chist.getState());
580 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
584 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
585 MessageManager.getString("label.show_logo"),
586 av.isShowSequenceLogo());
587 cprof.addActionListener(new ActionListener()
590 public void actionPerformed(ActionEvent e)
592 // TODO: pass on reference
598 av.setShowSequenceLogo(cprof.getState());
600 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
604 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
605 MessageManager.getString("label.normalise_logo"),
606 av.isNormaliseSequenceLogo());
607 cprofnorm.addActionListener(new ActionListener()
610 public void actionPerformed(ActionEvent e)
612 // TODO: pass on reference
618 av.setShowSequenceLogo(true);
619 av.setNormaliseSequenceLogo(cprofnorm.getState());
621 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
626 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
627 consclipbrd.addActionListener(this);
628 pop.add(consclipbrd);
630 else if (InformationThread.HMM_CALC_ID
631 .equals(aa[selectedRow].getCalcId()))
634 final AlignmentAnnotation aaa = aa[selectedRow];
636 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
637 MessageManager.getString(
638 "label.ignore_below_background_frequency"),
639 (aa[selectedRow].groupRef != null)
640 ? aa[selectedRow].groupRef
641 .getIgnoreBelowBackground()
642 : ap.av.isIgnoreBelowBackground());
644 cbmi.addActionListener(new ActionListener()
647 public void actionPerformed(ActionEvent e)
650 if (aaa.groupRef != null)
652 // TODO: pass on reference to ap so the view can be updated.
653 if (aaa.groupRef.getInfoLetterHeight() == false)
655 aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
656 ap.getAnnotationPanel()
657 .paint(ap.getAnnotationPanel().getGraphics());
660 else if (ap.av.isInfoLetterHeight() == false)
662 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
664 ap.alignmentChanged();
668 final JCheckBoxMenuItem letteHeight = new JCheckBoxMenuItem(
669 MessageManager.getString("label.use_info_for_height"),
670 (aa[selectedRow].groupRef != null)
671 ? aa[selectedRow].groupRef.getInfoLetterHeight()
672 : ap.av.isInfoLetterHeight());
674 letteHeight.addActionListener(new ActionListener()
677 public void actionPerformed(ActionEvent e)
679 if (aaa.groupRef != null)
681 // TODO: pass on reference to ap so the view can be updated.
682 aaa.groupRef.setInfoLetterHeight((letteHeight.getState()));
683 if (aaa.groupRef.getIgnoreBelowBackground() == false)
685 aaa.groupRef.setIgnoreBelowBackground(true);
687 ap.getAnnotationPanel()
688 .paint(ap.getAnnotationPanel().getGraphics());
692 ap.av.setInfoLetterHeight(letteHeight.getState(), ap);
693 if (ap.av.isIgnoreBelowBackground() == false)
695 ap.av.setIgnoreBelowBackground(true, ap);
698 ap.alignmentChanged();
701 pop.add(letteHeight);
702 if (aaa.groupRef != null)
704 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
705 MessageManager.getString("label.show_group_histogram"),
706 aa[selectedRow].groupRef.isShowInformationHistogram());
707 chist.addActionListener(new ActionListener()
710 public void actionPerformed(ActionEvent e)
712 // TODO: pass on reference
718 aaa.groupRef.setShowInformationHistogram(chist.getState());
720 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
724 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
725 MessageManager.getString("label.show_group_logo"),
726 aa[selectedRow].groupRef.isShowHMMSequenceLogo());
727 cprofl.addActionListener(new ActionListener()
730 public void actionPerformed(ActionEvent e)
732 // TODO: pass on reference
738 aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
740 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
744 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
745 MessageManager.getString("label.normalise_group_logo"),
746 aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
747 cproflnorm.addActionListener(new ActionListener()
750 public void actionPerformed(ActionEvent e)
753 // TODO: pass on reference
760 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
761 // automatically enable logo display if we're clicked
762 aaa.groupRef.setshowHMMSequenceLogo(true);
764 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
771 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
772 MessageManager.getString("label.show_histogram"),
773 av.isShowInformationHistogram());
774 chist.addActionListener(new ActionListener()
777 public void actionPerformed(ActionEvent e)
779 // TODO: pass on reference
785 av.setShowInformationHistogram(chist.getState());
787 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
791 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
792 MessageManager.getString("label.show_logo"),
793 av.isShowHMMSequenceLogo());
794 cprof.addActionListener(new ActionListener()
797 public void actionPerformed(ActionEvent e)
799 // TODO: pass on reference
805 av.updateInformation(ap);
806 av.setShowHMMSequenceLogo(cprof.getState());
808 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
812 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
813 MessageManager.getString("label.normalise_logo"),
814 av.isNormaliseHMMSequenceLogo());
815 cprofnorm.addActionListener(new ActionListener()
818 public void actionPerformed(ActionEvent e)
820 // TODO: pass on reference
826 av.setShowHMMSequenceLogo(true);
827 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
829 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
836 pop.show(this, evt.getX(), evt.getY());
840 * Reorders annotation rows after a drag of a label
845 public void mouseReleased(MouseEvent evt)
847 if (evt.isPopupTrigger())
853 int start = selectedRow;
854 getSelectedRow(evt.getY() - getScrollOffset());
855 int end = selectedRow;
858 * if dragging to resize instead, start == end
862 // Swap these annotations
863 AlignmentAnnotation startAA = ap.av.getAlignment()
864 .getAlignmentAnnotation()[start];
867 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
869 AlignmentAnnotation endAA = ap.av.getAlignment()
870 .getAlignmentAnnotation()[end];
872 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
873 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
879 ap.getAnnotationPanel().repaint();
883 * Removes the height adjuster image on leaving the panel, unless currently
887 public void mouseExited(MouseEvent evt)
889 if (resizePanel && dragEvent == null)
897 * A mouse drag may be either an adjustment of the panel height (if flag
898 * resizePanel is set on), or a reordering of the annotation rows. The former
899 * is dealt with by this method, the latter in mouseReleased.
904 public void mouseDragged(MouseEvent evt)
910 Dimension d = ap.annotationScroller.getPreferredSize();
911 int dif = evt.getY() - oldY;
913 dif /= ap.av.getCharHeight();
914 dif *= ap.av.getCharHeight();
916 if ((d.height - dif) > 20)
918 ap.annotationScroller
919 .setPreferredSize(new Dimension(d.width, d.height - dif));
920 d = ap.annotationSpaceFillerHolder.getPreferredSize();
921 ap.annotationSpaceFillerHolder
922 .setPreferredSize(new Dimension(d.width, d.height - dif));
923 ap.paintAlignment(true, false);
935 * Updates the tooltip as the mouse moves over the labels
940 public void mouseMoved(MouseEvent evt)
942 showOrHideAdjuster(evt);
944 getSelectedRow(evt.getY() - getScrollOffset());
946 if (selectedRow > -1 && ap.av.getAlignment()
947 .getAlignmentAnnotation().length > selectedRow)
949 AlignmentAnnotation aa = ap.av.getAlignment()
950 .getAlignmentAnnotation()[selectedRow];
952 StringBuffer desc = new StringBuffer();
953 if (aa.description != null
954 && !aa.description.equals("New description"))
956 // TODO: we could refactor and merge this code with the code in
957 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
959 desc.append(aa.getDescription(true).trim());
960 // check to see if the description is an html fragment.
961 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
962 .indexOf("<html>") < 0))
964 // clean the description ready for embedding in html
965 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
966 .replaceAll("<"));
967 desc.insert(0, "<html>");
971 // remove terminating html if any
972 int i = desc.substring(desc.length() - 7).toLowerCase()
973 .lastIndexOf("</html>");
976 desc.setLength(desc.length() - 7 + i);
981 desc.append("<br/>");
983 // if (aa.hasProperties())
985 // desc.append("<table>");
986 // for (String prop : aa.getProperties())
988 // desc.append("<tr><td>" + prop + "</td><td>"
989 // + aa.getProperty(prop) + "</td><tr>");
991 // desc.append("</table>");
996 // begin the tooltip's html fragment
997 desc.append("<html>");
1000 // TODO: limit precision of score to avoid noise from imprecise
1002 // (64.7 becomes 64.7+/some tiny value).
1003 desc.append(" Score: " + aa.score);
1006 if (desc.length() > 6)
1008 desc.append("</html>");
1009 this.setToolTipText(desc.toString());
1013 this.setToolTipText(null);
1019 * Shows the height adjuster image if the mouse moves into the top left
1020 * region, or hides it if the mouse leaves the regio
1024 protected void showOrHideAdjuster(MouseEvent evt)
1026 boolean was = resizePanel;
1027 resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
1029 if (resizePanel != was)
1031 setCursor(Cursor.getPredefinedCursor(
1032 resizePanel ? Cursor.S_RESIZE_CURSOR
1033 : Cursor.DEFAULT_CURSOR));
1039 public void mouseClicked(MouseEvent evt)
1041 final AlignmentAnnotation[] aa = ap.av.getAlignment()
1042 .getAlignmentAnnotation();
1043 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
1045 if (selectedRow > -1 && selectedRow < aa.length)
1047 if (aa[selectedRow].groupRef != null)
1049 if (evt.getClickCount() >= 2)
1051 // todo: make the ap scroll to the selection - not necessary, first
1052 // click highlights/scrolls, second selects
1053 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1054 // process modifiers
1055 SequenceGroup sg = ap.av.getSelectionGroup();
1056 if (sg == null || sg == aa[selectedRow].groupRef
1057 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
1059 if (Platform.isControlDown(evt) || evt.isShiftDown())
1061 // clone a new selection group from the associated group
1062 ap.av.setSelectionGroup(
1063 new SequenceGroup(aa[selectedRow].groupRef));
1067 // set selection to the associated group so it can be edited
1068 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1073 // modify current selection with associated group
1074 int remainToAdd = aa[selectedRow].groupRef.getSize();
1075 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1077 if (jalview.util.Platform.isControlDown(evt))
1079 sg.addOrRemove(sgs, --remainToAdd == 0);
1083 // notionally, we should also add intermediate sequences from
1084 // last added sequence ?
1085 sg.addSequence(sgs, --remainToAdd == 0);
1090 ap.paintAlignment(false, false);
1091 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1092 ap.av.sendSelection();
1096 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1097 aa[selectedRow].groupRef.getSequences(null));
1101 else if (aa[selectedRow].sequenceRef != null)
1103 if (evt.getClickCount() == 1)
1105 ap.getSeqPanel().ap.getIdPanel()
1106 .highlightSearchResults(Arrays.asList(new SequenceI[]
1107 { aa[selectedRow].sequenceRef }));
1109 else if (evt.getClickCount() >= 2)
1111 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1112 SequenceGroup sg = ap.av.getSelectionGroup();
1115 // we make a copy rather than edit the current selection if no
1116 // modifiers pressed
1117 // see Enhancement JAL-1557
1118 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
1120 sg = new SequenceGroup(sg);
1122 sg.addSequence(aa[selectedRow].sequenceRef, false);
1126 if (Platform.isControlDown(evt))
1128 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1132 // notionally, we should also add intermediate sequences from
1133 // last added sequence ?
1134 sg.addSequence(aa[selectedRow].sequenceRef, true);
1140 sg = new SequenceGroup();
1142 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1143 sg.addSequence(aa[selectedRow].sequenceRef, false);
1145 ap.av.setSelectionGroup(sg);
1146 ap.paintAlignment(false, false);
1147 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1148 ap.av.sendSelection();
1158 * do a single sequence copy to jalview and the system clipboard
1161 * sequence to be copied to clipboard
1163 protected void copy_annotseqtoclipboard(SequenceI sq)
1165 SequenceI[] seqs = new SequenceI[] { sq };
1166 String[] omitHidden = null;
1167 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1168 if (dseqs[0] == null)
1170 dseqs[0] = new Sequence(sq);
1171 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
1172 sq.getSequenceAsString()));
1174 sq.setDatasetSequence(dseqs[0]);
1176 Alignment ds = new Alignment(dseqs);
1177 if (av.hasHiddenColumns())
1179 omitHidden = av.getAlignment().getHiddenColumns()
1180 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
1183 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1184 if (av.hasHiddenColumns())
1186 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1187 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1190 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1191 seqs, omitHidden, alignmentStartEnd);
1193 Toolkit.getDefaultToolkit().getSystemClipboard()
1194 .setContents(new StringSelection(output), Desktop.instance);
1196 ArrayList<int[]> hiddenColumns = null;
1198 if (av.hasHiddenColumns())
1201 hiddenColumns = av.getAlignment().getHiddenColumns()
1202 .getHiddenColumnsCopy();
1206 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1208 // sequence ? need to
1210 // sequence as special.
1221 public void paintComponent(Graphics g)
1224 int width = getWidth();
1227 width = ap.calculateIdWidth().width + 4;
1230 Graphics2D g2 = (Graphics2D) g;
1233 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1234 RenderingHints.VALUE_ANTIALIAS_ON);
1237 drawComponent(g2, true, width);
1242 * Draw the full set of annotation Labels for the alignment at the given
1246 * Graphics2D instance (needed for font scaling)
1248 * Width for scaling labels
1251 public void drawComponent(Graphics g, int width)
1253 drawComponent(g, false, width);
1257 * Draw the full set of annotation Labels for the alignment at the given
1261 * Graphics2D instance (needed for font scaling)
1263 * - true indicates that only current visible area needs to be
1266 * Width for scaling labels
1268 public void drawComponent(Graphics g, boolean clip, int width)
1270 if (av.getFont().getSize() < 10)
1276 g.setFont(av.getFont());
1279 FontMetrics fm = g.getFontMetrics(g.getFont());
1280 g.setColor(Color.white);
1281 g.fillRect(0, 0, getWidth(), getHeight());
1283 g.translate(0, getScrollOffset());
1284 g.setColor(Color.black);
1286 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1287 int fontHeight = g.getFont().getSize();
1290 int graphExtras = 0;
1292 Font baseFont = g.getFont();
1293 FontMetrics baseMetrics = fm;
1294 int ofontH = fontHeight;
1297 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1298 ? ap.getAnnotationPanel().getVisibleVRange()
1300 if (clip && visr != null)
1303 visHeight = visr[1];
1305 boolean visible = true, before = false, after = false;
1308 hasHiddenRows = false;
1310 for (int i = 0; i < aa.length; i++)
1315 hasHiddenRows = true;
1328 System.out.println("before vis: " + i);
1332 // don't draw what isn't visible
1335 if (olY > visHeight)
1343 "Scroll offset: " + sOffset + " after vis: " + i);
1347 // don't draw what isn't visible
1351 g.setColor(Color.black);
1353 offset = -aa[i].height / 2;
1357 offset += fm.getHeight() / 2;
1358 offset -= fm.getDescent();
1362 offset += fm.getDescent();
1365 x = width - fm.stringWidth(aa[i].label) - 3;
1367 if (aa[i].graphGroup > -1)
1370 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1371 // computed efficiently for all visible labels
1372 for (int gg = 0; gg < aa.length; gg++)
1374 if (aa[gg].graphGroup == aa[i].graphGroup)
1379 if (groupSize * (fontHeight + 8) < aa[i].height)
1381 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1386 // scale font to fit
1387 float h = aa[i].height / (float) groupSize, s;
1394 fontHeight = -8 + (int) h;
1395 s = ((float) fontHeight) / (float) ofontH;
1397 .deriveFont(AffineTransform.getScaleInstance(s, s));
1399 fm = g.getFontMetrics();
1400 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1406 for (int gg = 0; gg < aa.length; gg++)
1408 if (aa[gg].graphGroup == aa[i].graphGroup)
1410 x = width - fm.stringWidth(aa[gg].label) - 3;
1411 g.drawString(aa[gg].label, x, y - graphExtras);
1413 if (aa[gg]._linecolour != null)
1416 g.setColor(aa[gg]._linecolour);
1417 g.drawLine(x, y - graphExtras + 3,
1418 x + fm.stringWidth(aa[gg].label),
1419 y - graphExtras + 3);
1422 g.setColor(Color.black);
1423 graphExtras += fontHeight + 8;
1427 g.setFont(baseFont);
1429 fontHeight = ofontH;
1433 g.drawString(aa[i].label, x, y + offset);
1440 // g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this);
1442 else if (dragEvent != null && aa != null)
1444 g.setColor(Color.lightGray);
1445 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1446 dragEvent.getY() - getScrollOffset());
1449 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1451 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1452 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1457 public int getScrollOffset()
1459 return scrollOffset;
1463 public void mouseEntered(MouseEvent e)