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 java.awt.Color;
24 import java.awt.Cursor;
25 import java.awt.Dimension;
27 import java.awt.FontMetrics;
28 import java.awt.Graphics;
29 import java.awt.Graphics2D;
30 import java.awt.RenderingHints;
31 import java.awt.Toolkit;
32 import java.awt.datatransfer.StringSelection;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.MouseEvent;
36 import java.awt.event.MouseListener;
37 import java.awt.event.MouseMotionListener;
38 import java.awt.geom.AffineTransform;
39 import java.io.IOException;
40 import java.util.Arrays;
41 import java.util.Collections;
42 import java.util.Iterator;
43 import java.util.Locale;
45 import javax.swing.JCheckBoxMenuItem;
46 import javax.swing.JMenuItem;
47 import javax.swing.JPanel;
48 import javax.swing.JPopupMenu;
49 import javax.swing.SwingUtilities;
50 import javax.swing.ToolTipManager;
52 import jalview.analysis.AlignSeq;
53 import jalview.analysis.AlignmentUtils;
54 import jalview.bin.Console;
55 import jalview.datamodel.Alignment;
56 import jalview.datamodel.AlignmentAnnotation;
57 import jalview.datamodel.Annotation;
58 import jalview.datamodel.ContactMatrixI;
59 import jalview.datamodel.HiddenColumns;
60 import jalview.datamodel.Sequence;
61 import jalview.datamodel.SequenceGroup;
62 import jalview.datamodel.SequenceI;
63 import jalview.io.DataSourceType;
64 import jalview.io.FileFormat;
65 import jalview.io.FormatAdapter;
66 import jalview.io.NewickFile;
67 import jalview.util.Comparison;
68 import jalview.util.MessageManager;
69 import jalview.util.Platform;
70 import jalview.ws.datamodel.alphafold.PAEContactMatrix;
73 * The panel that holds the labels for alignment annotations, providing
74 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
77 public class AnnotationLabels extends JPanel
78 implements MouseListener, MouseMotionListener, ActionListener
80 private static final String HTML_END_TAG = "</html>";
82 private static final String HTML_START_TAG = "<html>";
85 * width in pixels within which height adjuster arrows are shown and active
87 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
90 * height in pixels for allowing height adjuster to be active
92 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
94 private static final Font font = new Font("Arial", Font.PLAIN, 11);
96 private static final String TOGGLE_LABELSCALE = MessageManager
97 .getString("label.scale_label_to_column");
99 private static final String ADDNEW = MessageManager
100 .getString("label.add_new_row");
102 private static final String EDITNAME = MessageManager
103 .getString("label.edit_label_description");
105 private static final String HIDE = MessageManager
106 .getString("label.hide_row");
108 private static final String DELETE = MessageManager
109 .getString("label.delete_row");
111 private static final String SHOWALL = MessageManager
112 .getString("label.show_all_hidden_rows");
114 private static final String OUTPUT_TEXT = MessageManager
115 .getString("label.export_annotation");
117 private static final String COPYCONS_SEQ = MessageManager
118 .getString("label.copy_consensus_sequence");
120 private final boolean debugRedraw = false;
122 private AlignmentPanel ap;
126 private MouseEvent dragEvent;
130 private int selectedRow;
132 private int scrollOffset = 0;
134 private boolean hasHiddenRows;
136 private boolean resizePanel = false;
139 * Creates a new AnnotationLabels object
143 public AnnotationLabels(AlignmentPanel ap)
148 ToolTipManager.sharedInstance().registerComponent(this);
150 addMouseListener(this);
151 addMouseMotionListener(this);
152 addMouseWheelListener(ap.getAnnotationPanel());
155 public AnnotationLabels(AlignViewport av)
166 public void setScrollOffset(int y)
173 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
177 * coordinate position to search for a row
179 void getSelectedRow(int y)
182 AlignmentAnnotation[] aa = ap.av.getAlignment()
183 .getAlignmentAnnotation();
187 for (int i = 0; i < aa.length; i++)
195 height += aa[i].height;
214 public void actionPerformed(ActionEvent evt)
216 AlignmentAnnotation[] aa = ap.av.getAlignment()
217 .getAlignmentAnnotation();
219 String action = evt.getActionCommand();
220 if (ADDNEW.equals(action))
223 * non-returning dialog
225 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
226 null, new Annotation[ap.av.getAlignment().getWidth()]);
227 editLabelDescription(newAnnotation, true);
229 else if (EDITNAME.equals(action))
232 * non-returning dialog
234 editLabelDescription(aa[selectedRow], false);
236 else if (HIDE.equals(action))
238 aa[selectedRow].visible = false;
240 else if (DELETE.equals(action))
242 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
243 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
245 else if (SHOWALL.equals(action))
247 for (int i = 0; i < aa.length; i++)
249 if (!aa[i].visible && aa[i].annotations != null)
251 aa[i].visible = true;
255 else if (OUTPUT_TEXT.equals(action))
257 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
259 else if (COPYCONS_SEQ.equals(action))
261 SequenceI cons = null;
262 if (aa[selectedRow].groupRef != null)
264 cons = aa[selectedRow].groupRef.getConsensusSeq();
268 cons = av.getConsensusSeq();
272 copy_annotseqtoclipboard(cons);
275 else if (TOGGLE_LABELSCALE.equals(action))
277 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
284 * Shows a dialog where the annotation name and description may be edited. If
285 * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
286 * is added, else an existing annotation is updated.
291 void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
293 String name = MessageManager.getString("label.annotation_name");
294 String description = MessageManager
295 .getString("label.annotation_description");
296 String title = MessageManager
297 .getString("label.edit_annotation_name_description");
298 EditNameDialog dialog = new EditNameDialog(annotation.label,
299 annotation.description, name, description);
301 dialog.showDialog(ap.alignFrame, title, () -> {
302 annotation.label = dialog.getName();
303 String text = dialog.getDescription();
304 if (text != null && text.length() == 0)
308 annotation.description = text;
311 ap.av.getAlignment().addAnnotation(annotation);
312 ap.av.getAlignment().setAnnotationIndex(annotation, 0);
320 public void mousePressed(MouseEvent evt)
322 getSelectedRow(evt.getY() - getScrollOffset());
324 if (evt.isPopupTrigger())
331 * Build and show the Pop-up menu at the right-click mouse position
335 void showPopupMenu(MouseEvent evt)
338 final AlignmentAnnotation[] aa = ap.av.getAlignment()
339 .getAlignmentAnnotation();
341 JPopupMenu pop = new JPopupMenu(
342 MessageManager.getString("label.annotations"));
343 JMenuItem item = new JMenuItem(ADDNEW);
344 item.addActionListener(this);
349 { // let the user make everything visible again
350 item = new JMenuItem(SHOWALL);
351 item.addActionListener(this);
354 pop.show(this, evt.getX(), evt.getY());
357 item = new JMenuItem(EDITNAME);
358 item.addActionListener(this);
360 item = new JMenuItem(HIDE);
361 item.addActionListener(this);
363 // JAL-1264 hide all sequence-specific annotations of this type
364 if (selectedRow < aa.length)
366 if (aa[selectedRow].sequenceRef != null)
368 final String label = aa[selectedRow].label;
369 JMenuItem hideType = new JMenuItem();
370 String text = MessageManager.getString("label.hide_all") + " "
372 hideType.setText(text);
373 hideType.addActionListener(new ActionListener()
376 public void actionPerformed(ActionEvent e)
378 AlignmentUtils.showOrHideSequenceAnnotations(
379 ap.av.getAlignment(), Collections.singleton(label),
387 item = new JMenuItem(DELETE);
388 item.addActionListener(this);
392 item = new JMenuItem(SHOWALL);
393 item.addActionListener(this);
396 item = new JMenuItem(OUTPUT_TEXT);
397 item.addActionListener(this);
399 // TODO: annotation object should be typed for autocalculated/derived
401 if (selectedRow < aa.length)
403 final String label = aa[selectedRow].label;
404 if (!aa[selectedRow].autoCalculated)
406 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
408 // display formatting settings for this row.
410 // av and sequencegroup need to implement same interface for
411 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
412 aa[selectedRow].scaleColLabel);
413 item.addActionListener(this);
417 else if (label.indexOf("Consensus") > -1)
419 addConsensusMenuOptions(ap, aa[selectedRow], pop);
421 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
422 consclipbrd.addActionListener(this);
423 pop.add(consclipbrd);
425 if (aa[selectedRow].graph == AlignmentAnnotation.CONTACT_MAP
426 && PAEContactMatrix.PAEMATRIX
427 .equals(aa[selectedRow].getCalcId()))
429 final PAEContactMatrix cm = (PAEContactMatrix) av
430 .getContactMatrix(aa[selectedRow]);
431 if (cm != null && cm.getNewick() != null
432 && cm.getNewick().length() > 0)
434 item = new JMenuItem("Show Tree for Matrix");
435 item.addActionListener(new ActionListener()
439 public void actionPerformed(ActionEvent e)
442 ap.alignFrame.showContactMapTree(aa[selectedRow], cm);
452 pop.show(this, evt.getX(), evt.getY());
456 * A helper method that adds menu options for calculation and visualisation of
457 * group and/or alignment consensus annotation to a popup menu. This is
458 * designed to be reusable for either unwrapped mode (popup menu is shown on
459 * component AnnotationLabels), or wrapped mode (popup menu is shown on
460 * IdPanel when the mouse is over an annotation label).
466 static void addConsensusMenuOptions(AlignmentPanel ap,
467 AlignmentAnnotation ann, JPopupMenu pop)
471 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
472 MessageManager.getString("label.ignore_gaps_consensus"),
473 (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
474 : ap.av.isIgnoreGapsConsensus());
475 final AlignmentAnnotation aaa = ann;
476 cbmi.addActionListener(new ActionListener()
479 public void actionPerformed(ActionEvent e)
481 if (aaa.groupRef != null)
483 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
484 ap.getAnnotationPanel()
485 .paint(ap.getAnnotationPanel().getGraphics());
489 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
491 ap.alignmentChanged();
496 if (aaa.groupRef != null)
499 * group consensus options
501 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
502 MessageManager.getString("label.show_group_histogram"),
503 ann.groupRef.isShowConsensusHistogram());
504 chist.addActionListener(new ActionListener()
507 public void actionPerformed(ActionEvent e)
509 aaa.groupRef.setShowConsensusHistogram(chist.getState());
514 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
515 MessageManager.getString("label.show_group_logo"),
516 ann.groupRef.isShowSequenceLogo());
517 cprofl.addActionListener(new ActionListener()
520 public void actionPerformed(ActionEvent e)
522 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
527 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
528 MessageManager.getString("label.normalise_group_logo"),
529 ann.groupRef.isNormaliseSequenceLogo());
530 cproflnorm.addActionListener(new ActionListener()
533 public void actionPerformed(ActionEvent e)
535 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
536 // automatically enable logo display if we're clicked
537 aaa.groupRef.setshowSequenceLogo(true);
546 * alignment consensus options
548 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
549 MessageManager.getString("label.show_histogram"),
550 ap.av.isShowConsensusHistogram());
551 chist.addActionListener(new ActionListener()
554 public void actionPerformed(ActionEvent e)
556 ap.av.setShowConsensusHistogram(chist.getState());
557 ap.alignFrame.setMenusForViewport();
562 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
563 MessageManager.getString("label.show_logo"),
564 ap.av.isShowSequenceLogo());
565 cprof.addActionListener(new ActionListener()
568 public void actionPerformed(ActionEvent e)
570 ap.av.setShowSequenceLogo(cprof.getState());
571 ap.alignFrame.setMenusForViewport();
576 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
577 MessageManager.getString("label.normalise_logo"),
578 ap.av.isNormaliseSequenceLogo());
579 cprofnorm.addActionListener(new ActionListener()
582 public void actionPerformed(ActionEvent e)
584 ap.av.setShowSequenceLogo(true);
585 ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
586 ap.alignFrame.setMenusForViewport();
595 * Reorders annotation rows after a drag of a label
600 public void mouseReleased(MouseEvent evt)
602 if (evt.isPopupTrigger())
608 int start = selectedRow;
609 getSelectedRow(evt.getY() - getScrollOffset());
610 int end = selectedRow;
613 * if dragging to resize instead, start == end
617 // Swap these annotations
618 AlignmentAnnotation startAA = ap.av.getAlignment()
619 .getAlignmentAnnotation()[start];
622 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
624 AlignmentAnnotation endAA = ap.av.getAlignment()
625 .getAlignmentAnnotation()[end];
627 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
628 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
634 ap.getAnnotationPanel().repaint();
638 * Removes the height adjuster image on leaving the panel, unless currently
642 public void mouseExited(MouseEvent evt)
644 if (resizePanel && dragEvent == null)
652 * A mouse drag may be either an adjustment of the panel height (if flag
653 * resizePanel is set on), or a reordering of the annotation rows. The former
654 * is dealt with by this method, the latter in mouseReleased.
659 public void mouseDragged(MouseEvent evt)
665 Dimension d = ap.annotationScroller.getPreferredSize();
666 int dif = evt.getY() - oldY;
668 dif /= ap.av.getCharHeight();
669 dif *= ap.av.getCharHeight();
671 if ((d.height - dif) > 20)
673 ap.annotationScroller
674 .setPreferredSize(new Dimension(d.width, d.height - dif));
675 d = ap.annotationSpaceFillerHolder.getPreferredSize();
676 ap.annotationSpaceFillerHolder
677 .setPreferredSize(new Dimension(d.width, d.height - dif));
678 ap.paintAlignment(true, false);
690 * Updates the tooltip as the mouse moves over the labels
695 public void mouseMoved(MouseEvent evt)
697 showOrHideAdjuster(evt);
699 getSelectedRow(evt.getY() - getScrollOffset());
701 if (selectedRow > -1 && ap.av.getAlignment()
702 .getAlignmentAnnotation().length > selectedRow)
704 AlignmentAnnotation[] anns = ap.av.getAlignment()
705 .getAlignmentAnnotation();
706 AlignmentAnnotation aa = anns[selectedRow];
708 String desc = getTooltip(aa);
709 this.setToolTipText(desc);
710 String msg = getStatusMessage(aa, anns);
711 ap.alignFrame.setStatus(msg);
716 * Constructs suitable text to show in the status bar when over an annotation
717 * label, containing the associated sequence name (if any), and the annotation
718 * labels (or all labels for a graph group annotation)
724 static String getStatusMessage(AlignmentAnnotation aa,
725 AlignmentAnnotation[] anns)
732 StringBuilder msg = new StringBuilder(32);
733 if (aa.sequenceRef != null)
735 msg.append(aa.sequenceRef.getName()).append(" : ");
738 if (aa.graphGroup == -1)
740 msg.append(aa.label);
742 else if (anns != null)
744 boolean first = true;
745 for (int i = anns.length - 1; i >= 0; i--)
747 if (anns[i].graphGroup == aa.graphGroup)
753 msg.append(anns[i].label);
759 return msg.toString();
763 * Answers a tooltip, formatted as html, containing the annotation description
764 * (prefixed by associated sequence id if applicable), and the annotation
765 * (non-positional) score if it has one. Answers null if neither description
766 * nor score is found.
771 static String getTooltip(AlignmentAnnotation aa)
777 StringBuilder tooltip = new StringBuilder();
778 if (aa.description != null && !aa.description.equals("New description"))
780 // TODO: we could refactor and merge this code with the code in
781 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
783 String desc = aa.getDescription(true).trim();
784 if (!desc.toLowerCase(Locale.ROOT).startsWith(HTML_START_TAG))
786 tooltip.append(HTML_START_TAG);
787 desc = desc.replace("<", "<");
789 else if (desc.toLowerCase(Locale.ROOT).endsWith(HTML_END_TAG))
791 desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
793 tooltip.append(desc);
797 // begin the tooltip's html fragment
798 tooltip.append(HTML_START_TAG);
802 if (tooltip.length() > HTML_START_TAG.length())
804 tooltip.append("<br/>");
806 // TODO: limit precision of score to avoid noise from imprecise
808 // (64.7 becomes 64.7+/some tiny value).
809 tooltip.append(" Score: ").append(String.valueOf(aa.score));
812 if (tooltip.length() > HTML_START_TAG.length())
814 return tooltip.append(HTML_END_TAG).toString();
818 * nothing in the tooltip (except "<html>")
824 * Shows the height adjuster image if the mouse moves into the top left
825 * region, or hides it if the mouse leaves the regio
829 protected void showOrHideAdjuster(MouseEvent evt)
831 boolean was = resizePanel;
832 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
833 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
835 if (resizePanel != was)
838 .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
839 : Cursor.DEFAULT_CURSOR));
845 public void mouseClicked(MouseEvent evt)
847 final AlignmentAnnotation[] aa = ap.av.getAlignment()
848 .getAlignmentAnnotation();
849 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
851 if (selectedRow > -1 && selectedRow < aa.length)
853 if (aa[selectedRow].groupRef != null)
855 if (evt.getClickCount() >= 2)
857 // todo: make the ap scroll to the selection - not necessary, first
858 // click highlights/scrolls, second selects
859 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
861 SequenceGroup sg = ap.av.getSelectionGroup();
862 if (sg == null || sg == aa[selectedRow].groupRef
863 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
865 if (Platform.isControlDown(evt) || evt.isShiftDown())
867 // clone a new selection group from the associated group
868 ap.av.setSelectionGroup(
869 new SequenceGroup(aa[selectedRow].groupRef));
873 // set selection to the associated group so it can be edited
874 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
879 // modify current selection with associated group
880 int remainToAdd = aa[selectedRow].groupRef.getSize();
881 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
883 if (jalview.util.Platform.isControlDown(evt))
885 sg.addOrRemove(sgs, --remainToAdd == 0);
889 // notionally, we should also add intermediate sequences from
890 // last added sequence ?
891 sg.addSequence(sgs, --remainToAdd == 0);
896 ap.paintAlignment(false, false);
897 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
898 ap.av.sendSelection();
902 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
903 aa[selectedRow].groupRef.getSequences(null));
907 else if (aa[selectedRow].sequenceRef != null)
909 if (evt.getClickCount() == 1)
911 ap.getSeqPanel().ap.getIdPanel()
912 .highlightSearchResults(Arrays.asList(new SequenceI[]
913 { aa[selectedRow].sequenceRef }));
915 else if (evt.getClickCount() >= 2)
917 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
918 SequenceGroup sg = ap.av.getSelectionGroup();
921 // we make a copy rather than edit the current selection if no
923 // see Enhancement JAL-1557
924 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
926 sg = new SequenceGroup(sg);
928 sg.addSequence(aa[selectedRow].sequenceRef, false);
932 if (Platform.isControlDown(evt))
934 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
938 // notionally, we should also add intermediate sequences from
939 // last added sequence ?
940 sg.addSequence(aa[selectedRow].sequenceRef, true);
946 sg = new SequenceGroup();
948 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
949 sg.addSequence(aa[selectedRow].sequenceRef, false);
951 ap.av.setSelectionGroup(sg);
952 ap.paintAlignment(false, false);
953 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
954 ap.av.sendSelection();
964 * do a single sequence copy to jalview and the system clipboard
967 * sequence to be copied to clipboard
969 protected void copy_annotseqtoclipboard(SequenceI sq)
971 SequenceI[] seqs = new SequenceI[] { sq };
972 String[] omitHidden = null;
973 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
974 if (dseqs[0] == null)
976 dseqs[0] = new Sequence(sq);
977 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
978 sq.getSequenceAsString()));
980 sq.setDatasetSequence(dseqs[0]);
982 Alignment ds = new Alignment(dseqs);
983 if (av.hasHiddenColumns())
985 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
986 .getVisContigsIterator(0, sq.getLength(), false);
987 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
990 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
991 if (av.hasHiddenColumns())
993 alignmentStartEnd = av.getAlignment().getHiddenColumns()
994 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
997 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
998 seqs, omitHidden, alignmentStartEnd);
1000 Toolkit.getDefaultToolkit().getSystemClipboard()
1001 .setContents(new StringSelection(output), Desktop.instance);
1003 HiddenColumns hiddenColumns = null;
1005 if (av.hasHiddenColumns())
1007 hiddenColumns = new HiddenColumns(
1008 av.getAlignment().getHiddenColumns());
1011 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1013 // sequence ? need to
1015 // sequence as special.
1026 public void paintComponent(Graphics g)
1029 int width = getWidth();
1032 width = ap.calculateIdWidth().width;
1035 Graphics2D g2 = (Graphics2D) g;
1038 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1039 RenderingHints.VALUE_ANTIALIAS_ON);
1042 drawComponent(g2, true, width);
1047 * Draw the full set of annotation Labels for the alignment at the given
1051 * Graphics2D instance (needed for font scaling)
1053 * Width for scaling labels
1056 public void drawComponent(Graphics g, int width)
1058 drawComponent(g, false, width);
1062 * Draw the full set of annotation Labels for the alignment at the given
1066 * Graphics2D instance (needed for font scaling)
1068 * - true indicates that only current visible area needs to be
1071 * Width for scaling labels
1073 public void drawComponent(Graphics g, boolean clip, int width)
1075 if (av.getFont().getSize() < 10)
1081 g.setFont(av.getFont());
1084 FontMetrics fm = g.getFontMetrics(g.getFont());
1085 g.setColor(Color.white);
1086 g.fillRect(0, 0, getWidth(), getHeight());
1088 g.translate(0, getScrollOffset());
1089 g.setColor(Color.black);
1090 SequenceI lastSeqRef = null;
1091 String lastLabel = null;
1092 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1093 int fontHeight = g.getFont().getSize();
1096 int graphExtras = 0;
1098 Font baseFont = g.getFont();
1099 FontMetrics baseMetrics = fm;
1100 int ofontH = fontHeight;
1103 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1104 ? ap.getAnnotationPanel().getVisibleVRange()
1106 if (clip && visr != null)
1109 visHeight = visr[1];
1111 boolean visible = true, before = false, after = false;
1114 hasHiddenRows = false;
1117 for (int i = 0; i < aa.length; i++)
1122 hasHiddenRows = true;
1126 // look ahead to next annotation
1127 for (nexAA = i + 1; nexAA < aa.length
1128 && !aa[nexAA].visible; nexAA++)
1139 System.out.println("before vis: " + i);
1143 // don't draw what isn't visible
1146 if (olY > visHeight)
1154 "Scroll offset: " + sOffset + " after vis: " + i);
1158 // don't draw what isn't visible
1162 g.setColor(Color.black);
1164 offset = -aa[i].height / 2;
1168 offset += fm.getHeight() / 2;
1169 offset -= fm.getDescent();
1173 offset += fm.getDescent();
1175 String label = aa[i].label;
1176 boolean vertBar = false;
1177 if ((lastLabel != null && lastLabel.equals(label)))
1179 label = aa[i].description;
1183 if (nexAA < aa.length && label.equals(aa[nexAA].label)) // &&
1184 // aa[nexY].sequenceRef==aa[i].sequenceRef)
1187 // next label is the same as this label
1188 label = aa[i].description;
1195 if (aa[i].sequenceRef != null)
1197 if (aa[i].sequenceRef != lastSeqRef)
1199 label = aa[i].sequenceRef.getName() + " " + label;
1200 // TODO record relationship between sequence and this annotation and
1208 x = width - fm.stringWidth(label) - 3;
1210 if (aa[i].graphGroup > -1)
1213 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1214 // computed efficiently for all visible labels
1215 for (int gg = 0; gg < aa.length; gg++)
1217 if (aa[gg].graphGroup == aa[i].graphGroup)
1222 if (groupSize * (fontHeight + 8) < aa[i].height)
1224 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1229 // scale font to fit
1230 float h = aa[i].height / (float) groupSize, s;
1237 fontHeight = -8 + (int) h;
1238 s = ((float) fontHeight) / (float) ofontH;
1240 .deriveFont(AffineTransform.getScaleInstance(s, s));
1242 fm = g.getFontMetrics();
1243 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1249 for (int gg = 0; gg < aa.length; gg++)
1251 if (aa[gg].graphGroup == aa[i].graphGroup)
1253 x = width - fm.stringWidth(aa[gg].label) - 3;
1254 g.drawString(aa[gg].label, x, y - graphExtras);
1256 if (aa[gg]._linecolour != null)
1259 g.setColor(aa[gg]._linecolour);
1260 g.drawLine(x, y - graphExtras + 3,
1261 x + fm.stringWidth(aa[gg].label),
1262 y - graphExtras + 3);
1265 g.setColor(Color.black);
1266 graphExtras += fontHeight + 8;
1270 g.setFont(baseFont);
1272 fontHeight = ofontH;
1278 g.drawLine(width - 3, y + offset - fontHeight, width - 3,
1279 (int) (y - 1.5 * aa[i].height - offset - fontHeight));
1280 // g.drawLine(20, y + offset, x - 20, y + offset);
1283 g.drawString(label, x, y + offset);
1285 lastSeqRef = aa[i].sequenceRef;
1289 if (!resizePanel && dragEvent != null && aa != null)
1291 g.setColor(Color.lightGray);
1293 (aa[selectedRow].sequenceRef == null ? ""
1294 : aa[selectedRow].sequenceRef.getName())
1295 + aa[selectedRow].label,
1296 dragEvent.getX(), dragEvent.getY() - getScrollOffset());
1299 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1301 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1302 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1307 public int getScrollOffset()
1309 return scrollOffset;
1313 public void mouseEntered(MouseEvent e)