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());
392 final AlignmentAnnotation ann = aa[selectedRow];
393 final boolean isSequenceAnnotation = ann.sequenceRef != null;
395 item = new JMenuItem(EDITNAME);
396 item.addActionListener(this);
398 item = new JMenuItem(HIDE);
399 item.addActionListener(this);
401 // JAL-1264 hide all sequence-specific annotations of this type
402 if (selectedRow < aa.length)
404 if (isSequenceAnnotation)
406 final String label = ann.label;
407 JMenuItem hideType = new JMenuItem();
408 String text = MessageManager.getString("label.hide_all") + " "
410 hideType.setText(text);
411 hideType.addActionListener(new ActionListener()
414 public void actionPerformed(ActionEvent e)
416 AlignmentUtils.showOrHideSequenceAnnotations(
417 ap.av.getAlignment(), Collections.singleton(label),
425 item = new JMenuItem(DELETE);
426 item.addActionListener(this);
430 item = new JMenuItem(SHOWALL);
431 item.addActionListener(this);
434 item = new JMenuItem(OUTPUT_TEXT);
435 item.addActionListener(this);
437 // TODO: annotation object should be typed for autocalculated/derived
439 if (selectedRow < aa.length)
441 final String label = ann.label;
442 if (!(ann.autoCalculated)
443 && !(InformationThread.HMM_CALC_ID.equals(ann.getCalcId())))
445 if (ann.graph == AlignmentAnnotation.NO_GRAPH)
447 // display formatting settings for this row.
449 // av and sequencegroup need to implement same interface for
450 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
452 item.addActionListener(this);
456 else if (label.indexOf("Consensus") > -1)
458 addConsensusMenu(pop, ann);
460 else if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))
462 addHmmerMenu(pop, ann);
465 pop.show(this, evt.getX(), evt.getY());
469 * Adds context menu options for (alignment or group) Hmmer annotation
474 protected void addHmmerMenu(JPopupMenu pop, final AlignmentAnnotation ann)
476 final boolean isGroupAnnotation = ann.groupRef != null;
478 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
479 MessageManager.getString(
480 "label.ignore_below_background_frequency"),
483 .isIgnoreBelowBackground()
484 : ap.av.isIgnoreBelowBackground());
485 cbmi.addActionListener(new ActionListener()
488 public void actionPerformed(ActionEvent e)
490 if (isGroupAnnotation)
492 if (!ann.groupRef.isUseInfoLetterHeight())
494 ann.groupRef.setIgnoreBelowBackground(cbmi.getState());
497 else if (!ap.av.isInfoLetterHeight())
499 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
501 ap.alignmentChanged();
505 final JCheckBoxMenuItem letterHeight = new JCheckBoxMenuItem(
506 MessageManager.getString("label.use_info_for_height"),
507 isGroupAnnotation ? ann.groupRef.isUseInfoLetterHeight()
508 : ap.av.isInfoLetterHeight());
509 letterHeight.addActionListener(new ActionListener()
512 public void actionPerformed(ActionEvent e)
514 if (isGroupAnnotation)
516 ann.groupRef.setInfoLetterHeight((letterHeight.getState()));
517 ann.groupRef.setIgnoreBelowBackground(true);
521 ap.av.setInfoLetterHeight(letterHeight.getState(), ap);
522 ap.av.setIgnoreBelowBackground(true, ap);
524 ap.alignmentChanged();
527 pop.add(letterHeight);
528 if (isGroupAnnotation)
530 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
531 MessageManager.getString("label.show_group_histogram"),
532 ann.groupRef.isShowInformationHistogram());
533 chist.addActionListener(new ActionListener()
536 public void actionPerformed(ActionEvent e)
538 ann.groupRef.setShowInformationHistogram(chist.getState());
543 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
544 MessageManager.getString("label.show_group_logo"),
545 ann.groupRef.isShowHMMSequenceLogo());
546 cprofl.addActionListener(new ActionListener()
549 public void actionPerformed(ActionEvent e)
551 ann.groupRef.setshowHMMSequenceLogo(cprofl.getState());
556 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
557 MessageManager.getString("label.normalise_group_logo"),
558 ann.groupRef.isNormaliseHMMSequenceLogo());
559 cproflnorm.addActionListener(new ActionListener()
562 public void actionPerformed(ActionEvent e)
565 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
566 // automatically enable logo display if we're clicked
567 ann.groupRef.setshowHMMSequenceLogo(true);
575 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
576 MessageManager.getString("label.show_histogram"),
577 av.isShowInformationHistogram());
578 chist.addActionListener(new ActionListener()
581 public void actionPerformed(ActionEvent e)
583 av.setShowInformationHistogram(chist.getState());
588 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
589 MessageManager.getString("label.show_logo"),
590 av.isShowHMMSequenceLogo());
591 cprof.addActionListener(new ActionListener()
594 public void actionPerformed(ActionEvent e)
596 av.updateInformation(ap);
597 av.setShowHMMSequenceLogo(cprof.getState());
602 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
603 MessageManager.getString("label.normalise_logo"),
604 av.isNormaliseHMMSequenceLogo());
605 cprofnorm.addActionListener(new ActionListener()
608 public void actionPerformed(ActionEvent e)
610 av.setShowHMMSequenceLogo(true);
611 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
620 * Adds context menu options for (alignment or group) Consensus annotation
625 protected void addConsensusMenu(JPopupMenu pop,
626 final AlignmentAnnotation ann)
628 final boolean isGroupAnnotation = ann.groupRef != null;
631 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
632 MessageManager.getString("label.ignore_gaps_consensus"),
633 (ann.groupRef != null)
634 ? ann.groupRef.isIgnoreGapsConsensus()
635 : ap.av.isIgnoreGapsConsensus());
636 cbmi.addActionListener(new ActionListener()
639 public void actionPerformed(ActionEvent e)
641 if (isGroupAnnotation)
643 ann.groupRef.setIgnoreGapsConsensus(cbmi.getState());
647 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
649 ap.alignmentChanged();
653 if (isGroupAnnotation)
656 * group consensus options
658 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
659 MessageManager.getString("label.show_group_histogram"),
660 ann.groupRef.isShowConsensusHistogram());
661 chist.addActionListener(new ActionListener()
664 public void actionPerformed(ActionEvent e)
666 ann.groupRef.setShowConsensusHistogram(chist.getState());
671 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
672 MessageManager.getString("label.show_group_logo"),
673 ann.groupRef.isShowSequenceLogo());
674 cprofl.addActionListener(new ActionListener()
677 public void actionPerformed(ActionEvent e)
679 ann.groupRef.setshowSequenceLogo(cprofl.getState());
684 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
685 MessageManager.getString("label.normalise_group_logo"),
686 ann.groupRef.isNormaliseSequenceLogo());
687 cproflnorm.addActionListener(new ActionListener()
690 public void actionPerformed(ActionEvent e)
692 ann.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
693 // automatically enable logo display if we're clicked
694 ann.groupRef.setshowSequenceLogo(true);
703 * alignment consensus options
705 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
706 MessageManager.getString("label.show_histogram"),
707 av.isShowConsensusHistogram());
708 chist.addActionListener(new ActionListener()
711 public void actionPerformed(ActionEvent e)
713 av.setShowConsensusHistogram(chist.getState());
718 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
719 MessageManager.getString("label.show_logo"),
720 av.isShowSequenceLogo());
721 cprof.addActionListener(new ActionListener()
724 public void actionPerformed(ActionEvent e)
726 av.setShowSequenceLogo(cprof.getState());
731 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
732 MessageManager.getString("label.normalise_logo"),
733 av.isNormaliseSequenceLogo());
734 cprofnorm.addActionListener(new ActionListener()
737 public void actionPerformed(ActionEvent e)
739 av.setShowSequenceLogo(true);
740 av.setNormaliseSequenceLogo(cprofnorm.getState());
746 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
747 consclipbrd.addActionListener(this);
748 pop.add(consclipbrd);
752 * Reorders annotation rows after a drag of a label
757 public void mouseReleased(MouseEvent evt)
759 if (evt.isPopupTrigger())
765 int start = selectedRow;
766 getSelectedRow(evt.getY() - getScrollOffset());
767 int end = selectedRow;
770 * if dragging to resize instead, start == end
774 // Swap these annotations
775 AlignmentAnnotation startAA = ap.av.getAlignment()
776 .getAlignmentAnnotation()[start];
779 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
781 AlignmentAnnotation endAA = ap.av.getAlignment()
782 .getAlignmentAnnotation()[end];
784 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
785 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
791 ap.getAnnotationPanel().repaint();
795 * Removes the height adjuster image on leaving the panel, unless currently
799 public void mouseExited(MouseEvent evt)
801 if (resizePanel && dragEvent == null)
809 * A mouse drag may be either an adjustment of the panel height (if flag
810 * resizePanel is set on), or a reordering of the annotation rows. The former
811 * is dealt with by this method, the latter in mouseReleased.
816 public void mouseDragged(MouseEvent evt)
822 Dimension d = ap.annotationScroller.getPreferredSize();
823 int dif = evt.getY() - oldY;
825 dif /= ap.av.getCharHeight();
826 dif *= ap.av.getCharHeight();
828 if ((d.height - dif) > 20)
830 ap.annotationScroller
831 .setPreferredSize(new Dimension(d.width, d.height - dif));
832 d = ap.annotationSpaceFillerHolder.getPreferredSize();
833 ap.annotationSpaceFillerHolder
834 .setPreferredSize(new Dimension(d.width, d.height - dif));
835 ap.paintAlignment(true, false);
847 * Updates the tooltip as the mouse moves over the labels
852 public void mouseMoved(MouseEvent evt)
854 showOrHideAdjuster(evt);
856 getSelectedRow(evt.getY() - getScrollOffset());
858 if (selectedRow > -1 && ap.av.getAlignment()
859 .getAlignmentAnnotation().length > selectedRow)
861 AlignmentAnnotation aa = ap.av.getAlignment()
862 .getAlignmentAnnotation()[selectedRow];
864 StringBuffer desc = new StringBuffer();
865 if (aa.description != null
866 && !aa.description.equals("New description"))
868 // TODO: we could refactor and merge this code with the code in
869 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
871 desc.append(aa.getDescription(true).trim());
872 // check to see if the description is an html fragment.
873 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
874 .indexOf("<html>") < 0))
876 // clean the description ready for embedding in html
877 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
878 .replaceAll("<"));
879 desc.insert(0, "<html>");
883 // remove terminating html if any
884 int i = desc.substring(desc.length() - 7).toLowerCase()
885 .lastIndexOf("</html>");
888 desc.setLength(desc.length() - 7 + i);
893 desc.append("<br/>");
895 // if (aa.hasProperties())
897 // desc.append("<table>");
898 // for (String prop : aa.getProperties())
900 // desc.append("<tr><td>" + prop + "</td><td>"
901 // + aa.getProperty(prop) + "</td><tr>");
903 // desc.append("</table>");
908 // begin the tooltip's html fragment
909 desc.append("<html>");
912 // TODO: limit precision of score to avoid noise from imprecise
914 // (64.7 becomes 64.7+/some tiny value).
915 desc.append(" Score: " + aa.score);
918 if (desc.length() > 6)
920 desc.append("</html>");
921 this.setToolTipText(desc.toString());
925 this.setToolTipText(null);
931 * Shows the height adjuster image if the mouse moves into the top left
932 * region, or hides it if the mouse leaves the regio
936 protected void showOrHideAdjuster(MouseEvent evt)
938 boolean was = resizePanel;
939 resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
941 if (resizePanel != was)
943 setCursor(Cursor.getPredefinedCursor(
944 resizePanel ? Cursor.S_RESIZE_CURSOR
945 : Cursor.DEFAULT_CURSOR));
951 public void mouseClicked(MouseEvent evt)
953 final AlignmentAnnotation[] aa = ap.av.getAlignment()
954 .getAlignmentAnnotation();
955 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
957 if (selectedRow > -1 && selectedRow < aa.length)
959 if (aa[selectedRow].groupRef != null)
961 if (evt.getClickCount() >= 2)
963 // todo: make the ap scroll to the selection - not necessary, first
964 // click highlights/scrolls, second selects
965 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
967 SequenceGroup sg = ap.av.getSelectionGroup();
968 if (sg == null || sg == aa[selectedRow].groupRef
969 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
971 if (Platform.isControlDown(evt) || evt.isShiftDown())
973 // clone a new selection group from the associated group
974 ap.av.setSelectionGroup(
975 new SequenceGroup(aa[selectedRow].groupRef));
979 // set selection to the associated group so it can be edited
980 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
985 // modify current selection with associated group
986 int remainToAdd = aa[selectedRow].groupRef.getSize();
987 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
989 if (jalview.util.Platform.isControlDown(evt))
991 sg.addOrRemove(sgs, --remainToAdd == 0);
995 // notionally, we should also add intermediate sequences from
996 // last added sequence ?
997 sg.addSequence(sgs, --remainToAdd == 0);
1002 ap.paintAlignment(false, false);
1003 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1004 ap.av.sendSelection();
1008 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1009 aa[selectedRow].groupRef.getSequences(null));
1013 else if (aa[selectedRow].sequenceRef != null)
1015 if (evt.getClickCount() == 1)
1017 ap.getSeqPanel().ap.getIdPanel()
1018 .highlightSearchResults(Arrays.asList(new SequenceI[]
1019 { aa[selectedRow].sequenceRef }));
1021 else if (evt.getClickCount() >= 2)
1023 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1024 SequenceGroup sg = ap.av.getSelectionGroup();
1027 // we make a copy rather than edit the current selection if no
1028 // modifiers pressed
1029 // see Enhancement JAL-1557
1030 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
1032 sg = new SequenceGroup(sg);
1034 sg.addSequence(aa[selectedRow].sequenceRef, false);
1038 if (Platform.isControlDown(evt))
1040 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1044 // notionally, we should also add intermediate sequences from
1045 // last added sequence ?
1046 sg.addSequence(aa[selectedRow].sequenceRef, true);
1052 sg = new SequenceGroup();
1054 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1055 sg.addSequence(aa[selectedRow].sequenceRef, false);
1057 ap.av.setSelectionGroup(sg);
1058 ap.paintAlignment(false, false);
1059 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1060 ap.av.sendSelection();
1069 * do a single sequence copy to jalview and the system clipboard
1072 * sequence to be copied to clipboard
1074 protected void copy_annotseqtoclipboard(SequenceI sq)
1076 SequenceI[] seqs = new SequenceI[] { sq };
1077 String[] omitHidden = null;
1078 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1079 if (dseqs[0] == null)
1081 dseqs[0] = new Sequence(sq);
1082 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
1083 sq.getSequenceAsString()));
1085 sq.setDatasetSequence(dseqs[0]);
1087 Alignment ds = new Alignment(dseqs);
1088 if (av.hasHiddenColumns())
1090 omitHidden = av.getAlignment().getHiddenColumns()
1091 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
1094 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1095 if (av.hasHiddenColumns())
1097 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1098 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1101 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1102 seqs, omitHidden, alignmentStartEnd);
1104 Toolkit.getDefaultToolkit().getSystemClipboard()
1105 .setContents(new StringSelection(output), Desktop.instance);
1107 ArrayList<int[]> hiddenColumns = null;
1109 if (av.hasHiddenColumns())
1112 hiddenColumns = av.getAlignment().getHiddenColumns()
1113 .getHiddenColumnsCopy();
1116 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1118 // sequence ? need to
1120 // sequence as special.
1131 public void paintComponent(Graphics g)
1133 int width = getWidth();
1136 width = ap.calculateIdWidth().width + 4;
1139 Graphics2D g2 = (Graphics2D) g;
1142 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1143 RenderingHints.VALUE_ANTIALIAS_ON);
1146 drawComponent(g2, true, width);
1150 * Draw the full set of annotation Labels for the alignment at the given
1154 * Graphics2D instance (needed for font scaling)
1156 * Width for scaling labels
1159 public void drawComponent(Graphics g, int width)
1161 drawComponent(g, false, width);
1165 * Draw the full set of annotation Labels for the alignment at the given
1169 * Graphics2D instance (needed for font scaling)
1171 * - true indicates that only current visible area needs to be
1174 * Width for scaling labels
1176 public void drawComponent(Graphics g, boolean clip, int width)
1178 if (av.getFont().getSize() < 10)
1184 g.setFont(av.getFont());
1187 FontMetrics fm = g.getFontMetrics(g.getFont());
1188 g.setColor(Color.white);
1189 g.fillRect(0, 0, getWidth(), getHeight());
1191 g.translate(0, getScrollOffset());
1192 g.setColor(Color.black);
1194 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1195 int fontHeight = g.getFont().getSize();
1198 int graphExtras = 0;
1200 Font baseFont = g.getFont();
1201 FontMetrics baseMetrics = fm;
1202 int ofontH = fontHeight;
1205 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1206 ? ap.getAnnotationPanel().getVisibleVRange()
1208 if (clip && visr != null)
1211 visHeight = visr[1];
1213 boolean visible = true, before = false, after = false;
1216 hasHiddenRows = false;
1218 for (int i = 0; i < aa.length; i++)
1223 hasHiddenRows = true;
1236 System.out.println("before vis: " + i);
1240 // don't draw what isn't visible
1243 if (olY > visHeight)
1251 "Scroll offset: " + sOffset + " after vis: " + i);
1255 // don't draw what isn't visible
1259 g.setColor(Color.black);
1261 offset = -aa[i].height / 2;
1265 offset += fm.getHeight() / 2;
1266 offset -= fm.getDescent();
1270 offset += fm.getDescent();
1273 x = width - fm.stringWidth(aa[i].label) - 3;
1275 if (aa[i].graphGroup > -1)
1278 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1279 // computed efficiently for all visible labels
1280 for (int gg = 0; gg < aa.length; gg++)
1282 if (aa[gg].graphGroup == aa[i].graphGroup)
1287 if (groupSize * (fontHeight + 8) < aa[i].height)
1289 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1294 // scale font to fit
1295 float h = aa[i].height / (float) groupSize, s;
1302 fontHeight = -8 + (int) h;
1303 s = ((float) fontHeight) / (float) ofontH;
1305 .deriveFont(AffineTransform.getScaleInstance(s, s));
1307 fm = g.getFontMetrics();
1308 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1314 for (int gg = 0; gg < aa.length; gg++)
1316 if (aa[gg].graphGroup == aa[i].graphGroup)
1318 x = width - fm.stringWidth(aa[gg].label) - 3;
1319 g.drawString(aa[gg].label, x, y - graphExtras);
1321 if (aa[gg]._linecolour != null)
1324 g.setColor(aa[gg]._linecolour);
1325 g.drawLine(x, y - graphExtras + 3,
1326 x + fm.stringWidth(aa[gg].label),
1327 y - graphExtras + 3);
1330 g.setColor(Color.black);
1331 graphExtras += fontHeight + 8;
1335 g.setFont(baseFont);
1337 fontHeight = ofontH;
1341 g.drawString(aa[i].label, x, y + offset);
1348 // g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this);
1350 else if (dragEvent != null && aa != null)
1352 g.setColor(Color.lightGray);
1353 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1354 dragEvent.getY() - getScrollOffset());
1357 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1359 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1360 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1365 public int getScrollOffset()
1367 return scrollOffset;
1371 public void mouseEntered(MouseEvent e)