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 Content") > -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 Content") > -1) // TODO create labels
612 // in message resource
616 final AlignmentAnnotation aaa = aa[selectedRow];
618 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
619 "Ignore Below Background Frequency",
620 (aa[selectedRow].groupRef != null)
621 ? aa[selectedRow].groupRef
622 .getIgnoreBelowBackground()
623 : ap.av.isIgnoreBelowBackground());
625 cbmi.addActionListener(new ActionListener()
628 public void actionPerformed(ActionEvent e)
630 if (aaa.groupRef != null)
632 // TODO: pass on reference to ap so the view can be updated.
633 aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
634 ap.getAnnotationPanel()
635 .paint(ap.getAnnotationPanel().getGraphics());
639 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
641 ap.alignmentChanged();
645 if (aaa.groupRef != null)
647 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
648 MessageManager.getString("label.show_group_histogram"),
649 aa[selectedRow].groupRef.isShowInformationHistogram());
650 chist.addActionListener(new ActionListener()
653 public void actionPerformed(ActionEvent e)
655 // TODO: pass on reference
661 aaa.groupRef.setShowInformationHistogram(chist.getState());
663 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
667 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
668 MessageManager.getString("label.show_group_logo"),
669 aa[selectedRow].groupRef.isShowHMMSequenceLogo());
670 cprofl.addActionListener(new ActionListener()
673 public void actionPerformed(ActionEvent e)
675 // TODO: pass on reference
681 aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
683 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
687 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
688 MessageManager.getString("label.normalise_group_logo"),
689 aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
690 cproflnorm.addActionListener(new ActionListener()
693 public void actionPerformed(ActionEvent e)
696 // TODO: pass on reference
703 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
704 // automatically enable logo display if we're clicked
705 aaa.groupRef.setshowHMMSequenceLogo(true);
707 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
714 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
715 MessageManager.getString("label.show_histogram"),
716 av.isShowInformationHistogram());
717 chist.addActionListener(new ActionListener()
720 public void actionPerformed(ActionEvent e)
722 // TODO: pass on reference
728 av.setShowInformationHistogram(chist.getState());
729 ap.alignFrame.setMenusForViewport();
731 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
735 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
736 MessageManager.getString("label.show_logo"),
737 av.isShowHMMSequenceLogo());
738 cprof.addActionListener(new ActionListener()
741 public void actionPerformed(ActionEvent e)
743 // TODO: pass on reference
749 av.setShowHMMSequenceLogo(cprof.getState());
750 ap.alignFrame.setMenusForViewport();
752 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
756 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
757 MessageManager.getString("label.normalise_logo"),
758 av.isNormaliseHMMSequenceLogo());
759 cprofnorm.addActionListener(new ActionListener()
762 public void actionPerformed(ActionEvent e)
764 // TODO: pass on reference
770 av.setShowHMMSequenceLogo(true);
771 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
772 ap.alignFrame.setMenusForViewport();
774 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
779 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
780 consclipbrd.addActionListener(this);
781 pop.add(consclipbrd);
784 pop.show(this, evt.getX(), evt.getY());
794 public void mouseReleased(MouseEvent evt)
796 if (evt.isPopupTrigger())
802 int start = selectedRow;
803 getSelectedRow(evt.getY() - getScrollOffset());
804 int end = selectedRow;
808 // Swap these annotations
809 AlignmentAnnotation startAA = ap.av.getAlignment()
810 .getAlignmentAnnotation()[start];
813 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
815 AlignmentAnnotation endAA = ap.av.getAlignment()
816 .getAlignmentAnnotation()[end];
818 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
819 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
825 ap.getAnnotationPanel().repaint();
835 public void mouseEntered(MouseEvent evt)
851 public void mouseExited(MouseEvent evt)
853 if (dragEvent == null)
867 public void mouseDragged(MouseEvent evt)
873 Dimension d = ap.annotationScroller.getPreferredSize();
874 int dif = evt.getY() - oldY;
876 dif /= ap.av.getCharHeight();
877 dif *= ap.av.getCharHeight();
879 if ((d.height - dif) > 20)
881 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
883 d = ap.annotationSpaceFillerHolder.getPreferredSize();
884 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
885 d.width, d.height - dif));
886 ap.paintAlignment(true);
904 public void mouseMoved(MouseEvent evt)
906 resizePanel = evt.getY() < 10;
908 getSelectedRow(evt.getY() - getScrollOffset());
911 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
913 AlignmentAnnotation aa = ap.av.getAlignment()
914 .getAlignmentAnnotation()[selectedRow];
916 StringBuffer desc = new StringBuffer();
917 if (aa.description != null
918 && !aa.description.equals("New description"))
920 // TODO: we could refactor and merge this code with the code in
921 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
923 desc.append(aa.getDescription(true).trim());
924 // check to see if the description is an html fragment.
925 if (desc.length() < 6
926 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
928 // clean the description ready for embedding in html
929 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
930 .replaceAll("<"));
931 desc.insert(0, "<html>");
935 // remove terminating html if any
936 int i = desc.substring(desc.length() - 7).toLowerCase()
937 .lastIndexOf("</html>");
940 desc.setLength(desc.length() - 7 + i);
945 desc.append("<br/>");
947 // if (aa.hasProperties())
949 // desc.append("<table>");
950 // for (String prop : aa.getProperties())
952 // desc.append("<tr><td>" + prop + "</td><td>"
953 // + aa.getProperty(prop) + "</td><tr>");
955 // desc.append("</table>");
960 // begin the tooltip's html fragment
961 desc.append("<html>");
964 // TODO: limit precision of score to avoid noise from imprecise
966 // (64.7 becomes 64.7+/some tiny value).
967 desc.append(" Score: " + aa.score);
970 if (desc.length() > 6)
972 desc.append("</html>");
973 this.setToolTipText(desc.toString());
977 this.setToolTipText(null);
983 public void mouseClicked(MouseEvent evt)
985 final AlignmentAnnotation[] aa = ap.av.getAlignment()
986 .getAlignmentAnnotation();
987 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
989 if (selectedRow > -1 && selectedRow < aa.length)
991 if (aa[selectedRow].groupRef != null)
993 if (evt.getClickCount() >= 2)
995 // todo: make the ap scroll to the selection - not necessary, first
996 // click highlights/scrolls, second selects
997 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
999 SequenceGroup sg = ap.av.getSelectionGroup();
1001 || sg == aa[selectedRow].groupRef
1002 || !(jalview.util.Platform.isControlDown(evt) || evt
1005 if (jalview.util.Platform.isControlDown(evt)
1006 || evt.isShiftDown())
1008 // clone a new selection group from the associated group
1009 ap.av.setSelectionGroup(new SequenceGroup(
1010 aa[selectedRow].groupRef));
1014 // set selection to the associated group so it can be edited
1015 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1020 // modify current selection with associated group
1021 int remainToAdd = aa[selectedRow].groupRef.getSize();
1022 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1024 if (jalview.util.Platform.isControlDown(evt))
1026 sg.addOrRemove(sgs, --remainToAdd == 0);
1030 // notionally, we should also add intermediate sequences from
1031 // last added sequence ?
1032 sg.addSequence(sgs, --remainToAdd == 0);
1037 ap.paintAlignment(false);
1038 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1039 ap.av.sendSelection();
1043 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1044 aa[selectedRow].groupRef.getSequences(null));
1048 else if (aa[selectedRow].sequenceRef != null)
1050 if (evt.getClickCount() == 1)
1054 .highlightSearchResults(
1055 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
1057 else if (evt.getClickCount() >= 2)
1059 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1060 SequenceGroup sg = ap.av.getSelectionGroup();
1063 // we make a copy rather than edit the current selection if no
1064 // modifiers pressed
1065 // see Enhancement JAL-1557
1066 if (!(jalview.util.Platform.isControlDown(evt) || evt
1069 sg = new SequenceGroup(sg);
1071 sg.addSequence(aa[selectedRow].sequenceRef, false);
1075 if (jalview.util.Platform.isControlDown(evt))
1077 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1081 // notionally, we should also add intermediate sequences from
1082 // last added sequence ?
1083 sg.addSequence(aa[selectedRow].sequenceRef, true);
1089 sg = new SequenceGroup();
1091 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1092 sg.addSequence(aa[selectedRow].sequenceRef, false);
1094 ap.av.setSelectionGroup(sg);
1095 ap.paintAlignment(false);
1096 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1097 ap.av.sendSelection();
1107 * do a single sequence copy to jalview and the system clipboard
1110 * sequence to be copied to clipboard
1112 protected void copy_annotseqtoclipboard(SequenceI sq)
1114 SequenceI[] seqs = new SequenceI[] { sq };
1115 String[] omitHidden = null;
1116 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1117 if (dseqs[0] == null)
1119 dseqs[0] = new Sequence(sq);
1120 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
1121 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
1123 sq.setDatasetSequence(dseqs[0]);
1125 Alignment ds = new Alignment(dseqs);
1126 if (av.hasHiddenColumns())
1128 omitHidden = av.getAlignment().getHiddenColumns()
1129 .getVisibleSequenceStrings(0,
1130 sq.getLength(), seqs);
1133 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1134 List<int[]> hiddenCols = av.getAlignment().getHiddenColumns()
1135 .getHiddenRegions();
1136 if (hiddenCols != null)
1138 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
1141 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1142 seqs, omitHidden, alignmentStartEnd);
1144 Toolkit.getDefaultToolkit().getSystemClipboard()
1145 .setContents(new StringSelection(output), Desktop.instance);
1147 ArrayList<int[]> hiddenColumns = null;
1148 if (av.hasHiddenColumns())
1150 hiddenColumns = new ArrayList<>();
1151 for (int[] region : av.getAlignment().getHiddenColumns()
1152 .getHiddenRegions())
1154 hiddenColumns.add(new int[] { region[0], region[1] });
1158 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1160 // sequence ? need to
1162 // sequence as special.
1173 public void paintComponent(Graphics g)
1176 int width = getWidth();
1179 width = ap.calculateIdWidth().width + 4;
1182 Graphics2D g2 = (Graphics2D) g;
1185 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1186 RenderingHints.VALUE_ANTIALIAS_ON);
1189 drawComponent(g2, true, width);
1194 * Draw the full set of annotation Labels for the alignment at the given
1198 * Graphics2D instance (needed for font scaling)
1200 * Width for scaling labels
1203 public void drawComponent(Graphics g, int width)
1205 drawComponent(g, false, width);
1208 private final boolean debugRedraw = false;
1211 * Draw the full set of annotation Labels for the alignment at the given
1215 * Graphics2D instance (needed for font scaling)
1217 * - true indicates that only current visible area needs to be
1220 * Width for scaling labels
1222 public void drawComponent(Graphics g, boolean clip, int width)
1224 if (av.getFont().getSize() < 10)
1230 g.setFont(av.getFont());
1233 FontMetrics fm = g.getFontMetrics(g.getFont());
1234 g.setColor(Color.white);
1235 g.fillRect(0, 0, getWidth(), getHeight());
1237 g.translate(0, getScrollOffset());
1238 g.setColor(Color.black);
1240 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1241 int fontHeight = g.getFont().getSize();
1244 int graphExtras = 0;
1246 Font baseFont = g.getFont();
1247 FontMetrics baseMetrics = fm;
1248 int ofontH = fontHeight;
1251 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1252 .getAnnotationPanel().getVisibleVRange() : null;
1253 if (clip && visr != null)
1256 visHeight = visr[1];
1258 boolean visible = true, before = false, after = false;
1261 hasHiddenRows = false;
1263 for (int i = 0; i < aa.length; i++)
1268 hasHiddenRows = true;
1281 System.out.println("before vis: " + i);
1285 // don't draw what isn't visible
1288 if (olY > visHeight)
1295 System.out.println("Scroll offset: " + sOffset
1296 + " after vis: " + i);
1300 // don't draw what isn't visible
1304 g.setColor(Color.black);
1306 offset = -aa[i].height / 2;
1310 offset += fm.getHeight() / 2;
1311 offset -= fm.getDescent();
1315 offset += fm.getDescent();
1318 x = width - fm.stringWidth(aa[i].label) - 3;
1320 if (aa[i].graphGroup > -1)
1323 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1324 // computed efficiently for all visible labels
1325 for (int gg = 0; gg < aa.length; gg++)
1327 if (aa[gg].graphGroup == aa[i].graphGroup)
1332 if (groupSize * (fontHeight + 8) < aa[i].height)
1334 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1338 // scale font to fit
1339 float h = aa[i].height / (float) groupSize, s;
1346 fontHeight = -8 + (int) h;
1347 s = ((float) fontHeight) / (float) ofontH;
1348 Font f = baseFont.deriveFont(AffineTransform
1349 .getScaleInstance(s, s));
1351 fm = g.getFontMetrics();
1352 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1357 for (int gg = 0; gg < aa.length; gg++)
1359 if (aa[gg].graphGroup == aa[i].graphGroup)
1361 x = width - fm.stringWidth(aa[gg].label) - 3;
1362 g.drawString(aa[gg].label, x, y - graphExtras);
1364 if (aa[gg]._linecolour != null)
1367 g.setColor(aa[gg]._linecolour);
1368 g.drawLine(x, y - graphExtras + 3,
1369 x + fm.stringWidth(aa[gg].label), y - graphExtras
1373 g.setColor(Color.black);
1374 graphExtras += fontHeight + 8;
1378 g.setFont(baseFont);
1380 fontHeight = ofontH;
1384 g.drawString(aa[i].label, x, y + offset);
1391 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1393 else if (dragEvent != null && aa != null)
1395 g.setColor(Color.lightGray);
1396 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1397 dragEvent.getY() - getScrollOffset());
1400 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1402 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1403 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1408 public int getScrollOffset()
1410 return scrollOffset;