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.AlignSeq;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.io.FileFormat;
34 import jalview.io.FormatAdapter;
35 import jalview.util.Comparison;
36 import jalview.util.MessageManager;
37 import jalview.util.Platform;
39 import java.awt.Color;
40 import java.awt.Cursor;
41 import java.awt.Dimension;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.RenderingHints;
47 import java.awt.Toolkit;
48 import java.awt.datatransfer.StringSelection;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
52 import java.awt.event.MouseListener;
53 import java.awt.event.MouseMotionListener;
54 import java.awt.geom.AffineTransform;
55 import java.util.Arrays;
56 import java.util.Collections;
57 import java.util.Iterator;
59 import javax.swing.JCheckBoxMenuItem;
60 import javax.swing.JMenuItem;
61 import javax.swing.JPanel;
62 import javax.swing.JPopupMenu;
63 import javax.swing.SwingUtilities;
64 import javax.swing.ToolTipManager;
67 * The panel that holds the labels for alignment annotations, providing
68 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
71 public class AnnotationLabels extends JPanel
72 implements MouseListener, MouseMotionListener, ActionListener
74 private static final String HTML_END_TAG = "</html>";
76 private static final String HTML_START_TAG = "<html>";
79 * width in pixels within which height adjuster arrows are shown and active
81 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
84 * height in pixels for allowing height adjuster to be active
86 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
88 private static final Font font = new Font("Arial", Font.PLAIN, 11);
90 private static final String TOGGLE_LABELSCALE = MessageManager
91 .getString("label.scale_label_to_column");
93 private static final String ADDNEW = MessageManager
94 .getString("label.add_new_row");
96 private static final String EDITNAME = MessageManager
97 .getString("label.edit_label_description");
99 private static final String HIDE = MessageManager
100 .getString("label.hide_row");
102 private static final String DELETE = MessageManager
103 .getString("label.delete_row");
105 private static final String SHOWALL = MessageManager
106 .getString("label.show_all_hidden_rows");
108 private static final String OUTPUT_TEXT = MessageManager
109 .getString("label.export_annotation");
111 private static final String COPYCONS_SEQ = MessageManager
112 .getString("label.copy_consensus_sequence");
114 private final boolean debugRedraw = false;
116 private AlignmentPanel ap;
120 private MouseEvent dragEvent;
124 private int selectedRow;
126 private int scrollOffset = 0;
128 private boolean hasHiddenRows;
130 private boolean resizePanel = false;
133 * Creates a new AnnotationLabels object
137 public AnnotationLabels(AlignmentPanel ap)
141 ToolTipManager.sharedInstance().registerComponent(this);
143 addMouseListener(this);
144 addMouseMotionListener(this);
145 addMouseWheelListener(ap.getAnnotationPanel());
148 public AnnotationLabels(AlignViewport av)
159 public void setScrollOffset(int y)
166 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
170 * coordinate position to search for a row
172 void getSelectedRow(int y)
175 AlignmentAnnotation[] aa = ap.av.getAlignment()
176 .getAlignmentAnnotation();
180 for (int i = 0; i < aa.length; i++)
188 height += aa[i].height;
207 public void actionPerformed(ActionEvent evt)
209 AlignmentAnnotation[] aa = ap.av.getAlignment()
210 .getAlignmentAnnotation();
212 boolean fullRepaint = false;
213 if (evt.getActionCommand().equals(ADDNEW))
215 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
216 null, new Annotation[ap.av.getAlignment().getWidth()]);
218 if (!editLabelDescription(newAnnotation))
223 ap.av.getAlignment().addAnnotation(newAnnotation);
224 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
227 else if (evt.getActionCommand().equals(EDITNAME))
229 String name = aa[selectedRow].label;
230 editLabelDescription(aa[selectedRow]);
231 if (!name.equalsIgnoreCase(aa[selectedRow].label))
236 else if (evt.getActionCommand().equals(HIDE))
238 aa[selectedRow].visible = false;
240 else if (evt.getActionCommand().equals(DELETE))
242 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
243 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
246 else if (evt.getActionCommand().equals(SHOWALL))
248 for (int i = 0; i < aa.length; i++)
250 if (!aa[i].visible && aa[i].annotations != null)
252 aa[i].visible = true;
257 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
259 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
261 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
263 SequenceI cons = null;
264 if (aa[selectedRow].groupRef != null)
266 cons = aa[selectedRow].groupRef.getConsensusSeq();
270 cons = av.getConsensusSeq();
274 copy_annotseqtoclipboard(cons);
278 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
280 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
283 ap.refresh(fullRepaint);
293 boolean editLabelDescription(AlignmentAnnotation annotation)
296 EditNameDialog dialog = new EditNameDialog(annotation.label,
297 annotation.description, " Annotation Name ",
298 "Annotation Description ", "Edit Annotation Name/Description",
306 annotation.label = dialog.getName();
308 String text = dialog.getDescription();
309 if (text != null && text.length() == 0)
313 annotation.description = text;
319 public void mousePressed(MouseEvent evt)
321 getSelectedRow(evt.getY() - getScrollOffset());
323 if (evt.isPopupTrigger())
330 * Build and show the Pop-up menu at the right-click mouse position
334 void showPopupMenu(MouseEvent evt)
337 final AlignmentAnnotation[] aa = ap.av.getAlignment()
338 .getAlignmentAnnotation();
340 JPopupMenu pop = new JPopupMenu(
341 MessageManager.getString("label.annotations"));
342 JMenuItem item = new JMenuItem(ADDNEW);
343 item.addActionListener(this);
348 { // let the user make everything visible again
349 item = new JMenuItem(SHOWALL);
350 item.addActionListener(this);
353 pop.show(this, evt.getX(), evt.getY());
356 item = new JMenuItem(EDITNAME);
357 item.addActionListener(this);
359 item = new JMenuItem(HIDE);
360 item.addActionListener(this);
362 // JAL-1264 hide all sequence-specific annotations of this type
363 if (selectedRow < aa.length)
365 if (aa[selectedRow].sequenceRef != null)
367 final String label = aa[selectedRow].label;
368 JMenuItem hideType = new JMenuItem();
369 String text = MessageManager.getString("label.hide_all") + " "
371 hideType.setText(text);
372 hideType.addActionListener(new ActionListener()
375 public void actionPerformed(ActionEvent e)
377 AlignmentUtils.showOrHideSequenceAnnotations(
378 ap.av.getAlignment(), Collections.singleton(label),
386 item = new JMenuItem(DELETE);
387 item.addActionListener(this);
391 item = new JMenuItem(SHOWALL);
392 item.addActionListener(this);
395 item = new JMenuItem(OUTPUT_TEXT);
396 item.addActionListener(this);
398 // TODO: annotation object should be typed for autocalculated/derived
400 if (selectedRow < aa.length)
402 final String label = aa[selectedRow].label;
403 if (!aa[selectedRow].autoCalculated)
405 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
407 // display formatting settings for this row.
409 // av and sequencegroup need to implement same interface for
410 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
411 aa[selectedRow].scaleColLabel);
412 item.addActionListener(this);
416 else if (label.indexOf("Consensus") > -1)
418 addConsensusMenuOptions(ap, aa[selectedRow], pop);
420 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
421 consclipbrd.addActionListener(this);
422 pop.add(consclipbrd);
425 pop.show(this, evt.getX(), evt.getY());
429 * A helper method that adds menu options for calculation and visualisation of
430 * group and/or alignment consensus annotation to a popup menu. This is
431 * designed to be reusable for either unwrapped mode (popup menu is shown on
432 * component AnnotationLabels), or wrapped mode (popup menu is shown on
433 * IdPanel when the mouse is over an annotation label).
439 static void addConsensusMenuOptions(AlignmentPanel ap,
440 AlignmentAnnotation ann,
445 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
446 MessageManager.getString("label.ignore_gaps_consensus"),
447 (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
448 : ap.av.isIgnoreGapsConsensus());
449 final AlignmentAnnotation aaa = ann;
450 cbmi.addActionListener(new ActionListener()
453 public void actionPerformed(ActionEvent e)
455 if (aaa.groupRef != null)
457 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
458 ap.getAnnotationPanel()
459 .paint(ap.getAnnotationPanel().getGraphics());
463 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
465 ap.alignmentChanged();
470 if (aaa.groupRef != null)
473 * group consensus options
475 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
476 MessageManager.getString("label.show_group_histogram"),
477 ann.groupRef.isShowConsensusHistogram());
478 chist.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent e)
483 aaa.groupRef.setShowConsensusHistogram(chist.getState());
488 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
489 MessageManager.getString("label.show_group_logo"),
490 ann.groupRef.isShowSequenceLogo());
491 cprofl.addActionListener(new ActionListener()
494 public void actionPerformed(ActionEvent e)
496 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
501 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
502 MessageManager.getString("label.normalise_group_logo"),
503 ann.groupRef.isNormaliseSequenceLogo());
504 cproflnorm.addActionListener(new ActionListener()
507 public void actionPerformed(ActionEvent e)
509 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
510 // automatically enable logo display if we're clicked
511 aaa.groupRef.setshowSequenceLogo(true);
520 * alignment consensus options
522 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
523 MessageManager.getString("label.show_histogram"),
524 ap.av.isShowConsensusHistogram());
525 chist.addActionListener(new ActionListener()
528 public void actionPerformed(ActionEvent e)
530 ap.av.setShowConsensusHistogram(chist.getState());
531 ap.alignFrame.setMenusForViewport();
536 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
537 MessageManager.getString("label.show_logo"),
538 ap.av.isShowSequenceLogo());
539 cprof.addActionListener(new ActionListener()
542 public void actionPerformed(ActionEvent e)
544 ap.av.setShowSequenceLogo(cprof.getState());
545 ap.alignFrame.setMenusForViewport();
550 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
551 MessageManager.getString("label.normalise_logo"),
552 ap.av.isNormaliseSequenceLogo());
553 cprofnorm.addActionListener(new ActionListener()
556 public void actionPerformed(ActionEvent e)
558 ap.av.setShowSequenceLogo(true);
559 ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
560 ap.alignFrame.setMenusForViewport();
569 * Reorders annotation rows after a drag of a label
574 public void mouseReleased(MouseEvent evt)
576 if (evt.isPopupTrigger())
582 int start = selectedRow;
583 getSelectedRow(evt.getY() - getScrollOffset());
584 int end = selectedRow;
587 * if dragging to resize instead, start == end
591 // Swap these annotations
592 AlignmentAnnotation startAA = ap.av.getAlignment()
593 .getAlignmentAnnotation()[start];
596 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
598 AlignmentAnnotation endAA = ap.av.getAlignment()
599 .getAlignmentAnnotation()[end];
601 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
602 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
603 av.setSortAnnotationsBy(SequenceAnnotationOrder.CUSTOM);
609 ap.getAnnotationPanel().repaint();
613 * Removes the height adjuster image on leaving the panel, unless currently
617 public void mouseExited(MouseEvent evt)
619 if (resizePanel && dragEvent == null)
627 * A mouse drag may be either an adjustment of the panel height (if flag
628 * resizePanel is set on), or a reordering of the annotation rows. The former
629 * is dealt with by this method, the latter in mouseReleased.
634 public void mouseDragged(MouseEvent evt)
640 Dimension d = ap.annotationScroller.getPreferredSize();
641 int dif = evt.getY() - oldY;
643 dif /= ap.av.getCharHeight();
644 dif *= ap.av.getCharHeight();
646 if ((d.height - dif) > 20)
648 ap.annotationScroller
649 .setPreferredSize(new Dimension(d.width, d.height - dif));
650 d = ap.annotationSpaceFillerHolder.getPreferredSize();
651 ap.annotationSpaceFillerHolder
652 .setPreferredSize(new Dimension(d.width, d.height - dif));
653 ap.paintAlignment(true, false);
665 * Updates the tooltip as the mouse moves over the labels
670 public void mouseMoved(MouseEvent evt)
672 showOrHideAdjuster(evt);
674 getSelectedRow(evt.getY() - getScrollOffset());
676 if (selectedRow > -1 && ap.av.getAlignment()
677 .getAlignmentAnnotation().length > selectedRow)
679 AlignmentAnnotation[] anns = ap.av.getAlignment()
680 .getAlignmentAnnotation();
681 AlignmentAnnotation aa = anns[selectedRow];
683 String desc = getTooltip(aa);
684 this.setToolTipText(desc);
685 String msg = getStatusMessage(aa, anns);
686 ap.alignFrame.setStatus(msg);
691 * Constructs suitable text to show in the status bar when over an annotation
692 * label, containing the associated sequence name (if any), and the annotation
693 * labels (or all labels for a graph group annotation)
699 static String getStatusMessage(AlignmentAnnotation aa,
700 AlignmentAnnotation[] anns)
707 StringBuilder msg = new StringBuilder(32);
708 if (aa.sequenceRef != null)
710 msg.append(aa.sequenceRef.getName()).append(" : ");
713 if (aa.graphGroup == -1)
715 msg.append(aa.label);
717 else if (anns != null)
719 boolean first = true;
720 for (int i = anns.length - 1; i >= 0; i--)
722 if (anns[i].graphGroup == aa.graphGroup)
728 msg.append(anns[i].label);
734 return msg.toString();
738 * Answers a tooltip, formatted as html, containing the annotation description
739 * (prefixed by associated sequence id if applicable), and the annotation
740 * (non-positional) score if it has one. Answers null if neither description
741 * nor score is found.
746 static String getTooltip(AlignmentAnnotation aa)
752 StringBuilder tooltip = new StringBuilder();
753 if (aa.description != null && !aa.description.equals("New description"))
755 // TODO: we could refactor and merge this code with the code in
756 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
758 String desc = aa.getDescription(true).trim();
759 if (!desc.toLowerCase().startsWith(HTML_START_TAG))
761 tooltip.append(HTML_START_TAG);
762 desc = desc.replace("<", "<");
764 else if (desc.toLowerCase().endsWith(HTML_END_TAG))
766 desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
768 tooltip.append(desc);
772 // begin the tooltip's html fragment
773 tooltip.append(HTML_START_TAG);
777 if (tooltip.length() > HTML_START_TAG.length())
779 tooltip.append("<br/>");
781 // TODO: limit precision of score to avoid noise from imprecise
783 // (64.7 becomes 64.7+/some tiny value).
784 tooltip.append(" Score: ").append(String.valueOf(aa.score));
787 if (tooltip.length() > HTML_START_TAG.length())
789 return tooltip.append(HTML_END_TAG).toString();
793 * nothing in the tooltip (except "<html>")
799 * Shows the height adjuster image if the mouse moves into the top left
800 * region, or hides it if the mouse leaves the regio
804 protected void showOrHideAdjuster(MouseEvent evt)
806 boolean was = resizePanel;
807 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
809 if (resizePanel != was)
811 setCursor(Cursor.getPredefinedCursor(
812 resizePanel ? Cursor.S_RESIZE_CURSOR
813 : Cursor.DEFAULT_CURSOR));
819 public void mouseClicked(MouseEvent evt)
821 final AlignmentAnnotation[] aa = ap.av.getAlignment()
822 .getAlignmentAnnotation();
823 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
825 if (selectedRow > -1 && selectedRow < aa.length)
827 if (aa[selectedRow].groupRef != null)
829 if (evt.getClickCount() >= 2)
831 // todo: make the ap scroll to the selection - not necessary, first
832 // click highlights/scrolls, second selects
833 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
835 SequenceGroup sg = ap.av.getSelectionGroup();
836 if (sg == null || sg == aa[selectedRow].groupRef
837 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
839 if (Platform.isControlDown(evt) || evt.isShiftDown())
841 // clone a new selection group from the associated group
842 ap.av.setSelectionGroup(
843 new SequenceGroup(aa[selectedRow].groupRef));
847 // set selection to the associated group so it can be edited
848 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
853 // modify current selection with associated group
854 int remainToAdd = aa[selectedRow].groupRef.getSize();
855 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
857 if (jalview.util.Platform.isControlDown(evt))
859 sg.addOrRemove(sgs, --remainToAdd == 0);
863 // notionally, we should also add intermediate sequences from
864 // last added sequence ?
865 sg.addSequence(sgs, --remainToAdd == 0);
870 ap.paintAlignment(false, false);
871 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
872 ap.av.sendSelection();
876 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
877 aa[selectedRow].groupRef.getSequences(null));
881 else if (aa[selectedRow].sequenceRef != null)
883 if (evt.getClickCount() == 1)
885 ap.getSeqPanel().ap.getIdPanel()
886 .highlightSearchResults(Arrays.asList(new SequenceI[]
887 { aa[selectedRow].sequenceRef }));
889 else if (evt.getClickCount() >= 2)
891 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
892 SequenceGroup sg = ap.av.getSelectionGroup();
895 // we make a copy rather than edit the current selection if no
897 // see Enhancement JAL-1557
898 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
900 sg = new SequenceGroup(sg);
902 sg.addSequence(aa[selectedRow].sequenceRef, false);
906 if (Platform.isControlDown(evt))
908 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
912 // notionally, we should also add intermediate sequences from
913 // last added sequence ?
914 sg.addSequence(aa[selectedRow].sequenceRef, true);
920 sg = new SequenceGroup();
922 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
923 sg.addSequence(aa[selectedRow].sequenceRef, false);
925 ap.av.setSelectionGroup(sg);
926 ap.paintAlignment(false, false);
927 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
928 ap.av.sendSelection();
938 * do a single sequence copy to jalview and the system clipboard
941 * sequence to be copied to clipboard
943 protected void copy_annotseqtoclipboard(SequenceI sq)
945 SequenceI[] seqs = new SequenceI[] { sq };
946 String[] omitHidden = null;
947 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
948 if (dseqs[0] == null)
950 dseqs[0] = new Sequence(sq);
951 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
952 sq.getSequenceAsString()));
954 sq.setDatasetSequence(dseqs[0]);
956 Alignment ds = new Alignment(dseqs);
957 if (av.hasHiddenColumns())
959 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
960 .getVisContigsIterator(0, sq.getLength(), false);
961 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
964 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
965 if (av.hasHiddenColumns())
967 alignmentStartEnd = av.getAlignment().getHiddenColumns()
968 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
971 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
972 seqs, omitHidden, alignmentStartEnd);
974 Toolkit.getDefaultToolkit().getSystemClipboard()
975 .setContents(new StringSelection(output), Desktop.instance);
977 HiddenColumns hiddenColumns = null;
979 if (av.hasHiddenColumns())
981 hiddenColumns = new HiddenColumns(
982 av.getAlignment().getHiddenColumns());
985 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
987 // sequence ? need to
989 // sequence as special.
1000 public void paintComponent(Graphics g)
1003 int width = getWidth();
1006 width = ap.calculateIdWidth().width + 4;
1009 Graphics2D g2 = (Graphics2D) g;
1012 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1013 RenderingHints.VALUE_ANTIALIAS_ON);
1016 drawComponent(g2, true, width);
1021 * Draw the full set of annotation Labels for the alignment at the given
1025 * Graphics2D instance (needed for font scaling)
1027 * Width for scaling labels
1030 public void drawComponent(Graphics g, int width)
1032 drawComponent(g, false, width);
1036 * Draw the full set of annotation Labels for the alignment at the given
1040 * Graphics2D instance (needed for font scaling)
1042 * - true indicates that only current visible area needs to be
1045 * Width for scaling labels
1047 public void drawComponent(Graphics g, boolean clip, int width)
1049 if (av.getFont().getSize() < 10)
1055 g.setFont(av.getFont());
1058 FontMetrics fm = g.getFontMetrics(g.getFont());
1059 g.setColor(Color.white);
1060 g.fillRect(0, 0, getWidth(), getHeight());
1062 g.translate(0, getScrollOffset());
1063 g.setColor(Color.black);
1065 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1066 int fontHeight = g.getFont().getSize();
1069 int graphExtras = 0;
1071 Font baseFont = g.getFont();
1072 FontMetrics baseMetrics = fm;
1073 int ofontH = fontHeight;
1076 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1077 ? ap.getAnnotationPanel().getVisibleVRange()
1079 if (clip && visr != null)
1082 visHeight = visr[1];
1084 boolean visible = true, before = false, after = false;
1087 hasHiddenRows = false;
1089 for (int i = 0; i < aa.length; i++)
1094 hasHiddenRows = true;
1107 System.out.println("before vis: " + i);
1111 // don't draw what isn't visible
1114 if (olY > visHeight)
1122 "Scroll offset: " + sOffset + " after vis: " + i);
1126 // don't draw what isn't visible
1130 g.setColor(Color.black);
1132 offset = -aa[i].height / 2;
1136 offset += fm.getHeight() / 2;
1137 offset -= fm.getDescent();
1141 offset += fm.getDescent();
1144 x = width - fm.stringWidth(aa[i].label) - 3;
1146 if (aa[i].graphGroup > -1)
1149 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1150 // computed efficiently for all visible labels
1151 for (int gg = 0; gg < aa.length; gg++)
1153 if (aa[gg].graphGroup == aa[i].graphGroup)
1158 if (groupSize * (fontHeight + 8) < aa[i].height)
1160 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1165 // scale font to fit
1166 float h = aa[i].height / (float) groupSize, s;
1173 fontHeight = -8 + (int) h;
1174 s = ((float) fontHeight) / (float) ofontH;
1176 .deriveFont(AffineTransform.getScaleInstance(s, s));
1178 fm = g.getFontMetrics();
1179 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1185 for (int gg = 0; gg < aa.length; gg++)
1187 if (aa[gg].graphGroup == aa[i].graphGroup)
1189 x = width - fm.stringWidth(aa[gg].label) - 3;
1190 g.drawString(aa[gg].label, x, y - graphExtras);
1192 if (aa[gg]._linecolour != null)
1195 g.setColor(aa[gg]._linecolour);
1196 g.drawLine(x, y - graphExtras + 3,
1197 x + fm.stringWidth(aa[gg].label),
1198 y - graphExtras + 3);
1201 g.setColor(Color.black);
1202 graphExtras += fontHeight + 8;
1206 g.setFont(baseFont);
1208 fontHeight = ofontH;
1212 g.drawString(aa[i].label, x, y + offset);
1217 if (!resizePanel && dragEvent != null && aa != null)
1219 g.setColor(Color.lightGray);
1220 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1221 dragEvent.getY() - getScrollOffset());
1224 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1226 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1227 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1232 public int getScrollOffset()
1234 return scrollOffset;
1238 public void mouseEntered(MouseEvent e)