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.AlignmentUtils;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.Annotation;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.FileFormat;
31 import jalview.io.FormatAdapter;
32 import jalview.util.MessageManager;
34 import java.awt.Color;
35 import java.awt.Dimension;
37 import java.awt.FontMetrics;
38 import java.awt.Graphics;
39 import java.awt.Graphics2D;
40 import java.awt.Image;
41 import java.awt.MediaTracker;
42 import java.awt.RenderingHints;
43 import java.awt.Toolkit;
44 import java.awt.datatransfer.StringSelection;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseListener;
49 import java.awt.event.MouseMotionListener;
50 import java.awt.geom.AffineTransform;
51 import java.awt.image.BufferedImage;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.Collections;
55 import java.util.regex.Pattern;
57 import javax.swing.JCheckBoxMenuItem;
58 import javax.swing.JMenuItem;
59 import javax.swing.JPanel;
60 import javax.swing.JPopupMenu;
61 import javax.swing.SwingUtilities;
62 import javax.swing.ToolTipManager;
70 public class AnnotationLabels extends JPanel
71 implements MouseListener, MouseMotionListener, ActionListener
73 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
77 String TOGGLE_LABELSCALE = MessageManager
78 .getString("label.scale_label_to_column");
80 String ADDNEW = MessageManager.getString("label.add_new_row");
82 String EDITNAME = MessageManager
83 .getString("label.edit_label_description");
85 String HIDE = MessageManager.getString("label.hide_row");
87 String DELETE = MessageManager.getString("label.delete_row");
89 String SHOWALL = MessageManager.getString("label.show_all_hidden_rows");
91 String OUTPUT_TEXT = MessageManager.getString("label.export_annotation");
93 String COPYCONS_SEQ = MessageManager
94 .getString("label.copy_consensus_sequence");
96 boolean resizePanel = false;
104 boolean resizing = false;
106 MouseEvent dragEvent;
112 private int scrollOffset = 0;
114 Font font = new Font("Arial", Font.PLAIN, 11);
116 private boolean hasHiddenRows;
119 * Creates a new AnnotationLabels object.
124 public AnnotationLabels(AlignmentPanel ap)
128 ToolTipManager.sharedInstance().registerComponent(this);
130 java.net.URL url = getClass().getResource("/images/idwidth.gif");
135 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
140 MediaTracker mt = new MediaTracker(this);
141 mt.addImage(temp, 0);
143 } catch (Exception ex)
147 BufferedImage bi = new BufferedImage(temp.getHeight(this),
148 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
149 Graphics2D g = (Graphics2D) bi.getGraphics();
150 g.rotate(Math.toRadians(90));
151 g.drawImage(temp, 0, -bi.getWidth(this), this);
154 addMouseListener(this);
155 addMouseMotionListener(this);
156 addMouseWheelListener(ap.getAnnotationPanel());
159 public AnnotationLabels(AlignViewport av)
170 public void setScrollOffset(int y)
177 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
181 * coordinate position to search for a row
183 void getSelectedRow(int y)
186 AlignmentAnnotation[] aa = ap.av.getAlignment()
187 .getAlignmentAnnotation();
191 for (int i = 0; i < aa.length; i++)
199 height += aa[i].height;
218 public void actionPerformed(ActionEvent evt)
220 AlignmentAnnotation[] aa = ap.av.getAlignment()
221 .getAlignmentAnnotation();
223 boolean fullRepaint = false;
224 if (evt.getActionCommand().equals(ADDNEW))
226 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
227 null, new Annotation[ap.av.getAlignment().getWidth()]);
229 if (!editLabelDescription(newAnnotation))
234 ap.av.getAlignment().addAnnotation(newAnnotation);
235 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
238 else if (evt.getActionCommand().equals(EDITNAME))
240 String name = aa[selectedRow].label;
241 editLabelDescription(aa[selectedRow]);
242 if (!name.equalsIgnoreCase(aa[selectedRow].label))
247 else if (evt.getActionCommand().equals(HIDE))
249 aa[selectedRow].visible = false;
251 else if (evt.getActionCommand().equals(DELETE))
253 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
254 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
257 else if (evt.getActionCommand().equals(SHOWALL))
259 for (int i = 0; i < aa.length; i++)
261 if (!aa[i].visible && aa[i].annotations != null)
263 aa[i].visible = true;
268 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
270 new AnnotationExporter().exportAnnotations(ap,
271 new AlignmentAnnotation[]
272 { aa[selectedRow] });
274 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
276 SequenceI cons = null;
277 if (aa[selectedRow].groupRef != null)
279 cons = aa[selectedRow].groupRef.getConsensusSeq();
283 cons = av.getConsensusSeq();
287 copy_annotseqtoclipboard(cons);
291 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
293 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
296 ap.refresh(fullRepaint);
306 boolean editLabelDescription(AlignmentAnnotation annotation)
309 EditNameDialog dialog = new EditNameDialog(annotation.label,
310 annotation.description, " Annotation Name ",
311 "Annotation Description ", "Edit Annotation Name/Description",
319 annotation.label = dialog.getName();
321 String text = dialog.getDescription();
322 if (text != null && text.length() == 0)
326 annotation.description = text;
332 public void mousePressed(MouseEvent evt)
334 getSelectedRow(evt.getY() - getScrollOffset());
336 if (evt.isPopupTrigger())
343 * Build and show the Pop-up menu at the right-click mouse position
347 void showPopupMenu(MouseEvent evt)
350 final AlignmentAnnotation[] aa = ap.av.getAlignment()
351 .getAlignmentAnnotation();
353 JPopupMenu pop = new JPopupMenu(
354 MessageManager.getString("label.annotations"));
355 JMenuItem item = new JMenuItem(ADDNEW);
356 item.addActionListener(this);
361 { // let the user make everything visible again
362 item = new JMenuItem(SHOWALL);
363 item.addActionListener(this);
366 pop.show(this, evt.getX(), evt.getY());
369 item = new JMenuItem(EDITNAME);
370 item.addActionListener(this);
372 item = new JMenuItem(HIDE);
373 item.addActionListener(this);
375 // JAL-1264 hide all sequence-specific annotations of this type
376 if (selectedRow < aa.length)
378 if (aa[selectedRow].sequenceRef != null)
380 final String label = aa[selectedRow].label;
381 JMenuItem hideType = new JMenuItem();
382 String text = MessageManager.getString("label.hide_all") + " "
384 hideType.setText(text);
385 hideType.addActionListener(new ActionListener()
388 public void actionPerformed(ActionEvent e)
390 AlignmentUtils.showOrHideSequenceAnnotations(
391 ap.av.getAlignment(), Collections.singleton(label),
393 // for (AlignmentAnnotation ann : ap.av.getAlignment()
394 // .getAlignmentAnnotation())
396 // if (ann.sequenceRef != null && ann.label != null
397 // && ann.label.equals(label))
399 // ann.visible = false;
408 item = new JMenuItem(DELETE);
409 item.addActionListener(this);
413 item = new JMenuItem(SHOWALL);
414 item.addActionListener(this);
417 item = new JMenuItem(OUTPUT_TEXT);
418 item.addActionListener(this);
420 // TODO: annotation object should be typed for autocalculated/derived
422 if (selectedRow < aa.length)
424 final String label = aa[selectedRow].label;
425 if (!(aa[selectedRow].autoCalculated)
426 && !("HMM".equals(aa[selectedRow].getCalcId())))
428 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
430 // display formatting settings for this row.
432 // av and sequencegroup need to implement same interface for
433 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
434 aa[selectedRow].scaleColLabel);
435 item.addActionListener(this);
439 else if (label.indexOf("Consensus") > -1)
444 // av and sequencegroup need to implement same interface for
446 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
447 MessageManager.getString("label.ignore_gaps_consensus"),
448 (aa[selectedRow].groupRef != null)
449 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
450 : ap.av.isIgnoreGapsConsensus());
451 final AlignmentAnnotation aaa = aa[selectedRow];
452 cbmi.addActionListener(new ActionListener()
455 public void actionPerformed(ActionEvent e)
457 if (aaa.groupRef != null)
459 // TODO: pass on reference to ap so the view can be updated.
460 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
461 ap.getAnnotationPanel()
462 .paint(ap.getAnnotationPanel().getGraphics());
466 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
468 ap.alignmentChanged();
472 // av and sequencegroup need to implement same interface for
473 if (aaa.groupRef != null)
475 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
476 MessageManager.getString("label.show_group_histogram"),
477 aa[selectedRow].groupRef.isShowConsensusHistogram());
478 chist.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent e)
483 // TODO: pass on reference
489 aaa.groupRef.setShowConsensusHistogram(chist.getState());
491 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
495 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
496 MessageManager.getString("label.show_group_logo"),
497 aa[selectedRow].groupRef.isShowSequenceLogo());
498 cprofl.addActionListener(new ActionListener()
501 public void actionPerformed(ActionEvent e)
503 // TODO: pass on reference
509 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
511 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
515 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
516 MessageManager.getString("label.normalise_group_logo"),
517 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
518 cproflnorm.addActionListener(new ActionListener()
521 public void actionPerformed(ActionEvent e)
524 // TODO: pass on reference
530 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
531 // automatically enable logo display if we're clicked
532 aaa.groupRef.setshowSequenceLogo(true);
534 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
541 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
542 MessageManager.getString("label.show_histogram"),
543 av.isShowConsensusHistogram());
544 chist.addActionListener(new ActionListener()
547 public void actionPerformed(ActionEvent e)
549 // TODO: pass on reference
555 av.setShowConsensusHistogram(chist.getState());
557 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
561 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
562 MessageManager.getString("label.show_logo"),
563 av.isShowSequenceLogo());
564 cprof.addActionListener(new ActionListener()
567 public void actionPerformed(ActionEvent e)
569 // TODO: pass on reference
575 av.setShowSequenceLogo(cprof.getState());
577 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
581 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
582 MessageManager.getString("label.normalise_logo"),
583 av.isNormaliseSequenceLogo());
584 cprofnorm.addActionListener(new ActionListener()
587 public void actionPerformed(ActionEvent e)
589 // TODO: pass on reference
595 av.setShowSequenceLogo(true);
596 av.setNormaliseSequenceLogo(cprofnorm.getState());
598 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
603 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
604 consclipbrd.addActionListener(this);
605 pop.add(consclipbrd);
607 else if ("HMM".equals(aa[selectedRow].getCalcId())) // TODO create labels
608 // in message resource
612 final AlignmentAnnotation aaa = aa[selectedRow];
614 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
615 MessageManager.getString(
616 "label.ignore_below_background_frequency"),
617 (aa[selectedRow].groupRef != null)
618 ? aa[selectedRow].groupRef
619 .getIgnoreBelowBackground()
620 : ap.av.isIgnoreBelowBackground());
622 cbmi.addActionListener(new ActionListener()
625 public void actionPerformed(ActionEvent e)
628 if (aaa.groupRef != null)
630 // TODO: pass on reference to ap so the view can be updated.
631 if (aaa.groupRef.getInfoLetterHeight() == false)
633 aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
634 ap.getAnnotationPanel()
635 .paint(ap.getAnnotationPanel().getGraphics());
638 else if (ap.av.isInfoLetterHeight() == false)
640 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
642 ap.alignmentChanged();
646 final JCheckBoxMenuItem letteHeight = new JCheckBoxMenuItem(
647 MessageManager.getString("label.use_info_for_height"),
648 (aa[selectedRow].groupRef != null)
649 ? aa[selectedRow].groupRef.getInfoLetterHeight()
650 : ap.av.isInfoLetterHeight());
652 letteHeight.addActionListener(new ActionListener()
655 public void actionPerformed(ActionEvent e)
657 if (aaa.groupRef != null)
659 // TODO: pass on reference to ap so the view can be updated.
660 aaa.groupRef.setInfoLetterHeight((letteHeight.getState()));
661 if (aaa.groupRef.getIgnoreBelowBackground() == false)
663 aaa.groupRef.setIgnoreBelowBackground(true);
665 ap.getAnnotationPanel()
666 .paint(ap.getAnnotationPanel().getGraphics());
670 ap.av.setInfoLetterHeight(letteHeight.getState(), ap);
671 if (ap.av.isIgnoreBelowBackground() == false)
673 ap.av.setIgnoreBelowBackground(true, ap);
676 ap.alignmentChanged();
679 pop.add(letteHeight);
680 if (aaa.groupRef != null)
682 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
683 MessageManager.getString("label.show_group_histogram"),
684 aa[selectedRow].groupRef.isShowInformationHistogram());
685 chist.addActionListener(new ActionListener()
688 public void actionPerformed(ActionEvent e)
690 // TODO: pass on reference
696 aaa.groupRef.setShowInformationHistogram(chist.getState());
698 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
702 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
703 MessageManager.getString("label.show_group_logo"),
704 aa[selectedRow].groupRef.isShowHMMSequenceLogo());
705 cprofl.addActionListener(new ActionListener()
708 public void actionPerformed(ActionEvent e)
710 // TODO: pass on reference
716 aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
718 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
722 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
723 MessageManager.getString("label.normalise_group_logo"),
724 aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
725 cproflnorm.addActionListener(new ActionListener()
728 public void actionPerformed(ActionEvent e)
731 // TODO: pass on reference
738 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
739 // automatically enable logo display if we're clicked
740 aaa.groupRef.setshowHMMSequenceLogo(true);
742 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
749 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
750 MessageManager.getString("label.show_histogram"),
751 av.isShowInformationHistogram());
752 chist.addActionListener(new ActionListener()
755 public void actionPerformed(ActionEvent e)
757 // TODO: pass on reference
763 av.setShowInformationHistogram(chist.getState());
765 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
769 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
770 MessageManager.getString("label.show_logo"),
771 av.isShowHMMSequenceLogo());
772 cprof.addActionListener(new ActionListener()
775 public void actionPerformed(ActionEvent e)
777 // TODO: pass on reference
783 av.updateInformation(ap);
784 av.setShowHMMSequenceLogo(cprof.getState());
786 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
790 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
791 MessageManager.getString("label.normalise_logo"),
792 av.isNormaliseHMMSequenceLogo());
793 cprofnorm.addActionListener(new ActionListener()
796 public void actionPerformed(ActionEvent e)
798 // TODO: pass on reference
804 av.setShowHMMSequenceLogo(true);
805 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
807 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
814 pop.show(this, evt.getX(), evt.getY());
824 public void mouseReleased(MouseEvent evt)
826 if (evt.isPopupTrigger())
832 int start = selectedRow;
833 getSelectedRow(evt.getY() - getScrollOffset());
834 int end = selectedRow;
838 // Swap these annotations
839 AlignmentAnnotation startAA = ap.av.getAlignment()
840 .getAlignmentAnnotation()[start];
843 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
845 AlignmentAnnotation endAA = ap.av.getAlignment()
846 .getAlignmentAnnotation()[end];
848 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
849 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
855 ap.getAnnotationPanel().repaint();
865 public void mouseEntered(MouseEvent evt)
881 public void mouseExited(MouseEvent evt)
883 if (dragEvent == null)
897 public void mouseDragged(MouseEvent evt)
903 Dimension d = ap.annotationScroller.getPreferredSize();
904 int dif = evt.getY() - oldY;
906 dif /= ap.av.getCharHeight();
907 dif *= ap.av.getCharHeight();
909 if ((d.height - dif) > 20)
911 ap.annotationScroller
912 .setPreferredSize(new Dimension(d.width, d.height - dif));
913 d = ap.annotationSpaceFillerHolder.getPreferredSize();
914 ap.annotationSpaceFillerHolder
915 .setPreferredSize(new Dimension(d.width, d.height - dif));
916 ap.paintAlignment(true);
934 public void mouseMoved(MouseEvent evt)
936 resizePanel = evt.getY() < 10;
938 getSelectedRow(evt.getY() - getScrollOffset());
940 if (selectedRow > -1 && ap.av.getAlignment()
941 .getAlignmentAnnotation().length > selectedRow)
943 AlignmentAnnotation aa = ap.av.getAlignment()
944 .getAlignmentAnnotation()[selectedRow];
946 StringBuffer desc = new StringBuffer();
947 if (aa.description != null
948 && !aa.description.equals("New description"))
950 // TODO: we could refactor and merge this code with the code in
951 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
953 desc.append(aa.getDescription(true).trim());
954 // check to see if the description is an html fragment.
955 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
956 .indexOf("<html>") < 0))
958 // clean the description ready for embedding in html
959 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
960 .replaceAll("<"));
961 desc.insert(0, "<html>");
965 // remove terminating html if any
966 int i = desc.substring(desc.length() - 7).toLowerCase()
967 .lastIndexOf("</html>");
970 desc.setLength(desc.length() - 7 + i);
975 desc.append("<br/>");
977 // if (aa.hasProperties())
979 // desc.append("<table>");
980 // for (String prop : aa.getProperties())
982 // desc.append("<tr><td>" + prop + "</td><td>"
983 // + aa.getProperty(prop) + "</td><tr>");
985 // desc.append("</table>");
990 // begin the tooltip's html fragment
991 desc.append("<html>");
994 // TODO: limit precision of score to avoid noise from imprecise
996 // (64.7 becomes 64.7+/some tiny value).
997 desc.append(" Score: " + aa.score);
1000 if (desc.length() > 6)
1002 desc.append("</html>");
1003 this.setToolTipText(desc.toString());
1007 this.setToolTipText(null);
1013 public void mouseClicked(MouseEvent evt)
1015 final AlignmentAnnotation[] aa = ap.av.getAlignment()
1016 .getAlignmentAnnotation();
1017 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
1019 if (selectedRow > -1 && selectedRow < aa.length)
1021 if (aa[selectedRow].groupRef != null)
1023 if (evt.getClickCount() >= 2)
1025 // todo: make the ap scroll to the selection - not necessary, first
1026 // click highlights/scrolls, second selects
1027 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1028 // process modifiers
1029 SequenceGroup sg = ap.av.getSelectionGroup();
1030 if (sg == null || sg == aa[selectedRow].groupRef
1031 || !(jalview.util.Platform.isControlDown(evt)
1032 || evt.isShiftDown()))
1034 if (jalview.util.Platform.isControlDown(evt)
1035 || evt.isShiftDown())
1037 // clone a new selection group from the associated group
1038 ap.av.setSelectionGroup(
1039 new SequenceGroup(aa[selectedRow].groupRef));
1043 // set selection to the associated group so it can be edited
1044 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1049 // modify current selection with associated group
1050 int remainToAdd = aa[selectedRow].groupRef.getSize();
1051 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1053 if (jalview.util.Platform.isControlDown(evt))
1055 sg.addOrRemove(sgs, --remainToAdd == 0);
1059 // notionally, we should also add intermediate sequences from
1060 // last added sequence ?
1061 sg.addSequence(sgs, --remainToAdd == 0);
1066 ap.paintAlignment(false);
1067 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1068 ap.av.sendSelection();
1072 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1073 aa[selectedRow].groupRef.getSequences(null));
1077 else if (aa[selectedRow].sequenceRef != null)
1079 if (evt.getClickCount() == 1)
1081 ap.getSeqPanel().ap.getIdPanel()
1082 .highlightSearchResults(Arrays.asList(new SequenceI[]
1083 { aa[selectedRow].sequenceRef }));
1085 else if (evt.getClickCount() >= 2)
1087 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1088 SequenceGroup sg = ap.av.getSelectionGroup();
1091 // we make a copy rather than edit the current selection if no
1092 // modifiers pressed
1093 // see Enhancement JAL-1557
1094 if (!(jalview.util.Platform.isControlDown(evt)
1095 || evt.isShiftDown()))
1097 sg = new SequenceGroup(sg);
1099 sg.addSequence(aa[selectedRow].sequenceRef, false);
1103 if (jalview.util.Platform.isControlDown(evt))
1105 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1109 // notionally, we should also add intermediate sequences from
1110 // last added sequence ?
1111 sg.addSequence(aa[selectedRow].sequenceRef, true);
1117 sg = new SequenceGroup();
1119 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1120 sg.addSequence(aa[selectedRow].sequenceRef, false);
1122 ap.av.setSelectionGroup(sg);
1123 ap.paintAlignment(false);
1124 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1125 ap.av.sendSelection();
1135 * do a single sequence copy to jalview and the system clipboard
1138 * sequence to be copied to clipboard
1140 protected void copy_annotseqtoclipboard(SequenceI sq)
1142 SequenceI[] seqs = new SequenceI[] { sq };
1143 String[] omitHidden = null;
1144 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1145 if (dseqs[0] == null)
1147 dseqs[0] = new Sequence(sq);
1148 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
1149 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
1151 sq.setDatasetSequence(dseqs[0]);
1153 Alignment ds = new Alignment(dseqs);
1154 if (av.hasHiddenColumns())
1156 omitHidden = av.getAlignment().getHiddenColumns()
1157 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
1160 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1161 if (av.hasHiddenColumns())
1163 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1164 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1167 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1168 seqs, omitHidden, alignmentStartEnd);
1170 Toolkit.getDefaultToolkit().getSystemClipboard()
1171 .setContents(new StringSelection(output), Desktop.instance);
1173 ArrayList<int[]> hiddenColumns = null;
1175 if (av.hasHiddenColumns())
1178 hiddenColumns = av.getAlignment().getHiddenColumns()
1179 .getHiddenColumnsCopy();
1183 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1185 // sequence ? need to
1187 // sequence as special.
1198 public void paintComponent(Graphics g)
1201 int width = getWidth();
1204 width = ap.calculateIdWidth().width + 4;
1207 Graphics2D g2 = (Graphics2D) g;
1210 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1211 RenderingHints.VALUE_ANTIALIAS_ON);
1214 drawComponent(g2, true, width);
1219 * Draw the full set of annotation Labels for the alignment at the given
1223 * Graphics2D instance (needed for font scaling)
1225 * Width for scaling labels
1228 public void drawComponent(Graphics g, int width)
1230 drawComponent(g, false, width);
1233 private final boolean debugRedraw = false;
1236 * Draw the full set of annotation Labels for the alignment at the given
1240 * Graphics2D instance (needed for font scaling)
1242 * - true indicates that only current visible area needs to be
1245 * Width for scaling labels
1247 public void drawComponent(Graphics g, boolean clip, int width)
1249 if (av.getFont().getSize() < 10)
1255 g.setFont(av.getFont());
1258 FontMetrics fm = g.getFontMetrics(g.getFont());
1259 g.setColor(Color.white);
1260 g.fillRect(0, 0, getWidth(), getHeight());
1262 g.translate(0, getScrollOffset());
1263 g.setColor(Color.black);
1265 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1266 int fontHeight = g.getFont().getSize();
1269 int graphExtras = 0;
1271 Font baseFont = g.getFont();
1272 FontMetrics baseMetrics = fm;
1273 int ofontH = fontHeight;
1276 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1277 ? ap.getAnnotationPanel().getVisibleVRange()
1279 if (clip && visr != null)
1282 visHeight = visr[1];
1284 boolean visible = true, before = false, after = false;
1287 hasHiddenRows = false;
1289 for (int i = 0; i < aa.length; i++)
1294 hasHiddenRows = true;
1307 System.out.println("before vis: " + i);
1311 // don't draw what isn't visible
1314 if (olY > visHeight)
1322 "Scroll offset: " + sOffset + " after vis: " + i);
1326 // don't draw what isn't visible
1330 g.setColor(Color.black);
1332 offset = -aa[i].height / 2;
1336 offset += fm.getHeight() / 2;
1337 offset -= fm.getDescent();
1341 offset += fm.getDescent();
1344 x = width - fm.stringWidth(aa[i].label) - 3;
1346 if (aa[i].graphGroup > -1)
1349 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1350 // computed efficiently for all visible labels
1351 for (int gg = 0; gg < aa.length; gg++)
1353 if (aa[gg].graphGroup == aa[i].graphGroup)
1358 if (groupSize * (fontHeight + 8) < aa[i].height)
1360 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1365 // scale font to fit
1366 float h = aa[i].height / (float) groupSize, s;
1373 fontHeight = -8 + (int) h;
1374 s = ((float) fontHeight) / (float) ofontH;
1376 .deriveFont(AffineTransform.getScaleInstance(s, s));
1378 fm = g.getFontMetrics();
1379 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1385 for (int gg = 0; gg < aa.length; gg++)
1387 if (aa[gg].graphGroup == aa[i].graphGroup)
1389 x = width - fm.stringWidth(aa[gg].label) - 3;
1390 g.drawString(aa[gg].label, x, y - graphExtras);
1392 if (aa[gg]._linecolour != null)
1395 g.setColor(aa[gg]._linecolour);
1396 g.drawLine(x, y - graphExtras + 3,
1397 x + fm.stringWidth(aa[gg].label),
1398 y - graphExtras + 3);
1401 g.setColor(Color.black);
1402 graphExtras += fontHeight + 8;
1406 g.setFont(baseFont);
1408 fontHeight = ofontH;
1412 g.drawString(aa[i].label, x, y + offset);
1419 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1421 else if (dragEvent != null && aa != null)
1423 g.setColor(Color.lightGray);
1424 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1425 dragEvent.getY() - getScrollOffset());
1428 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1430 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1431 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1436 public int getScrollOffset()
1438 return scrollOffset;