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("_HMM") > -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());
558 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
562 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
563 MessageManager.getString("label.show_logo"),
564 av.isShowSequenceLogo());
565 cprof.addActionListener(new ActionListener()
568 public void actionPerformed(ActionEvent e)
570 // TODO: pass on reference
576 av.setShowSequenceLogo(cprof.getState());
578 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
582 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
583 MessageManager.getString("label.normalise_logo"),
584 av.isNormaliseSequenceLogo());
585 cprofnorm.addActionListener(new ActionListener()
588 public void actionPerformed(ActionEvent e)
590 // TODO: pass on reference
596 av.setShowSequenceLogo(true);
597 av.setNormaliseSequenceLogo(cprofnorm.getState());
599 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
604 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
605 consclipbrd.addActionListener(this);
606 pop.add(consclipbrd);
608 else if (label.indexOf("_HMM") > -1) // TODO create labels
609 // in message resource
613 final AlignmentAnnotation aaa = aa[selectedRow];
615 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
616 MessageManager.getString(
617 "label.ignore_below_background_frequency"),
618 (aa[selectedRow].groupRef != null)
619 ? aa[selectedRow].groupRef
620 .getIgnoreBelowBackground()
621 : ap.av.isIgnoreBelowBackground());
623 cbmi.addActionListener(new ActionListener()
626 public void actionPerformed(ActionEvent e)
628 if (aaa.groupRef != null)
630 // TODO: pass on reference to ap so the view can be updated.
631 aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
632 ap.getAnnotationPanel()
633 .paint(ap.getAnnotationPanel().getGraphics());
637 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
639 ap.alignmentChanged();
643 if (aaa.groupRef != null)
645 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
646 MessageManager.getString("label.show_group_histogram"),
647 aa[selectedRow].groupRef.isShowInformationHistogram());
648 chist.addActionListener(new ActionListener()
651 public void actionPerformed(ActionEvent e)
653 // TODO: pass on reference
659 aaa.groupRef.setShowInformationHistogram(chist.getState());
661 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
665 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
666 MessageManager.getString("label.show_group_logo"),
667 aa[selectedRow].groupRef.isShowHMMSequenceLogo());
668 cprofl.addActionListener(new ActionListener()
671 public void actionPerformed(ActionEvent e)
673 // TODO: pass on reference
679 aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
681 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
685 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
686 MessageManager.getString("label.normalise_group_logo"),
687 aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
688 cproflnorm.addActionListener(new ActionListener()
691 public void actionPerformed(ActionEvent e)
694 // TODO: pass on reference
701 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
702 // automatically enable logo display if we're clicked
703 aaa.groupRef.setshowHMMSequenceLogo(true);
705 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
712 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
713 MessageManager.getString("label.show_histogram"),
714 av.isShowInformationHistogram());
715 chist.addActionListener(new ActionListener()
718 public void actionPerformed(ActionEvent e)
720 // TODO: pass on reference
726 av.setShowInformationHistogram(chist.getState());
728 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
732 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
733 MessageManager.getString("label.show_logo"),
734 av.isShowHMMSequenceLogo());
735 cprof.addActionListener(new ActionListener()
738 public void actionPerformed(ActionEvent e)
740 // TODO: pass on reference
746 av.updateInformation(ap);
747 av.setShowHMMSequenceLogo(cprof.getState());
749 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
753 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
754 MessageManager.getString("label.normalise_logo"),
755 av.isNormaliseHMMSequenceLogo());
756 cprofnorm.addActionListener(new ActionListener()
759 public void actionPerformed(ActionEvent e)
761 // TODO: pass on reference
767 av.setShowHMMSequenceLogo(true);
768 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
770 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
777 pop.show(this, evt.getX(), evt.getY());
787 public void mouseReleased(MouseEvent evt)
789 if (evt.isPopupTrigger())
795 int start = selectedRow;
796 getSelectedRow(evt.getY() - getScrollOffset());
797 int end = selectedRow;
801 // Swap these annotations
802 AlignmentAnnotation startAA = ap.av.getAlignment()
803 .getAlignmentAnnotation()[start];
806 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
808 AlignmentAnnotation endAA = ap.av.getAlignment()
809 .getAlignmentAnnotation()[end];
811 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
812 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
818 ap.getAnnotationPanel().repaint();
828 public void mouseEntered(MouseEvent evt)
844 public void mouseExited(MouseEvent evt)
846 if (dragEvent == null)
860 public void mouseDragged(MouseEvent evt)
866 Dimension d = ap.annotationScroller.getPreferredSize();
867 int dif = evt.getY() - oldY;
869 dif /= ap.av.getCharHeight();
870 dif *= ap.av.getCharHeight();
872 if ((d.height - dif) > 20)
874 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
876 d = ap.annotationSpaceFillerHolder.getPreferredSize();
877 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
878 d.width, d.height - dif));
879 ap.paintAlignment(true);
897 public void mouseMoved(MouseEvent evt)
899 resizePanel = evt.getY() < 10;
901 getSelectedRow(evt.getY() - getScrollOffset());
904 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
906 AlignmentAnnotation aa = ap.av.getAlignment()
907 .getAlignmentAnnotation()[selectedRow];
909 StringBuffer desc = new StringBuffer();
910 if (aa.description != null
911 && !aa.description.equals("New description"))
913 // TODO: we could refactor and merge this code with the code in
914 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
916 desc.append(aa.getDescription(true).trim());
917 // check to see if the description is an html fragment.
918 if (desc.length() < 6
919 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
921 // clean the description ready for embedding in html
922 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
923 .replaceAll("<"));
924 desc.insert(0, "<html>");
928 // remove terminating html if any
929 int i = desc.substring(desc.length() - 7).toLowerCase()
930 .lastIndexOf("</html>");
933 desc.setLength(desc.length() - 7 + i);
938 desc.append("<br/>");
940 // if (aa.hasProperties())
942 // desc.append("<table>");
943 // for (String prop : aa.getProperties())
945 // desc.append("<tr><td>" + prop + "</td><td>"
946 // + aa.getProperty(prop) + "</td><tr>");
948 // desc.append("</table>");
953 // begin the tooltip's html fragment
954 desc.append("<html>");
957 // TODO: limit precision of score to avoid noise from imprecise
959 // (64.7 becomes 64.7+/some tiny value).
960 desc.append(" Score: " + aa.score);
963 if (desc.length() > 6)
965 desc.append("</html>");
966 this.setToolTipText(desc.toString());
970 this.setToolTipText(null);
976 public void mouseClicked(MouseEvent evt)
978 final AlignmentAnnotation[] aa = ap.av.getAlignment()
979 .getAlignmentAnnotation();
980 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
982 if (selectedRow > -1 && selectedRow < aa.length)
984 if (aa[selectedRow].groupRef != null)
986 if (evt.getClickCount() >= 2)
988 // todo: make the ap scroll to the selection - not necessary, first
989 // click highlights/scrolls, second selects
990 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
992 SequenceGroup sg = ap.av.getSelectionGroup();
994 || sg == aa[selectedRow].groupRef
995 || !(jalview.util.Platform.isControlDown(evt) || evt
998 if (jalview.util.Platform.isControlDown(evt)
999 || evt.isShiftDown())
1001 // clone a new selection group from the associated group
1002 ap.av.setSelectionGroup(new SequenceGroup(
1003 aa[selectedRow].groupRef));
1007 // set selection to the associated group so it can be edited
1008 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1013 // modify current selection with associated group
1014 int remainToAdd = aa[selectedRow].groupRef.getSize();
1015 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1017 if (jalview.util.Platform.isControlDown(evt))
1019 sg.addOrRemove(sgs, --remainToAdd == 0);
1023 // notionally, we should also add intermediate sequences from
1024 // last added sequence ?
1025 sg.addSequence(sgs, --remainToAdd == 0);
1030 ap.paintAlignment(false);
1031 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1032 ap.av.sendSelection();
1036 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1037 aa[selectedRow].groupRef.getSequences(null));
1041 else if (aa[selectedRow].sequenceRef != null)
1043 if (evt.getClickCount() == 1)
1047 .highlightSearchResults(
1048 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
1050 else if (evt.getClickCount() >= 2)
1052 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1053 SequenceGroup sg = ap.av.getSelectionGroup();
1056 // we make a copy rather than edit the current selection if no
1057 // modifiers pressed
1058 // see Enhancement JAL-1557
1059 if (!(jalview.util.Platform.isControlDown(evt) || evt
1062 sg = new SequenceGroup(sg);
1064 sg.addSequence(aa[selectedRow].sequenceRef, false);
1068 if (jalview.util.Platform.isControlDown(evt))
1070 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1074 // notionally, we should also add intermediate sequences from
1075 // last added sequence ?
1076 sg.addSequence(aa[selectedRow].sequenceRef, true);
1082 sg = new SequenceGroup();
1084 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1085 sg.addSequence(aa[selectedRow].sequenceRef, false);
1087 ap.av.setSelectionGroup(sg);
1088 ap.paintAlignment(false);
1089 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1090 ap.av.sendSelection();
1100 * do a single sequence copy to jalview and the system clipboard
1103 * sequence to be copied to clipboard
1105 protected void copy_annotseqtoclipboard(SequenceI sq)
1107 SequenceI[] seqs = new SequenceI[] { sq };
1108 String[] omitHidden = null;
1109 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1110 if (dseqs[0] == null)
1112 dseqs[0] = new Sequence(sq);
1113 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
1114 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
1116 sq.setDatasetSequence(dseqs[0]);
1118 Alignment ds = new Alignment(dseqs);
1119 if (av.hasHiddenColumns())
1121 omitHidden = av.getAlignment().getHiddenColumns()
1122 .getVisibleSequenceStrings(0,
1123 sq.getLength(), seqs);
1126 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1127 List<int[]> hiddenCols = av.getAlignment().getHiddenColumns()
1128 .getHiddenRegions();
1129 if (hiddenCols != null)
1131 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
1134 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1135 seqs, omitHidden, alignmentStartEnd);
1137 Toolkit.getDefaultToolkit().getSystemClipboard()
1138 .setContents(new StringSelection(output), Desktop.instance);
1140 ArrayList<int[]> hiddenColumns = null;
1141 if (av.hasHiddenColumns())
1143 hiddenColumns = new ArrayList<>();
1144 for (int[] region : av.getAlignment().getHiddenColumns()
1145 .getHiddenRegions())
1147 hiddenColumns.add(new int[] { region[0], region[1] });
1151 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1153 // sequence ? need to
1155 // sequence as special.
1166 public void paintComponent(Graphics g)
1169 int width = getWidth();
1172 width = ap.calculateIdWidth().width + 4;
1175 Graphics2D g2 = (Graphics2D) g;
1178 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1179 RenderingHints.VALUE_ANTIALIAS_ON);
1182 drawComponent(g2, true, width);
1187 * Draw the full set of annotation Labels for the alignment at the given
1191 * Graphics2D instance (needed for font scaling)
1193 * Width for scaling labels
1196 public void drawComponent(Graphics g, int width)
1198 drawComponent(g, false, width);
1201 private final boolean debugRedraw = false;
1204 * Draw the full set of annotation Labels for the alignment at the given
1208 * Graphics2D instance (needed for font scaling)
1210 * - true indicates that only current visible area needs to be
1213 * Width for scaling labels
1215 public void drawComponent(Graphics g, boolean clip, int width)
1217 if (av.getFont().getSize() < 10)
1223 g.setFont(av.getFont());
1226 FontMetrics fm = g.getFontMetrics(g.getFont());
1227 g.setColor(Color.white);
1228 g.fillRect(0, 0, getWidth(), getHeight());
1230 g.translate(0, getScrollOffset());
1231 g.setColor(Color.black);
1233 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1234 int fontHeight = g.getFont().getSize();
1237 int graphExtras = 0;
1239 Font baseFont = g.getFont();
1240 FontMetrics baseMetrics = fm;
1241 int ofontH = fontHeight;
1244 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1245 .getAnnotationPanel().getVisibleVRange() : null;
1246 if (clip && visr != null)
1249 visHeight = visr[1];
1251 boolean visible = true, before = false, after = false;
1254 hasHiddenRows = false;
1256 for (int i = 0; i < aa.length; i++)
1261 hasHiddenRows = true;
1274 System.out.println("before vis: " + i);
1278 // don't draw what isn't visible
1281 if (olY > visHeight)
1288 System.out.println("Scroll offset: " + sOffset
1289 + " after vis: " + i);
1293 // don't draw what isn't visible
1297 g.setColor(Color.black);
1299 offset = -aa[i].height / 2;
1303 offset += fm.getHeight() / 2;
1304 offset -= fm.getDescent();
1308 offset += fm.getDescent();
1311 x = width - fm.stringWidth(aa[i].label) - 3;
1313 if (aa[i].graphGroup > -1)
1316 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1317 // computed efficiently for all visible labels
1318 for (int gg = 0; gg < aa.length; gg++)
1320 if (aa[gg].graphGroup == aa[i].graphGroup)
1325 if (groupSize * (fontHeight + 8) < aa[i].height)
1327 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1331 // scale font to fit
1332 float h = aa[i].height / (float) groupSize, s;
1339 fontHeight = -8 + (int) h;
1340 s = ((float) fontHeight) / (float) ofontH;
1341 Font f = baseFont.deriveFont(AffineTransform
1342 .getScaleInstance(s, s));
1344 fm = g.getFontMetrics();
1345 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1350 for (int gg = 0; gg < aa.length; gg++)
1352 if (aa[gg].graphGroup == aa[i].graphGroup)
1354 x = width - fm.stringWidth(aa[gg].label) - 3;
1355 g.drawString(aa[gg].label, x, y - graphExtras);
1357 if (aa[gg]._linecolour != null)
1360 g.setColor(aa[gg]._linecolour);
1361 g.drawLine(x, y - graphExtras + 3,
1362 x + fm.stringWidth(aa[gg].label), y - graphExtras
1366 g.setColor(Color.black);
1367 graphExtras += fontHeight + 8;
1371 g.setFont(baseFont);
1373 fontHeight = ofontH;
1377 g.drawString(aa[i].label, x, y + offset);
1384 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1386 else if (dragEvent != null && aa != null)
1388 g.setColor(Color.lightGray);
1389 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1390 dragEvent.getY() - getScrollOffset());
1393 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1395 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1396 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1401 public int getScrollOffset()
1403 return scrollOffset;