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.getNewickString()!=null && cm.getNewickString().length()>0)
433 item = new JMenuItem("Show Matrix");
434 item.addActionListener(new ActionListener()
438 public void actionPerformed(ActionEvent e)
441 ap.alignFrame.showContactMapTree(aa[selectedRow],cm);
451 pop.show(this, evt.getX(), evt.getY());
455 * A helper method that adds menu options for calculation and visualisation of
456 * group and/or alignment consensus annotation to a popup menu. This is
457 * designed to be reusable for either unwrapped mode (popup menu is shown on
458 * component AnnotationLabels), or wrapped mode (popup menu is shown on
459 * IdPanel when the mouse is over an annotation label).
465 static void addConsensusMenuOptions(AlignmentPanel ap,
466 AlignmentAnnotation ann, JPopupMenu pop)
470 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
471 MessageManager.getString("label.ignore_gaps_consensus"),
472 (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
473 : ap.av.isIgnoreGapsConsensus());
474 final AlignmentAnnotation aaa = ann;
475 cbmi.addActionListener(new ActionListener()
478 public void actionPerformed(ActionEvent e)
480 if (aaa.groupRef != null)
482 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
483 ap.getAnnotationPanel()
484 .paint(ap.getAnnotationPanel().getGraphics());
488 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
490 ap.alignmentChanged();
495 if (aaa.groupRef != null)
498 * group consensus options
500 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
501 MessageManager.getString("label.show_group_histogram"),
502 ann.groupRef.isShowConsensusHistogram());
503 chist.addActionListener(new ActionListener()
506 public void actionPerformed(ActionEvent e)
508 aaa.groupRef.setShowConsensusHistogram(chist.getState());
513 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
514 MessageManager.getString("label.show_group_logo"),
515 ann.groupRef.isShowSequenceLogo());
516 cprofl.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent e)
521 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
526 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
527 MessageManager.getString("label.normalise_group_logo"),
528 ann.groupRef.isNormaliseSequenceLogo());
529 cproflnorm.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent e)
534 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
535 // automatically enable logo display if we're clicked
536 aaa.groupRef.setshowSequenceLogo(true);
545 * alignment consensus options
547 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
548 MessageManager.getString("label.show_histogram"),
549 ap.av.isShowConsensusHistogram());
550 chist.addActionListener(new ActionListener()
553 public void actionPerformed(ActionEvent e)
555 ap.av.setShowConsensusHistogram(chist.getState());
556 ap.alignFrame.setMenusForViewport();
561 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
562 MessageManager.getString("label.show_logo"),
563 ap.av.isShowSequenceLogo());
564 cprof.addActionListener(new ActionListener()
567 public void actionPerformed(ActionEvent e)
569 ap.av.setShowSequenceLogo(cprof.getState());
570 ap.alignFrame.setMenusForViewport();
575 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
576 MessageManager.getString("label.normalise_logo"),
577 ap.av.isNormaliseSequenceLogo());
578 cprofnorm.addActionListener(new ActionListener()
581 public void actionPerformed(ActionEvent e)
583 ap.av.setShowSequenceLogo(true);
584 ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
585 ap.alignFrame.setMenusForViewport();
594 * Reorders annotation rows after a drag of a label
599 public void mouseReleased(MouseEvent evt)
601 if (evt.isPopupTrigger())
607 int start = selectedRow;
608 getSelectedRow(evt.getY() - getScrollOffset());
609 int end = selectedRow;
612 * if dragging to resize instead, start == end
616 // Swap these annotations
617 AlignmentAnnotation startAA = ap.av.getAlignment()
618 .getAlignmentAnnotation()[start];
621 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
623 AlignmentAnnotation endAA = ap.av.getAlignment()
624 .getAlignmentAnnotation()[end];
626 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
627 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
633 ap.getAnnotationPanel().repaint();
637 * Removes the height adjuster image on leaving the panel, unless currently
641 public void mouseExited(MouseEvent evt)
643 if (resizePanel && dragEvent == null)
651 * A mouse drag may be either an adjustment of the panel height (if flag
652 * resizePanel is set on), or a reordering of the annotation rows. The former
653 * is dealt with by this method, the latter in mouseReleased.
658 public void mouseDragged(MouseEvent evt)
664 Dimension d = ap.annotationScroller.getPreferredSize();
665 int dif = evt.getY() - oldY;
667 dif /= ap.av.getCharHeight();
668 dif *= ap.av.getCharHeight();
670 if ((d.height - dif) > 20)
672 ap.annotationScroller
673 .setPreferredSize(new Dimension(d.width, d.height - dif));
674 d = ap.annotationSpaceFillerHolder.getPreferredSize();
675 ap.annotationSpaceFillerHolder
676 .setPreferredSize(new Dimension(d.width, d.height - dif));
677 ap.paintAlignment(true, false);
689 * Updates the tooltip as the mouse moves over the labels
694 public void mouseMoved(MouseEvent evt)
696 showOrHideAdjuster(evt);
698 getSelectedRow(evt.getY() - getScrollOffset());
700 if (selectedRow > -1 && ap.av.getAlignment()
701 .getAlignmentAnnotation().length > selectedRow)
703 AlignmentAnnotation[] anns = ap.av.getAlignment()
704 .getAlignmentAnnotation();
705 AlignmentAnnotation aa = anns[selectedRow];
707 String desc = getTooltip(aa);
708 this.setToolTipText(desc);
709 String msg = getStatusMessage(aa, anns);
710 ap.alignFrame.setStatus(msg);
715 * Constructs suitable text to show in the status bar when over an annotation
716 * label, containing the associated sequence name (if any), and the annotation
717 * labels (or all labels for a graph group annotation)
723 static String getStatusMessage(AlignmentAnnotation aa,
724 AlignmentAnnotation[] anns)
731 StringBuilder msg = new StringBuilder(32);
732 if (aa.sequenceRef != null)
734 msg.append(aa.sequenceRef.getName()).append(" : ");
737 if (aa.graphGroup == -1)
739 msg.append(aa.label);
741 else if (anns != null)
743 boolean first = true;
744 for (int i = anns.length - 1; i >= 0; i--)
746 if (anns[i].graphGroup == aa.graphGroup)
752 msg.append(anns[i].label);
758 return msg.toString();
762 * Answers a tooltip, formatted as html, containing the annotation description
763 * (prefixed by associated sequence id if applicable), and the annotation
764 * (non-positional) score if it has one. Answers null if neither description
765 * nor score is found.
770 static String getTooltip(AlignmentAnnotation aa)
776 StringBuilder tooltip = new StringBuilder();
777 if (aa.description != null && !aa.description.equals("New description"))
779 // TODO: we could refactor and merge this code with the code in
780 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
782 String desc = aa.getDescription(true).trim();
783 if (!desc.toLowerCase(Locale.ROOT).startsWith(HTML_START_TAG))
785 tooltip.append(HTML_START_TAG);
786 desc = desc.replace("<", "<");
788 else if (desc.toLowerCase(Locale.ROOT).endsWith(HTML_END_TAG))
790 desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
792 tooltip.append(desc);
796 // begin the tooltip's html fragment
797 tooltip.append(HTML_START_TAG);
801 if (tooltip.length() > HTML_START_TAG.length())
803 tooltip.append("<br/>");
805 // TODO: limit precision of score to avoid noise from imprecise
807 // (64.7 becomes 64.7+/some tiny value).
808 tooltip.append(" Score: ").append(String.valueOf(aa.score));
811 if (tooltip.length() > HTML_START_TAG.length())
813 return tooltip.append(HTML_END_TAG).toString();
817 * nothing in the tooltip (except "<html>")
823 * Shows the height adjuster image if the mouse moves into the top left
824 * region, or hides it if the mouse leaves the regio
828 protected void showOrHideAdjuster(MouseEvent evt)
830 boolean was = resizePanel;
831 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
832 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
834 if (resizePanel != was)
837 .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
838 : Cursor.DEFAULT_CURSOR));
844 public void mouseClicked(MouseEvent evt)
846 final AlignmentAnnotation[] aa = ap.av.getAlignment()
847 .getAlignmentAnnotation();
848 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
850 if (selectedRow > -1 && selectedRow < aa.length)
852 if (aa[selectedRow].groupRef != null)
854 if (evt.getClickCount() >= 2)
856 // todo: make the ap scroll to the selection - not necessary, first
857 // click highlights/scrolls, second selects
858 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
860 SequenceGroup sg = ap.av.getSelectionGroup();
861 if (sg == null || sg == aa[selectedRow].groupRef
862 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
864 if (Platform.isControlDown(evt) || evt.isShiftDown())
866 // clone a new selection group from the associated group
867 ap.av.setSelectionGroup(
868 new SequenceGroup(aa[selectedRow].groupRef));
872 // set selection to the associated group so it can be edited
873 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
878 // modify current selection with associated group
879 int remainToAdd = aa[selectedRow].groupRef.getSize();
880 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
882 if (jalview.util.Platform.isControlDown(evt))
884 sg.addOrRemove(sgs, --remainToAdd == 0);
888 // notionally, we should also add intermediate sequences from
889 // last added sequence ?
890 sg.addSequence(sgs, --remainToAdd == 0);
895 ap.paintAlignment(false, false);
896 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
897 ap.av.sendSelection();
901 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
902 aa[selectedRow].groupRef.getSequences(null));
906 else if (aa[selectedRow].sequenceRef != null)
908 if (evt.getClickCount() == 1)
910 ap.getSeqPanel().ap.getIdPanel()
911 .highlightSearchResults(Arrays.asList(new SequenceI[]
912 { aa[selectedRow].sequenceRef }));
914 else if (evt.getClickCount() >= 2)
916 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
917 SequenceGroup sg = ap.av.getSelectionGroup();
920 // we make a copy rather than edit the current selection if no
922 // see Enhancement JAL-1557
923 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
925 sg = new SequenceGroup(sg);
927 sg.addSequence(aa[selectedRow].sequenceRef, false);
931 if (Platform.isControlDown(evt))
933 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
937 // notionally, we should also add intermediate sequences from
938 // last added sequence ?
939 sg.addSequence(aa[selectedRow].sequenceRef, true);
945 sg = new SequenceGroup();
947 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
948 sg.addSequence(aa[selectedRow].sequenceRef, false);
950 ap.av.setSelectionGroup(sg);
951 ap.paintAlignment(false, false);
952 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
953 ap.av.sendSelection();
963 * do a single sequence copy to jalview and the system clipboard
966 * sequence to be copied to clipboard
968 protected void copy_annotseqtoclipboard(SequenceI sq)
970 SequenceI[] seqs = new SequenceI[] { sq };
971 String[] omitHidden = null;
972 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
973 if (dseqs[0] == null)
975 dseqs[0] = new Sequence(sq);
976 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
977 sq.getSequenceAsString()));
979 sq.setDatasetSequence(dseqs[0]);
981 Alignment ds = new Alignment(dseqs);
982 if (av.hasHiddenColumns())
984 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
985 .getVisContigsIterator(0, sq.getLength(), false);
986 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
989 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
990 if (av.hasHiddenColumns())
992 alignmentStartEnd = av.getAlignment().getHiddenColumns()
993 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
996 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
997 seqs, omitHidden, alignmentStartEnd);
999 Toolkit.getDefaultToolkit().getSystemClipboard()
1000 .setContents(new StringSelection(output), Desktop.instance);
1002 HiddenColumns hiddenColumns = null;
1004 if (av.hasHiddenColumns())
1006 hiddenColumns = new HiddenColumns(
1007 av.getAlignment().getHiddenColumns());
1010 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1012 // sequence ? need to
1014 // sequence as special.
1025 public void paintComponent(Graphics g)
1028 int width = getWidth();
1031 width = ap.calculateIdWidth().width;
1034 Graphics2D g2 = (Graphics2D) g;
1037 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1038 RenderingHints.VALUE_ANTIALIAS_ON);
1041 drawComponent(g2, true, width);
1046 * Draw the full set of annotation Labels for the alignment at the given
1050 * Graphics2D instance (needed for font scaling)
1052 * Width for scaling labels
1055 public void drawComponent(Graphics g, int width)
1057 drawComponent(g, false, width);
1061 * Draw the full set of annotation Labels for the alignment at the given
1065 * Graphics2D instance (needed for font scaling)
1067 * - true indicates that only current visible area needs to be
1070 * Width for scaling labels
1072 public void drawComponent(Graphics g, boolean clip, int width)
1074 if (av.getFont().getSize() < 10)
1080 g.setFont(av.getFont());
1083 FontMetrics fm = g.getFontMetrics(g.getFont());
1084 g.setColor(Color.white);
1085 g.fillRect(0, 0, getWidth(), getHeight());
1087 g.translate(0, getScrollOffset());
1088 g.setColor(Color.black);
1089 SequenceI lastSeqRef = null;
1090 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1091 int fontHeight = g.getFont().getSize();
1094 int graphExtras = 0;
1096 Font baseFont = g.getFont();
1097 FontMetrics baseMetrics = fm;
1098 int ofontH = fontHeight;
1101 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1102 ? ap.getAnnotationPanel().getVisibleVRange()
1104 if (clip && visr != null)
1107 visHeight = visr[1];
1109 boolean visible = true, before = false, after = false;
1112 hasHiddenRows = false;
1114 for (int i = 0; i < aa.length; i++)
1119 hasHiddenRows = true;
1132 System.out.println("before vis: " + i);
1136 // don't draw what isn't visible
1139 if (olY > visHeight)
1147 "Scroll offset: " + sOffset + " after vis: " + i);
1151 // don't draw what isn't visible
1155 g.setColor(Color.black);
1157 offset = -aa[i].height / 2;
1161 offset += fm.getHeight() / 2;
1162 offset -= fm.getDescent();
1166 offset += fm.getDescent();
1168 String label = aa[i].label;
1169 boolean vertBar = false;
1170 if (aa[i].sequenceRef != null)
1172 if (aa[i].sequenceRef != lastSeqRef)
1174 label = aa[i].sequenceRef.getName() + " " + label;
1175 // TODO record relationship between sequence and this annotation and
1183 x = width - fm.stringWidth(label) - 3;
1185 if (aa[i].graphGroup > -1)
1188 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1189 // computed efficiently for all visible labels
1190 for (int gg = 0; gg < aa.length; gg++)
1192 if (aa[gg].graphGroup == aa[i].graphGroup)
1197 if (groupSize * (fontHeight + 8) < aa[i].height)
1199 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1204 // scale font to fit
1205 float h = aa[i].height / (float) groupSize, s;
1212 fontHeight = -8 + (int) h;
1213 s = ((float) fontHeight) / (float) ofontH;
1215 .deriveFont(AffineTransform.getScaleInstance(s, s));
1217 fm = g.getFontMetrics();
1218 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1224 for (int gg = 0; gg < aa.length; gg++)
1226 if (aa[gg].graphGroup == aa[i].graphGroup)
1228 x = width - fm.stringWidth(aa[gg].label) - 3;
1229 g.drawString(aa[gg].label, x, y - graphExtras);
1231 if (aa[gg]._linecolour != null)
1234 g.setColor(aa[gg]._linecolour);
1235 g.drawLine(x, y - graphExtras + 3,
1236 x + fm.stringWidth(aa[gg].label),
1237 y - graphExtras + 3);
1240 g.setColor(Color.black);
1241 graphExtras += fontHeight + 8;
1245 g.setFont(baseFont);
1247 fontHeight = ofontH;
1253 g.drawLine(20, y + offset, 20, y - aa[i].height);
1254 g.drawLine(20, y + offset, x - 20, y + offset);
1257 g.drawString(label, x, y + offset);
1259 lastSeqRef = aa[i].sequenceRef;
1263 if (!resizePanel && dragEvent != null && aa != null)
1265 g.setColor(Color.lightGray);
1267 (aa[selectedRow].sequenceRef == null ? ""
1268 : aa[selectedRow].sequenceRef.getName())
1269 + aa[selectedRow].label,
1270 dragEvent.getX(), dragEvent.getY() - getScrollOffset());
1273 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1275 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1276 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1281 public int getScrollOffset()
1283 return scrollOffset;
1287 public void mouseEntered(MouseEvent e)