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.HiddenColumns;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.FileFormat;
33 import jalview.io.FormatAdapter;
34 import jalview.util.Comparison;
35 import jalview.util.MessageManager;
36 import jalview.util.Platform;
37 import jalview.workers.InformationThread;
39 import java.awt.Color;
40 import java.awt.Cursor;
41 import java.awt.Dimension;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.RenderingHints;
47 import java.awt.Toolkit;
48 import java.awt.datatransfer.StringSelection;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
52 import java.awt.event.MouseListener;
53 import java.awt.event.MouseMotionListener;
54 import java.awt.geom.AffineTransform;
55 import java.util.Arrays;
56 import java.util.Collections;
57 import java.util.Iterator;
58 import java.util.regex.Pattern;
60 import javax.swing.JCheckBoxMenuItem;
61 import javax.swing.JMenuItem;
62 import javax.swing.JPanel;
63 import javax.swing.JPopupMenu;
64 import javax.swing.SwingUtilities;
65 import javax.swing.ToolTipManager;
68 * The panel that holds the labels for alignment annotations, providing
69 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
72 public class AnnotationLabels extends JPanel
73 implements MouseListener, MouseMotionListener, ActionListener
76 * width in pixels within which height adjuster arrows are shown and active
78 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
81 * height in pixels for allowing height adjuster to be active
83 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
85 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
88 private static final Font font = new Font("Arial", Font.PLAIN, 11);
90 private static final String TOGGLE_LABELSCALE = MessageManager
91 .getString("label.scale_label_to_column");
93 private static final String ADDNEW = MessageManager
94 .getString("label.add_new_row");
96 private static final String EDITNAME = MessageManager
97 .getString("label.edit_label_description");
99 private static final String HIDE = MessageManager
100 .getString("label.hide_row");
102 private static final String DELETE = MessageManager
103 .getString("label.delete_row");
105 private static final String SHOWALL = MessageManager
106 .getString("label.show_all_hidden_rows");
108 private static final String OUTPUT_TEXT = MessageManager
109 .getString("label.export_annotation");
111 private static final String COPYCONS_SEQ = MessageManager
112 .getString("label.copy_consensus_sequence");
114 private final boolean debugRedraw = false;
116 private AlignmentPanel ap;
120 private MouseEvent dragEvent;
124 private int selectedRow;
126 private int scrollOffset = 0;
128 private boolean hasHiddenRows;
130 private boolean resizePanel = false;
133 * Creates a new AnnotationLabels object
137 public AnnotationLabels(AlignmentPanel ap)
141 ToolTipManager.sharedInstance().registerComponent(this);
143 addMouseListener(this);
144 addMouseMotionListener(this);
145 addMouseWheelListener(ap.getAnnotationPanel());
148 public AnnotationLabels(AlignViewport av)
159 public void setScrollOffset(int y)
166 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
170 * coordinate position to search for a row
172 void getSelectedRow(int y)
175 AlignmentAnnotation[] aa = ap.av.getAlignment()
176 .getAlignmentAnnotation();
180 for (int i = 0; i < aa.length; i++)
188 height += aa[i].height;
207 public void actionPerformed(ActionEvent evt)
209 AlignmentAnnotation[] aa = ap.av.getAlignment()
210 .getAlignmentAnnotation();
212 boolean fullRepaint = false;
213 if (evt.getActionCommand().equals(ADDNEW))
215 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
216 null, new Annotation[ap.av.getAlignment().getWidth()]);
218 if (!editLabelDescription(newAnnotation))
223 ap.av.getAlignment().addAnnotation(newAnnotation);
224 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
227 else if (evt.getActionCommand().equals(EDITNAME))
229 String name = aa[selectedRow].label;
230 editLabelDescription(aa[selectedRow]);
231 if (!name.equalsIgnoreCase(aa[selectedRow].label))
236 else if (evt.getActionCommand().equals(HIDE))
238 aa[selectedRow].visible = false;
240 else if (evt.getActionCommand().equals(DELETE))
242 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
243 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
246 else if (evt.getActionCommand().equals(SHOWALL))
248 for (int i = 0; i < aa.length; i++)
250 if (!aa[i].visible && aa[i].annotations != null)
252 aa[i].visible = true;
257 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
259 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
261 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
263 SequenceI cons = null;
264 if (aa[selectedRow].groupRef != null)
266 cons = aa[selectedRow].groupRef.getConsensusSeq();
270 cons = av.getConsensusSeq();
274 copy_annotseqtoclipboard(cons);
278 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
280 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
283 ap.refresh(fullRepaint);
293 boolean editLabelDescription(AlignmentAnnotation annotation)
296 EditNameDialog dialog = new EditNameDialog(annotation.label,
297 annotation.description, " Annotation Name ",
298 "Annotation Description ", "Edit Annotation Name/Description",
306 annotation.label = dialog.getName();
308 String text = dialog.getDescription();
309 if (text != null && text.length() == 0)
313 annotation.description = text;
319 public void mousePressed(MouseEvent evt)
321 getSelectedRow(evt.getY() - getScrollOffset());
323 if (evt.isPopupTrigger())
330 * Build and show the Pop-up menu at the right-click mouse position
334 void showPopupMenu(MouseEvent evt)
337 final AlignmentAnnotation[] aa = ap.av.getAlignment()
338 .getAlignmentAnnotation();
340 JPopupMenu pop = new JPopupMenu(
341 MessageManager.getString("label.annotations"));
342 JMenuItem item = new JMenuItem(ADDNEW);
343 item.addActionListener(this);
348 { // let the user make everything visible again
349 item = new JMenuItem(SHOWALL);
350 item.addActionListener(this);
353 pop.show(this, evt.getX(), evt.getY());
357 final AlignmentAnnotation ann = aa[selectedRow];
358 final boolean isSequenceAnnotation = ann.sequenceRef != null;
360 item = new JMenuItem(EDITNAME);
361 item.addActionListener(this);
363 item = new JMenuItem(HIDE);
364 item.addActionListener(this);
366 // JAL-1264 hide all sequence-specific annotations of this type
367 if (selectedRow < aa.length)
369 if (isSequenceAnnotation)
371 final String label = ann.label;
372 JMenuItem hideType = new JMenuItem();
373 String text = MessageManager.getString("label.hide_all") + " "
375 hideType.setText(text);
376 hideType.addActionListener(new ActionListener()
379 public void actionPerformed(ActionEvent e)
381 AlignmentUtils.showOrHideSequenceAnnotations(
382 ap.av.getAlignment(), Collections.singleton(label),
390 item = new JMenuItem(DELETE);
391 item.addActionListener(this);
395 item = new JMenuItem(SHOWALL);
396 item.addActionListener(this);
399 item = new JMenuItem(OUTPUT_TEXT);
400 item.addActionListener(this);
402 // TODO: annotation object should be typed for autocalculated/derived
404 if (selectedRow < aa.length)
406 final String label = ann.label;
407 if (!(ann.autoCalculated)
408 && !(InformationThread.HMM_CALC_ID.equals(ann.getCalcId())))
410 if (ann.graph == AlignmentAnnotation.NO_GRAPH)
412 // display formatting settings for this row.
414 // av and sequencegroup need to implement same interface for
415 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
417 item.addActionListener(this);
421 else if (label.indexOf("Consensus") > -1)
423 addConsensusMenu(pop, ann);
425 else if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))
427 addHmmerMenu(pop, ann);
430 pop.show(this, evt.getX(), evt.getY());
434 * Adds context menu options for (alignment or group) Hmmer annotation
439 protected void addHmmerMenu(JPopupMenu pop, final AlignmentAnnotation ann)
441 final boolean isGroupAnnotation = ann.groupRef != null;
443 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
444 MessageManager.getString(
445 "label.ignore_below_background_frequency"),
448 .isIgnoreBelowBackground()
449 : ap.av.isIgnoreBelowBackground());
450 cbmi.addActionListener(new ActionListener()
453 public void actionPerformed(ActionEvent e)
455 if (isGroupAnnotation)
457 if (!ann.groupRef.isUseInfoLetterHeight())
459 ann.groupRef.setIgnoreBelowBackground(cbmi.getState());
462 else if (!ap.av.isInfoLetterHeight())
464 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
466 ap.alignmentChanged();
470 final JCheckBoxMenuItem letterHeight = new JCheckBoxMenuItem(
471 MessageManager.getString("label.use_info_for_height"),
472 isGroupAnnotation ? ann.groupRef.isUseInfoLetterHeight()
473 : ap.av.isInfoLetterHeight());
474 letterHeight.addActionListener(new ActionListener()
477 public void actionPerformed(ActionEvent e)
479 if (isGroupAnnotation)
481 ann.groupRef.setInfoLetterHeight((letterHeight.getState()));
482 ann.groupRef.setIgnoreBelowBackground(true);
486 ap.av.setInfoLetterHeight(letterHeight.getState(), ap);
487 ap.av.setIgnoreBelowBackground(true, ap);
489 ap.alignmentChanged();
492 pop.add(letterHeight);
493 if (isGroupAnnotation)
495 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
496 MessageManager.getString("label.show_group_histogram"),
497 ann.groupRef.isShowInformationHistogram());
498 chist.addActionListener(new ActionListener()
501 public void actionPerformed(ActionEvent e)
503 ann.groupRef.setShowInformationHistogram(chist.getState());
508 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
509 MessageManager.getString("label.show_group_logo"),
510 ann.groupRef.isShowHMMSequenceLogo());
511 cprofl.addActionListener(new ActionListener()
514 public void actionPerformed(ActionEvent e)
516 ann.groupRef.setshowHMMSequenceLogo(cprofl.getState());
521 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
522 MessageManager.getString("label.normalise_group_logo"),
523 ann.groupRef.isNormaliseHMMSequenceLogo());
524 cproflnorm.addActionListener(new ActionListener()
527 public void actionPerformed(ActionEvent e)
530 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
531 // automatically enable logo display if we're clicked
532 ann.groupRef.setshowHMMSequenceLogo(true);
540 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
541 MessageManager.getString("label.show_histogram"),
542 av.isShowInformationHistogram());
543 chist.addActionListener(new ActionListener()
546 public void actionPerformed(ActionEvent e)
548 av.setShowInformationHistogram(chist.getState());
553 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
554 MessageManager.getString("label.show_logo"),
555 av.isShowHMMSequenceLogo());
556 cprof.addActionListener(new ActionListener()
559 public void actionPerformed(ActionEvent e)
561 av.setShowHMMSequenceLogo(cprof.getState());
566 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
567 MessageManager.getString("label.normalise_logo"),
568 av.isNormaliseHMMSequenceLogo());
569 cprofnorm.addActionListener(new ActionListener()
572 public void actionPerformed(ActionEvent e)
574 av.setShowHMMSequenceLogo(true);
575 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
584 * Adds context menu options for (alignment or group) Consensus annotation
589 protected void addConsensusMenu(JPopupMenu pop,
590 final AlignmentAnnotation ann)
592 final boolean isGroupAnnotation = ann.groupRef != null;
595 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
596 MessageManager.getString("label.ignore_gaps_consensus"),
597 (ann.groupRef != null)
598 ? ann.groupRef.isIgnoreGapsConsensus()
599 : ap.av.isIgnoreGapsConsensus());
600 cbmi.addActionListener(new ActionListener()
603 public void actionPerformed(ActionEvent e)
605 if (isGroupAnnotation)
607 ann.groupRef.setIgnoreGapsConsensus(cbmi.getState());
611 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
613 ap.alignmentChanged();
617 if (isGroupAnnotation)
620 * group consensus options
622 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
623 MessageManager.getString("label.show_group_histogram"),
624 ann.groupRef.isShowConsensusHistogram());
625 chist.addActionListener(new ActionListener()
628 public void actionPerformed(ActionEvent e)
630 ann.groupRef.setShowConsensusHistogram(chist.getState());
635 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
636 MessageManager.getString("label.show_group_logo"),
637 ann.groupRef.isShowSequenceLogo());
638 cprofl.addActionListener(new ActionListener()
641 public void actionPerformed(ActionEvent e)
643 ann.groupRef.setshowSequenceLogo(cprofl.getState());
648 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
649 MessageManager.getString("label.normalise_group_logo"),
650 ann.groupRef.isNormaliseSequenceLogo());
651 cproflnorm.addActionListener(new ActionListener()
654 public void actionPerformed(ActionEvent e)
656 ann.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
657 // automatically enable logo display if we're clicked
658 ann.groupRef.setshowSequenceLogo(true);
667 * alignment consensus options
669 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
670 MessageManager.getString("label.show_histogram"),
671 av.isShowConsensusHistogram());
672 chist.addActionListener(new ActionListener()
675 public void actionPerformed(ActionEvent e)
677 av.setShowConsensusHistogram(chist.getState());
682 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
683 MessageManager.getString("label.show_logo"),
684 av.isShowSequenceLogo());
685 cprof.addActionListener(new ActionListener()
688 public void actionPerformed(ActionEvent e)
690 av.setShowSequenceLogo(cprof.getState());
695 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
696 MessageManager.getString("label.normalise_logo"),
697 av.isNormaliseSequenceLogo());
698 cprofnorm.addActionListener(new ActionListener()
701 public void actionPerformed(ActionEvent e)
703 av.setShowSequenceLogo(true);
704 av.setNormaliseSequenceLogo(cprofnorm.getState());
710 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
711 consclipbrd.addActionListener(this);
712 pop.add(consclipbrd);
716 * Reorders annotation rows after a drag of a label
721 public void mouseReleased(MouseEvent evt)
723 if (evt.isPopupTrigger())
729 int start = selectedRow;
730 getSelectedRow(evt.getY() - getScrollOffset());
731 int end = selectedRow;
734 * if dragging to resize instead, start == end
738 // Swap these annotations
739 AlignmentAnnotation startAA = ap.av.getAlignment()
740 .getAlignmentAnnotation()[start];
743 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
745 AlignmentAnnotation endAA = ap.av.getAlignment()
746 .getAlignmentAnnotation()[end];
748 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
749 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
755 ap.getAnnotationPanel().repaint();
759 * Removes the height adjuster image on leaving the panel, unless currently
763 public void mouseExited(MouseEvent evt)
765 if (resizePanel && dragEvent == null)
773 * A mouse drag may be either an adjustment of the panel height (if flag
774 * resizePanel is set on), or a reordering of the annotation rows. The former
775 * is dealt with by this method, the latter in mouseReleased.
780 public void mouseDragged(MouseEvent evt)
786 Dimension d = ap.annotationScroller.getPreferredSize();
787 int dif = evt.getY() - oldY;
789 dif /= ap.av.getCharHeight();
790 dif *= ap.av.getCharHeight();
792 if ((d.height - dif) > 20)
794 ap.annotationScroller
795 .setPreferredSize(new Dimension(d.width, d.height - dif));
796 d = ap.annotationSpaceFillerHolder.getPreferredSize();
797 ap.annotationSpaceFillerHolder
798 .setPreferredSize(new Dimension(d.width, d.height - dif));
799 ap.paintAlignment(true, false);
811 * Updates the tooltip as the mouse moves over the labels
816 public void mouseMoved(MouseEvent evt)
818 showOrHideAdjuster(evt);
820 getSelectedRow(evt.getY() - getScrollOffset());
822 if (selectedRow > -1 && ap.av.getAlignment()
823 .getAlignmentAnnotation().length > selectedRow)
825 AlignmentAnnotation aa = ap.av.getAlignment()
826 .getAlignmentAnnotation()[selectedRow];
828 StringBuffer desc = new StringBuffer();
829 if (aa.description != null
830 && !aa.description.equals("New description"))
832 // TODO: we could refactor and merge this code with the code in
833 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
835 desc.append(aa.getDescription(true).trim());
836 // check to see if the description is an html fragment.
837 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
838 .indexOf("<html>") < 0))
840 // clean the description ready for embedding in html
841 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
842 .replaceAll("<"));
843 desc.insert(0, "<html>");
847 // remove terminating html if any
848 int i = desc.substring(desc.length() - 7).toLowerCase()
849 .lastIndexOf("</html>");
852 desc.setLength(desc.length() - 7 + i);
857 desc.append("<br/>");
859 // if (aa.hasProperties())
861 // desc.append("<table>");
862 // for (String prop : aa.getProperties())
864 // desc.append("<tr><td>" + prop + "</td><td>"
865 // + aa.getProperty(prop) + "</td><tr>");
867 // desc.append("</table>");
872 // begin the tooltip's html fragment
873 desc.append("<html>");
876 // TODO: limit precision of score to avoid noise from imprecise
878 // (64.7 becomes 64.7+/some tiny value).
879 desc.append(" Score: " + aa.score);
882 if (desc.length() > 6)
884 desc.append("</html>");
885 this.setToolTipText(desc.toString());
889 this.setToolTipText(null);
895 * Shows the height adjuster image if the mouse moves into the top left
896 * region, or hides it if the mouse leaves the regio
900 protected void showOrHideAdjuster(MouseEvent evt)
902 boolean was = resizePanel;
903 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
905 if (resizePanel != was)
907 setCursor(Cursor.getPredefinedCursor(
908 resizePanel ? Cursor.S_RESIZE_CURSOR
909 : Cursor.DEFAULT_CURSOR));
915 public void mouseClicked(MouseEvent evt)
917 final AlignmentAnnotation[] aa = ap.av.getAlignment()
918 .getAlignmentAnnotation();
919 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
921 if (selectedRow > -1 && selectedRow < aa.length)
923 if (aa[selectedRow].groupRef != null)
925 if (evt.getClickCount() >= 2)
927 // todo: make the ap scroll to the selection - not necessary, first
928 // click highlights/scrolls, second selects
929 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
931 SequenceGroup sg = ap.av.getSelectionGroup();
932 if (sg == null || sg == aa[selectedRow].groupRef
933 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
935 if (Platform.isControlDown(evt) || evt.isShiftDown())
937 // clone a new selection group from the associated group
938 ap.av.setSelectionGroup(
939 new SequenceGroup(aa[selectedRow].groupRef));
943 // set selection to the associated group so it can be edited
944 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
949 // modify current selection with associated group
950 int remainToAdd = aa[selectedRow].groupRef.getSize();
951 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
953 if (jalview.util.Platform.isControlDown(evt))
955 sg.addOrRemove(sgs, --remainToAdd == 0);
959 // notionally, we should also add intermediate sequences from
960 // last added sequence ?
961 sg.addSequence(sgs, --remainToAdd == 0);
966 ap.paintAlignment(false, false);
967 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
968 ap.av.sendSelection();
972 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
973 aa[selectedRow].groupRef.getSequences(null));
977 else if (aa[selectedRow].sequenceRef != null)
979 if (evt.getClickCount() == 1)
981 ap.getSeqPanel().ap.getIdPanel()
982 .highlightSearchResults(Arrays.asList(new SequenceI[]
983 { aa[selectedRow].sequenceRef }));
985 else if (evt.getClickCount() >= 2)
987 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
988 SequenceGroup sg = ap.av.getSelectionGroup();
991 // we make a copy rather than edit the current selection if no
993 // see Enhancement JAL-1557
994 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
996 sg = new SequenceGroup(sg);
998 sg.addSequence(aa[selectedRow].sequenceRef, false);
1002 if (Platform.isControlDown(evt))
1004 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1008 // notionally, we should also add intermediate sequences from
1009 // last added sequence ?
1010 sg.addSequence(aa[selectedRow].sequenceRef, true);
1016 sg = new SequenceGroup();
1018 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1019 sg.addSequence(aa[selectedRow].sequenceRef, false);
1021 ap.av.setSelectionGroup(sg);
1022 ap.paintAlignment(false, false);
1023 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1024 ap.av.sendSelection();
1033 * do a single sequence copy to jalview and the system clipboard
1036 * sequence to be copied to clipboard
1038 protected void copy_annotseqtoclipboard(SequenceI sq)
1040 SequenceI[] seqs = new SequenceI[] { sq };
1041 String[] omitHidden = null;
1042 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1043 if (dseqs[0] == null)
1045 dseqs[0] = new Sequence(sq);
1046 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
1047 sq.getSequenceAsString()));
1049 sq.setDatasetSequence(dseqs[0]);
1051 Alignment ds = new Alignment(dseqs);
1052 if (av.hasHiddenColumns())
1054 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
1055 .getVisContigsIterator(0, sq.getLength(), false);
1056 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
1059 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1060 if (av.hasHiddenColumns())
1062 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1063 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1066 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1067 seqs, omitHidden, alignmentStartEnd);
1069 Toolkit.getDefaultToolkit().getSystemClipboard()
1070 .setContents(new StringSelection(output), Desktop.instance);
1072 HiddenColumns hiddenColumns = null;
1074 if (av.hasHiddenColumns())
1076 hiddenColumns = new HiddenColumns(
1077 av.getAlignment().getHiddenColumns());
1080 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1082 // sequence ? need to
1084 // sequence as special.
1095 public void paintComponent(Graphics g)
1097 int width = getWidth();
1100 width = ap.calculateIdWidth().width + 4;
1103 Graphics2D g2 = (Graphics2D) g;
1106 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1107 RenderingHints.VALUE_ANTIALIAS_ON);
1110 drawComponent(g2, true, width);
1114 * Draw the full set of annotation Labels for the alignment at the given
1118 * Graphics2D instance (needed for font scaling)
1120 * Width for scaling labels
1123 public void drawComponent(Graphics g, int width)
1125 drawComponent(g, false, width);
1129 * Draw the full set of annotation Labels for the alignment at the given
1133 * Graphics2D instance (needed for font scaling)
1135 * - true indicates that only current visible area needs to be
1138 * Width for scaling labels
1140 public void drawComponent(Graphics g, boolean clip, int width)
1142 if (av.getFont().getSize() < 10)
1148 g.setFont(av.getFont());
1151 FontMetrics fm = g.getFontMetrics(g.getFont());
1152 g.setColor(Color.white);
1153 g.fillRect(0, 0, getWidth(), getHeight());
1155 g.translate(0, getScrollOffset());
1156 g.setColor(Color.black);
1158 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1159 int fontHeight = g.getFont().getSize();
1162 int graphExtras = 0;
1164 Font baseFont = g.getFont();
1165 FontMetrics baseMetrics = fm;
1166 int ofontH = fontHeight;
1169 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1170 ? ap.getAnnotationPanel().getVisibleVRange()
1172 if (clip && visr != null)
1175 visHeight = visr[1];
1177 boolean visible = true, before = false, after = false;
1180 hasHiddenRows = false;
1182 for (int i = 0; i < aa.length; i++)
1187 hasHiddenRows = true;
1200 System.out.println("before vis: " + i);
1204 // don't draw what isn't visible
1207 if (olY > visHeight)
1215 "Scroll offset: " + sOffset + " after vis: " + i);
1219 // don't draw what isn't visible
1223 g.setColor(Color.black);
1225 offset = -aa[i].height / 2;
1229 offset += fm.getHeight() / 2;
1230 offset -= fm.getDescent();
1234 offset += fm.getDescent();
1237 x = width - fm.stringWidth(aa[i].label) - 3;
1239 if (aa[i].graphGroup > -1)
1242 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1243 // computed efficiently for all visible labels
1244 for (int gg = 0; gg < aa.length; gg++)
1246 if (aa[gg].graphGroup == aa[i].graphGroup)
1251 if (groupSize * (fontHeight + 8) < aa[i].height)
1253 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1258 // scale font to fit
1259 float h = aa[i].height / (float) groupSize, s;
1266 fontHeight = -8 + (int) h;
1267 s = ((float) fontHeight) / (float) ofontH;
1269 .deriveFont(AffineTransform.getScaleInstance(s, s));
1271 fm = g.getFontMetrics();
1272 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1278 for (int gg = 0; gg < aa.length; gg++)
1280 if (aa[gg].graphGroup == aa[i].graphGroup)
1282 x = width - fm.stringWidth(aa[gg].label) - 3;
1283 g.drawString(aa[gg].label, x, y - graphExtras);
1285 if (aa[gg]._linecolour != null)
1288 g.setColor(aa[gg]._linecolour);
1289 g.drawLine(x, y - graphExtras + 3,
1290 x + fm.stringWidth(aa[gg].label),
1291 y - graphExtras + 3);
1294 g.setColor(Color.black);
1295 graphExtras += fontHeight + 8;
1299 g.setFont(baseFont);
1301 fontHeight = ofontH;
1305 g.drawString(aa[i].label, x, y + offset);
1310 if (!resizePanel && dragEvent != null && aa != null)
1312 g.setColor(Color.lightGray);
1313 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1314 dragEvent.getY() - getScrollOffset());
1317 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1319 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1320 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1325 public int getScrollOffset()
1327 return scrollOffset;
1331 public void mouseEntered(MouseEvent e)