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.List;
56 import java.util.regex.Pattern;
58 import javax.swing.JCheckBoxMenuItem;
59 import javax.swing.JMenuItem;
60 import javax.swing.JPanel;
61 import javax.swing.JPopupMenu;
62 import javax.swing.SwingUtilities;
63 import javax.swing.ToolTipManager;
71 public class AnnotationLabels extends JPanel implements MouseListener,
72 MouseMotionListener, ActionListener
74 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
78 String TOGGLE_LABELSCALE = MessageManager
79 .getString("label.scale_label_to_column");
81 String ADDNEW = MessageManager.getString("label.add_new_row");
83 String EDITNAME = MessageManager
84 .getString("label.edit_label_description");
86 String HIDE = MessageManager.getString("label.hide_row");
88 String DELETE = MessageManager.getString("label.delete_row");
90 String SHOWALL = MessageManager.getString("label.show_all_hidden_rows");
92 String OUTPUT_TEXT = MessageManager.getString("label.export_annotation");
94 String COPYCONS_SEQ = MessageManager
95 .getString("label.copy_consensus_sequence");
97 boolean resizePanel = false;
105 boolean resizing = false;
107 MouseEvent dragEvent;
113 private int scrollOffset = 0;
115 Font font = new Font("Arial", Font.PLAIN, 11);
117 private boolean hasHiddenRows;
120 * Creates a new AnnotationLabels object.
125 public AnnotationLabels(AlignmentPanel ap)
129 ToolTipManager.sharedInstance().registerComponent(this);
131 java.net.URL url = getClass().getResource("/images/idwidth.gif");
136 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
141 MediaTracker mt = new MediaTracker(this);
142 mt.addImage(temp, 0);
144 } catch (Exception ex)
148 BufferedImage bi = new BufferedImage(temp.getHeight(this),
149 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
150 Graphics2D g = (Graphics2D) bi.getGraphics();
151 g.rotate(Math.toRadians(90));
152 g.drawImage(temp, 0, -bi.getWidth(this), this);
155 addMouseListener(this);
156 addMouseMotionListener(this);
157 addMouseWheelListener(ap.getAnnotationPanel());
160 public AnnotationLabels(AlignViewport av)
171 public void setScrollOffset(int y)
178 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
182 * coordinate position to search for a row
184 void getSelectedRow(int y)
187 AlignmentAnnotation[] aa = ap.av.getAlignment()
188 .getAlignmentAnnotation();
192 for (int i = 0; i < aa.length; i++)
200 height += aa[i].height;
219 public void actionPerformed(ActionEvent evt)
221 AlignmentAnnotation[] aa = ap.av.getAlignment()
222 .getAlignmentAnnotation();
224 boolean fullRepaint = false;
225 if (evt.getActionCommand().equals(ADDNEW))
227 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
228 null, new Annotation[ap.av.getAlignment().getWidth()]);
230 if (!editLabelDescription(newAnnotation))
235 ap.av.getAlignment().addAnnotation(newAnnotation);
236 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
239 else if (evt.getActionCommand().equals(EDITNAME))
241 String name = aa[selectedRow].label;
242 editLabelDescription(aa[selectedRow]);
243 if (!name.equalsIgnoreCase(aa[selectedRow].label))
248 else if (evt.getActionCommand().equals(HIDE))
250 aa[selectedRow].visible = false;
252 else if (evt.getActionCommand().equals(DELETE))
254 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
255 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
258 else if (evt.getActionCommand().equals(SHOWALL))
260 for (int i = 0; i < aa.length; i++)
262 if (!aa[i].visible && aa[i].annotations != null)
264 aa[i].visible = true;
269 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
271 new AnnotationExporter().exportAnnotations(ap,
272 new AlignmentAnnotation[] { 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 && !(label.indexOf("Information") > -1))
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
445 final AlignmentAnnotation aaa = aa[selectedRow];
447 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
448 MessageManager.getString("label.ignore_gaps_consensus"),
449 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
450 .getIgnoreGapsConsensus() : ap.av
451 .isIgnoreGapsConsensus());
453 cbmi.addActionListener(new ActionListener()
456 public void actionPerformed(ActionEvent e)
458 if (aaa.groupRef != null)
460 // TODO: pass on reference to ap so the view can be updated.
461 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
462 ap.getAnnotationPanel().paint(
463 ap.getAnnotationPanel().getGraphics());
467 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
469 ap.alignmentChanged();
473 // av and sequencegroup need to implement same interface for
474 if (aaa.groupRef != null)
476 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
477 MessageManager.getString("label.show_group_histogram"),
478 aa[selectedRow].groupRef.isShowConsensusHistogram());
479 chist.addActionListener(new ActionListener()
482 public void actionPerformed(ActionEvent e)
484 // TODO: pass on reference
490 aaa.groupRef.setShowConsensusHistogram(chist.getState());
492 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
496 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
497 MessageManager.getString("label.show_group_logo"),
498 aa[selectedRow].groupRef.isShowSequenceLogo());
499 cprofl.addActionListener(new ActionListener()
502 public void actionPerformed(ActionEvent e)
504 // TODO: pass on reference
510 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
512 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
516 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
517 MessageManager.getString("label.normalise_group_logo"),
518 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
519 cproflnorm.addActionListener(new ActionListener()
522 public void actionPerformed(ActionEvent e)
525 // TODO: pass on reference
531 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
532 // automatically enable logo display if we're clicked
533 aaa.groupRef.setshowSequenceLogo(true);
535 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
542 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
543 MessageManager.getString("label.show_histogram"),
544 av.isShowConsensusHistogram());
545 chist.addActionListener(new ActionListener()
548 public void actionPerformed(ActionEvent e)
550 // TODO: pass on reference
556 av.setShowConsensusHistogram(chist.getState());
557 ap.alignFrame.setMenusForViewport();
559 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
563 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
564 MessageManager.getString("label.show_logo"),
565 av.isShowSequenceLogo());
566 cprof.addActionListener(new ActionListener()
569 public void actionPerformed(ActionEvent e)
571 // TODO: pass on reference
577 av.setShowSequenceLogo(cprof.getState());
578 ap.alignFrame.setMenusForViewport();
580 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
584 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
585 MessageManager.getString("label.normalise_logo"),
586 av.isNormaliseSequenceLogo());
587 cprofnorm.addActionListener(new ActionListener()
590 public void actionPerformed(ActionEvent e)
592 // TODO: pass on reference
598 av.setShowSequenceLogo(true);
599 av.setNormaliseSequenceLogo(cprofnorm.getState());
600 ap.alignFrame.setMenusForViewport();
602 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
607 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
608 consclipbrd.addActionListener(this);
609 pop.add(consclipbrd);
611 else if (label.indexOf("Information") > -1) // TODO create labels
612 // in message resource
616 final AlignmentAnnotation aaa = aa[selectedRow];
618 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
619 MessageManager.getString(
620 "label.ignore_below_background_frequency"),
621 (aa[selectedRow].groupRef != null)
622 ? aa[selectedRow].groupRef
623 .getIgnoreBelowBackground()
624 : ap.av.isIgnoreBelowBackground());
626 cbmi.addActionListener(new ActionListener()
629 public void actionPerformed(ActionEvent e)
631 if (aaa.groupRef != null)
633 // TODO: pass on reference to ap so the view can be updated.
634 aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
635 ap.getAnnotationPanel()
636 .paint(ap.getAnnotationPanel().getGraphics());
640 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
642 ap.alignmentChanged();
646 if (aaa.groupRef != null)
648 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
649 MessageManager.getString("label.show_group_histogram"),
650 aa[selectedRow].groupRef.isShowInformationHistogram());
651 chist.addActionListener(new ActionListener()
654 public void actionPerformed(ActionEvent e)
656 // TODO: pass on reference
662 aaa.groupRef.setShowInformationHistogram(chist.getState());
664 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
668 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
669 MessageManager.getString("label.show_group_logo"),
670 aa[selectedRow].groupRef.isShowHMMSequenceLogo());
671 cprofl.addActionListener(new ActionListener()
674 public void actionPerformed(ActionEvent e)
676 // TODO: pass on reference
682 aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
684 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
688 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
689 MessageManager.getString("label.normalise_group_logo"),
690 aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
691 cproflnorm.addActionListener(new ActionListener()
694 public void actionPerformed(ActionEvent e)
697 // TODO: pass on reference
704 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
705 // automatically enable logo display if we're clicked
706 aaa.groupRef.setshowHMMSequenceLogo(true);
708 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
715 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
716 MessageManager.getString("label.show_histogram"),
717 av.isShowInformationHistogram());
718 chist.addActionListener(new ActionListener()
721 public void actionPerformed(ActionEvent e)
723 // TODO: pass on reference
729 av.setShowInformationHistogram(chist.getState());
730 ap.alignFrame.setMenusForViewport();
732 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
736 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
737 MessageManager.getString("label.show_logo"),
738 av.isShowHMMSequenceLogo());
739 cprof.addActionListener(new ActionListener()
742 public void actionPerformed(ActionEvent e)
744 // TODO: pass on reference
750 av.setShowHMMSequenceLogo(cprof.getState());
751 ap.alignFrame.setMenusForViewport();
753 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
757 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
758 MessageManager.getString("label.normalise_logo"),
759 av.isNormaliseHMMSequenceLogo());
760 cprofnorm.addActionListener(new ActionListener()
763 public void actionPerformed(ActionEvent e)
765 // TODO: pass on reference
771 av.setShowHMMSequenceLogo(true);
772 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
773 ap.alignFrame.setMenusForViewport();
775 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
780 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
781 consclipbrd.addActionListener(this);
782 pop.add(consclipbrd);
785 pop.show(this, evt.getX(), evt.getY());
795 public void mouseReleased(MouseEvent evt)
797 if (evt.isPopupTrigger())
803 int start = selectedRow;
804 getSelectedRow(evt.getY() - getScrollOffset());
805 int end = selectedRow;
809 // Swap these annotations
810 AlignmentAnnotation startAA = ap.av.getAlignment()
811 .getAlignmentAnnotation()[start];
814 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
816 AlignmentAnnotation endAA = ap.av.getAlignment()
817 .getAlignmentAnnotation()[end];
819 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
820 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
826 ap.getAnnotationPanel().repaint();
836 public void mouseEntered(MouseEvent evt)
852 public void mouseExited(MouseEvent evt)
854 if (dragEvent == null)
868 public void mouseDragged(MouseEvent evt)
874 Dimension d = ap.annotationScroller.getPreferredSize();
875 int dif = evt.getY() - oldY;
877 dif /= ap.av.getCharHeight();
878 dif *= ap.av.getCharHeight();
880 if ((d.height - dif) > 20)
882 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
884 d = ap.annotationSpaceFillerHolder.getPreferredSize();
885 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
886 d.width, d.height - dif));
887 ap.paintAlignment(true);
905 public void mouseMoved(MouseEvent evt)
907 resizePanel = evt.getY() < 10;
909 getSelectedRow(evt.getY() - getScrollOffset());
912 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
914 AlignmentAnnotation aa = ap.av.getAlignment()
915 .getAlignmentAnnotation()[selectedRow];
917 StringBuffer desc = new StringBuffer();
918 if (aa.description != null
919 && !aa.description.equals("New description"))
921 // TODO: we could refactor and merge this code with the code in
922 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
924 desc.append(aa.getDescription(true).trim());
925 // check to see if the description is an html fragment.
926 if (desc.length() < 6
927 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
929 // clean the description ready for embedding in html
930 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
931 .replaceAll("<"));
932 desc.insert(0, "<html>");
936 // remove terminating html if any
937 int i = desc.substring(desc.length() - 7).toLowerCase()
938 .lastIndexOf("</html>");
941 desc.setLength(desc.length() - 7 + i);
946 desc.append("<br/>");
948 // if (aa.hasProperties())
950 // desc.append("<table>");
951 // for (String prop : aa.getProperties())
953 // desc.append("<tr><td>" + prop + "</td><td>"
954 // + aa.getProperty(prop) + "</td><tr>");
956 // desc.append("</table>");
961 // begin the tooltip's html fragment
962 desc.append("<html>");
965 // TODO: limit precision of score to avoid noise from imprecise
967 // (64.7 becomes 64.7+/some tiny value).
968 desc.append(" Score: " + aa.score);
971 if (desc.length() > 6)
973 desc.append("</html>");
974 this.setToolTipText(desc.toString());
978 this.setToolTipText(null);
984 public void mouseClicked(MouseEvent evt)
986 final AlignmentAnnotation[] aa = ap.av.getAlignment()
987 .getAlignmentAnnotation();
988 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
990 if (selectedRow > -1 && selectedRow < aa.length)
992 if (aa[selectedRow].groupRef != null)
994 if (evt.getClickCount() >= 2)
996 // todo: make the ap scroll to the selection - not necessary, first
997 // click highlights/scrolls, second selects
998 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1000 SequenceGroup sg = ap.av.getSelectionGroup();
1002 || sg == aa[selectedRow].groupRef
1003 || !(jalview.util.Platform.isControlDown(evt) || evt
1006 if (jalview.util.Platform.isControlDown(evt)
1007 || evt.isShiftDown())
1009 // clone a new selection group from the associated group
1010 ap.av.setSelectionGroup(new SequenceGroup(
1011 aa[selectedRow].groupRef));
1015 // set selection to the associated group so it can be edited
1016 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1021 // modify current selection with associated group
1022 int remainToAdd = aa[selectedRow].groupRef.getSize();
1023 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1025 if (jalview.util.Platform.isControlDown(evt))
1027 sg.addOrRemove(sgs, --remainToAdd == 0);
1031 // notionally, we should also add intermediate sequences from
1032 // last added sequence ?
1033 sg.addSequence(sgs, --remainToAdd == 0);
1038 ap.paintAlignment(false);
1039 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1040 ap.av.sendSelection();
1044 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1045 aa[selectedRow].groupRef.getSequences(null));
1049 else if (aa[selectedRow].sequenceRef != null)
1051 if (evt.getClickCount() == 1)
1055 .highlightSearchResults(
1056 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
1058 else if (evt.getClickCount() >= 2)
1060 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1061 SequenceGroup sg = ap.av.getSelectionGroup();
1064 // we make a copy rather than edit the current selection if no
1065 // modifiers pressed
1066 // see Enhancement JAL-1557
1067 if (!(jalview.util.Platform.isControlDown(evt) || evt
1070 sg = new SequenceGroup(sg);
1072 sg.addSequence(aa[selectedRow].sequenceRef, false);
1076 if (jalview.util.Platform.isControlDown(evt))
1078 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1082 // notionally, we should also add intermediate sequences from
1083 // last added sequence ?
1084 sg.addSequence(aa[selectedRow].sequenceRef, true);
1090 sg = new SequenceGroup();
1092 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1093 sg.addSequence(aa[selectedRow].sequenceRef, false);
1095 ap.av.setSelectionGroup(sg);
1096 ap.paintAlignment(false);
1097 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1098 ap.av.sendSelection();
1108 * do a single sequence copy to jalview and the system clipboard
1111 * sequence to be copied to clipboard
1113 protected void copy_annotseqtoclipboard(SequenceI sq)
1115 SequenceI[] seqs = new SequenceI[] { sq };
1116 String[] omitHidden = null;
1117 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1118 if (dseqs[0] == null)
1120 dseqs[0] = new Sequence(sq);
1121 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
1122 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
1124 sq.setDatasetSequence(dseqs[0]);
1126 Alignment ds = new Alignment(dseqs);
1127 if (av.hasHiddenColumns())
1129 omitHidden = av.getAlignment().getHiddenColumns()
1130 .getVisibleSequenceStrings(0,
1131 sq.getLength(), seqs);
1134 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1135 List<int[]> hiddenCols = av.getAlignment().getHiddenColumns()
1136 .getHiddenRegions();
1137 if (hiddenCols != null)
1139 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
1142 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1143 seqs, omitHidden, alignmentStartEnd);
1145 Toolkit.getDefaultToolkit().getSystemClipboard()
1146 .setContents(new StringSelection(output), Desktop.instance);
1148 ArrayList<int[]> hiddenColumns = null;
1149 if (av.hasHiddenColumns())
1151 hiddenColumns = new ArrayList<>();
1152 for (int[] region : av.getAlignment().getHiddenColumns()
1153 .getHiddenRegions())
1155 hiddenColumns.add(new int[] { region[0], region[1] });
1159 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1161 // sequence ? need to
1163 // sequence as special.
1174 public void paintComponent(Graphics g)
1177 int width = getWidth();
1180 width = ap.calculateIdWidth().width + 4;
1183 Graphics2D g2 = (Graphics2D) g;
1186 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1187 RenderingHints.VALUE_ANTIALIAS_ON);
1190 drawComponent(g2, true, width);
1195 * Draw the full set of annotation Labels for the alignment at the given
1199 * Graphics2D instance (needed for font scaling)
1201 * Width for scaling labels
1204 public void drawComponent(Graphics g, int width)
1206 drawComponent(g, false, width);
1209 private final boolean debugRedraw = false;
1212 * Draw the full set of annotation Labels for the alignment at the given
1216 * Graphics2D instance (needed for font scaling)
1218 * - true indicates that only current visible area needs to be
1221 * Width for scaling labels
1223 public void drawComponent(Graphics g, boolean clip, int width)
1225 if (av.getFont().getSize() < 10)
1231 g.setFont(av.getFont());
1234 FontMetrics fm = g.getFontMetrics(g.getFont());
1235 g.setColor(Color.white);
1236 g.fillRect(0, 0, getWidth(), getHeight());
1238 g.translate(0, getScrollOffset());
1239 g.setColor(Color.black);
1241 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1242 int fontHeight = g.getFont().getSize();
1245 int graphExtras = 0;
1247 Font baseFont = g.getFont();
1248 FontMetrics baseMetrics = fm;
1249 int ofontH = fontHeight;
1252 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1253 .getAnnotationPanel().getVisibleVRange() : null;
1254 if (clip && visr != null)
1257 visHeight = visr[1];
1259 boolean visible = true, before = false, after = false;
1262 hasHiddenRows = false;
1264 for (int i = 0; i < aa.length; i++)
1269 hasHiddenRows = true;
1282 System.out.println("before vis: " + i);
1286 // don't draw what isn't visible
1289 if (olY > visHeight)
1296 System.out.println("Scroll offset: " + sOffset
1297 + " after vis: " + i);
1301 // don't draw what isn't visible
1305 g.setColor(Color.black);
1307 offset = -aa[i].height / 2;
1311 offset += fm.getHeight() / 2;
1312 offset -= fm.getDescent();
1316 offset += fm.getDescent();
1319 x = width - fm.stringWidth(aa[i].label) - 3;
1321 if (aa[i].graphGroup > -1)
1324 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1325 // computed efficiently for all visible labels
1326 for (int gg = 0; gg < aa.length; gg++)
1328 if (aa[gg].graphGroup == aa[i].graphGroup)
1333 if (groupSize * (fontHeight + 8) < aa[i].height)
1335 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1339 // scale font to fit
1340 float h = aa[i].height / (float) groupSize, s;
1347 fontHeight = -8 + (int) h;
1348 s = ((float) fontHeight) / (float) ofontH;
1349 Font f = baseFont.deriveFont(AffineTransform
1350 .getScaleInstance(s, s));
1352 fm = g.getFontMetrics();
1353 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1358 for (int gg = 0; gg < aa.length; gg++)
1360 if (aa[gg].graphGroup == aa[i].graphGroup)
1362 x = width - fm.stringWidth(aa[gg].label) - 3;
1363 g.drawString(aa[gg].label, x, y - graphExtras);
1365 if (aa[gg]._linecolour != null)
1368 g.setColor(aa[gg]._linecolour);
1369 g.drawLine(x, y - graphExtras + 3,
1370 x + fm.stringWidth(aa[gg].label), y - graphExtras
1374 g.setColor(Color.black);
1375 graphExtras += fontHeight + 8;
1379 g.setFont(baseFont);
1381 fontHeight = ofontH;
1385 g.drawString(aa[i].label, x, y + offset);
1392 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1394 else if (dragEvent != null && aa != null)
1396 g.setColor(Color.lightGray);
1397 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1398 dragEvent.getY() - getScrollOffset());
1401 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1403 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1404 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1409 public int getScrollOffset()
1411 return scrollOffset;